Guest User

Untitled

a guest
Feb 25th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. #include "argcv/c/sys/signal.h"
  2.  
  3. #include <sys/types.h> // pid_t
  4.  
  5. #include <stdio.h> // printf
  6.  
  7. #include <signal.h> // signal
  8. #include <sys/wait.h> // wait
  9.  
  10. sigfunc* _signal(int signo, sigfunc* func) {
  11. struct sigaction act; // bits/sigaction.h
  12. struct sigaction oact;
  13. printf("signal called ...\n");
  14.  
  15. act.sa_handler = func;
  16. sigemptyset(&act.sa_mask); // signal.h
  17. act.sa_flags = 0;
  18.  
  19. if (signo == SIGALRM) {
  20. #ifdef SA_INTERRUPT
  21. act.sa_flags |= SA_INTERRUPT; // SunOS 4.x
  22. #endif // SA_INTERRUPT
  23. } else {
  24. #ifdef SA_RESTART
  25. act.sa_flags |= SA_RESTART; // SVR4, 4.4BSD
  26. #endif // SA_RESTART
  27. }
  28. if (sigaction(signo, &act, &oact) < 0) return SIG_ERR;
  29. return oact.sa_handler;
  30. }
  31.  
  32. /**
  33. *
  34. */
  35. void sig_chld(int signo) {
  36. pid_t pid;
  37. int stat;
  38. while ((pid = waitpid(-1, &stat, WNOHANG)) > 0) {
  39. // #ifdef __DEBUG__
  40. // if (daemon_proc) {
  41. // syslog(LOG_DEBUG, "child %d terminated \n", pid);
  42. // } else {
  43. // fprintf(stdout, "child %d terminated \n", pid);
  44. // }
  45. // #endif // __DEBUG__
  46. }
  47. return;
  48. }
Add Comment
Please, Sign In to add comment