X-Git-Url: http://git.annexia.org/?p=libguestfs.git;a=blobdiff_plain;f=fish%2Frc.c;h=a2bde4ae1cca3d999ff002d1c89ad57f7c9cd275;hp=5d64c709704ecef600672d76b189400222809fb1;hb=fab75c0337d7897d10ea5e95e47ac05eab81ace9;hpb=d5b89d36224b394391af09fba7ed0a7921175610 diff --git a/fish/rc.c b/fish/rc.c index 5d64c70..a2bde4a 100644 --- a/fish/rc.c +++ b/fish/rc.c @@ -66,7 +66,7 @@ receive_stdout (int s) cmptr = malloc (controllen); if (NULL == cmptr) { perror ("malloc"); - exit (1); + exit (EXIT_FAILURE); } } @@ -88,7 +88,7 @@ receive_stdout (int s) ssize_t n = recvmsg (s, &msg, 0); if (n < 0) { perror ("recvmsg stdout fd"); - exit (1); + exit (EXIT_FAILURE); } h = CMSG_FIRSTHDR(&msg); @@ -98,7 +98,8 @@ receive_stdout (int s) else { /* Extract the transferred file descriptor from the control data */ - int fd = *(int *)CMSG_DATA (h); + unsigned char *data = CMSG_DATA (h); + int fd = *(int *)data; /* Duplicate the received file descriptor to stdout */ dup2 (fd, STDOUT_FILENO); @@ -134,7 +135,7 @@ send_stdout (int s) cmptr = malloc (controllen); if (NULL == cmptr) { perror ("malloc"); - exit (1); + exit (EXIT_FAILURE); } } cmptr->cmsg_level = SOL_SOCKET; @@ -146,11 +147,12 @@ send_stdout (int s) msg.msg_controllen = controllen; /* Add STDOUT to the control data */ - *(int *)CMSG_DATA (cmptr) = STDOUT_FILENO; + unsigned char *data = CMSG_DATA (cmptr); + *(int *)data = STDOUT_FILENO; if (sendmsg (s, &msg, 0) != 1) { perror ("sendmsg stdout fd"); - exit (1); + exit (EXIT_FAILURE); } } @@ -175,14 +177,15 @@ rc_listen (void) char sockpath[128]; pid_t pid; struct sockaddr_un addr; - int sock, s, i; + int sock, s; + size_t i; FILE *fp; XDR xdr, xdr2; guestfish_hello hello; guestfish_call call; guestfish_reply reply; char **argv; - int argc; + size_t argc; memset (&hello, 0, sizeof hello); memset (&call, 0, sizeof call); @@ -190,12 +193,17 @@ rc_listen (void) pid = fork (); if (pid == -1) { perror ("fork"); - exit (1); + exit (EXIT_FAILURE); } if (pid > 0) { /* Parent process. */ - printf ("export GUESTFISH_PID=%d\n", pid); + + if (!remote_control_csh) + printf ("GUESTFISH_PID=%d; export GUESTFISH_PID\n", pid); + else + printf ("setenv GUESTFISH_PID %d\n", pid); + fflush (stdout); _exit (0); } @@ -215,16 +223,16 @@ rc_listen (void) sock = socket (AF_UNIX, SOCK_STREAM, 0); if (sock == -1) { perror ("socket"); - exit (1); + exit (EXIT_FAILURE); } unlink (sockpath); if (bind (sock, (struct sockaddr *) &addr, sizeof addr) == -1) { perror (sockpath); - exit (1); + exit (EXIT_FAILURE); } if (listen (sock, 4) == -1) { perror ("listen"); - exit (1); + exit (EXIT_FAILURE); } /* Now close stdout and substitute /dev/null. This is necessary @@ -248,7 +256,7 @@ rc_listen (void) goto error; } - if (strcmp (hello.vers, PACKAGE_VERSION) != 0) { + if (STRNEQ (hello.vers, PACKAGE_VERSION)) { fprintf (stderr, _("guestfish: protocol error: version mismatch, server version '%s' does not match client version '%s'. The two versions must match exactly.\n"), PACKAGE_VERSION, hello.vers); @@ -263,7 +271,7 @@ rc_listen (void) argv = realloc (call.args.args_val, (argc+1) * sizeof (char *)); if (argv == NULL) { perror ("realloc"); - exit (1); + exit (EXIT_FAILURE); } call.args.args_val = argv; argv[argc] = NULL; @@ -288,7 +296,7 @@ rc_listen (void) /* Exit on error? */ if (call.exit_on_error && reply.r == -1) { unlink (sockpath); - exit (1); + exit (EXIT_FAILURE); } } @@ -300,12 +308,12 @@ rc_listen (void) } unlink (sockpath); - exit (0); + exit (EXIT_SUCCESS); } /* Remote control client. */ int -rc_remote (int pid, const char *cmd, int argc, char *argv[], +rc_remote (int pid, const char *cmd, size_t argc, char *argv[], int exit_on_error) { guestfish_hello hello;