Changeset 1770 in MondoRescue for branches/stable/mindi-busybox/miscutils/watchdog.c
- Timestamp:
- Nov 6, 2007, 11:01:53 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/stable/mindi-busybox/miscutils/watchdog.c
r821 r1770 9 9 */ 10 10 11 #include "busybox.h" 12 #include <stdio.h> 13 #include <fcntl.h> 14 #include <unistd.h> 15 #include <stdlib.h> 16 #include <signal.h> 11 #include "libbb.h" 17 12 18 13 #define OPT_FOREGROUND 0x01 19 14 #define OPT_TIMER 0x02 20 15 21 /* Watchdog file descriptor */ 22 static int fd; 23 24 static void watchdog_shutdown(int ATTRIBUTE_UNUSED unused) 16 static void watchdog_shutdown(int ATTRIBUTE_UNUSED sig) ATTRIBUTE_NORETURN; 17 static void watchdog_shutdown(int ATTRIBUTE_UNUSED sig) 25 18 { 26 write(fd, "V", 1); /* Magic, see watchdog-api.txt in kernel */ 27 close(fd); 19 write(3, "V", 1); /* Magic, see watchdog-api.txt in kernel */ 20 if (ENABLE_FEATURE_CLEAN_UP) 21 close(3); 28 22 exit(0); 29 23 } 30 24 25 int watchdog_main(int argc, char **argv); 31 26 int watchdog_main(int argc, char **argv) 32 27 { 33 unsigned longopts;34 unsigned longtimer_duration = 30; /* Userspace timer duration, in seconds */28 unsigned opts; 29 unsigned timer_duration = 30; /* Userspace timer duration, in seconds */ 35 30 char *t_arg; 36 31 37 opts = bb_getopt_ulflags(argc, argv, "Ft:", &t_arg); 32 opt_complementary = "=1"; /* must have 1 argument */ 33 opts = getopt32(argv, "Ft:", &t_arg); 38 34 39 35 if (opts & OPT_TIMER) 40 timer_duration = bb_xgetlarg(t_arg, 10, 0, INT_MAX);36 timer_duration = xatou(t_arg); 41 37 42 /* We're only interested in the watchdog device .. */ 43 if (optind < argc - 1 || argc == 1) 44 bb_show_usage(); 45 46 #ifdef BB_NOMMU 47 if (!(opts & OPT_FOREGROUND)) 48 vfork_daemon_rexec(0, 1, argc, argv, "-F"); 49 #else 50 bb_xdaemon(0, 1); 51 #endif 38 if (!(opts & OPT_FOREGROUND)) { 39 bb_daemonize_or_rexec(DAEMON_CHDIR_ROOT, argv); 40 } 52 41 53 42 signal(SIGHUP, watchdog_shutdown); 54 43 signal(SIGINT, watchdog_shutdown); 55 44 56 fd = bb_xopen(argv[argc - 1], O_WRONLY); 45 /* Use known fd # - avoid needing global 'int fd' */ 46 xmove_fd(xopen(argv[argc - 1], O_WRONLY), 3); 57 47 58 48 while (1) { … … 61 51 * is undefined at this point -- PFM 62 52 */ 63 write( fd, "\0", 1);53 write(3, "", 1); 64 54 sleep(timer_duration); 65 55 } 66 56 67 57 watchdog_shutdown(0); 68 69 return EXIT_SUCCESS; 58 /* return EXIT_SUCCESS; */ 70 59 }
Note:
See TracChangeset
for help on using the changeset viewer.