Changeset 3621 in MondoRescue for branches/3.3/mindi-busybox/libbb/rtc.c


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/libbb/rtc.c

    r2725 r3621  
    2323
    2424        while (fgets(buffer, sizeof(buffer), f)) {
    25             if (strncmp(buffer, "UTC", 3) == 0) {
     25            if (is_prefixed_with(buffer, "UTC")) {
    2626                utc = 1;
    2727                break;
     
    3434}
    3535
     36/* rtc opens are exclusive.
     37 * Try to run two "hwclock -w" at the same time to see it.
     38 * Users wouldn't expect that to fail merely because /dev/rtc
     39 * was momentarily busy, let's try a bit harder on errno == EBUSY.
     40 */
     41static int open_loop_on_busy(const char *name, int flags)
     42{
     43    int rtc;
     44    /*
     45     * Tested with two parallel "hwclock -w" loops.
     46     * With try = 10, no failures with 2x1000000 loop iterations.
     47     */
     48    int try = 1000 / 20;
     49 again:
     50    errno = 0;
     51    rtc = open(name, flags);
     52    if (errno == EBUSY) {
     53        usleep(20 * 1000);
     54        if (--try != 0)
     55            goto again;
     56        /* EBUSY. Last try, exit on error instead of returning -1 */
     57        return xopen(name, flags);
     58    }
     59    return rtc;
     60}
     61
     62/* Never fails */
    3663int FAST_FUNC rtc_xopen(const char **default_rtc, int flags)
    3764{
    3865    int rtc;
     66    const char *name =
     67        "/dev/rtc""\0"
     68        "/dev/rtc0""\0"
     69        "/dev/misc/rtc""\0";
    3970
    40     if (!*default_rtc) {
    41         *default_rtc = "/dev/rtc";
    42         rtc = open(*default_rtc, flags);
     71    if (!*default_rtc)
     72        goto try_name;
     73    name = ""; /*else: we have rtc name, don't try other names */
     74
     75    for (;;) {
     76        rtc = open_loop_on_busy(*default_rtc, flags);
    4377        if (rtc >= 0)
    4478            return rtc;
    45         *default_rtc = "/dev/rtc0";
    46         rtc = open(*default_rtc, flags);
    47         if (rtc >= 0)
    48             return rtc;
    49         *default_rtc = "/dev/misc/rtc";
     79        if (!name[0])
     80            return xopen(*default_rtc, flags);
     81 try_name:
     82        *default_rtc = name;
     83        name += strlen(name) + 1;
    5084    }
    51 
    52     return xopen(*default_rtc, flags);
    5385}
    5486
Note: See TracChangeset for help on using the changeset viewer.