tst-exec4.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /* Signal handler and mask set in thread which calls exec.
  2. Copyright (C) 2003 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. Contributed by Ulrich Drepper <drepper@redhat.com>, 2003.
  5. The GNU C Library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Lesser General Public
  7. License as published by the Free Software Foundation; either
  8. version 2.1 of the License, or (at your option) any later version.
  9. The GNU C Library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. Lesser General Public License for more details.
  13. You should have received a copy of the GNU Lesser General Public
  14. License along with the GNU C Library; if not, write to the Free
  15. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  16. 02111-1307 USA. */
  17. #include <pthread.h>
  18. #include <signal.h>
  19. #include <stdio.h>
  20. #include <stdlib.h>
  21. #include <unistd.h>
  22. static void *
  23. tf (void *arg)
  24. {
  25. /* Ignore SIGUSR1 and block SIGUSR2. */
  26. if (sigignore (SIGUSR1) != 0)
  27. {
  28. puts ("sigignore failed");
  29. exit (1);
  30. }
  31. sigset_t ss;
  32. sigemptyset (&ss);
  33. sigaddset (&ss, SIGUSR2);
  34. if (pthread_sigmask (SIG_BLOCK, &ss, NULL) != 0)
  35. {
  36. puts ("1st run: sigmask failed");
  37. exit (1);
  38. }
  39. char **oldargv = (char **) arg;
  40. size_t n = 1;
  41. while (oldargv[n] != NULL)
  42. ++n;
  43. char **argv = (char **) alloca ((n + 1) * sizeof (char *));
  44. for (n = 0; oldargv[n + 1] != NULL; ++n)
  45. argv[n] = oldargv[n + 1];
  46. argv[n++] = (char *) "--direct";
  47. argv[n] = NULL;
  48. execv (argv[0], argv);
  49. puts ("execv failed");
  50. exit (1);
  51. }
  52. static int
  53. do_test (int argc, char *argv[])
  54. {
  55. if (argc == 1)
  56. {
  57. /* This is the second call. Perform the test. */
  58. struct sigaction sa;
  59. if (sigaction (SIGUSR1, NULL, &sa) != 0)
  60. {
  61. puts ("2nd run: sigaction failed");
  62. return 1;
  63. }
  64. if (sa.sa_handler != SIG_IGN)
  65. {
  66. puts ("SIGUSR1 not ignored");
  67. return 1;
  68. }
  69. sigset_t ss;
  70. if (pthread_sigmask (SIG_SETMASK, NULL, &ss) != 0)
  71. {
  72. puts ("2nd run: sigmask failed");
  73. return 1;
  74. }
  75. if (! sigismember (&ss, SIGUSR2))
  76. {
  77. puts ("SIGUSR2 not blocked");
  78. return 1;
  79. }
  80. return 0;
  81. }
  82. pthread_t th;
  83. if (pthread_create (&th, NULL, tf, argv) != 0)
  84. {
  85. puts ("create failed");
  86. exit (1);
  87. }
  88. /* This call should never return. */
  89. pthread_join (th, NULL);
  90. puts ("join returned");
  91. return 1;
  92. }
  93. #define TEST_FUNCTION do_test (argc, argv)
  94. #include "../test-skeleton.c"