X-Git-Url: http://git.annexia.org/?p=libguestfs.git;a=blobdiff_plain;f=daemon%2Fguestfsd.c;h=067c91659b79b6105d434ff162c7e9bc59c06f03;hp=61a62368a0c5731fbb14c55ecc98af59a7f90baa;hb=c372c7c23a298a940b8a0868396ef2ae0d824e4d;hpb=627f89351d06e43564b47ea42cabaa522284c2a1 diff --git a/daemon/guestfsd.c b/daemon/guestfsd.c index 61a6236..067c916 100644 --- a/daemon/guestfsd.c +++ b/daemon/guestfsd.c @@ -27,15 +27,27 @@ #include #include #include -#include #include -#include #include -#include #include #include #include + +#ifdef HAVE_NETDB_H +#include +#endif + +#ifdef HAVE_SYS_SELECT_H +#include +#endif + +#ifdef HAVE_SYS_WAIT_H +#include +#endif + +#ifdef HAVE_PRINTF_H #include +#endif #include "c-ctype.h" #include "ignore-value.h" @@ -121,17 +133,17 @@ main (int argc, char *argv[]) case '?': usage (); - exit (0); + exit (EXIT_SUCCESS); default: fprintf (stderr, "guestfsd: unexpected command line option 0x%x\n", c); - exit (1); + exit (EXIT_FAILURE); } } if (optind < argc) { usage (); - exit (1); + exit (EXIT_FAILURE); } cmdline = read_cmdline (); @@ -190,7 +202,7 @@ main (int argc, char *argv[]) vmchannel = strndup (p + 18, len); if (!vmchannel) { perror ("strndup"); - exit (1); + exit (EXIT_FAILURE); } } @@ -204,7 +216,7 @@ main (int argc, char *argv[]) vmchannel = strndup (p + 4, len); if (!vmchannel) { perror ("strndup"); - exit (1); + exit (EXIT_FAILURE); } memcpy (vmchannel, "tcp:", 4); } @@ -216,7 +228,7 @@ main (int argc, char *argv[]) vmchannel = strdup ("tcp:" GUESTFWD_ADDR ":" GUESTFWD_PORT); if (!vmchannel) { perror ("strdup"); - exit (1); + exit (EXIT_FAILURE); } } @@ -226,7 +238,7 @@ main (int argc, char *argv[]) /* Connect to vmchannel. */ int sock = -1; - if (strncmp (vmchannel, "tcp:", 4) == 0) { + if (STREQLEN (vmchannel, "tcp:", 4)) { /* Resolve the hostname. */ struct addrinfo *res, *rr; struct addrinfo hints; @@ -241,7 +253,7 @@ main (int argc, char *argv[]) } else { fprintf (stderr, "vmchannel: expecting \"tcp::\": %s\n", vmchannel); - exit (1); + exit (EXIT_FAILURE); } memset (&hints, 0, sizeof hints); @@ -251,7 +263,7 @@ main (int argc, char *argv[]) if (r != 0) { fprintf (stderr, "%s:%s: %s\n", host, port, gai_strerror (r)); - exit (1); + exit (EXIT_FAILURE); } /* Connect to the given TCP socket. */ @@ -272,7 +284,7 @@ main (int argc, char *argv[]) "unknown vmchannel connection type: %s\n" "expecting \"tcp::\"\n", vmchannel); - exit (1); + exit (EXIT_FAILURE); } if (sock == -1) { @@ -291,7 +303,7 @@ main (int argc, char *argv[]) "or on the libguestfs redhat com mailing list.\n" "\n", vmchannel); - exit (1); + exit (EXIT_FAILURE); } /* Send the magic length message which indicates that @@ -304,7 +316,7 @@ main (int argc, char *argv[]) xdr_uint32_t (&xdr, &len); if (xwrite (sock, lenbuf, sizeof lenbuf) == -1) - exit (1); + exit (EXIT_FAILURE); xdr_destroy (&xdr); @@ -312,14 +324,14 @@ main (int argc, char *argv[]) if (!dont_fork) { if (daemon (0, 1) == -1) { perror ("daemon"); - exit (1); + exit (EXIT_FAILURE); } } /* Enter the main loop, reading and performing actions. */ main_loop (sock); - exit (0); + exit (EXIT_SUCCESS); } /* Read /proc/cmdline. */ @@ -831,7 +843,7 @@ split_lines (char *str) int size = 0, alloc = 0; char *p, *pend; - if (strcmp (str, "") == 0) + if (STREQ (str, "")) goto empty_list; p = str; @@ -976,5 +988,25 @@ device_name_translation (char *device, const char *func) void udev_settle (void) { - command (NULL, NULL, "/sbin/udevadm", "settle", NULL); + 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: + ; + } }