diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2010-01-07 08:31:46 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2010-01-07 08:31:46 +0100 |
commit | 6959f6bc23abb9057c3ed4330dad1bc8f4a1dd7a (patch) | |
tree | 62eb6ad011ac1cb269e881c2b95c739ce8b948f6 | |
parent | 5e3b14069e3fe25ec2595124e6e0103c7be4f813 (diff) | |
download | busybox-w32-6959f6bc23abb9057c3ed4330dad1bc8f4a1dd7a.tar.gz busybox-w32-6959f6bc23abb9057c3ed4330dad1bc8f4a1dd7a.tar.bz2 busybox-w32-6959f6bc23abb9057c3ed4330dad1bc8f4a1dd7a.zip |
hwclock: disable time diff code; ntpd -S script: do not wait for completion
function old new delta
rtcname 4 - -4
run_script 278 273 -5
hwclock_main 466 439 -27
read_rtc 86 38 -48
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 0/3 up/down: 0/-84) Total: -84 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | networking/ntpd.c | 8 | ||||
-rw-r--r-- | util-linux/hwclock.c | 51 |
2 files changed, 39 insertions, 20 deletions
diff --git a/networking/ntpd.c b/networking/ntpd.c index d23b2c984..038f2bded 100644 --- a/networking/ntpd.c +++ b/networking/ntpd.c | |||
@@ -709,7 +709,10 @@ static void run_script(const char *action) | |||
709 | * last_update_offset, last_update_recv_time, discipline_jitter | 709 | * last_update_offset, last_update_recv_time, discipline_jitter |
710 | */ | 710 | */ |
711 | 711 | ||
712 | wait4pid(spawn(argv)); | 712 | /* Don't want to wait: it may run hwclock --systohc, and that |
713 | * may take some time (seconds): */ | ||
714 | /*wait4pid(spawn(argv));*/ | ||
715 | spawn(argv); | ||
713 | G.last_script_run = G.cur_time; | 716 | G.last_script_run = G.cur_time; |
714 | 717 | ||
715 | unsetenv("stratum"); | 718 | unsetenv("stratum"); |
@@ -1805,7 +1808,8 @@ static NOINLINE void ntp_init(char **argv) | |||
1805 | setpriority(PRIO_PROCESS, 0, -15); | 1808 | setpriority(PRIO_PROCESS, 0, -15); |
1806 | 1809 | ||
1807 | bb_signals((1 << SIGTERM) | (1 << SIGINT), record_signo); | 1810 | bb_signals((1 << SIGTERM) | (1 << SIGINT), record_signo); |
1808 | bb_signals((1 << SIGPIPE) | (1 << SIGHUP), SIG_IGN); | 1811 | /* Removed SIGHUP here: */ |
1812 | bb_signals((1 << SIGPIPE) | (1 << SIGCHLD), SIG_IGN); | ||
1809 | } | 1813 | } |
1810 | 1814 | ||
1811 | int ntpd_main(int argc UNUSED_PARAM, char **argv) MAIN_EXTERNALLY_VISIBLE; | 1815 | int ntpd_main(int argc UNUSED_PARAM, char **argv) MAIN_EXTERNALLY_VISIBLE; |
diff --git a/util-linux/hwclock.c b/util-linux/hwclock.c index 606721e2c..7f4c563e6 100644 --- a/util-linux/hwclock.c +++ b/util-linux/hwclock.c | |||
@@ -18,17 +18,29 @@ | |||
18 | # endif | 18 | # endif |
19 | #endif | 19 | #endif |
20 | 20 | ||
21 | static const char *rtcname; | ||
22 | 21 | ||
23 | static time_t read_rtc(struct timeval *sys_tv, int utc) | 22 | /* diff code is disabled: it's not sys/hw clock diff, it's some useless |
23 | * "time between hwclock was started and we saw CMOS tick" quantity. | ||
24 | * It's useless since hwclock is started at a random moment, | ||
25 | * thus the quantity is also random, useless. Showing 0.000000 does not | ||
26 | * deprive us from any useful info. */ | ||
27 | #define SHOW_HWCLOCK_DIFF 0 | ||
28 | |||
29 | |||
30 | #if !SHOW_HWCLOCK_DIFF | ||
31 | # define read_rtc(pp_rtcname, sys_tv, utc) read_rtc(pp_rtcname, utc) | ||
32 | #endif | ||
33 | static time_t read_rtc(const char **pp_rtcname, struct timeval *sys_tv, int utc) | ||
24 | { | 34 | { |
25 | struct tm tm; | 35 | struct tm tm; |
26 | int fd; | 36 | int fd; |
27 | int before; | ||
28 | 37 | ||
29 | fd = rtc_xopen(&rtcname, O_RDONLY); | 38 | fd = rtc_xopen(pp_rtcname, O_RDONLY); |
30 | 39 | ||
31 | rtc_read_tm(&tm, fd); | 40 | rtc_read_tm(&tm, fd); |
41 | |||
42 | #if SHOW_HWCLOCK_DIFF | ||
43 | int before; | ||
32 | before = tm.tm_sec; | 44 | before = tm.tm_sec; |
33 | while (1) { | 45 | while (1) { |
34 | rtc_read_tm(&tm, fd); | 46 | rtc_read_tm(&tm, fd); |
@@ -36,6 +48,7 @@ static time_t read_rtc(struct timeval *sys_tv, int utc) | |||
36 | if (before != tm.tm_sec) | 48 | if (before != tm.tm_sec) |
37 | break; | 49 | break; |
38 | } | 50 | } |
51 | #endif | ||
39 | 52 | ||
40 | if (ENABLE_FEATURE_CLEAN_UP) | 53 | if (ENABLE_FEATURE_CLEAN_UP) |
41 | close(fd); | 54 | close(fd); |
@@ -43,19 +56,19 @@ static time_t read_rtc(struct timeval *sys_tv, int utc) | |||
43 | return rtc_tm2time(&tm, utc); | 56 | return rtc_tm2time(&tm, utc); |
44 | } | 57 | } |
45 | 58 | ||
46 | static void show_clock(int utc) | 59 | static void show_clock(const char **pp_rtcname, int utc) |
47 | { | 60 | { |
48 | struct timeval sys_tv; | ||
49 | time_t t; | 61 | time_t t; |
50 | long diff; | ||
51 | char *cp; | 62 | char *cp; |
52 | 63 | ||
53 | t = read_rtc(&sys_tv, utc); | 64 | t = read_rtc(pp_rtcname, &sys_tv, utc); |
54 | |||
55 | cp = ctime(&t); | 65 | cp = ctime(&t); |
56 | strchrnul(cp, '\n')[0] = '\0'; | 66 | strchrnul(cp, '\n')[0] = '\0'; |
67 | printf("%s 0.000000 seconds\n", cp); | ||
57 | 68 | ||
58 | //printf("%s 0.000000 seconds %s\n", cp, utc ? "" : (ptm->tm_isdst ? tzname[1] : tzname[0])); | 69 | #if SHOW_HWCLOCK_DIFF |
70 | struct timeval sys_tv; | ||
71 | long diff; | ||
59 | diff = sys_tv.tv_sec - t; | 72 | diff = sys_tv.tv_sec - t; |
60 | if (diff < 0 /*&& tv.tv_usec != 0*/) { | 73 | if (diff < 0 /*&& tv.tv_usec != 0*/) { |
61 | /* Why? */ | 74 | /* Why? */ |
@@ -68,9 +81,10 @@ static void show_clock(int utc) | |||
68 | sys_tv.tv_usec = 999999 - sys_tv.tv_usec; | 81 | sys_tv.tv_usec = 999999 - sys_tv.tv_usec; |
69 | } | 82 | } |
70 | printf("%s %ld.%06lu seconds\n", cp, diff, (unsigned long)sys_tv.tv_usec); | 83 | printf("%s %ld.%06lu seconds\n", cp, diff, (unsigned long)sys_tv.tv_usec); |
84 | #endif | ||
71 | } | 85 | } |
72 | 86 | ||
73 | static void to_sys_clock(int utc) | 87 | static void to_sys_clock(const char **pp_rtcname, int utc) |
74 | { | 88 | { |
75 | struct timeval tv; | 89 | struct timeval tv; |
76 | struct timezone tz; | 90 | struct timezone tz; |
@@ -78,19 +92,19 @@ static void to_sys_clock(int utc) | |||
78 | tz.tz_minuteswest = timezone/60 - 60*daylight; | 92 | tz.tz_minuteswest = timezone/60 - 60*daylight; |
79 | tz.tz_dsttime = 0; | 93 | tz.tz_dsttime = 0; |
80 | 94 | ||
81 | tv.tv_sec = read_rtc(NULL, utc); | 95 | tv.tv_sec = read_rtc(pp_rtcname, NULL, utc); |
82 | tv.tv_usec = 0; | 96 | tv.tv_usec = 0; |
83 | if (settimeofday(&tv, &tz)) | 97 | if (settimeofday(&tv, &tz)) |
84 | bb_perror_msg_and_die("settimeofday() failed"); | 98 | bb_perror_msg_and_die("settimeofday"); |
85 | } | 99 | } |
86 | 100 | ||
87 | static void from_sys_clock(int utc) | 101 | static void from_sys_clock(const char **pp_rtcname, int utc) |
88 | { | 102 | { |
89 | #define TWEAK_USEC 200 | 103 | #define TWEAK_USEC 200 |
90 | struct tm tm; | 104 | struct tm tm; |
91 | struct timeval tv; | 105 | struct timeval tv; |
92 | unsigned adj = TWEAK_USEC; | 106 | unsigned adj = TWEAK_USEC; |
93 | int rtc = rtc_xopen(&rtcname, O_WRONLY); | 107 | int rtc = rtc_xopen(pp_rtcname, O_WRONLY); |
94 | 108 | ||
95 | /* Try to catch the moment when whole second is close */ | 109 | /* Try to catch the moment when whole second is close */ |
96 | while (1) { | 110 | while (1) { |
@@ -165,6 +179,7 @@ static void from_sys_clock(int utc) | |||
165 | int hwclock_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 179 | int hwclock_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
166 | int hwclock_main(int argc UNUSED_PARAM, char **argv) | 180 | int hwclock_main(int argc UNUSED_PARAM, char **argv) |
167 | { | 181 | { |
182 | const char *rtcname = NULL; | ||
168 | unsigned opt; | 183 | unsigned opt; |
169 | int utc; | 184 | int utc; |
170 | 185 | ||
@@ -189,12 +204,12 @@ int hwclock_main(int argc UNUSED_PARAM, char **argv) | |||
189 | utc = rtc_adjtime_is_utc(); | 204 | utc = rtc_adjtime_is_utc(); |
190 | 205 | ||
191 | if (opt & HWCLOCK_OPT_HCTOSYS) | 206 | if (opt & HWCLOCK_OPT_HCTOSYS) |
192 | to_sys_clock(utc); | 207 | to_sys_clock(&rtcname, utc); |
193 | else if (opt & HWCLOCK_OPT_SYSTOHC) | 208 | else if (opt & HWCLOCK_OPT_SYSTOHC) |
194 | from_sys_clock(utc); | 209 | from_sys_clock(&rtcname, utc); |
195 | else | 210 | else |
196 | /* default HWCLOCK_OPT_SHOW */ | 211 | /* default HWCLOCK_OPT_SHOW */ |
197 | show_clock(utc); | 212 | show_clock(&rtcname, utc); |
198 | 213 | ||
199 | return 0; | 214 | return 0; |
200 | } | 215 | } |