php_signal.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*
  2. +----------------------------------------------------------------------+
  3. | Copyright (c) The PHP Group |
  4. +----------------------------------------------------------------------+
  5. | This source file is subject to version 3.01 of the PHP license, |
  6. | that is bundled with this package in the file LICENSE, and is |
  7. | available through the world-wide-web at the following url: |
  8. | https://www.php.net/license/3_01.txt |
  9. | If you did not receive a copy of the PHP license and are unable to |
  10. | obtain it through the world-wide-web, please send a note to |
  11. | license@php.net so we can mail you a copy immediately. |
  12. +----------------------------------------------------------------------+
  13. | Author: Jason Greene <jason@inetgurus.net> |
  14. +----------------------------------------------------------------------+
  15. */
  16. #include "TSRM.h"
  17. #include "php_signal.h"
  18. #include "Zend/zend.h"
  19. #include "Zend/zend_signal.h"
  20. /* php_signal using sigaction is derived from Advanced Programming
  21. * in the Unix Environment by W. Richard Stevens p 298. */
  22. Sigfunc *php_signal4(int signo, Sigfunc *func, int restart, int mask_all)
  23. {
  24. struct sigaction act,oact;
  25. #ifdef HAVE_STRUCT_SIGINFO_T
  26. act.sa_sigaction = func;
  27. #else
  28. act.sa_handler = func;
  29. #endif
  30. if (mask_all) {
  31. sigfillset(&act.sa_mask);
  32. } else {
  33. sigemptyset(&act.sa_mask);
  34. }
  35. act.sa_flags = 0;
  36. #ifdef HAVE_STRUCT_SIGINFO_T
  37. act.sa_flags |= SA_SIGINFO;
  38. #endif
  39. if (!restart) {
  40. #ifdef SA_INTERRUPT
  41. act.sa_flags |= SA_INTERRUPT; /* SunOS */
  42. #endif
  43. } else {
  44. #ifdef SA_RESTART
  45. act.sa_flags |= SA_RESTART; /* SVR4, 4.3+BSD */
  46. #endif
  47. }
  48. zend_sigaction(signo, &act, &oact);
  49. #ifdef HAVE_STRUCT_SIGINFO_T
  50. return oact.sa_sigaction;
  51. #else
  52. return oact.sa_handler;
  53. #endif
  54. }
  55. Sigfunc *php_signal(int signo, Sigfunc *func, int restart)
  56. {
  57. return php_signal4(signo, func, restart, 0);
  58. }