subproc.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*
  2. * libdpkg - Debian packaging suite library routines
  3. * subproc.c - subprocess helper routines
  4. *
  5. * Copyright © 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 <compat.h>
  23. #include <dpkg-i18n.h>
  24. #include <errno.h>
  25. #include <stdio.h>
  26. #include <string.h>
  27. #include <signal.h>
  28. #include <dpkg.h>
  29. #include <dpkg-priv.h>
  30. static int catch_signals[] = { SIGQUIT, SIGINT };
  31. static struct sigaction uncatch_signals[sizeof_array(catch_signals)];
  32. void
  33. setup_subproc_signals(const char *name)
  34. {
  35. size_t i;
  36. struct sigaction catchsig;
  37. onerr_abort++;
  38. memset(&catchsig, 0, sizeof(catchsig));
  39. catchsig.sa_handler = SIG_IGN;
  40. sigemptyset(&catchsig.sa_mask);
  41. catchsig.sa_flags = 0;
  42. for (i = 0; i < sizeof_array(catch_signals); i++)
  43. if (sigaction(catch_signals[i], &catchsig, &uncatch_signals[i]))
  44. ohshite(_("unable to ignore signal %s before running %.250s"),
  45. strsignal(catch_signals[i]), name);
  46. push_cleanup(cu_subproc_signals, ~0, NULL, 0, 0);
  47. onerr_abort--;
  48. }
  49. void
  50. cu_subproc_signals(int argc, void **argv)
  51. {
  52. size_t i;
  53. for (i = 0; i < sizeof_array(catch_signals); i++) {
  54. if (sigaction(catch_signals[i], &uncatch_signals[i], NULL)) {
  55. fprintf(stderr, _("error un-catching signal %s: %s\n"),
  56. strsignal(catch_signals[i]), strerror(errno));
  57. onerr_abort++;
  58. }
  59. }
  60. }