Discussion:
[Libstoragemgmt-devel] [PATCH 2/2] lsmd: Fix clean_up function
Tony Asleson
2014-04-23 22:54:19 UTC
Permalink
The call to waitid was used incorrectly. The code
incorrectly used the behavior of waitpid. With this
change we will correctly cleanup all of the outstanding
exited child processes instead of just cleaning up one
process per call into this function. With this change
we get <defunct> processes cleaned up much cleaner and
it's now working as initially intended.

Signed-off-by: Tony Asleson <***@redhat.com>
---
src/lsm_daemon.c | 22 +++++++++++++++-------
1 file changed, 15 insertions(+), 7 deletions(-)

diff --git a/src/lsm_daemon.c b/src/lsm_daemon.c
index 3bbbc9d..39d2d3d 100644
--- a/src/lsm_daemon.c
+++ b/src/lsm_daemon.c
@@ -410,7 +410,7 @@ int process_plugin(void *p, char *full_name)
LIST_INSERT_HEAD((struct plugin_list*)p, item, pointers);
info("Plugin %s added\n", full_name);
} else {
- loud("strdup failed %s\n", item->file_path);
+ loud("strdup failed %s\n", full_name);
}
} else {
loud("Memory allocation failure!\n");
@@ -422,11 +422,12 @@ int process_plugin(void *p, char *full_name)
}

/**
- * Cleans up any children that have existed.
+ * Cleans up any children that have exited.
*/
void child_cleanup(void)
{
int rc;
+ int err;

do {
siginfo_t si;
@@ -434,12 +435,19 @@ void child_cleanup(void)

rc = waitid(P_ALL, 0, &si, WNOHANG|WEXITED);

- if( rc > 0 ) {
- if( si.si_code == CLD_EXITED && si.si_status != 0 ) {
- info("Plug-in process %d exited with %d\n", rc, si.si_status);
- }
- } else {
+ if( -1 == rc ) {
+ err = errno;
+ warn("Error: waitid %d - %s\n", err, strerror(err));
break;
+ } else {
+ if( 0 == rc && si.si_pid == 0 ) {
+ break;
+ } else {
+ if( si.si_code == CLD_EXITED && si.si_status != 0 ) {
+ info("Plug-in process %d exited with %d\n", si.si_pid,
+ si.si_status);
+ }
+ }
}
} while(1);
}
--
1.8.2.1
Loading...