diff options
author | Přemysl Janouch <p.janouch@gmail.com> | 2015-06-15 00:58:56 +0200 |
---|---|---|
committer | Přemysl Janouch <p.janouch@gmail.com> | 2015-06-15 00:58:56 +0200 |
commit | f2998db30b494d0247d302bb5f97e4e2bf70d21a (patch) | |
tree | c438984552462aa6e57223d6cab77f13d84605ef /zyklonb.c | |
parent | e34ecd6bb9cef25833bdb941ab7fc9fd67a6487f (diff) | |
download | xK-f2998db30b494d0247d302bb5f97e4e2bf70d21a.tar.gz xK-f2998db30b494d0247d302bb5f97e4e2bf70d21a.tar.xz xK-f2998db30b494d0247d302bb5f97e4e2bf70d21a.zip |
ZyklonB: factor out try_reap_plugin()
Diffstat (limited to 'zyklonb.c')
-rw-r--r-- | zyklonb.c | 55 |
1 files changed, 30 insertions, 25 deletions
@@ -1787,6 +1787,32 @@ on_plugin_death (struct plugin *plugin, int status) try_finish_quit (ctx); } +static bool +try_reap_plugin (struct bot_context *ctx) +{ + int status; + pid_t zombie = waitpid (-1, &status, WNOHANG); + + if (zombie == -1) + { + // No children to wait on + if (errno == ECHILD) + return false; + + hard_assert (errno == EINTR); + return true; + } + + if (zombie == 0) + return false; + + struct plugin *plugin = plugin_find_by_pid (ctx, zombie); + // XXX: re-exec if something has died that we don't recognize? + if (soft_assert (plugin != NULL)) + on_plugin_death (plugin, status); + return true; +} + static void on_signal_pipe_readable (const struct pollfd *fd, struct bot_context *ctx) { @@ -1803,31 +1829,10 @@ on_signal_pipe_readable (const struct pollfd *fd, struct bot_context *ctx) initiate_quit (ctx); } - // Reap all dead children (since the pipe may overflow, we ask waitpid() - // to return all the zombies it knows about). - while (true) - { - int status; - pid_t zombie = waitpid (-1, &status, WNOHANG); - - if (zombie == -1) - { - // No children to wait on - if (errno == ECHILD) - break; - - hard_assert (errno == EINTR); - continue; - } - - if (zombie == 0) - break; - - struct plugin *plugin = plugin_find_by_pid (ctx, zombie); - // XXX: re-exec if something has died that we don't recognize? - if (soft_assert (plugin != NULL)) - on_plugin_death (plugin, status); - } + // Reap all dead children (since the signal pipe may overflow etc. we run + // waitpid() in a loop to return all the zombies it knows about). + while (try_reap_plugin (ctx)) + ; } int |