X-Git-Url: http://git.annexia.org/?a=blobdiff_plain;f=src%2Fguestfs.c;h=ed514dceaaa77be4011b6227338183ba448827b7;hb=fb4ec82d97f71963ea7f830cb0bc38abefcbac99;hp=61e93022d21c495c03a2b0073aadcfed5273a0de;hpb=b369fa6f91185efd4503aba4565671b8a0380d23;p=libguestfs.git diff --git a/src/guestfs.c b/src/guestfs.c index 61e9302..ed514dc 100644 --- a/src/guestfs.c +++ b/src/guestfs.c @@ -86,6 +86,12 @@ #define safe_strdup guestfs_safe_strdup //#define safe_memdup guestfs_safe_memdup +#ifdef __linux__ +#define CAN_CHECK_PEER_EUID 1 +#else +#define CAN_CHECK_PEER_EUID 0 +#endif + static void default_error_cb (guestfs_h *g, void *data, const char *msg); static int send_to_daemon (guestfs_h *g, const void *v_buf, size_t n); static int recv_from_daemon (guestfs_h *g, uint32_t *size_rtn, void **buf_rtn); @@ -100,6 +106,10 @@ static int qemu_supports (guestfs_h *g, const char *option); #define MAX(a,b) ((a)>(b)?(a):(b)) #endif +#ifdef __APPLE__ +#define xdr_uint32_t xdr_u_int32_t +#endif + /* Also in guestfsd.c */ #define GUESTFWD_ADDR "10.0.2.4" #define GUESTFWD_PORT "6666" @@ -1049,7 +1059,7 @@ guestfs__launch (guestfs_h *g) goto cleanup0; /* Choose which vmchannel implementation to use. */ - if (qemu_supports (g, "-net user")) { + if (CAN_CHECK_PEER_EUID && qemu_supports (g, "-net user")) { /* The "null vmchannel" implementation. Requires SLIRP (user mode * networking in qemu) but no other vmchannel support. The daemon * will connect back to a random port number on localhost. @@ -1247,10 +1257,12 @@ guestfs__launch (guestfs_h *g) "%s " /* (selinux) */ "%s " /* (vmchannel) */ "%s " /* (verbose) */ + "TERM=%s " /* (TERM environment variable) */ "%s", /* (append) */ g->selinux ? "selinux=1 enforcing=0" : "selinux=0", vmchannel ? vmchannel : "", g->verbose ? "guestfs_verbose=1" : "", + getenv ("TERM") ? : "linux", g->append ? g->append : ""); add_cmdline (g, "-kernel"); @@ -1277,7 +1289,7 @@ guestfs__launch (guestfs_h *g) if (dup (wfd[0]) == -1) { dup_failed: perror ("dup failed"); - _exit (1); + _exit (EXIT_FAILURE); } if (dup (rfd[1]) == -1) goto dup_failed; @@ -1297,7 +1309,7 @@ guestfs__launch (guestfs_h *g) execv (g->qemu, g->cmdline); /* Run qemu. */ perror (g->qemu); - _exit (1); + _exit (EXIT_FAILURE); } /* Parent (library). */ @@ -1329,11 +1341,11 @@ guestfs__launch (guestfs_h *g) */ for (;;) { if (kill (qemu_pid, 0) == -1) /* qemu's gone away, we aren't needed */ - _exit (0); + _exit (EXIT_SUCCESS); if (kill (parent_pid, 0) == -1) { /* Parent's gone away, qemu still around, so kill qemu. */ kill (qemu_pid, 9); - _exit (0); + _exit (EXIT_SUCCESS); } sleep (2); } @@ -1393,6 +1405,7 @@ guestfs__launch (guestfs_h *g) "libguestfs: warning: unexpected connection from UID %d to port %d\n", uid, null_vmchannel_sock); close (sock); + sock = -1; continue; } } @@ -1733,6 +1746,7 @@ is_openable (guestfs_h *g, const char *path, int flags) static int check_peer_euid (guestfs_h *g, int sock, uid_t *rtn) { +#if CAN_CHECK_PEER_EUID struct sockaddr_in peer; socklen_t addrlen = sizeof peer; @@ -1801,6 +1815,12 @@ check_peer_euid (guestfs_h *g, int sock, uid_t *rtn) error (g, "check_peer_euid: no matching TCP connection found in /proc/net/tcp"); fclose (fp); return -1; +#else /* !CAN_CHECK_PEER_EUID */ + /* This function exists but should never be called in this + * configuration. + */ + abort (); +#endif /* !CAN_CHECK_PEER_EUID */ } /* You had to call this function after launch in versions <= 1.0.70,