-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 One more overlooked area where the thread group ID has to be used. Compile and run the following code. The program should always exit with value zero, but currently it doesn't if a parameter is passed (i.e., if the semaphore is modified in a thread other than the main one). If somebody wants to add the code to a kernel test suite, feel free. The attached patch is against the current 2.5 tree. #define _GNU_SOURCE #include #include #include #include #include #include #include union semun { int val; }; static int sem; static void eh (void) { semctl (sem, 0, IPC_RMID); } static void second_process (void) { int val = semctl (sem, 0, GETPID); printf ("parent PID: %ld\nsem PID: %d\n", (long int) getppid (), val); exit (getppid () != val); } static void setval (void) { union semun su = { .val = 1 }; if (semctl (sem, 0, SETVAL, su) == -1) error (EXIT_FAILURE, errno, "semctl failed"); } static void * tf (void *arg) { setval (); return NULL; } int main (int argc, char *argv[]) { sem = semget (IPC_PRIVATE, 1, IPC_CREAT | IPC_EXCL | 0666); if (sem == -1) error (EXIT_FAILURE, errno, "semget failed"); atexit (eh); if (argc == 1) setval (); else { pthread_t th; int r = pthread_create (&th, NULL, tf, NULL); if (r != 0) error (EXIT_FAILURE, r, "pthread_create failed"); r = pthread_join (th, NULL); if (r != 0) error (EXIT_FAILURE, r, "pthread_join failed"); } pid_t pid = fork (); if (pid == -1) error (EXIT_FAILURE, errno, "fork failed"); if (pid == 0) second_process (); int status; if (TEMP_FAILURE_RETRY (waitpid (pid, &status, 0)) != pid) error (EXIT_FAILURE, errno, "waitpid failed"); if (!WIFEXITED (status)) error (EXIT_FAILURE, 0, "child process didn't exit normally"); return WEXITSTATUS (status); } - -- - --------------. ,-. 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/Tjqg2ijCOnn/RHQRAs4KAJ9HlFJo3pfh/nChsLvldaDpk02KKwCeLXMz kODgRkSVcOfNXs693xo1iK8= =krhV -----END PGP SIGNATURE-----