linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* wrong pid in siginfo_t
@ 2003-07-04 21:05 Ulrich Drepper
  0 siblings, 0 replies; only message in thread
From: Ulrich Drepper @ 2003-07-04 21:05 UTC (permalink / raw)
  To: Linus Torvalds, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 1170 bytes --]

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

If a signal is sent via kill() or tkill() the kernel fills in the wrong
PID value in the siginfo_t structure (obviously only if the handler has
SA_SIGINFO set).  POSIX specifies the the si_pid field is filled with
the process ID.  The kernel currently fills in the thread ID.  The
thread IDs are not useful at all at userlevel.  They are not exposed
anywhere.

One might argue that sending up the ID of the thread as well is a good
thing but I don't agree.  This is what sigqueue is for: one can attach
arbitrary data to the signal and get it transmitted (the sigval_t
parameter).


I've attached a patch for the current 2.5 kernel and a test case.
Whoever collects kernel tests might want to add the program.

- --
- --------------.                        ,-.            444 Castro Street
Ulrich Drepper \    ,-----------------'   \ Mountain View, CA 94041 USA
Red Hat         `--' drepper at redhat.com `---------------------------
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)

iD8DBQE/BewL2ijCOnn/RHQRAtnYAKCmG6vX3YFo9ko8kjwzvNObxrklfACfVga3
43za5G4ljJwJD1SZEqrr+eU=
=lfde
-----END PGP SIGNATURE-----

[-- Attachment #2: d-kernel-signal --]
[-- Type: text/plain, Size: 619 bytes --]

--- kernel/signal.c-save	2003-06-03 10:14:55.000000000 -0700
+++ kernel/signal.c	2003-07-04 13:46:55.000000000 -0700
@@ -2081,7 +2081,7 @@ sys_kill(int pid, int sig)
 	info.si_signo = sig;
 	info.si_errno = 0;
 	info.si_code = SI_USER;
-	info.si_pid = current->pid;
+	info.si_pid = current->tgid;
 	info.si_uid = current->uid;
 
 	return kill_something_info(sig, &info, pid);
@@ -2104,7 +2104,7 @@ sys_tkill(int pid, int sig)
 	info.si_signo = sig;
 	info.si_errno = 0;
 	info.si_code = SI_TKILL;
-	info.si_pid = current->pid;
+	info.si_pid = current->tgid;
 	info.si_uid = current->uid;
 
 	read_lock(&tasklist_lock);

[-- Attachment #3: tst-sipid.c --]
[-- Type: text/plain, Size: 1488 bytes --]

#include <semaphore.h>
#include <signal.h>
#include <unistd.h>

static int failed;
static pid_t pid;
static uid_t uid;
static sem_t sem;
static int is_kill;

#define THESIG SIGRTMIN

static void
sh (int sig, siginfo_t *si, void *ctx)
{
  if (sig != si->si_signo)
    {
      printf ("sig != si->si_signo: %d vs %d\n", sig, (int) si->si_signo);
      failed = 1;
    }
  if (si->si_code != is_kill ? SI_USER : SI_QUEUE)
    {
      printf ("si->si_code wrong: %d\n", si->si_code);
      failed = 1;
    }
  if (si->si_pid != pid)
    {
      printf ("si->si_pid wrong: %d vs %d\n", (int) si->si_pid, (int) pid);
      failed = 1;
    }
  if (si->si_uid != uid)
    {
      printf ("si->si_uid wrong: %d vs %d\n", (int) si->si_uid, (int) uid);
      failed = 1;
    }
  sem_post (&sem);
}


static void *
tf (void *arg)
{
  puts ("trying kill");
  is_kill = 1;
  kill (pid, THESIG);
  sem_wait (&sem);

  puts ("trying sigqueue");
  sigval_t sv;
  sv.sival_int = 42;
  is_kill = 0;
  sigqueue (pid, THESIG, sv);
  sem_wait (&sem);
}


int
main (void)
{
  pid = getpid ();
  uid = getuid ();

  struct sigaction sa;
  sa.sa_sigaction = sh;
  sa.sa_flags = SA_SIGINFO;
  sigemptyset (&sa.sa_mask);
  sigaction (THESIG, &sa, NULL);

  sem_init (&sem, 0, 0);

  pthread_t th;
  puts ("starting 1st thread");
  pthread_create (&th, NULL, tf, NULL);
  pthread_join (th, NULL);
  puts ("starting 2nd thread");
  pthread_create (&th, NULL, tf, NULL);
  pthread_join (th, NULL);

  return failed;
}

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2003-07-04 20:51 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-07-04 21:05 wrong pid in siginfo_t Ulrich Drepper

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).