reboot.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. * JUN/99 -- copied from shutdown.c to make new reboot command.
  11. * (gerg@snapgear.com)
  12. * AUG/99 -- added delay option to reboot
  13. */
  14. #include <stdlib.h>
  15. #include <stdio.h>
  16. #include <string.h>
  17. #include <fcntl.h>
  18. #include <sys/types.h>
  19. #include <sys/stat.h>
  20. #include <dirent.h>
  21. #include <pwd.h>
  22. #include <grp.h>
  23. #include <time.h>
  24. #include <signal.h>
  25. #include <unistd.h>
  26. #include <getopt.h>
  27. #if __GNU_LIBRARY__ > 5
  28. #include <sys/reboot.h>
  29. #endif
  30. int main(int argc, char *argv[])
  31. {
  32. int delay = 0; /* delay in seconds before rebooting */
  33. int rc;
  34. int force = 0;
  35. while ((rc = getopt(argc, argv, "h?d:f")) > 0) {
  36. switch (rc) {
  37. case 'd':
  38. delay = atoi(optarg);
  39. break;
  40. case 'f':
  41. force = 1;
  42. break;
  43. case 'h':
  44. case '?':
  45. default:
  46. printf("usage: reboot [-h] [-d <delay>] [-f]\n");
  47. exit(0);
  48. break;
  49. }
  50. }
  51. if(delay > 0)
  52. sleep(delay);
  53. #ifdef CONFIG_DISKtel
  54. printf("unmounting /home\n");
  55. if(umount("/home") != 0){
  56. printf("unmounting failed!!!\n");
  57. }
  58. #endif
  59. #ifdef CONFIG_USER_FLATFSD_FLATFSD
  60. if (!force) {
  61. /* Ask flatfsd to reboot us safely */
  62. execlp("flatfsd", "flatfsd", "-b", NULL);
  63. /* if this returns, then force a reboot */
  64. }
  65. #endif
  66. kill(1, SIGTSTP);
  67. sync();
  68. signal(SIGTERM,SIG_IGN);
  69. signal(SIGHUP,SIG_IGN);
  70. setpgrp();
  71. kill(-1, SIGTERM);
  72. sleep(1);
  73. kill(-1, SIGHUP);
  74. sleep(1);
  75. sync();
  76. sleep(1);
  77. #if __GNU_LIBRARY__ > 5
  78. reboot(0x01234567);
  79. #else
  80. reboot(0xfee1dead, 672274793, 0x01234567);
  81. #endif
  82. exit(0); /* Shrug */
  83. }