tst-exec4.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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, see
  15. <http://www.gnu.org/licenses/>. */
  16. #include <pthread.h>
  17. #include <signal.h>
  18. #include <stdio.h>
  19. #include <stdlib.h>
  20. #include <unistd.h>
  21. static void *
  22. tf (void *arg)
  23. {
  24. /* Ignore SIGUSR1 and block SIGUSR2. */
  25. if (sigignore (SIGUSR1) != 0)
  26. {
  27. puts ("sigignore failed");
  28. exit (1);
  29. }
  30. sigset_t ss;
  31. sigemptyset (&ss);
  32. sigaddset (&ss, SIGUSR2);
  33. if (pthread_sigmask (SIG_BLOCK, &ss, NULL) != 0)
  34. {
  35. puts ("1st run: sigmask failed");
  36. exit (1);
  37. }
  38. char **oldargv = (char **) arg;
  39. size_t n = 1;
  40. while (oldargv[n] != NULL)
  41. ++n;
  42. char **argv = (char **) alloca ((n + 1) * sizeof (char *));
  43. for (n = 0; oldargv[n + 1] != NULL; ++n)
  44. argv[n] = oldargv[n + 1];
  45. argv[n++] = (char *) "--direct";
  46. argv[n] = NULL;
  47. execv (argv[0], argv);
  48. puts ("execv failed");
  49. exit (1);
  50. }
  51. static int
  52. do_test (int argc, char *argv[])
  53. {
  54. if (argc == 1)
  55. {
  56. /* This is the second call. Perform the test. */
  57. struct sigaction sa;
  58. if (sigaction (SIGUSR1, NULL, &sa) != 0)
  59. {
  60. puts ("2nd run: sigaction failed");
  61. return 1;
  62. }
  63. if (sa.sa_handler != SIG_IGN)
  64. {
  65. puts ("SIGUSR1 not ignored");
  66. return 1;
  67. }
  68. sigset_t ss;
  69. if (pthread_sigmask (SIG_SETMASK, NULL, &ss) != 0)
  70. {
  71. puts ("2nd run: sigmask failed");
  72. return 1;
  73. }
  74. if (! sigismember (&ss, SIGUSR2))
  75. {
  76. puts ("SIGUSR2 not blocked");
  77. return 1;
  78. }
  79. return 0;
  80. }
  81. pthread_t th;
  82. if (pthread_create (&th, NULL, tf, argv) != 0)
  83. {
  84. puts ("create failed");
  85. exit (1);
  86. }
  87. /* This call should never return. */
  88. pthread_join (th, NULL);
  89. puts ("join returned");
  90. return 1;
  91. }
  92. #define TEST_FUNCTION do_test (argc, argv)
  93. #include "../test-skeleton.c"