Ignore:
Timestamp:
Dec 20, 2016, 4:07:32 PM (7 years ago)
Author:
Bruno Cornec
Message:

New 3?3 banch for incorporation of latest busybox 1.25. Changing minor version to handle potential incompatibilities.

Location:
branches/3.3
Files:
1 edited
1 copied

Legend:

Unmodified
Added
Removed
  • branches/3.3/mindi-busybox/util-linux/rtcwake.c

    r3232 r3621  
    3333//usage:     "\n    -u,--utc    Clock is set to UTC time"
    3434//usage:     "\n    -d,--device=DEV Specify the RTC device"
    35 //usage:     "\n    -m,--mode=MODE  Set the sleep state (default: standby)"
    36 //usage:     "\n    -s,--seconds=SEC Set the timeout in SEC seconds from now"
    37 //usage:     "\n    -t,--time=TIME  Set the timeout to TIME seconds from epoch"
     35//usage:     "\n    -m,--mode=MODE  Set sleep state (default: standby)"
     36//usage:     "\n    -s,--seconds=SEC Set timeout in SEC seconds from now"
     37//usage:     "\n    -t,--time=TIME  Set timeout to TIME seconds from epoch"
    3838//usage:    )
    3939//usage:    IF_NOT_LONG_OPTS(
     
    4242//usage:     "\n    -u  Clock is set to UTC time"
    4343//usage:     "\n    -d DEV  Specify the RTC device"
    44 //usage:     "\n    -m MODE Set the sleep state (default: standby)"
    45 //usage:     "\n    -s SEC  Set the timeout in SEC seconds from now"
    46 //usage:     "\n    -t TIME Set the timeout to TIME seconds from epoch"
     44//usage:     "\n    -m MODE Set sleep state (default: standby)"
     45//usage:     "\n    -s SEC  Set timeout in SEC seconds from now"
     46//usage:     "\n    -t TIME Set timeout to TIME seconds from epoch"
    4747//usage:    )
    4848
     
    5252#define SYS_RTC_PATH   "/sys/class/rtc/%s/device/power/wakeup"
    5353#define SYS_POWER_PATH "/sys/power/state"
    54 #define DEFAULT_MODE   "standby"
    5554
    5655static NOINLINE bool may_wakeup(const char *rtcname)
     
    6867
    6968    /* wakeup events could be disabled or not supported */
    70     return strncmp(buf, "enabled\n", 8) == 0;
     69    return is_prefixed_with(buf, "enabled\n") != NULL;
    7170}
    7271
     
    123122int rtcwake_main(int argc UNUSED_PARAM, char **argv)
    124123{
    125     time_t rtc_time;
    126 
    127124    unsigned opt;
    128125    const char *rtcname = NULL;
    129     const char *suspend;
     126    const char *suspend = "standby";
    130127    const char *opt_seconds;
    131128    const char *opt_time;
    132129
     130    time_t rtc_time;
    133131    time_t sys_time;
    134     time_t alarm_time = 0;
    135     unsigned seconds = 0;
     132    time_t alarm_time = alarm_time;
     133    unsigned seconds = seconds; /* for compiler */
    136134    int utc = -1;
    137135    int fd;
     
    149147    applet_long_options = rtcwake_longopts;
    150148#endif
     149    /* Must have -s or -t, exclusive */
     150    opt_complementary = "s:t:s--t:t--s";
    151151    opt = getopt32(argv, "alud:m:s:t:", &rtcname, &suspend, &opt_seconds, &opt_time);
    152152
     
    157157    if (opt & (RTCWAKE_OPT_UTC | RTCWAKE_OPT_LOCAL))
    158158        utc = opt & RTCWAKE_OPT_UTC;
    159     if (!(opt & RTCWAKE_OPT_SUSPEND_MODE))
    160         suspend = DEFAULT_MODE;
    161     if (opt & RTCWAKE_OPT_SECONDS)
     159    if (opt & RTCWAKE_OPT_SECONDS) {
    162160        /* alarm time, seconds-to-sleep (relative) */
    163         seconds = xatoi(opt_seconds);
    164     if (opt & RTCWAKE_OPT_TIME)
     161        seconds = xatou(opt_seconds);
     162    } else {
     163        /* RTCWAKE_OPT_TIME */
    165164        /* alarm time, time_t (absolute, seconds since 1/1 1970 UTC) */
    166         alarm_time = xatol(opt_time);
    167 
    168     if (!alarm_time && !seconds)
    169         bb_error_msg_and_die("must provide wake time");
     165        if (sizeof(alarm_time) <= sizeof(long))
     166            alarm_time = xatol(opt_time);
     167        else
     168            alarm_time = xatoll(opt_time);
     169    }
    170170
    171171    if (utc == -1)
     
    178178    fd = rtc_xopen(&rtcname, O_RDONLY);
    179179
    180     if (strcmp(suspend, "on") && !may_wakeup(rtcname))
    181         bb_error_msg_and_die("%s not enabled for wakeup events", rtcname);
     180    if (strcmp(suspend, "on") != 0)
     181        if (!may_wakeup(rtcname))
     182            bb_error_msg_and_die("%s not enabled for wakeup events", rtcname);
    182183
    183184    /* relative or absolute alarm time, normalized to time_t */
     
    189190    }
    190191
    191 
    192     if (alarm_time) {
    193         if (alarm_time < sys_time)
     192    if (opt & RTCWAKE_OPT_TIME) {
     193        /* Correct for RTC<->system clock difference */
     194        alarm_time += rtc_time - sys_time;
     195        if (alarm_time < rtc_time)
     196            /*
     197             * Compat message text.
     198             * I'd say "RTC time is already ahead of ..." instead.
     199             */
    194200            bb_error_msg_and_die("time doesn't go backward to %s", ctime(&alarm_time));
    195         alarm_time += sys_time - rtc_time;
    196201    } else
    197202        alarm_time = rtc_time + seconds + 1;
     203
    198204    setup_alarm(fd, &alarm_time, rtc_time);
    199 
    200205    sync();
     206#if 0 /*debug*/
     207    printf("sys_time: %s", ctime(&sys_time));
     208    printf("rtc_time: %s", ctime(&rtc_time));
     209#endif
    201210    printf("wakeup from \"%s\" at %s", suspend, ctime(&alarm_time));
    202211    fflush_all();
    203212    usleep(10 * 1000);
    204213
    205     if (strcmp(suspend, "on"))
     214    if (strcmp(suspend, "on") != 0)
    206215        xopen_xwrite_close(SYS_POWER_PATH, suspend);
    207216    else {
Note: See TracChangeset for help on using the changeset viewer.