[git commit] *: use safe_waitpid() or wait_any_nohang() where approppriate
Denys Vlasenko
vda.linux at googlemail.com
Wed Jul 30 18:02:23 UTC 2025
commit: https://git.busybox.net/busybox/commit/?id=a98b95b715359a8b002d1cb8e1f998a4afa2c73e
branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master
function old new delta
crond_main 1227 1237 +10
init_main 804 794 -10
wait_one 263 252 -11
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/2 up/down: 10/-21) Total: -11 bytes
Signed-off-by: Denys Vlasenko <vda.linux at googlemail.com>
---
e2fsprogs/fsck.c | 4 +---
init/init.c | 2 +-
miscutils/crond.c | 10 +++++++---
3 files changed, 9 insertions(+), 7 deletions(-)
diff --git a/e2fsprogs/fsck.c b/e2fsprogs/fsck.c
index fd4ea737c..f7e93497d 100644
--- a/e2fsprogs/fsck.c
+++ b/e2fsprogs/fsck.c
@@ -423,13 +423,11 @@ static int wait_one(int flags)
/* if (G.noexecute) { already returned -1; } */
while (1) {
- pid = waitpid(-1, &status, flags);
+ pid = safe_waitpid(-1, &status, flags);
kill_all_if_got_signal();
if (pid == 0) /* flags == WNOHANG and no children exited */
return -1;
if (pid < 0) {
- if (errno == EINTR)
- continue;
if (errno == ECHILD) { /* paranoia */
bb_simple_error_msg("wait: no more children");
return -1;
diff --git a/init/init.c b/init/init.c
index 797e0a0eb..294be9952 100644
--- a/init/init.c
+++ b/init/init.c
@@ -1201,7 +1201,7 @@ int init_main(int argc UNUSED_PARAM, char **argv)
int status;
struct init_action *a;
- wpid = waitpid(-1, &status, WNOHANG);
+ wpid = wait_any_nohang(&status);
if (wpid <= 0)
break;
diff --git a/miscutils/crond.c b/miscutils/crond.c
index b29745576..6a384fdfb 100644
--- a/miscutils/crond.c
+++ b/miscutils/crond.c
@@ -989,7 +989,7 @@ static int check_completions(void)
if (line->cl_pid <= 0)
continue;
- r = waitpid(line->cl_pid, NULL, WNOHANG);
+ r = safe_waitpid(line->cl_pid, NULL, WNOHANG);
if (r < 0 || r == line->cl_pid) {
process_finished_job(file->cf_username, line);
if (line->cl_pid == 0) {
@@ -1002,8 +1002,12 @@ static int check_completions(void)
file->cf_has_running = 1;
}
- /* Reap any other children we don't actively track */
- while (waitpid(-1, NULL, WNOHANG) > 0);
+ /* Reap any other children we don't actively track.
+ * Reportedly, some people run crond as init process!
+ * Thus, we need to reap orphans, like init does.
+ */
+ while (wait_any_nohang(NULL) > 0)
+ continue;
//FIXME: if !file->cf_has_running && file->deleted: delete it!
//otherwise deleted entries will stay forever, right?
More information about the busybox-cvs
mailing list