X-Git-Url: http://git.annexia.org/?a=blobdiff_plain;f=fish%2Frc.c;h=5423c22725b9f02b95cc1759425f6d2762ce3d48;hb=05fd2a60466cb7c270b60e9b93c46548acf319cd;hp=0d67a62b8003dab618d7eef37f912f00283e92b3;hpb=a86aa7d152ed996170714a3a4516eab58bf8b59d;p=libguestfs.git diff --git a/fish/rc.c b/fish/rc.c index 0d67a62..5423c22 100644 --- a/fish/rc.c +++ b/fish/rc.c @@ -34,8 +34,6 @@ #include "fish.h" #include "rc_protocol.h" -#define UNIX_PATH_MAX 108 - static void create_sockpath (pid_t pid, char *sockpath, int len, struct sockaddr_un *addr) { @@ -131,52 +129,52 @@ rc_listen (void) xdrstdio_create (&xdr, fp, XDR_DECODE); if (!xdr_guestfish_hello (&xdr, &hello)) { - fprintf (stderr, _("guestfish: protocol error: could not read 'hello' message\n")); - goto error; + fprintf (stderr, _("guestfish: protocol error: could not read 'hello' message\n")); + goto error; } if (strcmp (hello.vers, PACKAGE_VERSION) != 0) { - 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); - xdr_free ((xdrproc_t) xdr_guestfish_hello, (char *) &hello); - goto error; + 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); + xdr_free ((xdrproc_t) xdr_guestfish_hello, (char *) &hello); + goto error; } xdr_free ((xdrproc_t) xdr_guestfish_hello, (char *) &hello); while (xdr_guestfish_call (&xdr, &call)) { - /* We have to extend and NULL-terminate the argv array. */ - argc = call.args.args_len; - argv = realloc (call.args.args_val, (argc+1) * sizeof (char *)); - if (argv == NULL) { - perror ("realloc"); - exit (1); - } - call.args.args_val = argv; - argv[argc] = NULL; - - if (verbose) { - fprintf (stderr, "guestfish(%d): %s", pid, call.cmd); - for (i = 0; i < argc; ++i) - fprintf (stderr, " %s", argv[i]); - fprintf (stderr, "\n"); - } - - /* Run the command. */ - reply.r = issue_command (call.cmd, argv, NULL); - - xdr_free ((xdrproc_t) xdr_guestfish_call, (char *) &call); - - /* Send the reply. */ - xdrstdio_create (&xdr2, fp, XDR_ENCODE); - (void) xdr_guestfish_reply (&xdr2, &reply); - xdr_destroy (&xdr2); - - /* Exit on error? */ - if (call.exit_on_error && reply.r == -1) { - unlink (sockpath); - exit (1); - } + /* We have to extend and NULL-terminate the argv array. */ + argc = call.args.args_len; + argv = realloc (call.args.args_val, (argc+1) * sizeof (char *)); + if (argv == NULL) { + perror ("realloc"); + exit (1); + } + call.args.args_val = argv; + argv[argc] = NULL; + + if (verbose) { + fprintf (stderr, "guestfish(%d): %s", pid, call.cmd); + for (i = 0; i < argc; ++i) + fprintf (stderr, " %s", argv[i]); + fprintf (stderr, "\n"); + } + + /* Run the command. */ + reply.r = issue_command (call.cmd, argv, NULL); + + xdr_free ((xdrproc_t) xdr_guestfish_call, (char *) &call); + + /* Send the reply. */ + xdrstdio_create (&xdr2, fp, XDR_ENCODE); + (void) xdr_guestfish_reply (&xdr2, &reply); + xdr_destroy (&xdr2); + + /* Exit on error? */ + if (call.exit_on_error && reply.r == -1) { + unlink (sockpath); + exit (1); + } } error: @@ -192,7 +190,7 @@ rc_listen (void) /* Remote control client. */ int rc_remote (int pid, const char *cmd, int argc, char *argv[], - int exit_on_error) + int exit_on_error) { guestfish_hello hello; guestfish_call call; @@ -235,8 +233,8 @@ rc_remote (int pid, const char *cmd, int argc, char *argv[], if (!xdr_guestfish_hello (&xdr, &hello)) { fprintf (stderr, _("guestfish: protocol error: could not send initial greeting to server\n")); - fclose (fp); xdr_destroy (&xdr); + fclose (fp); return -1; } @@ -249,8 +247,8 @@ rc_remote (int pid, const char *cmd, int argc, char *argv[], call.exit_on_error = exit_on_error; if (!xdr_guestfish_call (&xdr, &call)) { fprintf (stderr, _("guestfish: protocol error: could not send initial greeting to server\n")); - fclose (fp); xdr_destroy (&xdr); + fclose (fp); return -1; } xdr_destroy (&xdr); @@ -260,13 +258,13 @@ rc_remote (int pid, const char *cmd, int argc, char *argv[], if (!xdr_guestfish_reply (&xdr, &reply)) { fprintf (stderr, _("guestfish: protocol error: could not decode reply from server\n")); - fclose (fp); xdr_destroy (&xdr); + fclose (fp); return -1; } - fclose (fp); xdr_destroy (&xdr); + fclose (fp); return reply.r; }