aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2020-11-29 11:37:34 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2020-11-29 11:37:34 +0100
commitec16c030bd5527137f95a1c30e6a1f3c9054dcf7 (patch)
tree16beb4e6302936d6015230cab5e3e2a9758ed98f
parent87bd558f3f0452ed62f2686472e03a1be4a6e36d (diff)
downloadbusybox-w32-ec16c030bd5527137f95a1c30e6a1f3c9054dcf7.tar.gz
busybox-w32-ec16c030bd5527137f95a1c30e6a1f3c9054dcf7.tar.bz2
busybox-w32-ec16c030bd5527137f95a1c30e6a1f3c9054dcf7.zip
libbb: introduce and use sleep1()
function old new delta sleep1 - 9 +9 run_shutdown_and_kill_processes 97 95 -2 restore_state_and_exit 116 114 -2 reread_partition_table 67 65 -2 flush_buffer_cache 80 78 -2 chat_main 1302 1300 -2 timeout_main 310 307 -3 telnet_main 1235 1232 -3 stop_handler 86 83 -3 process_action 1078 1075 -3 nbdclient_main 1185 1182 -3 init_main 789 786 -3 getty_main 1541 1538 -3 do_time 410 407 -3 runsv_main 1682 1677 -5 pause_and_low_level_reboot 59 54 -5 inetd_main 1917 1911 -6 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 0/16 up/down: 9/-50) Total: -41 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--coreutils/timeout.c2
-rw-r--r--e2fsprogs/fsck.c2
-rw-r--r--include/libbb.h4
-rw-r--r--init/halt.c4
-rw-r--r--init/init.c12
-rw-r--r--libbb/bb_do_delay.c6
-rw-r--r--loginutils/getty.c2
-rw-r--r--miscutils/chat.c2
-rw-r--r--miscutils/hdparm.c4
-rw-r--r--networking/ifplugd.c2
-rw-r--r--networking/inetd.c4
-rw-r--r--networking/nbd-client.c2
-rw-r--r--networking/nc_bloaty.c2
-rw-r--r--networking/slattach.c2
-rw-r--r--networking/telnet.c2
-rw-r--r--runit/runsv.c4
-rw-r--r--sysklogd/logread.c2
-rw-r--r--util-linux/fdisk.c2
-rw-r--r--util-linux/mdev.c2
19 files changed, 33 insertions, 29 deletions
diff --git a/coreutils/timeout.c b/coreutils/timeout.c
index 8b7bc2eaa..2a628b71d 100644
--- a/coreutils/timeout.c
+++ b/coreutils/timeout.c
@@ -105,7 +105,7 @@ int timeout_main(int argc UNUSED_PARAM, char **argv)
105 grandchild: 105 grandchild:
106 /* Just sleep(HUGE_NUM); kill(parent) may kill wrong process! */ 106 /* Just sleep(HUGE_NUM); kill(parent) may kill wrong process! */
107 while (1) { 107 while (1) {
108 sleep(1); 108 sleep1();
109 if (--timeout <= 0) 109 if (--timeout <= 0)
110 break; 110 break;
111 if (kill(parent, 0)) { 111 if (kill(parent, 0)) {
diff --git a/e2fsprogs/fsck.c b/e2fsprogs/fsck.c
index fc53a9043..96c1e51e0 100644
--- a/e2fsprogs/fsck.c
+++ b/e2fsprogs/fsck.c
@@ -480,7 +480,7 @@ static int wait_one(int flags)
480 * time to set up the signal handler 480 * time to set up the signal handler
481 */ 481 */
482 if (inst2->start_time >= time(NULL) - 1) 482 if (inst2->start_time >= time(NULL) - 1)
483 sleep(1); 483 sleep1();
484 kill(inst2->pid, SIGUSR1); 484 kill(inst2->pid, SIGUSR1);
485 inst2->flags |= FLAG_PROGRESS; 485 inst2->flags |= FLAG_PROGRESS;
486 break; 486 break;
diff --git a/include/libbb.h b/include/libbb.h
index 6b822016e..9fa0ce90d 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -1601,11 +1601,9 @@ char *bb_simplify_path(const char *path) FAST_FUNC;
1601/* Returns ptr to NUL */ 1601/* Returns ptr to NUL */
1602char *bb_simplify_abs_path_inplace(char *path) FAST_FUNC; 1602char *bb_simplify_abs_path_inplace(char *path) FAST_FUNC;
1603 1603
1604#ifndef LOGIN_FAIL_DELAY
1605#define LOGIN_FAIL_DELAY 3
1606#endif
1607void pause_after_failed_login(void) FAST_FUNC; 1604void pause_after_failed_login(void) FAST_FUNC;
1608void bb_do_delay(int seconds) FAST_FUNC; 1605void bb_do_delay(int seconds) FAST_FUNC;
1606void sleep1(void) FAST_FUNC;
1609void change_identity(const struct passwd *pw) FAST_FUNC; 1607void change_identity(const struct passwd *pw) FAST_FUNC;
1610void run_shell(const char *shell, int loginshell, const char **args) NORETURN FAST_FUNC; 1608void run_shell(const char *shell, int loginshell, const char **args) NORETURN FAST_FUNC;
1611 1609
diff --git a/init/halt.c b/init/halt.c
index 785c38130..2070eaa4d 100644
--- a/init/halt.c
+++ b/init/halt.c
@@ -144,14 +144,14 @@ static int init_was_not_there(void)
144 */ 144 */
145#if 0 145#if 0
146 while (kill(1, 0) != 0 && --cnt >= 0) 146 while (kill(1, 0) != 0 && --cnt >= 0)
147 sleep(1); 147 sleep1();
148#endif 148#endif
149 /* ... so let's wait for some evidence a usual startup event, 149 /* ... so let's wait for some evidence a usual startup event,
150 * mounting of /proc, happened. By that time init should be ready 150 * mounting of /proc, happened. By that time init should be ready
151 * for signals. 151 * for signals.
152 */ 152 */
153 while (access("/proc/meminfo", F_OK) != 0 && --cnt >= 0) 153 while (access("/proc/meminfo", F_OK) != 0 && --cnt >= 0)
154 sleep(1); 154 sleep1();
155 155
156 /* Does it look like init wasn't there? */ 156 /* Does it look like init wasn't there? */
157 return (cnt != initial - 1); 157 return (cnt != initial - 1);
diff --git a/init/init.c b/init/init.c
index 28775a65c..efab5dcb4 100644
--- a/init/init.c
+++ b/init/init.c
@@ -736,7 +736,7 @@ static void pause_and_low_level_reboot(unsigned magic)
736 pid_t pid; 736 pid_t pid;
737 737
738 /* Allow time for last message to reach serial console, etc */ 738 /* Allow time for last message to reach serial console, etc */
739 sleep(1); 739 sleep1();
740 740
741 /* We have to fork here, since the kernel calls do_exit(EXIT_SUCCESS) 741 /* We have to fork here, since the kernel calls do_exit(EXIT_SUCCESS)
742 * in linux/kernel/sys.c, which can cause the machine to panic when 742 * in linux/kernel/sys.c, which can cause the machine to panic when
@@ -751,7 +751,7 @@ static void pause_and_low_level_reboot(unsigned magic)
751 * we would eternally sleep here - not what we want. 751 * we would eternally sleep here - not what we want.
752 */ 752 */
753 waitpid(pid, NULL, 0); 753 waitpid(pid, NULL, 0);
754 sleep(1); /* paranoia */ 754 sleep1(); /* paranoia */
755 _exit(EXIT_SUCCESS); 755 _exit(EXIT_SUCCESS);
756} 756}
757 757
@@ -768,12 +768,12 @@ static void run_shutdown_and_kill_processes(void)
768 kill(-1, SIGTERM); 768 kill(-1, SIGTERM);
769 message(L_CONSOLE, "Sent SIG%s to all processes", "TERM"); 769 message(L_CONSOLE, "Sent SIG%s to all processes", "TERM");
770 sync(); 770 sync();
771 sleep(1); 771 sleep1();
772 772
773 kill(-1, SIGKILL); 773 kill(-1, SIGKILL);
774 message(L_CONSOLE, "Sent SIG%s to all processes", "KILL"); 774 message(L_CONSOLE, "Sent SIG%s to all processes", "KILL");
775 sync(); 775 sync();
776 /*sleep(1); - callers take care about making a pause */ 776 /*sleep1(); - callers take care about making a pause */
777} 777}
778 778
779/* Signal handling by init: 779/* Signal handling by init:
@@ -904,7 +904,7 @@ static void stop_handler(int sig UNUSED_PARAM)
904 wpid = wait_any_nohang(NULL); 904 wpid = wait_any_nohang(NULL);
905 mark_terminated(wpid); 905 mark_terminated(wpid);
906 if (wpid <= 0) /* no processes exited? sleep a bit */ 906 if (wpid <= 0) /* no processes exited? sleep a bit */
907 sleep(1); 907 sleep1();
908 } 908 }
909 909
910 signal(SIGCONT, SIG_DFL); 910 signal(SIGCONT, SIG_DFL);
@@ -1209,7 +1209,7 @@ int init_main(int argc UNUSED_PARAM, char **argv)
1209 } 1209 }
1210 1210
1211 /* Don't consume all CPU time - sleep a bit */ 1211 /* Don't consume all CPU time - sleep a bit */
1212 sleep(1); 1212 sleep1();
1213 } /* while (1) */ 1213 } /* while (1) */
1214} 1214}
1215 1215
diff --git a/libbb/bb_do_delay.c b/libbb/bb_do_delay.c
index 29343305d..3a86dc2ae 100644
--- a/libbb/bb_do_delay.c
+++ b/libbb/bb_do_delay.c
@@ -28,3 +28,9 @@ void FAST_FUNC pause_after_failed_login(void)
28 sleep(LOGIN_FAIL_DELAY); 28 sleep(LOGIN_FAIL_DELAY);
29#endif 29#endif
30} 30}
31
32void FAST_FUNC sleep1(void)
33{
34 sleep(1);
35}
36
diff --git a/loginutils/getty.c b/loginutils/getty.c
index 7393a3d1c..99af72f68 100644
--- a/loginutils/getty.c
+++ b/loginutils/getty.c
@@ -434,7 +434,7 @@ static void auto_baud(void)
434 * Wait for a while, then read everything the modem has said so far and 434 * Wait for a while, then read everything the modem has said so far and
435 * try to extract the speed of the dial-in call. 435 * try to extract the speed of the dial-in call.
436 */ 436 */
437 sleep(1); 437 sleep1();
438 nread = safe_read(STDIN_FILENO, G.line_buf, sizeof(G.line_buf) - 1); 438 nread = safe_read(STDIN_FILENO, G.line_buf, sizeof(G.line_buf) - 1);
439 if (nread > 0) { 439 if (nread > 0) {
440 int speed; 440 int speed;
diff --git a/miscutils/chat.c b/miscutils/chat.c
index a04565063..a7faaf284 100644
--- a/miscutils/chat.c
+++ b/miscutils/chat.c
@@ -473,7 +473,7 @@ int chat_main(int argc UNUSED_PARAM, char **argv)
473 if ('\\' == c) { 473 if ('\\' == c) {
474 c = *++buf; 474 c = *++buf;
475 if ('d' == c) { 475 if ('d' == c) {
476 sleep(1); 476 sleep1();
477 len--; 477 len--;
478 continue; 478 continue;
479 } 479 }
diff --git a/miscutils/hdparm.c b/miscutils/hdparm.c
index d25a2466e..431a0ad96 100644
--- a/miscutils/hdparm.c
+++ b/miscutils/hdparm.c
@@ -1436,7 +1436,7 @@ static void flush_buffer_cache(/*int fd*/ void)
1436 fsync(fd); /* flush buffers */ 1436 fsync(fd); /* flush buffers */
1437 ioctl_or_warn(fd, BLKFLSBUF, NULL); /* do it again, big time */ 1437 ioctl_or_warn(fd, BLKFLSBUF, NULL); /* do it again, big time */
1438#ifdef HDIO_DRIVE_CMD 1438#ifdef HDIO_DRIVE_CMD
1439 sleep(1); 1439 sleep1();
1440 if (ioctl(fd, HDIO_DRIVE_CMD, NULL) && errno != EINVAL) { /* await completion */ 1440 if (ioctl(fd, HDIO_DRIVE_CMD, NULL) && errno != EINVAL) { /* await completion */
1441 if (ENABLE_IOCTL_HEX2STR_ERROR) /* To be coherent with ioctl_or_warn */ 1441 if (ENABLE_IOCTL_HEX2STR_ERROR) /* To be coherent with ioctl_or_warn */
1442 bb_simple_perror_msg("HDIO_DRIVE_CMD"); 1442 bb_simple_perror_msg("HDIO_DRIVE_CMD");
@@ -1511,7 +1511,7 @@ static void do_time(int cache /*,int fd*/)
1511 * NB: *small* delay. User is expected to have a clue and to not run 1511 * NB: *small* delay. User is expected to have a clue and to not run
1512 * heavy io in parallel with measurements. */ 1512 * heavy io in parallel with measurements. */
1513 sync(); 1513 sync();
1514 sleep(1); 1514 sleep1();
1515 if (cache) { /* Time cache */ 1515 if (cache) { /* Time cache */
1516 seek_to_zero(); 1516 seek_to_zero();
1517 read_big_block(buf); 1517 read_big_block(buf);
diff --git a/networking/ifplugd.c b/networking/ifplugd.c
index 0d17b7d8c..60916eae6 100644
--- a/networking/ifplugd.c
+++ b/networking/ifplugd.c
@@ -735,7 +735,7 @@ int ifplugd_main(int argc UNUSED_PARAM, char **argv)
735 delay_time += G.delay_down; 735 delay_time += G.delay_down;
736#if 0 /* if you are back in 1970... */ 736#if 0 /* if you are back in 1970... */
737 if (delay_time == 0) { 737 if (delay_time == 0) {
738 sleep(1); 738 sleep1();
739 delay_time = 1; 739 delay_time = 1;
740 } 740 }
741#endif 741#endif
diff --git a/networking/inetd.c b/networking/inetd.c
index 3cd2b11f0..44b1ac700 100644
--- a/networking/inetd.c
+++ b/networking/inetd.c
@@ -1305,7 +1305,7 @@ int inetd_main(int argc UNUSED_PARAM, char **argv)
1305 if (ready_fd_cnt < 0) { 1305 if (ready_fd_cnt < 0) {
1306 if (errno != EINTR) { 1306 if (errno != EINTR) {
1307 bb_simple_perror_msg("select"); 1307 bb_simple_perror_msg("select");
1308 sleep(1); 1308 sleep1();
1309 } 1309 }
1310 continue; 1310 continue;
1311 } 1311 }
@@ -1406,7 +1406,7 @@ int inetd_main(int argc UNUSED_PARAM, char **argv)
1406 1406
1407 if (pid < 0) { /* fork error */ 1407 if (pid < 0) { /* fork error */
1408 bb_simple_perror_msg("vfork"+1); 1408 bb_simple_perror_msg("vfork"+1);
1409 sleep(1); 1409 sleep1();
1410 restore_sigmask(&omask); 1410 restore_sigmask(&omask);
1411 maybe_close(new_udp_fd); 1411 maybe_close(new_udp_fd);
1412 maybe_close(accepted_fd); 1412 maybe_close(accepted_fd);
diff --git a/networking/nbd-client.c b/networking/nbd-client.c
index 3db3b46f9..755b42ccd 100644
--- a/networking/nbd-client.c
+++ b/networking/nbd-client.c
@@ -270,7 +270,7 @@ int nbdclient_main(int argc, char **argv)
270 close(fd); 270 close(fd);
271 break; 271 break;
272 } 272 }
273 sleep(1); 273 sleep1();
274 } 274 }
275 open(device, O_RDONLY); 275 open(device, O_RDONLY);
276 return 0; 276 return 0;
diff --git a/networking/nc_bloaty.c b/networking/nc_bloaty.c
index 88eda6b28..25b95246f 100644
--- a/networking/nc_bloaty.c
+++ b/networking/nc_bloaty.c
@@ -196,7 +196,7 @@ enum {
196/* Debug: squirt whatever message and sleep a bit so we can see it go by. */ 196/* Debug: squirt whatever message and sleep a bit so we can see it go by. */
197/* Beware: writes to stdOUT... */ 197/* Beware: writes to stdOUT... */
198#if 0 198#if 0
199#define Debug(...) do { printf(__VA_ARGS__); printf("\n"); fflush_all(); sleep(1); } while (0) 199#define Debug(...) do { printf(__VA_ARGS__); printf("\n"); fflush_all(); sleep1(); } while (0)
200#else 200#else
201#define Debug(...) do { } while (0) 201#define Debug(...) do { } while (0)
202#endif 202#endif
diff --git a/networking/slattach.c b/networking/slattach.c
index 51fbc1f49..6d2a252fc 100644
--- a/networking/slattach.c
+++ b/networking/slattach.c
@@ -76,7 +76,7 @@ static void restore_state_and_exit(int exitcode)
76 cfsetispeed(&state, B0); 76 cfsetispeed(&state, B0);
77 cfsetospeed(&state, B0); 77 cfsetospeed(&state, B0);
78 exitcode |= tcsetattr_serial_or_warn(&state); 78 exitcode |= tcsetattr_serial_or_warn(&state);
79 sleep(1); 79 sleep1();
80 80
81 /* Restore line status */ 81 /* Restore line status */
82 if (tcsetattr_serial_or_warn(&G.saved_state)) 82 if (tcsetattr_serial_or_warn(&G.saved_state))
diff --git a/networking/telnet.c b/networking/telnet.c
index 9fc85050b..19a414b30 100644
--- a/networking/telnet.c
+++ b/networking/telnet.c
@@ -673,7 +673,7 @@ int telnet_main(int argc UNUSED_PARAM, char **argv)
673 if (bb_got_signal) 673 if (bb_got_signal)
674 con_escape(); 674 con_escape();
675 else 675 else
676 sleep(1); 676 sleep1();
677 continue; 677 continue;
678 } 678 }
679 679
diff --git a/runit/runsv.c b/runit/runsv.c
index 36d85101e..7e22862cd 100644
--- a/runit/runsv.c
+++ b/runit/runsv.c
@@ -651,7 +651,7 @@ int runsv_main(int argc UNUSED_PARAM, char **argv)
651 gettimeofday_ns(&svd[0].start); 651 gettimeofday_ns(&svd[0].start);
652 update_status(&svd[0]); 652 update_status(&svd[0]);
653 if (LESS(svd[0].start.tv_sec, deadline)) 653 if (LESS(svd[0].start.tv_sec, deadline))
654 sleep(1); 654 sleep1();
655 } 655 }
656 if (haslog) { 656 if (haslog) {
657 if (child == svd[1].pid) { 657 if (child == svd[1].pid) {
@@ -664,7 +664,7 @@ int runsv_main(int argc UNUSED_PARAM, char **argv)
664 gettimeofday_ns(&svd[1].start); 664 gettimeofday_ns(&svd[1].start);
665 update_status(&svd[1]); 665 update_status(&svd[1]);
666 if (LESS(svd[1].start.tv_sec, deadline)) 666 if (LESS(svd[1].start.tv_sec, deadline))
667 sleep(1); 667 sleep1();
668 } 668 }
669 } 669 }
670 } /* for (;;) */ 670 } /* for (;;) */
diff --git a/sysklogd/logread.c b/sysklogd/logread.c
index 1e1f1347f..b52dc9cac 100644
--- a/sysklogd/logread.c
+++ b/sysklogd/logread.c
@@ -180,7 +180,7 @@ int logread_main(int argc UNUSED_PARAM, char **argv)
180 if (cur == shbuf_tail) { 180 if (cur == shbuf_tail) {
181 sem_up(log_semid); 181 sem_up(log_semid);
182 fflush_all(); 182 fflush_all();
183 sleep(1); /* TODO: replace me with a sleep_on */ 183 sleep1(); /* TODO: replace me with a sleep_on */
184 continue; 184 continue;
185 } 185 }
186 } 186 }
diff --git a/util-linux/fdisk.c b/util-linux/fdisk.c
index 0fb2e3e17..0df3ebf7d 100644
--- a/util-linux/fdisk.c
+++ b/util-linux/fdisk.c
@@ -2667,7 +2667,7 @@ reread_partition_table(int leave)
2667 /* Users with slow external USB disks on a 320MHz ARM system (year 2011) 2667 /* Users with slow external USB disks on a 320MHz ARM system (year 2011)
2668 * report that sleep is needed, otherwise BLKRRPART may fail with -EIO: 2668 * report that sleep is needed, otherwise BLKRRPART may fail with -EIO:
2669 */ 2669 */
2670 sleep(1); 2670 sleep1();
2671 i = ioctl_or_perror(dev_fd, BLKRRPART, NULL, 2671 i = ioctl_or_perror(dev_fd, BLKRRPART, NULL,
2672 "WARNING: rereading partition table " 2672 "WARNING: rereading partition table "
2673 "failed, kernel still uses old table"); 2673 "failed, kernel still uses old table");
diff --git a/util-linux/mdev.c b/util-linux/mdev.c
index 9a8c14456..ebf83d1a3 100644
--- a/util-linux/mdev.c
+++ b/util-linux/mdev.c
@@ -920,7 +920,7 @@ static void load_firmware(const char *firmware, const char *sysfs_path)
920 loading_fd = open("loading", O_WRONLY); 920 loading_fd = open("loading", O_WRONLY);
921 if (loading_fd >= 0) 921 if (loading_fd >= 0)
922 goto loading; 922 goto loading;
923 sleep(1); 923 sleep1();
924 } 924 }
925 goto out; 925 goto out;
926 926