mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Michael Kerrisk" <mtk.manpages@googlemail.com>
To: "Thomas Gleixner" <tglx@linutronix.de>
Cc: LKML <linux-kernel@vger.kernel.org>,
	"Ingo Molnar" <mingo@elte.hu>,
	"Ulrich Drepper" <drepper@redhat.com>,
	"Roland McGrath" <roland@redhat.com>,
	"Oleg Nesterov" <oleg@tv-sign.ru>
Subject: Re: [RFC patch 0/3] signals: add rt_tgsigqueueinfo syscall
Date: Tue, 7 Oct 2008 15:49:00 +0200	[thread overview]
Message-ID: <cfd18e0f0810070649l391978f9v345a5591728bbf41@mail.gmail.com> (raw)
In-Reply-To: <20080930194445.978351700@linutronix.de>

Thomas,

On Tue, Sep 30, 2008 at 9:48 PM, Thomas Gleixner <tglx@linutronix.de> wrote:
> sys_kill has a counterpart sys_tgkill which allows to send signals to
> a particular thread. sys_rt_sigqueueinfo is lacking such a counterpart.
>
> Aside of the asymetry it is a show stopper for migrating applications
> from other unix-alike RTOSes.
>
> The following patch series implements rt_tgsigqueueinfo and hooks it
> up for x86.

I'm not sure if I've run across a bug or (maybe more likely) have a
bug in my test code.  Could you take a look at the test programs
below.

When I use t_rt_tgsigqueueinfo.c to send a signal to my receiving
program it crashes because the siginfo_t argument to the signal
handler has a bad value (0x33); it's not obvious to me how it should
get to have that value (have I misconstructed something in the
t_rt_tgsigqueuinfo.c program?).

Cheers,

Michael

==========

$ ./multithread_sig_receiver 44 x
Established handler for signal 44
Main: TGID = 6105; TID = 6105
Thread 1: PID = 6105; TID = 6106; arg = x
Thread 1: about to pause
                                                              $
./t_rt_tgsigqueuinfo 6105 6106 44 1
PID = 6105; TID = 6106; caught signal 44:
0x33
Segmentation fault (core dumped)

=========

/*#* t_rt_tgsigqueueinfo.c

   Copyright 2008, Linux Foundation;
   written by Michael Kerrisk <mtk.manpages@gmail.com>
*/
#define _GNU_SOURCE
#include <unistd.h>
#include <sys/syscall.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <signal.h>
#include <sys/types.h>

#define errExit(msg)    do { perror(msg); exit(EXIT_FAILURE); \
                        } while (0)

#if defined(__i386__)
#define SYS_rt_tgsigqueueinfo 333
#endif

static int
rt_tgsigqueueinfo(pid_t tgid, pid_t tid, int sig, siginfo_t *si)
{
    return syscall(SYS_rt_tgsigqueueinfo, tgid, tid, sig, si);
}


int
main(int argc, char *argv[])
{
    pid_t tgid, tid;
    siginfo_t si;
    int sig, val;

    if (argc < 5) {
        fprintf(stderr, "Usage: %s <tgid> <tid> <sig> <val>\n", argv[0]);
        exit(EXIT_SUCCESS);
    }

    printf("My PID is %ld\n", (long) getpid());

    tgid = atoi(argv[1]);
    tid = atoi(argv[2]);
    sig = atoi(argv[3]);
    val = atoi(argv[4]);

    si.si_signo = sig;
    si.si_code = SI_QUEUE;
    si.si_pid = getpid();
    si.si_uid = getuid();
    si.si_value.sival_int = val;

    if (rt_tgsigqueueinfo(tgid, tid, sig, &si) == -1)
        errExit("rt_tgsigqueueinfo");

    exit(EXIT_SUCCESS);
} /* main */

=====================

/*#* multithread_sig_receiver.c

   Copyright 2008, Linux Foundation;
   written by Michael Kerrisk <mtk.manpages@gmail.com>
*/
#define _GNU_SOURCE
#include <sys/syscall.h>
#include <ctype.h>
#include <unistd.h>
#include <signal.h>
#include <pthread.h>
#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>

#define errExit(msg)    do { perror(msg); exit(EXIT_FAILURE); \
                        } while (0)

#define errExitEN(en, msg) \
                        do { errno = en; perror(msg); \
                             exit(EXIT_FAILURE); } while (0)

static int test_sig;

struct thread_arg {
    int   thread_num;
    char *argv_string;
};

static pid_t
gettid(void)
{
    return syscall(SYS_gettid);
}

static void
handler(int sig, siginfo_t *si, void *uc)
{
    printf("PID = %ld; TID = %ld; caught signal %d: \n",
            (long) getpid(), (long) gettid(), sig);
    printf("%p\n", si);
    printf("si_signo=%d ", si->si_signo);
    printf("si_code=%d ", si->si_code);
    printf("si_pid=%ld ", (long) si->si_pid);
    printf("si_uid=%ld ", (long) si->si_uid);
    printf("si_value.sival_int=%d\n", si->si_value.sival_int);
}

static void *
threadFunc(void *arg)
{
    struct thread_arg *ta = (struct thread_arg *) arg;
    sigset_t new;
    int s;

    printf("Thread %d: PID = %ld; TID = %ld; arg = %s\n", ta->thread_num,
            (long) getpid(), (long) gettid(), ta->argv_string);

    if (ta->argv_string[0] == 'b') {
        printf("Thread %d: blocking signal\n", ta->thread_num);
        sigemptyset(&new);
        sigaddset(&new, test_sig);
        s = pthread_sigmask(SIG_SETMASK, &new, NULL);
        if (s != 0)
            errExit("pthread_sigmask");
    }

    if (isdigit(ta->argv_string[1])) {
        sleep(atoi(&ta->argv_string[1]));
        printf("Thread %d: unblocking signal\n", ta->thread_num);
        sigemptyset(&new);
        s = pthread_sigmask(SIG_SETMASK, &new, NULL);
        if (s != 0)
            errExit("pthread_sigmask");
    }

    printf("Thread %d: about to pause\n", ta->thread_num);

    for (;;)
        pause();
} /* threadFunc */


#define MAX_ARGS 1000

int
main(int argc, char *argv[])
{
    pthread_t t;
    int s, j;
    struct sigaction sa;
    struct thread_arg ta[MAX_ARGS];
    sigset_t new;

    if (argc < 3) {
        fprintf(stderr, "Usage: %s <sig> <thread-config>...\n", argv[0]);
        exit(EXIT_SUCCESS);
    }

    if (argc > MAX_ARGS) {
        fprintf(stderr, "Too many arguments\n");
        exit(EXIT_SUCCESS);
    }

    test_sig = atoi(argv[1]);

    sigemptyset(&new);
    if (sigprocmask(SIG_SETMASK, &new, NULL) == -1)
        errExit("sigprocmask");

    sa.sa_flags = 0;
    sa.sa_sigaction = handler;
    sigemptyset(&sa.sa_mask);
    if (sigaction(test_sig, &sa, NULL) == -1)
        errExit("sigaction");
    printf("Established handler for signal %d\n", test_sig);

    printf("Main: TGID = %ld; TID = %ld\n",
            (long) getpid(), (long) gettid());

    for (j = 0; j + 2 < argc; j++) {
        ta[j].thread_num = j + 1;
        ta[j].argv_string = argv[j + 2];

        s = pthread_create(&t, NULL, threadFunc, &ta[j]);
        if (s != 0)
            errExitEN(s, "pthread_create");
    }

    pause();
} /* main */

  parent reply	other threads:[~2008-10-07 13:49 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-09-30 19:48 Thomas Gleixner
2008-09-30 19:48 ` [RFC patch 1/3] signals: split do_tkill Thomas Gleixner
2008-09-30 19:49 ` [RFC patch 2/3] signals: implement sys_rt_tgsigqueueinfo Thomas Gleixner
2008-09-30 19:49 ` [RFC patch 3/3] x86: hookup sys_rt_tgsigqueueinfo Thomas Gleixner
2008-10-01  6:39 ` [RFC patch 0/3] signals: add rt_tgsigqueueinfo syscall Roland McGrath
2008-10-01  7:51   ` Thomas Gleixner
2008-10-07 13:49 ` Michael Kerrisk [this message]
2008-10-07 20:21   ` Roland McGrath
2008-10-08  2:50     ` Michael Kerrisk

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=cfd18e0f0810070649l391978f9v345a5591728bbf41@mail.gmail.com \
    --to=mtk.manpages@googlemail.com \
    --cc=drepper@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=mtk.manpages@gmail.com \
    --cc=oleg@tv-sign.ru \
    --cc=roland@redhat.com \
    --cc=tglx@linutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®