Ignore:
Timestamp:
Nov 4, 2007, 3:16:40 AM (16 years ago)
Author:
Bruno Cornec
Message:

Update to busybox 1.7.2

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2.2.5/mindi-busybox/miscutils/watchdog.c

    r821 r1765  
    99 */
    1010
    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"
    1712
    1813#define OPT_FOREGROUND 0x01
    1914#define OPT_TIMER      0x02
    2015
    21 /* Watchdog file descriptor */
    22 static int fd;
    23 
    24 static void watchdog_shutdown(int ATTRIBUTE_UNUSED unused)
     16static void watchdog_shutdown(int ATTRIBUTE_UNUSED sig) ATTRIBUTE_NORETURN;
     17static void watchdog_shutdown(int ATTRIBUTE_UNUSED sig)
    2518{
    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);
    2822    exit(0);
    2923}
    3024
     25int watchdog_main(int argc, char **argv);
    3126int watchdog_main(int argc, char **argv)
    3227{
    33     unsigned long opts;
    34     unsigned long timer_duration = 30; /* Userspace timer duration, in seconds */
     28    unsigned opts;
     29    unsigned timer_duration = 30; /* Userspace timer duration, in seconds */
    3530    char *t_arg;
    3631
    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);
    3834
    3935    if (opts & OPT_TIMER)
    40         timer_duration = bb_xgetlarg(t_arg, 10, 0, INT_MAX);
     36        timer_duration = xatou(t_arg);
    4137
    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    }
    5241
    5342    signal(SIGHUP, watchdog_shutdown);
    5443    signal(SIGINT, watchdog_shutdown);
    5544
    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);
    5747
    5848    while (1) {
     
    6151         * is undefined at this point -- PFM
    6252         */
    63         write(fd, "\0", 1);
     53        write(3, "", 1);
    6454        sleep(timer_duration);
    6555    }
    6656
    6757    watchdog_shutdown(0);
    68 
    69     return EXIT_SUCCESS;
     58    /* return EXIT_SUCCESS; */
    7059}
Note: See TracChangeset for help on using the changeset viewer.