X-Git-Url: http://git.annexia.org/?a=blobdiff_plain;f=daemon%2Fguestfsd.c;h=84b62ab58e3602aec93fc949e0aa2b5cbe4f9315;hb=9e0b31a2af26b8d58a44dd80993a5e73d4942307;hp=0fc01283901fa84156baa988bb09d67bcaec304e;hpb=5c6147ecc7ee3cf657edb1e19ad5ab4e973424e0;p=libguestfs.git diff --git a/daemon/guestfsd.c b/daemon/guestfsd.c index 0fc0128..84b62ab 100644 --- a/daemon/guestfsd.c +++ b/daemon/guestfsd.c @@ -220,8 +220,11 @@ main (int argc, char *argv[]) /* Set up a basic environment. After we are called by /init the * environment is essentially empty. * https://bugzilla.redhat.com/show_bug.cgi?id=502074#c5 + * + * NOTE: if you change $PATH, you must also change 'prog_exists' + * function below. */ - setenv ("PATH", "/usr/bin:/bin", 1); + setenv ("PATH", "/sbin:/usr/sbin:/bin:/usr/bin", 1); setenv ("SHELL", "/bin/sh", 1); setenv ("LC_ALL", "C", 1); @@ -928,6 +931,28 @@ split_lines (char *str) return lines; } +/* Skip leading and trailing whitespace, updating the original string + * in-place. + */ +void +trim (char *str) +{ + size_t len = strlen (str); + + while (len > 0 && c_isspace (str[len-1])) { + str[len-1] = '\0'; + len--; + } + + const char *p = str; + while (*p && c_isspace (*p)) { + p++; + len--; + } + + memmove (str, p, len+1); +} + /* printf helper function so we can use %Q ("quoted") and %R to print * shell-quoted strings. See HACKING file for more details. */ @@ -1034,6 +1059,25 @@ device_name_translation (char *device, const char *func) goto error; } +/* Check program exists and is executable on $PATH. Actually, we + * just assume PATH contains the default entries (see main() above). + */ +int +prog_exists (const char *prog) +{ + static const char *dirs[] = + { "/sbin", "/usr/sbin", "/bin", "/usr/bin" }; + size_t i; + char buf[1024]; + + for (i = 0; i < sizeof dirs / sizeof dirs[0]; ++i) { + snprintf (buf, sizeof buf, "%s/%s", dirs[i], prog); + if (access (buf, X_OK) == 0) + return 1; + } + return 0; +} + /* 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 @@ -1051,6 +1095,6 @@ device_name_translation (char *device, const char *func) void udev_settle (void) { - (void) command (NULL, NULL, "/sbin/udevadm", "settle", NULL); - (void) command (NULL, NULL, "/sbin/udevsettle", NULL); + (void) command (NULL, NULL, "udevadm", "settle", NULL); + (void) command (NULL, NULL, "udevsettle", NULL); }