X-Git-Url: http://git.annexia.org/?a=blobdiff_plain;f=daemon%2Fguestfsd.c;h=070684de81802926628d73a3496337ad441efbce;hb=ab7f296b63280d183b6574c896cab6d6cafb660a;hp=5265ab5235e2344d4bec4d3b2746d19c619cd0cc;hpb=27e73269d384814eb5f76468f609f7844cb75b0b;p=libguestfs.git diff --git a/daemon/guestfsd.c b/daemon/guestfsd.c index 5265ab5..070684d 100644 --- a/daemon/guestfsd.c +++ b/daemon/guestfsd.c @@ -55,9 +55,14 @@ static char *read_cmdline (void); -/* Also in guestfs.c */ -#define GUESTFWD_ADDR "10.0.2.4" -#define GUESTFWD_PORT "6666" +/* This is the default address we connect to for very old libraries + * which didn't specify the address and port number explicitly on the + * kernel command line. It's now recommended to always specify the + * address and port number on the command line, so this will not be + * used any more. + */ +#define OLD_GUESTFWD_ADDR "10.0.2.4" +#define OLD_GUESTFWD_PORT "6666" /* This is only a hint. If not defined, ignore it. */ #ifndef AI_ADDRCONFIG @@ -220,10 +225,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). */ @@ -281,7 +290,7 @@ main (int argc, char *argv[]) /* Default vmchannel. */ if (vmchannel == NULL) { - vmchannel = strdup ("tcp:" GUESTFWD_ADDR ":" GUESTFWD_PORT); + vmchannel = strdup ("tcp:" OLD_GUESTFWD_ADDR ":" OLD_GUESTFWD_PORT); if (!vmchannel) { perror ("strdup"); exit (EXIT_FAILURE); @@ -1056,6 +1065,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 * 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 @@ -1073,6 +1101,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); }