X-Git-Url: http://git.annexia.org/?p=libguestfs.git;a=blobdiff_plain;f=daemon%2Fguestfsd.c;h=51bb0b7341fa680b3200c53a27d2c3044b52dfef;hp=448f3b4506b91c886e06e27dc5d347c40c4fe515;hb=e2249b7ce1dd0a2f8f110e0e47aca397185a6373;hpb=4b91462bad010a0b214e808f94a916002be65b91 diff --git a/daemon/guestfsd.c b/daemon/guestfsd.c index 448f3b4..51bb0b7 100644 --- a/daemon/guestfsd.c +++ b/daemon/guestfsd.c @@ -111,6 +111,9 @@ int autosync_umount = 1; /* Not used explicitly, but required by the gnulib 'error' module. */ const char *program_name = "guestfsd"; +/* Name of the virtio-serial channel. */ +#define VIRTIO_SERIAL_CHANNEL "/dev/virtio-ports/org.libguestfs.channel.0" + static void usage (void) { @@ -237,8 +240,7 @@ main (int argc, char *argv[]) #endif /* Connect to virtio-serial channel. */ - int sock = open ("/dev/virtio-ports/org.libguestfs.channel.0", - O_RDWR | O_CLOEXEC); + int sock = open (VIRTIO_SERIAL_CHANNEL, O_RDWR | O_CLOEXEC); if (sock == -1) { fprintf (stderr, "\n" @@ -253,7 +255,7 @@ main (int argc, char *argv[]) "output to the libguestfs developers, either in a bug report\n" "or on the libguestfs redhat com mailing list.\n" "\n"); - perror ("/dev/virtio-ports/org.libguestfs.channel.0"); + perror (VIRTIO_SERIAL_CHANNEL); exit (EXIT_FAILURE); } @@ -429,6 +431,7 @@ add_string (char ***argv, int *size, int *alloc, const char *str) if (new_str == NULL) { reply_with_perror ("strdup"); free_strings (*argv); + return -1; } } else new_str = NULL; @@ -688,7 +691,7 @@ commandrvf (char **stdoutput, char **stderror, int flags, close (stdin_fd[1]); } else { /* Set stdin to /dev/null (ignore failure) */ - open ("/dev/null", O_RDONLY); + ignore_value (open ("/dev/null", O_RDONLY)); } close (so_fd[0]); close (se_fd[0]); @@ -778,8 +781,20 @@ commandrvf (char **stdoutput, char **stderror, int flags, perror ("select"); quit: - if (stdoutput) free (*stdoutput); - if (stderror) free (*stderror); + if (stdoutput) { + free (*stdoutput); + *stdoutput = NULL; + } + if (stderror) { + free (*stderror); + /* Need to return non-NULL *stderror here since most callers + * will try to print and then free the err string. + * Unfortunately recovery from strdup failure here is not + * possible. + */ + *stderror = strdup ("error running external command, " + "see debug output for details"); + } close (so_fd[0]); close (se_fd[0]); waitpid (pid, NULL, 0);