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>
This commit is contained in:
parent
87bd558f3f
commit
ec16c030bd
@ -105,7 +105,7 @@ int timeout_main(int argc UNUSED_PARAM, char **argv)
|
|||||||
grandchild:
|
grandchild:
|
||||||
/* Just sleep(HUGE_NUM); kill(parent) may kill wrong process! */
|
/* Just sleep(HUGE_NUM); kill(parent) may kill wrong process! */
|
||||||
while (1) {
|
while (1) {
|
||||||
sleep(1);
|
sleep1();
|
||||||
if (--timeout <= 0)
|
if (--timeout <= 0)
|
||||||
break;
|
break;
|
||||||
if (kill(parent, 0)) {
|
if (kill(parent, 0)) {
|
||||||
|
@ -480,7 +480,7 @@ static int wait_one(int flags)
|
|||||||
* time to set up the signal handler
|
* time to set up the signal handler
|
||||||
*/
|
*/
|
||||||
if (inst2->start_time >= time(NULL) - 1)
|
if (inst2->start_time >= time(NULL) - 1)
|
||||||
sleep(1);
|
sleep1();
|
||||||
kill(inst2->pid, SIGUSR1);
|
kill(inst2->pid, SIGUSR1);
|
||||||
inst2->flags |= FLAG_PROGRESS;
|
inst2->flags |= FLAG_PROGRESS;
|
||||||
break;
|
break;
|
||||||
|
@ -1601,11 +1601,9 @@ char *bb_simplify_path(const char *path) FAST_FUNC;
|
|||||||
/* Returns ptr to NUL */
|
/* Returns ptr to NUL */
|
||||||
char *bb_simplify_abs_path_inplace(char *path) FAST_FUNC;
|
char *bb_simplify_abs_path_inplace(char *path) FAST_FUNC;
|
||||||
|
|
||||||
#ifndef LOGIN_FAIL_DELAY
|
|
||||||
#define LOGIN_FAIL_DELAY 3
|
|
||||||
#endif
|
|
||||||
void pause_after_failed_login(void) FAST_FUNC;
|
void pause_after_failed_login(void) FAST_FUNC;
|
||||||
void bb_do_delay(int seconds) FAST_FUNC;
|
void bb_do_delay(int seconds) FAST_FUNC;
|
||||||
|
void sleep1(void) FAST_FUNC;
|
||||||
void change_identity(const struct passwd *pw) FAST_FUNC;
|
void change_identity(const struct passwd *pw) FAST_FUNC;
|
||||||
void run_shell(const char *shell, int loginshell, const char **args) NORETURN FAST_FUNC;
|
void run_shell(const char *shell, int loginshell, const char **args) NORETURN FAST_FUNC;
|
||||||
|
|
||||||
|
@ -144,14 +144,14 @@ static int init_was_not_there(void)
|
|||||||
*/
|
*/
|
||||||
#if 0
|
#if 0
|
||||||
while (kill(1, 0) != 0 && --cnt >= 0)
|
while (kill(1, 0) != 0 && --cnt >= 0)
|
||||||
sleep(1);
|
sleep1();
|
||||||
#endif
|
#endif
|
||||||
/* ... so let's wait for some evidence a usual startup event,
|
/* ... so let's wait for some evidence a usual startup event,
|
||||||
* mounting of /proc, happened. By that time init should be ready
|
* mounting of /proc, happened. By that time init should be ready
|
||||||
* for signals.
|
* for signals.
|
||||||
*/
|
*/
|
||||||
while (access("/proc/meminfo", F_OK) != 0 && --cnt >= 0)
|
while (access("/proc/meminfo", F_OK) != 0 && --cnt >= 0)
|
||||||
sleep(1);
|
sleep1();
|
||||||
|
|
||||||
/* Does it look like init wasn't there? */
|
/* Does it look like init wasn't there? */
|
||||||
return (cnt != initial - 1);
|
return (cnt != initial - 1);
|
||||||
|
12
init/init.c
12
init/init.c
@ -736,7 +736,7 @@ static void pause_and_low_level_reboot(unsigned magic)
|
|||||||
pid_t pid;
|
pid_t pid;
|
||||||
|
|
||||||
/* Allow time for last message to reach serial console, etc */
|
/* Allow time for last message to reach serial console, etc */
|
||||||
sleep(1);
|
sleep1();
|
||||||
|
|
||||||
/* We have to fork here, since the kernel calls do_exit(EXIT_SUCCESS)
|
/* We have to fork here, since the kernel calls do_exit(EXIT_SUCCESS)
|
||||||
* in linux/kernel/sys.c, which can cause the machine to panic when
|
* 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)
|
|||||||
* we would eternally sleep here - not what we want.
|
* we would eternally sleep here - not what we want.
|
||||||
*/
|
*/
|
||||||
waitpid(pid, NULL, 0);
|
waitpid(pid, NULL, 0);
|
||||||
sleep(1); /* paranoia */
|
sleep1(); /* paranoia */
|
||||||
_exit(EXIT_SUCCESS);
|
_exit(EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -768,12 +768,12 @@ static void run_shutdown_and_kill_processes(void)
|
|||||||
kill(-1, SIGTERM);
|
kill(-1, SIGTERM);
|
||||||
message(L_CONSOLE, "Sent SIG%s to all processes", "TERM");
|
message(L_CONSOLE, "Sent SIG%s to all processes", "TERM");
|
||||||
sync();
|
sync();
|
||||||
sleep(1);
|
sleep1();
|
||||||
|
|
||||||
kill(-1, SIGKILL);
|
kill(-1, SIGKILL);
|
||||||
message(L_CONSOLE, "Sent SIG%s to all processes", "KILL");
|
message(L_CONSOLE, "Sent SIG%s to all processes", "KILL");
|
||||||
sync();
|
sync();
|
||||||
/*sleep(1); - callers take care about making a pause */
|
/*sleep1(); - callers take care about making a pause */
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Signal handling by init:
|
/* Signal handling by init:
|
||||||
@ -904,7 +904,7 @@ static void stop_handler(int sig UNUSED_PARAM)
|
|||||||
wpid = wait_any_nohang(NULL);
|
wpid = wait_any_nohang(NULL);
|
||||||
mark_terminated(wpid);
|
mark_terminated(wpid);
|
||||||
if (wpid <= 0) /* no processes exited? sleep a bit */
|
if (wpid <= 0) /* no processes exited? sleep a bit */
|
||||||
sleep(1);
|
sleep1();
|
||||||
}
|
}
|
||||||
|
|
||||||
signal(SIGCONT, SIG_DFL);
|
signal(SIGCONT, SIG_DFL);
|
||||||
@ -1209,7 +1209,7 @@ int init_main(int argc UNUSED_PARAM, char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Don't consume all CPU time - sleep a bit */
|
/* Don't consume all CPU time - sleep a bit */
|
||||||
sleep(1);
|
sleep1();
|
||||||
} /* while (1) */
|
} /* while (1) */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,3 +28,9 @@ void FAST_FUNC pause_after_failed_login(void)
|
|||||||
sleep(LOGIN_FAIL_DELAY);
|
sleep(LOGIN_FAIL_DELAY);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FAST_FUNC sleep1(void)
|
||||||
|
{
|
||||||
|
sleep(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -434,7 +434,7 @@ static void auto_baud(void)
|
|||||||
* Wait for a while, then read everything the modem has said so far and
|
* Wait for a while, then read everything the modem has said so far and
|
||||||
* try to extract the speed of the dial-in call.
|
* try to extract the speed of the dial-in call.
|
||||||
*/
|
*/
|
||||||
sleep(1);
|
sleep1();
|
||||||
nread = safe_read(STDIN_FILENO, G.line_buf, sizeof(G.line_buf) - 1);
|
nread = safe_read(STDIN_FILENO, G.line_buf, sizeof(G.line_buf) - 1);
|
||||||
if (nread > 0) {
|
if (nread > 0) {
|
||||||
int speed;
|
int speed;
|
||||||
|
@ -473,7 +473,7 @@ int chat_main(int argc UNUSED_PARAM, char **argv)
|
|||||||
if ('\\' == c) {
|
if ('\\' == c) {
|
||||||
c = *++buf;
|
c = *++buf;
|
||||||
if ('d' == c) {
|
if ('d' == c) {
|
||||||
sleep(1);
|
sleep1();
|
||||||
len--;
|
len--;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -1436,7 +1436,7 @@ static void flush_buffer_cache(/*int fd*/ void)
|
|||||||
fsync(fd); /* flush buffers */
|
fsync(fd); /* flush buffers */
|
||||||
ioctl_or_warn(fd, BLKFLSBUF, NULL); /* do it again, big time */
|
ioctl_or_warn(fd, BLKFLSBUF, NULL); /* do it again, big time */
|
||||||
#ifdef HDIO_DRIVE_CMD
|
#ifdef HDIO_DRIVE_CMD
|
||||||
sleep(1);
|
sleep1();
|
||||||
if (ioctl(fd, HDIO_DRIVE_CMD, NULL) && errno != EINVAL) { /* await completion */
|
if (ioctl(fd, HDIO_DRIVE_CMD, NULL) && errno != EINVAL) { /* await completion */
|
||||||
if (ENABLE_IOCTL_HEX2STR_ERROR) /* To be coherent with ioctl_or_warn */
|
if (ENABLE_IOCTL_HEX2STR_ERROR) /* To be coherent with ioctl_or_warn */
|
||||||
bb_simple_perror_msg("HDIO_DRIVE_CMD");
|
bb_simple_perror_msg("HDIO_DRIVE_CMD");
|
||||||
@ -1511,7 +1511,7 @@ static void do_time(int cache /*,int fd*/)
|
|||||||
* NB: *small* delay. User is expected to have a clue and to not run
|
* NB: *small* delay. User is expected to have a clue and to not run
|
||||||
* heavy io in parallel with measurements. */
|
* heavy io in parallel with measurements. */
|
||||||
sync();
|
sync();
|
||||||
sleep(1);
|
sleep1();
|
||||||
if (cache) { /* Time cache */
|
if (cache) { /* Time cache */
|
||||||
seek_to_zero();
|
seek_to_zero();
|
||||||
read_big_block(buf);
|
read_big_block(buf);
|
||||||
|
@ -735,7 +735,7 @@ int ifplugd_main(int argc UNUSED_PARAM, char **argv)
|
|||||||
delay_time += G.delay_down;
|
delay_time += G.delay_down;
|
||||||
#if 0 /* if you are back in 1970... */
|
#if 0 /* if you are back in 1970... */
|
||||||
if (delay_time == 0) {
|
if (delay_time == 0) {
|
||||||
sleep(1);
|
sleep1();
|
||||||
delay_time = 1;
|
delay_time = 1;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -1305,7 +1305,7 @@ int inetd_main(int argc UNUSED_PARAM, char **argv)
|
|||||||
if (ready_fd_cnt < 0) {
|
if (ready_fd_cnt < 0) {
|
||||||
if (errno != EINTR) {
|
if (errno != EINTR) {
|
||||||
bb_simple_perror_msg("select");
|
bb_simple_perror_msg("select");
|
||||||
sleep(1);
|
sleep1();
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -1406,7 +1406,7 @@ int inetd_main(int argc UNUSED_PARAM, char **argv)
|
|||||||
|
|
||||||
if (pid < 0) { /* fork error */
|
if (pid < 0) { /* fork error */
|
||||||
bb_simple_perror_msg("vfork"+1);
|
bb_simple_perror_msg("vfork"+1);
|
||||||
sleep(1);
|
sleep1();
|
||||||
restore_sigmask(&omask);
|
restore_sigmask(&omask);
|
||||||
maybe_close(new_udp_fd);
|
maybe_close(new_udp_fd);
|
||||||
maybe_close(accepted_fd);
|
maybe_close(accepted_fd);
|
||||||
|
@ -270,7 +270,7 @@ int nbdclient_main(int argc, char **argv)
|
|||||||
close(fd);
|
close(fd);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
sleep(1);
|
sleep1();
|
||||||
}
|
}
|
||||||
open(device, O_RDONLY);
|
open(device, O_RDONLY);
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -196,7 +196,7 @@ enum {
|
|||||||
/* Debug: squirt whatever message and sleep a bit so we can see it go by. */
|
/* Debug: squirt whatever message and sleep a bit so we can see it go by. */
|
||||||
/* Beware: writes to stdOUT... */
|
/* Beware: writes to stdOUT... */
|
||||||
#if 0
|
#if 0
|
||||||
#define Debug(...) do { printf(__VA_ARGS__); printf("\n"); fflush_all(); sleep(1); } while (0)
|
#define Debug(...) do { printf(__VA_ARGS__); printf("\n"); fflush_all(); sleep1(); } while (0)
|
||||||
#else
|
#else
|
||||||
#define Debug(...) do { } while (0)
|
#define Debug(...) do { } while (0)
|
||||||
#endif
|
#endif
|
||||||
|
@ -76,7 +76,7 @@ static void restore_state_and_exit(int exitcode)
|
|||||||
cfsetispeed(&state, B0);
|
cfsetispeed(&state, B0);
|
||||||
cfsetospeed(&state, B0);
|
cfsetospeed(&state, B0);
|
||||||
exitcode |= tcsetattr_serial_or_warn(&state);
|
exitcode |= tcsetattr_serial_or_warn(&state);
|
||||||
sleep(1);
|
sleep1();
|
||||||
|
|
||||||
/* Restore line status */
|
/* Restore line status */
|
||||||
if (tcsetattr_serial_or_warn(&G.saved_state))
|
if (tcsetattr_serial_or_warn(&G.saved_state))
|
||||||
|
@ -673,7 +673,7 @@ int telnet_main(int argc UNUSED_PARAM, char **argv)
|
|||||||
if (bb_got_signal)
|
if (bb_got_signal)
|
||||||
con_escape();
|
con_escape();
|
||||||
else
|
else
|
||||||
sleep(1);
|
sleep1();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -651,7 +651,7 @@ int runsv_main(int argc UNUSED_PARAM, char **argv)
|
|||||||
gettimeofday_ns(&svd[0].start);
|
gettimeofday_ns(&svd[0].start);
|
||||||
update_status(&svd[0]);
|
update_status(&svd[0]);
|
||||||
if (LESS(svd[0].start.tv_sec, deadline))
|
if (LESS(svd[0].start.tv_sec, deadline))
|
||||||
sleep(1);
|
sleep1();
|
||||||
}
|
}
|
||||||
if (haslog) {
|
if (haslog) {
|
||||||
if (child == svd[1].pid) {
|
if (child == svd[1].pid) {
|
||||||
@ -664,7 +664,7 @@ int runsv_main(int argc UNUSED_PARAM, char **argv)
|
|||||||
gettimeofday_ns(&svd[1].start);
|
gettimeofday_ns(&svd[1].start);
|
||||||
update_status(&svd[1]);
|
update_status(&svd[1]);
|
||||||
if (LESS(svd[1].start.tv_sec, deadline))
|
if (LESS(svd[1].start.tv_sec, deadline))
|
||||||
sleep(1);
|
sleep1();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} /* for (;;) */
|
} /* for (;;) */
|
||||||
|
@ -180,7 +180,7 @@ int logread_main(int argc UNUSED_PARAM, char **argv)
|
|||||||
if (cur == shbuf_tail) {
|
if (cur == shbuf_tail) {
|
||||||
sem_up(log_semid);
|
sem_up(log_semid);
|
||||||
fflush_all();
|
fflush_all();
|
||||||
sleep(1); /* TODO: replace me with a sleep_on */
|
sleep1(); /* TODO: replace me with a sleep_on */
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2667,7 +2667,7 @@ reread_partition_table(int leave)
|
|||||||
/* Users with slow external USB disks on a 320MHz ARM system (year 2011)
|
/* Users with slow external USB disks on a 320MHz ARM system (year 2011)
|
||||||
* report that sleep is needed, otherwise BLKRRPART may fail with -EIO:
|
* report that sleep is needed, otherwise BLKRRPART may fail with -EIO:
|
||||||
*/
|
*/
|
||||||
sleep(1);
|
sleep1();
|
||||||
i = ioctl_or_perror(dev_fd, BLKRRPART, NULL,
|
i = ioctl_or_perror(dev_fd, BLKRRPART, NULL,
|
||||||
"WARNING: rereading partition table "
|
"WARNING: rereading partition table "
|
||||||
"failed, kernel still uses old table");
|
"failed, kernel still uses old table");
|
||||||
|
@ -920,7 +920,7 @@ static void load_firmware(const char *firmware, const char *sysfs_path)
|
|||||||
loading_fd = open("loading", O_WRONLY);
|
loading_fd = open("loading", O_WRONLY);
|
||||||
if (loading_fd >= 0)
|
if (loading_fd >= 0)
|
||||||
goto loading;
|
goto loading;
|
||||||
sleep(1);
|
sleep1();
|
||||||
}
|
}
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user