subproc.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*
  2. * libdpkg - Debian packaging suite library routines
  3. * subproc.c - subprocess helper routines
  4. *
  5. * Copyright (C) 1995 Ian Jackson <ian@chiark.greenend.org.uk>
  6. *
  7. * This is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as
  9. * published by the Free Software Foundation; either version 2,
  10. * or (at your option) any later version.
  11. *
  12. * This is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public
  18. * License along with dpkg; if not, write to the Free Software
  19. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20. */
  21. #include <config.h>
  22. #include <errno.h>
  23. #include <stdio.h>
  24. #include <string.h>
  25. #include <signal.h>
  26. #include <dpkg.h>
  27. #include <dpkg-priv.h>
  28. #define NCATCHSIGNALS (int)(sizeof(catch_signals) / sizeof(int) - 1)
  29. static int catch_signals[] = { SIGQUIT, SIGINT, 0 };
  30. static struct sigaction uncatch_signals[NCATCHSIGNALS];
  31. void
  32. setup_subproc_signals(const char *name)
  33. {
  34. int i;
  35. struct sigaction catchsig;
  36. onerr_abort++;
  37. memset(&catchsig, 0, sizeof(catchsig));
  38. catchsig.sa_handler = SIG_IGN;
  39. sigemptyset(&catchsig.sa_mask);
  40. catchsig.sa_flags = 0;
  41. for (i = 0; i < NCATCHSIGNALS; i++)
  42. if (sigaction(catch_signals[i], &catchsig, &uncatch_signals[i]))
  43. ohshite(_("unable to ignore signal %s before running %.250s"),
  44. strsignal(catch_signals[i]), name);
  45. push_cleanup(cu_subproc_signals, ~0, NULL, 0, 0);
  46. onerr_abort--;
  47. }
  48. void
  49. cu_subproc_signals(int argc, void **argv)
  50. {
  51. int i;
  52. for (i = 0; i < NCATCHSIGNALS; i++) {
  53. if (sigaction(catch_signals[i], &uncatch_signals[i], NULL)) {
  54. fprintf(stderr, _("error un-catching signal %s: %s\n"),
  55. strsignal(catch_signals[i]), strerror(errno));
  56. onerr_abort++;
  57. }
  58. }
  59. }