OpenSDE Packages Database (without history before r20070)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

103 lines
3.1 KiB

  1. # --- SDE-COPYRIGHT-NOTE-BEGIN ---
  2. # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
  3. #
  4. # Filename: package/.../tcp_wrappers/0015-tcp_wrappers-7.6-catch-sigchld.patch
  5. # Copyright (C) 2011 The OpenSDE Project
  6. #
  7. # More information can be found in the files COPYING and README.
  8. #
  9. # This patch file is dual-licensed. It is available under the license the
  10. # patched project is licensed under, as long as it is an OpenSource license
  11. # as defined at http://www.opensource.org/ (e.g. BSD, X11) or under the terms
  12. # of the GNU General Public License as published by the Free Software
  13. # Foundation; either version 2 of the License, or (at your option) any later
  14. # version.
  15. # --- SDE-COPYRIGHT-NOTE-END ---
  16. --- tcp_wrappers_7.6/shell_cmd.c.sigchld 1994-12-28 17:42:44.000000000 +0100
  17. +++ tcp_wrappers_7.6/shell_cmd.c 2007-06-28 15:42:17.000000000 +0200
  18. @@ -20,6 +20,11 @@
  19. #include <stdio.h>
  20. #include <syslog.h>
  21. #include <string.h>
  22. +#include <errno.h>
  23. +#include <unistd.h>
  24. +#include <sys/wait.h>
  25. +#include <sys/stat.h>
  26. +#include <fcntl.h>
  27. extern void exit();
  28. @@ -31,13 +36,42 @@
  29. static void do_child();
  30. +/*
  31. + * The sigchld handler. If there is a SIGCHLD caused by a child other than
  32. + * ours, we set a flag and raise the signal later.
  33. + */
  34. +volatile static int foreign_sigchld;
  35. +volatile static int our_child_pid;
  36. +static void sigchld(int sig, siginfo_t *si, void *unused)
  37. +{
  38. + if (si && si->si_pid != our_child_pid)
  39. + foreign_sigchld = 1;
  40. +}
  41. +
  42. /* shell_cmd - execute shell command */
  43. void shell_cmd(command)
  44. char *command;
  45. {
  46. int child_pid;
  47. - int wait_pid;
  48. +
  49. + struct sigaction new_action, old_action;
  50. + sigset_t new_mask, old_mask, empty_mask;
  51. +
  52. + new_action.sa_sigaction = &sigchld;
  53. + new_action.sa_flags = SA_SIGINFO;
  54. + sigemptyset(&new_action.sa_mask);
  55. + sigemptyset(&new_mask);
  56. + sigemptyset(&empty_mask);
  57. + sigaddset(&new_mask, SIGCHLD);
  58. +
  59. + /*
  60. + * Set the variables for handler, set the handler and block the signal
  61. + * until we have the pid.
  62. + */
  63. + foreign_sigchld = 0; our_child_pid = 0;
  64. + sigprocmask(SIG_BLOCK, &new_mask, &old_mask);
  65. + sigaction(SIGCHLD, &new_action, &old_action);
  66. /*
  67. * Most of the work is done within the child process, to minimize the
  68. @@ -49,12 +83,26 @@
  69. tcpd_warn("cannot fork: %m");
  70. break;
  71. case 00: /* child */
  72. + /* Clear the blocked mask for the child not to be surprised. */
  73. + sigprocmask(SIG_SETMASK, &empty_mask, 0);
  74. do_child(command);
  75. /* NOTREACHED */
  76. default: /* parent */
  77. - while ((wait_pid = wait((int *) 0)) != -1 && wait_pid != child_pid)
  78. - /* void */ ;
  79. + our_child_pid = child_pid;
  80. + sigprocmask(SIG_UNBLOCK, &new_mask, 0);
  81. + while (waitpid(child_pid, (int *) 0, 0) == -1 && errno == EINTR);
  82. }
  83. +
  84. + /*
  85. + * Revert the signal mask and the SIGCHLD handler.
  86. + */
  87. + sigprocmask(SIG_SETMASK, &old_mask, 0);
  88. + sigaction(SIGCHLD, &old_action, 0);
  89. +
  90. + /* If there was a foreign SIGCHLD, raise it after we have restored the old
  91. + * mask and handler. */
  92. + if (foreign_sigchld)
  93. + raise(SIGCHLD);
  94. }
  95. /* do_child - exec command with { stdin, stdout, stderr } to /dev/null */