Ignore:
Timestamp:
Jan 1, 2014, 12:47:38 AM (5 years ago)
Author:
bruno
Message:
  • Update mindi-busybox to 1.21.1
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/3.2/mindi-busybox/util-linux/hwclock.c

    r2725 r3232  
    4444            rtc_read_tm(&tm_time, fd);
    4545            gettimeofday(sys_tv, NULL);
    46             if (before != tm_time.tm_sec)
     46            if (before != (int)tm_time.tm_sec)
    4747                break;
    4848        }
     
    6161    struct timeval sys_tv;
    6262#endif
    63     time_t t;
    64     char *cp;
    65 
    66     t = read_rtc(pp_rtcname, &sys_tv, utc);
    67     cp = ctime(&t);
     63    time_t t = read_rtc(pp_rtcname, &sys_tv, utc);
     64
     65#if ENABLE_LOCALE_SUPPORT
     66    /* Standard hwclock uses locale-specific output format */
     67    char cp[64];
     68    struct tm *ptm = localtime(&t);
     69    strftime(cp, sizeof(cp), "%c", ptm);
     70#else
     71    char *cp = ctime(&t);
    6872    strchrnul(cp, '\n')[0] = '\0';
     73#endif
     74
    6975#if !SHOW_HWCLOCK_DIFF
    7076    printf("%s  0.000000 seconds\n", cp);
     
    7379        long diff = sys_tv.tv_sec - t;
    7480        if (diff < 0 /*&& tv.tv_usec != 0*/) {
    75             /* Why? */
    76             /* diff >= 0 is ok:   diff < 0, can't just use tv.tv_usec: */
    77             /*   45.520820          43.520820 */
    78             /* - 44.000000        - 45.000000 */
    79             /* =  1.520820        = -1.479180, not -2.520820! */
     81            /* Why we need diff++? */
     82            /* diff >= 0 is ok: | diff < 0, can't just use tv.tv_usec: */
     83            /*   45.520820      |   43.520820 */
     84            /* - 44.000000      | - 45.000000 */
     85            /* =  1.520820      | = -1.479180, not -2.520820! */
    8086            diff++;
    81             /* should be 1000000 - tv.tv_usec, but then we must check tv.tv_usec != 0 */
     87            /* Should be 1000000 - tv.tv_usec, but then we must check tv.tv_usec != 0 */
    8288            sys_tv.tv_usec = 999999 - sys_tv.tv_usec;
    8389        }
     
    224230}
    225231
     232/*
     233 * At system boot, kernel may set system time from RTC,
     234 * but it knows nothing about timezones. If RTC is in local time,
     235 * then system time is wrong - it is offset by timezone.
     236 * This option corrects system time if RTC is in local time,
     237 * and (always) sets in-kernel timezone.
     238 *
     239 * This is an alternate option to --hctosys that does not read the
     240 * hardware clock.
     241 */
     242static void set_system_clock_timezone(int utc)
     243{
     244    struct timeval tv;
     245    struct tm *broken;
     246    struct timezone tz;
     247
     248    gettimeofday(&tv, NULL);
     249    broken = localtime(&tv.tv_sec);
     250    tz.tz_minuteswest = timezone / 60;
     251    if (broken->tm_isdst)
     252        tz.tz_minuteswest -= 60;
     253    tz.tz_dsttime = 0;
     254    gettimeofday(&tv, NULL);
     255    if (!utc)
     256        tv.tv_sec += tz.tz_minuteswest * 60;
     257    if (settimeofday(&tv, &tz))
     258        bb_perror_msg_and_die("settimeofday");
     259}
     260
     261//usage:#define hwclock_trivial_usage
     262//usage:    IF_FEATURE_HWCLOCK_LONG_OPTIONS(
     263//usage:       "[-r|--show] [-s|--hctosys] [-w|--systohc] [-t|--systz]"
     264//usage:       " [-l|--localtime] [-u|--utc]"
     265//usage:       " [-f|--rtc FILE]"
     266//usage:    )
     267//usage:    IF_NOT_FEATURE_HWCLOCK_LONG_OPTIONS(
     268//usage:       "[-r] [-s] [-w] [-t] [-l] [-u] [-f FILE]"
     269//usage:    )
     270//usage:#define hwclock_full_usage "\n\n"
     271//usage:       "Query and set hardware clock (RTC)\n"
     272//usage:     "\n    -r  Show hardware clock time"
     273//usage:     "\n    -s  Set system time from hardware clock"
     274//usage:     "\n    -w  Set hardware clock from system time"
     275//usage:     "\n    -t  Set in-kernel timezone, correct system time"
     276//usage:     "\n        if hardware clock is in local time"
     277//usage:     "\n    -u  Assume hardware clock is kept in UTC"
     278//usage:     "\n    -l  Assume hardware clock is kept in local time"
     279//usage:     "\n    -f FILE Use specified device (e.g. /dev/rtc2)"
     280
    226281#define HWCLOCK_OPT_LOCALTIME   0x01
    227282#define HWCLOCK_OPT_UTC         0x02
     
    229284#define HWCLOCK_OPT_HCTOSYS     0x08
    230285#define HWCLOCK_OPT_SYSTOHC     0x10
    231 #define HWCLOCK_OPT_RTCFILE     0x20
     286#define HWCLOCK_OPT_SYSTZ       0x20
     287#define HWCLOCK_OPT_RTCFILE     0x40
    232288
    233289int hwclock_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
     
    240296#if ENABLE_FEATURE_HWCLOCK_LONG_OPTIONS
    241297    static const char hwclock_longopts[] ALIGN1 =
    242         "localtime\0" No_argument "l"
     298        "localtime\0" No_argument "l" /* short opt is non-standard */
    243299        "utc\0"       No_argument "u"
    244300        "show\0"      No_argument "r"
    245301        "hctosys\0"   No_argument "s"
    246302        "systohc\0"   No_argument "w"
    247         "file\0"      Required_argument "f"
     303        "systz\0"     No_argument "t" /* short opt is non-standard */
     304        "rtc\0"       Required_argument "f"
    248305        ;
    249306    applet_long_options = hwclock_longopts;
    250307#endif
    251     opt_complementary = "r--ws:w--rs:s--wr:l--u:u--l";
    252     opt = getopt32(argv, "lurswf:", &rtcname);
     308    opt_complementary = "r--wst:w--rst:s--wrt:t--rsw:l--u:u--l";
     309    opt = getopt32(argv, "lurswtf:", &rtcname);
    253310
    254311    /* If -u or -l wasn't given check if we are using utc */
     
    262319    else if (opt & HWCLOCK_OPT_SYSTOHC)
    263320        from_sys_clock(&rtcname, utc);
     321    else if (opt & HWCLOCK_OPT_SYSTZ)
     322        set_system_clock_timezone(utc);
    264323    else
    265324        /* default HWCLOCK_OPT_SHOW */
Note: See TracChangeset for help on using the changeset viewer.