shutdown.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /* shutdown.c:
  2. *
  3. * Copyright (C) 1998 Kenneth Albanowski <kjahds@kjahds.com>,
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. */
  10. #include "sash.h"
  11. #include <stdio.h>
  12. #include <stdlib.h>
  13. #include <unistd.h>
  14. #include <string.h>
  15. #include <fcntl.h>
  16. #include <sys/types.h>
  17. #include <sys/stat.h>
  18. #include <dirent.h>
  19. #include <pwd.h>
  20. #include <grp.h>
  21. #include <time.h>
  22. #include <signal.h>
  23. #if __GNU_LIBRARY__ > 5
  24. #include <sys/reboot.h>
  25. #endif
  26. int
  27. main(argc, argv)
  28. int argc;
  29. char **argv;
  30. {
  31. char *progname = argv[0];
  32. if (argc > 2 && strcmp(argv[1], "-d") == 0) {
  33. sleep(atoi(argv[2]));
  34. argc -= 2;
  35. }
  36. if ((argc != 3) || (strcmp(argv[1], "-h") && strcmp(argv[1], "-r")) || strcmp(argv[2], "now")) {
  37. printf("Usage: %s [-d delay] -h|-r now\n", progname);
  38. exit(0);
  39. }
  40. kill(1, SIGTSTP);
  41. sync();
  42. signal(SIGTERM,SIG_IGN);
  43. setpgrp();
  44. kill(-1, SIGTERM);
  45. sleep(1);
  46. kill(-1, SIGHUP); /* Force PPPD's down, too */
  47. sleep(1);
  48. kill(-1, SIGKILL);
  49. sync();
  50. sleep(1);
  51. if (strcmp(argv[1], "-h")==0) {
  52. #if __GNU_LIBRARY__ > 5
  53. reboot(0xCDEF0123);
  54. #else
  55. reboot(0xfee1dead, 672274793, 0xCDEF0123);
  56. #endif
  57. } else {
  58. #if __GNU_LIBRARY__ > 5
  59. reboot(0x01234567);
  60. #else
  61. reboot(0xfee1dead, 672274793, 0x01234567);
  62. #endif
  63. }
  64. exit(0); /* Shrug */
  65. }