aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2023-02-13 10:01:35 +0000
committerRon Yorston <rmy@pobox.com>2023-02-13 10:01:35 +0000
commit4e5fb4341fddc2b99e815f27ac577d85a57994c2 (patch)
treec9e2eae6d2752d7e7f907ad39e3797b0fd5c3e02
parent0f2feac4b7e518e838b80d7b8ceac8f9699ae997 (diff)
parent93ae7464e6e460f25b73e4ffefd2d9a6499eae30 (diff)
downloadbusybox-w32-4e5fb4341fddc2b99e815f27ac577d85a57994c2.tar.gz
busybox-w32-4e5fb4341fddc2b99e815f27ac577d85a57994c2.tar.bz2
busybox-w32-4e5fb4341fddc2b99e815f27ac577d85a57994c2.zip
Merge branch 'busybox' into merge
-rw-r--r--editors/ed.c2
-rw-r--r--libbb/lineedit.c17
-rw-r--r--networking/ntpd.c36
-rw-r--r--procps/nmeter.c9
-rw-r--r--shell/ash.c3
-rw-r--r--shell/hush.c51
6 files changed, 77 insertions, 41 deletions
diff --git a/editors/ed.c b/editors/ed.c
index 209ce9942..4a84f7433 100644
--- a/editors/ed.c
+++ b/editors/ed.c
@@ -720,7 +720,7 @@ static void subCommand(const char *cmd, int num1, int num2)
720 if (deltaLen <= 0) { 720 if (deltaLen <= 0) {
721 memcpy(&lp->data[offset], newStr, newLen); 721 memcpy(&lp->data[offset], newStr, newLen);
722 if (deltaLen) { 722 if (deltaLen) {
723 memcpy(&lp->data[offset + newLen], 723 memmove(&lp->data[offset + newLen],
724 &lp->data[offset + oldLen], 724 &lp->data[offset + oldLen],
725 lp->len - offset - oldLen); 725 lp->len - offset - oldLen);
726 726
diff --git a/libbb/lineedit.c b/libbb/lineedit.c
index bee423553..c4f0c65f1 100644
--- a/libbb/lineedit.c
+++ b/libbb/lineedit.c
@@ -2300,7 +2300,8 @@ static int lineedit_read_key(char *read_key_buffer, int timeout)
2300 * "\xff\n",pause,"ls\n" invalid and thus won't lose "ls". 2300 * "\xff\n",pause,"ls\n" invalid and thus won't lose "ls".
2301 * 2301 *
2302 * If LI_INTERRUPTIBLE, return -1 if got EINTR in poll() 2302 * If LI_INTERRUPTIBLE, return -1 if got EINTR in poll()
2303 * inside read_key, or if bb_got_signal != 0 (IOW: if signal 2303 * inside read_key and bb_got_signal became != 0,
2304 * or if bb_got_signal != 0 (IOW: if signal
2304 * arrived before poll() is reached). 2305 * arrived before poll() is reached).
2305 * 2306 *
2306 * Note: read_key sets errno to 0 on success. 2307 * Note: read_key sets errno to 0 on success.
@@ -2317,14 +2318,16 @@ static int lineedit_read_key(char *read_key_buffer, int timeout)
2317 IF_FEATURE_EDITING_WINCH(S.ok_to_redraw = 0;) 2318 IF_FEATURE_EDITING_WINCH(S.ok_to_redraw = 0;)
2318 if (errno != EINTR) 2319 if (errno != EINTR)
2319 break; 2320 break;
2321 /* It was EINTR. Repeat read_key() unless... */
2320 if (state->flags & LI_INTERRUPTIBLE) { 2322 if (state->flags & LI_INTERRUPTIBLE) {
2321 /* LI_INTERRUPTIBLE bails out on EINTR, 2323 /* LI_INTERRUPTIBLE bails out on EINTR
2322 * but nothing really guarantees that bb_got_signal 2324 * if bb_got_signal became nonzero.
2323 * is nonzero. Follow the least surprise principle: 2325 * (It may stay zero: for example, our SIGWINCH
2326 * handler does not set it. This is used for signals
2327 * which should not interrupt line editing).
2324 */ 2328 */
2325 if (bb_got_signal == 0) 2329 if (bb_got_signal != 0)
2326 bb_got_signal = 255; 2330 goto ret; /* will return -1 */
2327 goto ret;
2328 } 2331 }
2329 } 2332 }
2330 2333
diff --git a/networking/ntpd.c b/networking/ntpd.c
index 204e1d7c2..c7519b8fb 100644
--- a/networking/ntpd.c
+++ b/networking/ntpd.c
@@ -551,20 +551,21 @@ gettime1900d(void)
551 return G.cur_time; 551 return G.cur_time;
552} 552}
553 553
554static void
555d_to_tv(struct timeval *tv, double d)
556{
557 tv->tv_sec = (long)d;
558 tv->tv_usec = (d - tv->tv_sec) * 1000000;
559}
560
561static NOINLINE double 554static NOINLINE double
562lfp_to_d(l_fixedpt_t lfp) 555lfp_to_d(l_fixedpt_t lfp)
563{ 556{
564 double ret; 557 double ret;
565 lfp.int_partl = ntohl(lfp.int_partl); 558 lfp.int_partl = ntohl(lfp.int_partl);
566 lfp.fractionl = ntohl(lfp.fractionl); 559 lfp.fractionl = ntohl(lfp.fractionl);
567 ret = (double)lfp.int_partl + ((double)lfp.fractionl / UINT_MAX); 560 ret = (double)lfp.int_partl + ((double)lfp.fractionl / (1ULL << 32));
561 /*
562 * Shift timestamps before 1970 to the second NTP era (2036-2106):
563 * int_partl value of OFFSET_1900_1970 (2208988800) is interpreted as
564 * the start of year 1970 and it is the minimal representable time,
565 * all values form the sequence 2208988800..0xffffffff,0..2208988799.
566 */
567 if (lfp.int_partl < OFFSET_1900_1970)
568 ret += (double)(1ULL << 32); /* because int_partl is 32-bit wide */
568 return ret; 569 return ret;
569} 570}
570static NOINLINE double 571static NOINLINE double
@@ -573,7 +574,7 @@ sfp_to_d(s_fixedpt_t sfp)
573 double ret; 574 double ret;
574 sfp.int_parts = ntohs(sfp.int_parts); 575 sfp.int_parts = ntohs(sfp.int_parts);
575 sfp.fractions = ntohs(sfp.fractions); 576 sfp.fractions = ntohs(sfp.fractions);
576 ret = (double)sfp.int_parts + ((double)sfp.fractions / USHRT_MAX); 577 ret = (double)sfp.int_parts + ((double)sfp.fractions / (1 << 16));
577 return ret; 578 return ret;
578} 579}
579#if ENABLE_FEATURE_NTPD_SERVER 580#if ENABLE_FEATURE_NTPD_SERVER
@@ -582,8 +583,8 @@ d_to_lfp(l_fixedpt_t *lfp, double d)
582{ 583{
583 uint32_t intl; 584 uint32_t intl;
584 uint32_t frac; 585 uint32_t frac;
585 intl = (uint32_t)d; 586 intl = (uint32_t)(time_t)d;
586 frac = (uint32_t)((d - intl) * UINT_MAX); 587 frac = (uint32_t)((d - (time_t)d) * 0xffffffff);
587 lfp->int_partl = htonl(intl); 588 lfp->int_partl = htonl(intl);
588 lfp->fractionl = htonl(frac); 589 lfp->fractionl = htonl(frac);
589} 590}
@@ -593,7 +594,7 @@ d_to_sfp(s_fixedpt_t *sfp, double d)
593 uint16_t ints; 594 uint16_t ints;
594 uint16_t frac; 595 uint16_t frac;
595 ints = (uint16_t)d; 596 ints = (uint16_t)d;
596 frac = (uint16_t)((d - ints) * USHRT_MAX); 597 frac = (uint16_t)((d - ints) * 0xffff);
597 sfp->int_parts = htons(ints); 598 sfp->int_parts = htons(ints);
598 sfp->fractions = htons(frac); 599 sfp->fractions = htons(frac);
599} 600}
@@ -1036,8 +1037,17 @@ step_time(double offset)
1036 time_t tval; 1037 time_t tval;
1037 1038
1038 xgettimeofday(&tvc); 1039 xgettimeofday(&tvc);
1040 /* This code adds floating point value on the order of 1.0
1041 * to a value of ~4 billion (as of years 203x).
1042 * With 52-bit mantissa, "only" 20 bits of offset's precision
1043 * are used (~1 microsecond), the rest is lost.
1044 * Some 200 billion years later, when tvc.tv_sec would have
1045 * 63 significant bits, the precision loss would be catastrophic,
1046 * a more complex code would be needed.
1047 */
1039 dtime = tvc.tv_sec + (1.0e-6 * tvc.tv_usec) + offset; 1048 dtime = tvc.tv_sec + (1.0e-6 * tvc.tv_usec) + offset;
1040 d_to_tv(&tvn, dtime); 1049 tvn.tv_sec = (time_t)dtime;
1050 tvn.tv_usec = (dtime - tvn.tv_sec) * 1000000;
1041 xsettimeofday(&tvn); 1051 xsettimeofday(&tvn);
1042 1052
1043 VERB2 { 1053 VERB2 {
diff --git a/procps/nmeter.c b/procps/nmeter.c
index 68e6f3325..e52c868df 100644
--- a/procps/nmeter.c
+++ b/procps/nmeter.c
@@ -59,9 +59,9 @@
59 59
60typedef unsigned long long ullong; 60typedef unsigned long long ullong;
61 61
62enum { /* Preferably use powers of 2 */ 62enum {
63 PROC_MIN_FILE_SIZE = 256, 63 PROC_MIN_FILE_SIZE = 256,
64 PROC_MAX_FILE_SIZE = 16 * 1024, 64 PROC_MAX_FILE_SIZE = 64 * 1024, /* 16k was a bit too small for a 128-CPU machine */
65}; 65};
66 66
67typedef struct proc_file { 67typedef struct proc_file {
@@ -176,7 +176,10 @@ static void readfile_z(proc_file *pf, const char* fname)
176 close(fd); 176 close(fd);
177 if (rdsz > 0) { 177 if (rdsz > 0) {
178 if (rdsz == sz-1 && sz < PROC_MAX_FILE_SIZE) { 178 if (rdsz == sz-1 && sz < PROC_MAX_FILE_SIZE) {
179 sz *= 2; 179 if (sz < 4 * 1024)
180 sz *= 2;
181 else
182 sz += 4 * 1024;
180 buf = xrealloc(buf, sz); 183 buf = xrealloc(buf, sz);
181 goto again; 184 goto again;
182 } 185 }
diff --git a/shell/ash.c b/shell/ash.c
index 87190c453..94eb49d79 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -11769,7 +11769,8 @@ preadfd(void)
11769 again: 11769 again:
11770 /* For shell, LI_INTERRUPTIBLE is set: 11770 /* For shell, LI_INTERRUPTIBLE is set:
11771 * read_line_input will abort on either 11771 * read_line_input will abort on either
11772 * getting EINTR in poll(), or if it sees bb_got_signal != 0 11772 * getting EINTR in poll() and bb_got_signal became != 0,
11773 * or if it sees bb_got_signal != 0
11773 * (IOW: if signal arrives before poll() is reached). 11774 * (IOW: if signal arrives before poll() is reached).
11774 * Interactive testcases: 11775 * Interactive testcases:
11775 * (while kill -INT $$; do sleep 1; done) & 11776 * (while kill -INT $$; do sleep 1; done) &
diff --git a/shell/hush.c b/shell/hush.c
index d111f0cc5..e6be70078 100644
--- a/shell/hush.c
+++ b/shell/hush.c
@@ -1829,7 +1829,13 @@ static void restore_G_args(save_arg_t *sv, char **argv)
1829 * SIGQUIT: ignore 1829 * SIGQUIT: ignore
1830 * SIGTERM (interactive): ignore 1830 * SIGTERM (interactive): ignore
1831 * SIGHUP (interactive): 1831 * SIGHUP (interactive):
1832 * send SIGCONT to stopped jobs, send SIGHUP to all jobs and exit 1832 * Send SIGCONT to stopped jobs, send SIGHUP to all jobs and exit.
1833 * Kernel would do this for us ("orphaned process group" handling
1834 * according to POSIX) if we are a session leader and thus our death
1835 * frees the controlling tty, but to be bash-compatible, we also do it
1836 * for every interactive shell's death by SIGHUP.
1837 * (Also, we need to restore tty pgrp, otherwise e.g. Midnight Commander
1838 * backgrounds when hush started from it gets killed by SIGHUP).
1833 * SIGTTIN, SIGTTOU, SIGTSTP (if job control is on): ignore 1839 * SIGTTIN, SIGTTOU, SIGTSTP (if job control is on): ignore
1834 * Note that ^Z is handled not by trapping SIGTSTP, but by seeing 1840 * Note that ^Z is handled not by trapping SIGTSTP, but by seeing
1835 * that all pipe members are stopped. Try this in bash: 1841 * that all pipe members are stopped. Try this in bash:
@@ -1946,7 +1952,12 @@ static void record_pending_signo(int sig)
1946{ 1952{
1947 sigaddset(&G.pending_set, sig); 1953 sigaddset(&G.pending_set, sig);
1948#if ENABLE_FEATURE_EDITING 1954#if ENABLE_FEATURE_EDITING
1949 bb_got_signal = sig; /* for read_line_input: "we got a signal" */ 1955 if (sig != SIGCHLD
1956 || (G_traps && G_traps[SIGCHLD] && G_traps[SIGCHLD][0])
1957 /* ^^^ if SIGCHLD, interrupt line reading only if it has a trap */
1958 ) {
1959 bb_got_signal = sig; /* for read_line_input: "we got a signal" */
1960 }
1950#endif 1961#endif
1951#if ENABLE_HUSH_FAST 1962#if ENABLE_HUSH_FAST
1952 if (sig == SIGCHLD) { 1963 if (sig == SIGCHLD) {
@@ -2173,20 +2184,27 @@ static int check_and_run_traps(void)
2173 break; 2184 break;
2174#if ENABLE_HUSH_JOB 2185#if ENABLE_HUSH_JOB
2175 case SIGHUP: { 2186 case SIGHUP: {
2176//TODO: why are we doing this? ash and dash don't do this, 2187 /* if (G_interactive_fd) - no need to check, the handler
2177//they have no handler for SIGHUP at all, 2188 * is only installed if we *are* interactive */
2178//they rely on kernel to send SIGHUP+SIGCONT to orphaned process groups 2189 {
2179 struct pipe *job; 2190 /* bash compat: "Before exiting, an interactive
2180 debug_printf_exec("%s: sig:%d default SIGHUP handler\n", __func__, sig); 2191 * shell resends the SIGHUP to all jobs, running
2181 /* bash is observed to signal whole process groups, 2192 * or stopped. Stopped jobs are sent SIGCONT
2182 * not individual processes */ 2193 * to ensure that they receive the SIGHUP."
2183 for (job = G.job_list; job; job = job->next) { 2194 */
2184 if (job->pgrp <= 0) 2195 struct pipe *job;
2185 continue; 2196 debug_printf_exec("%s: sig:%d default SIGHUP handler\n", __func__, sig);
2186 debug_printf_exec("HUPing pgrp %d\n", job->pgrp); 2197 /* bash is observed to signal whole process groups,
2187 if (kill(- job->pgrp, SIGHUP) == 0) 2198 * not individual processes */
2188 kill(- job->pgrp, SIGCONT); 2199 for (job = G.job_list; job; job = job->next) {
2200 if (job->pgrp <= 0)
2201 continue;
2202 debug_printf_exec("HUPing pgrp %d\n", job->pgrp);
2203 if (kill(- job->pgrp, SIGHUP) == 0)
2204 kill(- job->pgrp, SIGCONT);
2205 }
2189 } 2206 }
2207 /* this restores tty pgrp, then kills us with SIGHUP */
2190 sigexit(SIGHUP); 2208 sigexit(SIGHUP);
2191 } 2209 }
2192#endif 2210#endif
@@ -2669,7 +2687,8 @@ static int get_user_input(struct in_str *i)
2669 } else { 2687 } else {
2670 /* For shell, LI_INTERRUPTIBLE is set: 2688 /* For shell, LI_INTERRUPTIBLE is set:
2671 * read_line_input will abort on either 2689 * read_line_input will abort on either
2672 * getting EINTR in poll(), or if it sees bb_got_signal != 0 2690 * getting EINTR in poll() and bb_got_signal became != 0,
2691 * or if it sees bb_got_signal != 0
2673 * (IOW: if signal arrives before poll() is reached). 2692 * (IOW: if signal arrives before poll() is reached).
2674 * Interactive testcases: 2693 * Interactive testcases:
2675 * (while kill -INT $$; do sleep 1; done) & 2694 * (while kill -INT $$; do sleep 1; done) &