signals.cpp 902 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /* (C) C.D.F. Miller, Heriot-Watt University, March 1984
  2. *
  3. * Permission is hereby given to reproduce or modify this
  4. * software freely, provided that this notice be retained,
  5. * and that no use be made of the software for commercial
  6. * purposes without the express written permission of the
  7. * author.
  8. */
  9. #include <lbl.h>
  10. #include <signal.h>
  11. #include <unistd.h>
  12. #include "signals.h"
  13. typedef void (*sig_t) (int);
  14. extern char tempname[];
  15. static void onsignal(int unused) __attribute__((noreturn));
  16. static void
  17. onsignal(int unused)
  18. {
  19. (void)unused;
  20. unlink(tempname);
  21. _exit(2);
  22. }
  23. void
  24. setsignals()
  25. {
  26. if (signal(SIGINT, onsignal) == SIG_IGN)
  27. signal(SIGINT, SIG_IGN);
  28. if (signal(SIGQUIT, onsignal) == SIG_IGN)
  29. signal(SIGQUIT, SIG_IGN);
  30. if (signal(SIGHUP, onsignal) == SIG_IGN)
  31. signal(SIGHUP, SIG_IGN);
  32. if (signal(SIGTERM, onsignal) == SIG_IGN)
  33. signal(SIGTERM, SIG_IGN);
  34. }