init_shared.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /* vi: set sw=4 ts=4: */
  2. /*
  3. * Stuff shared between init, reboot, halt, and poweroff
  4. *
  5. * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
  6. *
  7. * Licensed under GPL version 2, see file LICENSE in this tarball for details.
  8. */
  9. #include "busybox.h"
  10. #include <sys/reboot.h>
  11. #include <sys/syslog.h>
  12. #include "init_shared.h"
  13. const char * const init_sending_format = "Sending SIG%s to all processes.";
  14. #ifndef CONFIG_INIT
  15. const char * const bb_shutdown_format = "\r%s\n";
  16. int bb_shutdown_system(unsigned long magic)
  17. {
  18. int pri = LOG_KERN|LOG_NOTICE|LOG_FACMASK;
  19. const char *message;
  20. /* Don't kill ourself */
  21. signal(SIGTERM,SIG_IGN);
  22. signal(SIGHUP,SIG_IGN);
  23. bb_setpgrp;
  24. /* Allow Ctrl-Alt-Del to reboot system. */
  25. #ifndef RB_ENABLE_CAD
  26. #define RB_ENABLE_CAD 0x89abcdef
  27. #endif
  28. reboot(RB_ENABLE_CAD);
  29. openlog(applet_name, 0, pri);
  30. message = "\nThe system is going down NOW !!";
  31. syslog(pri, "%s", message);
  32. printf(bb_shutdown_format, message);
  33. sync();
  34. /* Send signals to every process _except_ pid 1 */
  35. message = "TERM";
  36. syslog(pri, init_sending_format, message);
  37. printf(bb_shutdown_format, message);
  38. kill(-1, SIGTERM);
  39. sleep(1);
  40. sync();
  41. message = "KILL";
  42. syslog(pri, init_sending_format, message);
  43. printf(bb_shutdown_format, message);
  44. kill(-1, SIGKILL);
  45. sleep(1);
  46. sync();
  47. reboot(magic);
  48. return 0; /* Shrug */
  49. }
  50. #endif