subproc.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. static int catch_signals[] = { SIGQUIT, SIGINT };
  29. static struct sigaction uncatch_signals[sizeof_array(catch_signals)];
  30. void
  31. setup_subproc_signals(const char *name)
  32. {
  33. size_t i;
  34. struct sigaction catchsig;
  35. onerr_abort++;
  36. memset(&catchsig, 0, sizeof(catchsig));
  37. catchsig.sa_handler = SIG_IGN;
  38. sigemptyset(&catchsig.sa_mask);
  39. catchsig.sa_flags = 0;
  40. for (i = 0; i < sizeof_array(catch_signals); i++)
  41. if (sigaction(catch_signals[i], &catchsig, &uncatch_signals[i]))
  42. ohshite(_("unable to ignore signal %s before running %.250s"),
  43. strsignal(catch_signals[i]), name);
  44. push_cleanup(cu_subproc_signals, ~0, NULL, 0, 0);
  45. onerr_abort--;
  46. }
  47. void
  48. cu_subproc_signals(int argc, void **argv)
  49. {
  50. size_t i;
  51. for (i = 0; i < sizeof_array(catch_signals); i++) {
  52. if (sigaction(catch_signals[i], &uncatch_signals[i], NULL)) {
  53. fprintf(stderr, _("error un-catching signal %s: %s\n"),
  54. strsignal(catch_signals[i]), strerror(errno));
  55. onerr_abort++;
  56. }
  57. }
  58. }