X-Git-Url: http://git.annexia.org/?p=libguestfs.git;a=blobdiff_plain;f=daemon%2Fguestfsd.c;h=7eabbd4710c0f7d5f26879d3475ff93aa440d68a;hp=1d740545468640f3d4ec418778eef658d72a2aad;hb=0884d8bbae6d76a603ec1385ada2938f88981c5c;hpb=f7ef94f5158cc56d7b1fb391e5907abd87dc4c3f diff --git a/daemon/guestfsd.c b/daemon/guestfsd.c index 1d74054..7eabbd4 100644 --- a/daemon/guestfsd.c +++ b/daemon/guestfsd.c @@ -32,6 +32,8 @@ #include #include #include +#include +#include #include #include @@ -158,6 +160,9 @@ main (int argc, char *argv[]) setenv ("SHELL", "/bin/sh", 1); setenv ("LANG", "C", 1); + /* We document that umask defaults to 022 (it should be this anyway). */ + umask (022); + /* Resolve the hostname. */ memset (&hints, 0, sizeof hints); hints.ai_socktype = SOCK_STREAM; @@ -451,7 +456,8 @@ commandrv (char **stdoutput, char **stderror, char * const* const argv) { int so_size = 0, se_size = 0; int so_fd[2], se_fd[2]; - int pid, r, quit, i; + pid_t pid; + int r, quit, i; fd_set rset, rset2; char buf[256]; char *p; @@ -587,7 +593,10 @@ commandrv (char **stdoutput, char **stderror, char * const* const argv) } /* Get the exit status of the command. */ - waitpid (pid, &r, 0); + if (waitpid (pid, &r, 0) != pid) { + perror ("waitpid"); + return -1; + } if (WIFEXITED (r)) { return WEXITSTATUS (r); @@ -685,3 +694,50 @@ shell_quote (char *out, int len, const char *in) return outlen; } + +/* Perform device name translation. Don't call this directly - + * use the IS_DEVICE macro. + * + * See guestfs(3) for the algorithm. + * + * We have to open the device and test for ENXIO, because + * the device nodes themselves will exist in the appliance. + */ +int +device_name_translation (char *device, const char *func) +{ + int fd; + + fd = open (device, O_RDONLY); + if (fd >= 0) { + close (fd); + return 0; + } + + if (errno != ENXIO) { + error: + reply_with_perror ("%s: %s", func, device); + return -1; + } + + /* If the name begins with "/dev/sd" then try the alternatives. */ + if (strncmp (device, "/dev/sd", 7) != 0) + goto error; + + device[5] = 'h'; /* /dev/hd (old IDE driver) */ + fd = open (device, O_RDONLY); + if (fd >= 0) { + close (fd); + return 0; + } + + device[5] = 'v'; /* /dev/vd (for virtio devices) */ + fd = open (device, O_RDONLY); + if (fd >= 0) { + close (fd); + return 0; + } + + device[5] = 's'; /* Restore original device name. */ + goto error; +}