From: Benjamin Marzinski Date: Sun, 18 Jan 2009 22:44:51 +0000 (+0100) Subject: [lib] plug fd leak in callout error path and and error messages X-Git-Tag: 0.4.9~148 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b80ff7e38cd3cf32fcd8e17b6b91c4929327e963;p=platform%2Fupstream%2Fmultipath-tools.git [lib] plug fd leak in callout error path and and error messages multipathd was not releasing fds when a fork failed in execute_program. Also, the error messages from execute_program were not very helpful. This patch fixes both --- diff --git a/libmultipath/callout.c b/libmultipath/callout.c index 4dd33c5..a0f74e9 100644 --- a/libmultipath/callout.c +++ b/libmultipath/callout.c @@ -64,9 +64,10 @@ int execute_program(char *path, char *value, int len) retval = pipe(fds); - if (retval != 0) + if (retval != 0) { + condlog(0, "error creating pipe for callout: %s", strerror(errno)); return -1; - + } pid = fork(); @@ -88,9 +89,12 @@ int execute_program(char *path, char *value, int len) } retval = execv(argv[0], argv); - + condlog(0, "error execing %s : %s", argv[0], strerror(errno)); exit(-1); case -1: + condlog(0, "fork failed: %s", strerror(errno)); + close(fds[0]); + close(fds[1]); return -1; default: /* parent reads from fds[0] */ @@ -104,13 +108,16 @@ int execute_program(char *path, char *value, int len) i += count; if (i >= len-1) { + condlog(0, "not enough space for response from %s", argv[0]); retval = -1; break; } } - if (count < 0) + if (count < 0) { + condlog(0, "no response from %s", argv[0]); retval = -1; + } if (i > 0 && value[i-1] == '\n') i--; @@ -119,8 +126,18 @@ int execute_program(char *path, char *value, int len) wait(&status); close(fds[0]); - if (!WIFEXITED(status) || (WEXITSTATUS(status) != 0)) - retval = -1; + retval = -1; + if (WIFEXITED(status)) { + status = WEXITSTATUS(status); + if (status == 0) + retval = 0; + else + condlog(0, "%s exitted with %d", argv[0], status); + } + else if (WIFSIGNALED(status)) + condlog(0, "%s was terminated by signal %d", argv[0], WTERMSIG(status)); + else + condlog(0, "%s terminated abnormally", argv[0]); } return retval; }