Back to index

glibc  2.9
tst-signal5.c
Go to the documentation of this file.
00001 /* Copyright (C) 2003 Free Software Foundation, Inc.
00002    This file is part of the GNU C Library.
00003    Contributed by Ulrich Drepper <drepper@redhat.com>, 2003.
00004 
00005    The GNU C Library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Lesser General Public
00007    License as published by the Free Software Foundation; either
00008    version 2.1 of the License, or (at your option) any later version.
00009 
00010    The GNU C Library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Lesser General Public License for more details.
00014 
00015    You should have received a copy of the GNU Lesser General Public
00016    License along with the GNU C Library; if not, write to the Free
00017    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00018    02111-1307 USA.  */
00019 
00020 #include <errno.h>
00021 #include <pthread.h>
00022 #include <signal.h>
00023 #include <stdio.h>
00024 #include <stdlib.h>
00025 #include <string.h>
00026 #include <unistd.h>
00027 #include <sys/mman.h>
00028 #include <sys/wait.h>
00029 
00030 
00031 static sigset_t ss;
00032 
00033 
00034 static void *
00035 tf (void *arg)
00036 {
00037   sigset_t ss2;
00038   if (pthread_sigmask (SIG_SETMASK, NULL, &ss2) != 0)
00039     {
00040       puts ("child: sigmask failed");
00041       exit (1);
00042     }
00043 
00044   int i;
00045   for (i = 1; i < 32; ++i)
00046     if (sigismember (&ss, i) && ! sigismember (&ss2, i))
00047       {
00048        printf ("signal %d set in parent mask, but not in child\n", i);
00049        exit (1);
00050       }
00051     else if (! sigismember (&ss, i) && sigismember (&ss2, i))
00052       {
00053        printf ("signal %d set in child mask, but not in parent\n", i);
00054        exit (1);
00055       }
00056 
00057   return NULL;
00058 }
00059 
00060 
00061 static int
00062 do_test (void)
00063 {
00064   sigemptyset (&ss);
00065   sigaddset (&ss, SIGUSR1);
00066   if (pthread_sigmask (SIG_SETMASK, &ss, NULL) != 0)
00067     {
00068       puts ("1st sigmask failed");
00069       exit (1);
00070     }
00071 
00072   pthread_t th;
00073   if (pthread_create (&th, NULL, tf, NULL) != 0)
00074     {
00075       puts ("1st create failed");
00076       exit (1);
00077     }
00078 
00079   void *r;
00080   if (pthread_join (th, &r) != 0)
00081     {
00082       puts ("1st join failed");
00083       exit (1);
00084     }
00085 
00086   sigemptyset (&ss);
00087   sigaddset (&ss, SIGUSR2);
00088   sigaddset (&ss, SIGFPE);
00089   if (pthread_sigmask (SIG_SETMASK, &ss, NULL) != 0)
00090     {
00091       puts ("2nd sigmask failed");
00092       exit (1);
00093     }
00094 
00095   if (pthread_create (&th, NULL, tf, NULL) != 0)
00096     {
00097       puts ("2nd create failed");
00098       exit (1);
00099     }
00100 
00101   if (pthread_join (th, &r) != 0)
00102     {
00103       puts ("2nd join failed");
00104       exit (1);
00105     }
00106 
00107   return 0;
00108 }
00109 
00110 #define TEST_FUNCTION do_test ()
00111 #include "../test-skeleton.c"