*/
#include "busybox.h"
-#include <stdio.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <signal.h>
+
+#define OPT_FOREGROUND 0x01
+#define OPT_TIMER 0x02
/* Watchdog file descriptor */
static int fd;
static void watchdog_shutdown(int ATTRIBUTE_UNUSED unused)
{
- write(fd, "V", 1); /* Magic */
+ write(fd, "V", 1); /* Magic, see watchdog-api.txt in kernel */
close(fd);
exit(0);
}
int watchdog_main(int argc, char **argv)
{
- unsigned long timer_duration = 30; /* Userspace timer duration, in seconds */
+ unsigned opts;
+ unsigned timer_duration = 30; /* Userspace timer duration, in seconds */
char *t_arg;
- if (bb_getopt_ulflags(argc, argv, "t:", &t_arg))
- timer_duration = bb_xgetlarg(t_arg, 10, 0, INT_MAX);
+ opts = getopt32(argc, argv, "Ft:", &t_arg);
+
+ if (opts & OPT_TIMER)
+ timer_duration = xatou(t_arg);
/* We're only interested in the watchdog device .. */
if (optind < argc - 1 || argc == 1)
bb_show_usage();
- bb_xdaemon(0, 1);
+#ifdef BB_NOMMU
+ if (!(opts & OPT_FOREGROUND))
+ vfork_daemon_rexec(0, 1, argc, argv, "-F");
+#else
+ xdaemon(0, 1);
+#endif
signal(SIGHUP, watchdog_shutdown);
signal(SIGINT, watchdog_shutdown);
- fd = bb_xopen(argv[argc - 1], O_WRONLY);
+ fd = xopen(argv[argc - 1], O_WRONLY);
while (1) {
/*