Ignore:
Timestamp:
Feb 25, 2011, 9:26:54 PM (13 years ago)
Author:
Bruno Cornec
Message:
  • Update mindi-busybox to 1.18.3 to avoid problems with the tar command which is now failing on recent versions with busybox 1.7.3
File:
1 edited

Legend:

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

    r1765 r2725  
    44 *
    55 * Copyright (C) 2003  Paul Mundt <lethal@linux-sh.org>
    6  * Copyright (C) 2006  Bernhard Fischer <busybox@busybox.net>
     6 * Copyright (C) 2006  Bernhard Reutner-Fischer <busybox@busybox.net>
     7 * Copyright (C) 2008  Darius Augulis <augulis.darius@gmail.com>
    78 *
    8  * Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
     9 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
    910 */
    1011
    1112#include "libbb.h"
     13#include "linux/types.h" /* for __u32 */
     14#include "linux/watchdog.h"
    1215
    13 #define OPT_FOREGROUND 0x01
    14 #define OPT_TIMER      0x02
     16#define OPT_FOREGROUND  (1 << 0)
     17#define OPT_STIMER      (1 << 1)
     18#define OPT_HTIMER      (1 << 2)
    1519
    16 static void watchdog_shutdown(int ATTRIBUTE_UNUSED sig) ATTRIBUTE_NORETURN;
    17 static void watchdog_shutdown(int ATTRIBUTE_UNUSED sig)
     20static void watchdog_shutdown(int sig UNUSED_PARAM)
    1821{
    19     write(3, "V", 1);   /* Magic, see watchdog-api.txt in kernel */
     22    static const char V = 'V';
     23
     24    write(3, &V, 1);  /* Magic, see watchdog-api.txt in kernel */
    2025    if (ENABLE_FEATURE_CLEAN_UP)
    2126        close(3);
    22     exit(0);
     27    _exit(EXIT_SUCCESS);
    2328}
    2429
    25 int watchdog_main(int argc, char **argv);
     30int watchdog_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
    2631int watchdog_main(int argc, char **argv)
    2732{
     33    static const struct suffix_mult suffixes[] = {
     34        { "ms", 1 },
     35        { "", 1000 },
     36        { "", 0 }
     37    };
     38
    2839    unsigned opts;
    29     unsigned timer_duration = 30; /* Userspace timer duration, in seconds */
    30     char *t_arg;
     40    unsigned stimer_duration; /* how often to restart */
     41    unsigned htimer_duration = 60000; /* reboots after N ms if not restarted */
     42    char *st_arg;
     43    char *ht_arg;
    3144
    32     opt_complementary = "=1"; /* must have 1 argument */
    33     opts = getopt32(argv, "Ft:", &t_arg);
     45    opt_complementary = "=1"; /* must have exactly 1 argument */
     46    opts = getopt32(argv, "Ft:T:", &st_arg, &ht_arg);
    3447
    35     if (opts & OPT_TIMER)
    36         timer_duration = xatou(t_arg);
     48    /* We need to daemonize *before* opening the watchdog as many drivers
     49     * will only allow one process at a time to do so.  Since daemonizing
     50     * is not perfect (child may run before parent finishes exiting), we
     51     * can't rely on parent exiting before us (let alone *cleanly* releasing
     52     * the watchdog fd -- something else that may not even be allowed).
     53     */
     54    if (!(opts & OPT_FOREGROUND))
     55        bb_daemonize_or_rexec(DAEMON_CHDIR_ROOT, argv);
    3756
    38     if (!(opts & OPT_FOREGROUND)) {
    39         bb_daemonize_or_rexec(DAEMON_CHDIR_ROOT, argv);
    40     }
     57    if (opts & OPT_HTIMER)
     58        htimer_duration = xatou_sfx(ht_arg, suffixes);
     59    stimer_duration = htimer_duration / 2;
     60    if (opts & OPT_STIMER)
     61        stimer_duration = xatou_sfx(st_arg, suffixes);
    4162
    42     signal(SIGHUP, watchdog_shutdown);
    43     signal(SIGINT, watchdog_shutdown);
     63    bb_signals(BB_FATAL_SIGS, watchdog_shutdown);
    4464
    4565    /* Use known fd # - avoid needing global 'int fd' */
    4666    xmove_fd(xopen(argv[argc - 1], O_WRONLY), 3);
    4767
     68    /* WDIOC_SETTIMEOUT takes seconds, not milliseconds */
     69    htimer_duration = htimer_duration / 1000;
     70#ifndef WDIOC_SETTIMEOUT
     71# error WDIOC_SETTIMEOUT is not defined, cannot compile watchdog applet
     72#else
     73# if defined WDIOC_SETOPTIONS && defined WDIOS_ENABLECARD
     74    {
     75        static const int enable = WDIOS_ENABLECARD;
     76        ioctl_or_warn(3, WDIOC_SETOPTIONS, (void*) &enable);
     77    }
     78# endif
     79    ioctl_or_warn(3, WDIOC_SETTIMEOUT, &htimer_duration);
     80#endif
     81
     82#if 0
     83    ioctl_or_warn(3, WDIOC_GETTIMEOUT, &htimer_duration);
     84    printf("watchdog: SW timer is %dms, HW timer is %ds\n",
     85        stimer_duration, htimer_duration * 1000);
     86#endif
     87
    4888    while (1) {
    4989        /*
    50          * Make sure we clear the counter before sleeping, as the counter value
    51          * is undefined at this point -- PFM
     90         * Make sure we clear the counter before sleeping,
     91         * as the counter value is undefined at this point -- PFM
    5292         */
    53         write(3, "", 1);
    54         sleep(timer_duration);
     93        write(3, "", 1); /* write zero byte */
     94        usleep(stimer_duration * 1000L);
    5595    }
    56 
    57     watchdog_shutdown(0);
    58     /* return EXIT_SUCCESS; */
     96    return EXIT_SUCCESS; /* - not reached, but gcc 4.2.1 is too dumb! */
    5997}
Note: See TracChangeset for help on using the changeset viewer.