Back to index

glibc  2.9
Defines | Functions
tst-sigset2.c File Reference
#include <errno.h>
#include <error.h>
#include <inttypes.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>

Go to the source code of this file.

Defines

#define TEST_SIG   SIGINT

Functions

static void printSigMask (const char *msg)
static void handler (int sig)
static void printDisposition (sighandler_t disp)
static int returnTest1 (void)
static int returnTest2 (void)
static int returnTest3 (void)
int main (int argc, char *argv[])

Define Documentation

#define TEST_SIG   SIGINT

Definition at line 13 of file tst-sigset2.c.


Function Documentation

static void handler ( int  sig) [static]

Definition at line 45 of file tst-sigset2.c.

{
  printf ("Caught signal %d\n", sig);
  printSigMask ("Signal mask in handler\n");
  printf ("Handler returning\n");
  _exit (1);
} /* handler */

Here is the call graph for this function:

int main ( int  argc,
char *  argv[] 
)

Definition at line 145 of file tst-sigset2.c.

{
  pid_t childPid;

  childPid = fork();
  if (childPid == -1)
    error (1, errno, "fork");

  if (childPid == 0)
    exit (returnTest1 ());

  int status;
  if (TEMP_FAILURE_RETRY (waitpid (childPid, &status, 0)) != childPid)
    error (1, errno, "waitpid");
  int result = !WIFEXITED (status) || WEXITSTATUS (status) != 0;

  childPid = fork();
  if (childPid == -1)
    error (1, errno, "fork");

  if (childPid == 0)
    exit (returnTest2 ());

  if (TEMP_FAILURE_RETRY (waitpid (childPid, &status, 0)) != childPid)
    error (1, errno, "waitpid");
  result |= !WIFEXITED (status) || WEXITSTATUS (status) != 0;

  childPid = fork();
  if (childPid == -1)
    error (1, errno, "fork");

  if (childPid == 0)
    exit (returnTest3 ());

  if (TEMP_FAILURE_RETRY (waitpid (childPid, &status, 0)) != childPid)
    error (1, errno, "waitpid");
  result |= !WIFEXITED (status) || WEXITSTATUS (status) != 0;

  return result;
} /* main */

Here is the call graph for this function:

static void printDisposition ( sighandler_t  disp) [static]

Definition at line 54 of file tst-sigset2.c.

{
  if (disp == SIG_HOLD)
    printf ("SIG_HOLD");
  else if (disp == SIG_DFL)
    printf ("SIG_DFL");
  else if (disp == SIG_IGN)
    printf ("SIG_IGN");
  else
    printf ("handled at %" PRIxPTR, (uintptr_t) disp);
} /* printDisposition */

Here is the call graph for this function:

Here is the caller graph for this function:

static void printSigMask ( const char *  msg) [static]

Definition at line 18 of file tst-sigset2.c.

{
  sigset_t currMask;
  int sig;
  int cnt;

  if (msg != NULL)
    printf ("%s", msg);

  if (sigprocmask (SIG_BLOCK, NULL, &currMask) == -1)
    error (1, errno, "sigaction");

  cnt = 0;
  for (sig = 1; sig < NSIG; sig++)
    {
      if (sigismember (&currMask, sig))
       {
         cnt++;
         printf ("\t\t%d (%s)\n", sig, strsignal (sig));
        }
    }

  if (cnt == 0)
    printf ("\t\t<empty signal set>\n");
} /* printSigMask */

Here is the call graph for this function:

Here is the caller graph for this function:

static int returnTest1 ( void  ) [static]

Definition at line 67 of file tst-sigset2.c.

{
  sighandler_t prev;

  printf ("===== TEST 1 =====\n");
  printf ("Blocking signal with sighold()\n");
  if (sighold (TEST_SIG) == -1)
    error (1, errno, "sighold");
  printSigMask ("Signal mask after sighold()\n");

  printf ("About to use sigset() to establish handler\n");
  prev = sigset (TEST_SIG, handler);
  if (prev == SIG_ERR)
    error(1, errno, "sigset");

  printf ("Previous disposition: ");
  printDisposition (prev);
  printf (" (should be SIG_HOLD)\n");
  if (prev != SIG_HOLD)
    {
      printf("TEST FAILED!!!\n");
      return 1;
    }
  return 0;
} /* returnTest1 */

Here is the call graph for this function:

Here is the caller graph for this function:

static int returnTest2 ( void  ) [static]

Definition at line 94 of file tst-sigset2.c.

{
  sighandler_t prev;

  printf ("\n===== TEST 2 =====\n");

  printf ("About to use sigset() to set SIG_HOLD\n");
  prev = sigset (TEST_SIG, SIG_HOLD);
  if (prev == SIG_ERR)
    error (1, errno, "sigset");

  printf ("Previous disposition: ");
  printDisposition (prev);
  printf (" (should be SIG_DFL)\n");
  if (prev != SIG_DFL)
    {
      printf("TEST FAILED!!!\n");
      return 1;
    }
  return 0;
} /* returnTest2 */

Here is the call graph for this function:

Here is the caller graph for this function:

static int returnTest3 ( void  ) [static]

Definition at line 117 of file tst-sigset2.c.

{
  sighandler_t prev;

  printf ("\n===== TEST 3 =====\n");

  printf ("About to use sigset() to set SIG_HOLD\n");
  prev = sigset (TEST_SIG, SIG_HOLD);
  if (prev == SIG_ERR)
    error (1, errno, "sigset");

  printf ("About to use sigset() to set SIG_HOLD (again)\n");
  prev = sigset (TEST_SIG, SIG_HOLD);
  if (prev == SIG_ERR)
    error (1, errno, "sigset");

  printf ("Previous disposition: ");
  printDisposition (prev);
  printf (" (should be SIG_HOLD)\n");
  if (prev != SIG_HOLD)
    {
      printf("TEST FAILED!!!\n");
      return 1;
    }
  return 0;
} /* returnTest3 */

Here is the call graph for this function:

Here is the caller graph for this function: