Back to index

glibc  2.9
tst-signal.c
Go to the documentation of this file.
00001 /* Test sigaction wrapper.  */
00002 /* Copyright (C) 2002 Free Software Foundation, Inc.
00003    This file is part of the GNU C Library.
00004    Contributed by Andreas Schwab <schwab@suse.de>.
00005 
00006    The GNU C Library is free software; you can redistribute it and/or
00007    modify it under the terms of the GNU Lesser General Public
00008    License as published by the Free Software Foundation; either
00009    version 2.1 of the License, or (at your option) any later version.
00010 
00011    The GNU C Library is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014    Lesser General Public License for more details.
00015 
00016    You should have received a copy of the GNU Lesser General Public
00017    License along with the GNU C Library; if not, write to the Free
00018    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00019    02111-1307 USA.  */
00020 
00021 #include <stdio.h>
00022 #include <stdlib.h>
00023 #include <signal.h>
00024 
00025 int
00026 main (int argc, char *argv[])
00027 {
00028   struct sigaction old_sa, new_sa;
00029 
00030   if (sigaction (SIGHUP, NULL, &old_sa) < 0)
00031     {
00032       printf ("cannot get signal action for SIGHUP: %m\n");
00033       exit (1);
00034     }
00035 
00036   if (old_sa.sa_handler != SIG_IGN)
00037     {
00038       printf ("SIGHUP action should be SIG_IGN, is %p\n",
00039              (void *) old_sa.sa_handler);
00040       exit (1);
00041     }
00042 
00043   new_sa.sa_handler = SIG_DFL;
00044   if (sigaction (SIGHUP, &new_sa, NULL) < 0)
00045     {
00046       printf ("cannot set signal action for SIGHUP: %m\n");
00047       exit (1);
00048     }
00049 
00050   if (sigaction (SIGHUP, NULL, &old_sa) < 0)
00051     {
00052       printf ("cannot get signal action for SIGHUP: %m\n");
00053       exit (1);
00054     }
00055 
00056   if (old_sa.sa_handler != SIG_DFL)
00057     {
00058       printf ("SIGHUP action should be SIG_DFL, is %p\n",
00059              (void *) old_sa.sa_handler);
00060       exit (1);
00061     }
00062 
00063   return 0;
00064 }