From: Richard W.M. Jones Date: Mon, 2 Jan 2012 21:00:18 +0000 (+0000) Subject: More updates to RPC. X-Git-Url: http://git.annexia.org/?a=commitdiff_plain;ds=sidebyside;h=0571e7d0a290a9c3e0f3880363d0f2dbe93fc616;p=wrappi.git More updates to RPC. --- diff --git a/daemon/Makefile.am b/daemon/Makefile.am index c44c53b..cdbc244 100644 --- a/daemon/Makefile.am +++ b/daemon/Makefile.am @@ -19,6 +19,9 @@ sbin_PROGRAMS = wrappid wrappid_SOURCES = \ ../lib/wrappi.h \ + ../lib/internal.h \ + ../lib/internal-procs.h \ + ../lib/proto-xdr.h \ wrappid.c wrappid_CFLAGS = -I../lib $(WARN_CFLAGS) $(WERROR_CFLAGS) wrappid_LDADD = ../lib/libwrappi.la diff --git a/daemon/wrappid.c b/daemon/wrappid.c index ea0f00f..4fb1f11 100644 --- a/daemon/wrappid.c +++ b/daemon/wrappid.c @@ -20,26 +20,95 @@ #include #include +#include #include "wrappi.h" +/* XXX XDR code should be in its own mini-library. + * OR we should export a way to serialize function calls. + */ +#include "internal.h" + static void main_loop (void); +static wrap_h *w; + int main (int argc, char *argv[]) { /* Command line XXX */ + w = wrap_create (); + if (!w) { + fprintf (stderr, "could not allocate wrappi handle\n"); + exit (EXIT_FAILURE); + } + + wrap_connect (w); + if (wrap_error (w)) + exit (EXIT_FAILURE); + main_loop (); + + wrap_close (w); + exit (EXIT_SUCCESS); } static void main_loop (void) { - /* XXX */ + XDR xdr; + xdrproc_t xdrp_args; + xdrproc_t xdrp_ret; + struct wrap_int_message_header hdr; + struct wrap_int_message_error err; + size_t i; + + for (;;) { + /* Receive the request header. */ + xdrstdio_create (&xdr, stdin, XDR_DECODE); + memset (&hdr, 0, sizeof hdr); + if (!wrap_int_xdr_message_header (&xdr, &hdr)) { + fprintf (stderr, "error receiving request header\n"); + return; + } + + if (hdr.magic != WRAP_INT_PROTO_MAGIC) { + fprintf (stderr, "error in request: unexpected magic (%x)\n", + hdr.magic); + return; + } + if (hdr.protocol != WRAP_INT_PROTOCOL) { + fprintf (stderr, "error in request: unexpected protocol number (%d)\n", + hdr.protocol); + return; + } + if (hdr.type != WRAP_INT_PROTO_TYPE_REQUEST) { + fprintf (stderr, "error in request: unexpected type (%d)\n", + hdr.type); + return; + } + + /* Convert the proc name to the internal entry point. */ + /* XXX We're going to use gperf here, as we do in libguestfs. */ + for (i = 0; i < wrap_int_nr_procs; ++i) { + if (STREQ (wrap_int_proc_table[i].name, hdr.proc)) + goto found; + } + fprintf (stderr, "unknown proc name in request: %s\n", hdr.proc); + exit (EXIT_FAILURE); + + found: + xdrp_args = wrap_int_proc_table[i].xdr_args; + assert (xdrp_args); + xdrp_ret = wrap_int_proc_table[i].xdr_ret; + assert (xdrp_ret); + /* Receive the arguments. */ + + } } diff --git a/lib/proto-ssh.c b/lib/proto-ssh.c index 117f772..1b505f5 100644 --- a/lib/proto-ssh.c +++ b/lib/proto-ssh.c @@ -69,7 +69,7 @@ wrap_int_connect_ssh (wrap_h *w) "ssh", "-T", "-o", "BatchMode=yes", "-e", "none", w->hostname, - "sh", "-c", "cat", + "sh", "-c", /*XXX*/ "/home/rjones/d/wrappi/daemon/wrappid", NULL); perror ("ssh"); _exit (EXIT_FAILURE);