X-Git-Url: http://git.annexia.org/?p=libguestfs.git;a=blobdiff_plain;f=daemon%2Fguestfsd.c;h=69baf9e845010f139700927a40d3159e569200cd;hp=520a4a4de53eefb5d7fdaa0e446342a0e782888f;hb=de7ef2a0fdcbcddfd35ecb8ee2804e1ca0968454;hpb=9799810df94af7fa67dc23106b407ffed2dc0ec4 diff --git a/daemon/guestfsd.c b/daemon/guestfsd.c index 520a4a4..69baf9e 100644 --- a/daemon/guestfsd.c +++ b/daemon/guestfsd.c @@ -220,10 +220,14 @@ 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); + setenv ("TERM", "dumb", 1); #ifndef WIN32 /* We document that umask defaults to 022 (it should be this anyway). */ @@ -928,6 +932,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,35 +1060,42 @@ 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 * const 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 * 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. + * + * 'udevsettle' was the old name for this command (RHEL 5). This was + * deprecated in favour of 'udevadm settle'. The old 'udevsettle' + * command was left as a symlink. Then in Fedora 13 the old symlink + * remained but it stopped working (RHBZ#548121), so we have to be + * careful not to assume that we can use 'udevsettle' if it exists. */ void udev_settle (void) { - static int which_prog = 0; - - if (which_prog == 0) { - if (access ("/sbin/udevsettle", X_OK) == 0) - which_prog = 2; - else if (access ("/sbin/udevadm", X_OK) == 0) - which_prog = 1; - else - which_prog = 3; - } - - switch (which_prog) { - case 1: - command (NULL, NULL, "/sbin/udevadm", "settle", NULL); - break; - case 2: - command (NULL, NULL, "/sbin/udevsettle", NULL); - break; - default: - ; - } + (void) command (NULL, NULL, "udevadm", "settle", NULL); + (void) command (NULL, NULL, "udevsettle", NULL); }