X-Git-Url: http://git.annexia.org/?p=libguestfs.git;a=blobdiff_plain;f=daemon%2Fguestfsd.c;h=a9576836b0d7ea35339933f68cb9a8cef29888ef;hp=c3f5e82195f6f0e35f20a15e9fb2c49833b48f65;hb=2069ade88144d8efd272a74be24b5c9ff49844dc;hpb=d5151686d82b66c50935010fd5458be0e4386bab diff --git a/daemon/guestfsd.c b/daemon/guestfsd.c index c3f5e82..a957683 100644 --- a/daemon/guestfsd.c +++ b/daemon/guestfsd.c @@ -41,6 +41,8 @@ static void usage (void); #define VMCHANNEL_PORT "6666" #define VMCHANNEL_ADDR "10.0.2.4" +int verbose = 0; + int main (int argc, char *argv[]) { @@ -108,6 +110,14 @@ main (int argc, char *argv[]) fclose (fp); buf[n] = '\0'; + /* Set the verbose flag. Not quite right because this will only + * set the flag if host and port aren't set on the command line. + * Don't worry about this for now. (XXX) + */ + verbose = strstr (buf, "guestfs_verbose=1") != NULL; + if (verbose) + printf ("verbose daemon enabled\n"); + p = strstr (buf, "guestfs="); if (p) { @@ -359,10 +369,12 @@ commandv (char **stdoutput, char **stderror, char * const* const argv) if (stdoutput) *stdoutput = NULL; if (stderror) *stderror = NULL; - printf ("%s", argv[0]); - for (i = 1; argv[i] != NULL; ++i) - printf (" %s", argv[i]); - printf ("\n"); + if (verbose) { + printf ("%s", argv[0]); + for (i = 1; argv[i] != NULL; ++i) + printf (" %s", argv[i]); + printf ("\n"); + } if (pipe (so_fd) == -1 || pipe (se_fd) == -1) { perror ("pipe"); @@ -372,6 +384,10 @@ commandv (char **stdoutput, char **stderror, char * const* const argv) pid = fork (); if (pid == -1) { perror ("fork"); + close (so_fd[0]); + close (so_fd[1]); + close (se_fd[0]); + close (se_fd[1]); return -1; } @@ -403,6 +419,8 @@ commandv (char **stdoutput, char **stderror, char * const* const argv) r = select (MAX (so_fd[0], se_fd[0]) + 1, &rset2, NULL, NULL, NULL); if (r == -1) { perror ("select"); + close (so_fd[0]); + close (se_fd[0]); waitpid (pid, NULL, 0); return -1; } @@ -411,6 +429,8 @@ commandv (char **stdoutput, char **stderror, char * const* const argv) r = read (so_fd[0], buf, sizeof buf); if (r == -1) { perror ("read"); + close (so_fd[0]); + close (se_fd[0]); waitpid (pid, NULL, 0); return -1; } @@ -432,6 +452,8 @@ commandv (char **stdoutput, char **stderror, char * const* const argv) r = read (se_fd[0], buf, sizeof buf); if (r == -1) { perror ("read"); + close (so_fd[0]); + close (se_fd[0]); waitpid (pid, NULL, 0); return -1; } @@ -450,6 +472,9 @@ commandv (char **stdoutput, char **stderror, char * const* const argv) } } + close (so_fd[0]); + close (se_fd[0]); + /* Make sure the output buffers are \0-terminated. Also remove any * trailing \n characters from the error buffer (not from stdout). */