X-Git-Url: http://git.annexia.org/?a=blobdiff_plain;f=daemon%2Fguestfsd.c;h=5c250f0184420c3c5bdd07ad53e1be64c5a3ca28;hb=22eb7fc966bafebedfde437c9b9c9fb903a8bc35;hp=7eabbd4710c0f7d5f26879d3475ff93aa440d68a;hpb=0884d8bbae6d76a603ec1385ada2938f88981c5c;p=libguestfs.git diff --git a/daemon/guestfsd.c b/daemon/guestfsd.c index 7eabbd4..5c250f0 100644 --- a/daemon/guestfsd.c +++ b/daemon/guestfsd.c @@ -1,5 +1,5 @@ /* libguestfs - the guestfsd daemon - * Copyright (C) 2009 Red Hat Inc. + * Copyright (C) 2009 Red Hat Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -47,6 +47,10 @@ static void usage (void); int verbose = 0; +/* Location to mount root device. */ +const char *sysroot = "/sysroot"; /* No trailing slash. */ +int sysroot_len = 8; + int main (int argc, char *argv[]) { @@ -221,6 +225,25 @@ main (int argc, char *argv[]) exit (0); } +/* Turn "/path" into "/sysroot/path". + * + * Caller must check for NULL and call reply_with_perror ("malloc") + * if it is. Caller must also free the string. + */ +char * +sysroot_path (const char *path) +{ + char *r; + int len = strlen (path) + sysroot_len + 1; + + r = malloc (len); + if (r == NULL) + return NULL; + + snprintf (r, len, "%s%s", sysroot, path); + return r; +} + int xwrite (int sock, const void *buf, size_t len) { @@ -572,19 +595,23 @@ commandrv (char **stdoutput, char **stderror, char * const* const argv) * trailing \n characters from the error buffer (not from stdout). */ if (stdoutput) { - *stdoutput = realloc (*stdoutput, so_size+1); - if (*stdoutput == NULL) { + void *q = realloc (*stdoutput, so_size+1); + if (q == NULL) { perror ("realloc"); - *stdoutput = NULL; - } else + free (*stdoutput); + } + *stdoutput = q; + if (*stdoutput) (*stdoutput)[so_size] = '\0'; } if (stderror) { - *stderror = realloc (*stderror, se_size+1); - if (*stderror == NULL) { + void *q = realloc (*stderror, se_size+1); + if (q == NULL) { perror ("realloc"); - *stderror = NULL; - } else { + free (*stderror); + } + *stderror = q; + if (*stderror) { (*stderror)[se_size] = '\0'; se_size--; while (se_size >= 0 && (*stderror)[se_size] == '\n') @@ -714,7 +741,7 @@ device_name_translation (char *device, const char *func) return 0; } - if (errno != ENXIO) { + if (errno != ENXIO && errno != ENOENT) { error: reply_with_perror ("%s: %s", func, device); return -1; @@ -741,3 +768,16 @@ device_name_translation (char *device, const char *func) device[5] = 's'; /* Restore original device name. */ goto error; } + +/* LVM and other commands aren't synchronous, especially when udev is + * involved. eg. You can create or remove some device, but the /dev + * device node won't appear until some time later. This means that + * you get an error if you run one command followed by another. + * Use 'udevadm settle' after certain commands, but don't be too + * fussed if it fails. + */ +void +udev_settle (void) +{ + command (NULL, NULL, "/sbin/udevadm", "settle", NULL); +}