]> arthur.barton.de Git - netatalk.git/commitdiff
netalockd starts and listens for RPCs
authorFrank Lahm <franklahm@googlemail.com>
Mon, 24 Jan 2011 14:18:29 +0000 (15:18 +0100)
committerFrank Lahm <franklahm@googlemail.com>
Mon, 24 Jan 2011 14:18:29 +0000 (15:18 +0100)
configure.in
etc/netalockd/Makefile.am
etc/netalockd/main.c
include/atalk/.gitignore
include/atalk/Makefile.am
libatalk/Makefile.am
libatalk/rpc/.gitignore [new file with mode: 0644]
libatalk/rpc/Makefile.am [new file with mode: 0644]
libatalk/rpc/locking.c [new file with mode: 0644]
libatalk/rpc/lockrpc.rpc [new file with mode: 0644]
libatalk/util/Makefile.am

index 71655d587e1834187740f6f70251ac36081f006c..0b87ad81375dbeecfaa1f7eaac455596e875d76f 100644 (file)
@@ -1335,13 +1335,14 @@ AC_OUTPUT([Makefile
        libatalk/dsi/Makefile
        libatalk/nbp/Makefile
        libatalk/netddp/Makefile
-       libatalk/util/Makefile
+       libatalk/rpc/Makefile
        libatalk/talloc/Makefile
        libatalk/tevent/Makefile
        libatalk/tsocket/Makefile
        libatalk/tdb/Makefile
        libatalk/unicode/Makefile
        libatalk/unicode/charsets/Makefile
+       libatalk/util/Makefile
        libatalk/vfs/Makefile
        macros/Makefile
        man/Makefile
index c28827fad639f266d91044dcfb7d22fbeca3def5..9d4eb45ae7e7fec69b214d9235008e813022c049 100644 (file)
@@ -4,7 +4,7 @@ sbin_PROGRAMS = netalockd
 
 netalockd_SOURCES = main.c
 netalockd_LDADD = \
-       $(top_builddir)/libatalk/libatalk.la \
        $(top_builddir)/libevent/libevent.la \
+       $(top_builddir)/libatalk/libatalk.la \
        @PTHREAD_LIBS@
 netalockd_LDFLAGS = -static
index 518ccfb650a6b53534314b14e8b1af87b37af8e1..77a195a5f74d01d25e8fbd65d88ea981e9f108e9 100644 (file)
 #include <atalk/logger.h>
 #include <atalk/paths.h>
 #include <atalk/util.h>
-#include <atalk/tevent.h>
-#include <atalk/tsocket.h>
-
-static void sighandler(struct tevent_context *ev,
-                       struct tevent_signal *se,
-                       int signal,
-                       int count,
-                       void *siginfo,
-                       void *private_data)
+
+#include "event2/event.h"
+#include "event2/http.h"
+#include "event2/rpc.h"
+
+#include <atalk/lockrpc.gen.h>
+
+EVRPC_HEADER(lock_msg, lock_req, lock_rep)
+EVRPC_GENERATE(lock_msg, lock_req, lock_rep)
+
+struct event_base *eventbase;
+struct evrpc_base *rpcbase;
+struct evhttp *http;
+
+static void sighandler(int signal)
 {
     switch( signal ) {
 
@@ -44,17 +50,9 @@ static void sighandler(struct tevent_context *ev,
 }
 
 
-static void set_signal(struct tevent_context *event_ctx)
+static void set_signal(void)
 {
     /* catch SIGTERM, SIGINT */
-    if (tevent_add_signal(event_ctx, event_ctx, SIGTERM, 0, sighandler, NULL) == NULL) {
-        LOG(log_error, logtype_default, "failed to setup SIGTERM handler");
-        exit(EXIT_FAILURE);
-    }
-    if (tevent_add_signal(event_ctx, event_ctx, SIGINT, 0, sighandler, NULL) == NULL) {
-        LOG(log_error, logtype_default, "failed to setup SIGINT handler");
-        exit(EXIT_FAILURE);
-    }
 
     /* Log SIGBUS/SIGSEGV SBT */
     fault_setup(NULL);
@@ -93,10 +91,56 @@ static void set_signal(struct tevent_context *event_ctx)
 
 }
 
+static void lock_msg_cb(EVRPC_STRUCT(lock_msg)* rpc, void *arg _U_)
+{
+    int ret = 0;
+    char *filename;
+    struct lock_req *request = rpc->request;
+    struct lock_rep *reply = rpc->reply;
+
+    if (EVTAG_GET(request, req_filename, &filename) == -1) {
+        LOG(log_error, logtype_default, "lock_msg_cb: no filename");
+        exit(1);
+    }
+
+    LOG(log_warning, logtype_default, "lock_msg_cb(file: \"%s\")", filename);
+
+       /* we just want to fill in some non-sense */
+       EVTAG_ASSIGN(reply, result, 0);
+
+       /* no reply to the RPC */
+       EVRPC_REQUEST_DONE(rpc);
+}
+
+static int rpc_setup(const char *addr, uint16_t port)
+{
+    eventbase = event_base_new();
+    
+       if ((http = evhttp_new(eventbase)) == NULL) {
+        LOG(log_error, logtype_default, "rpc_setup: error in evhttp_new: %s", strerror(errno));
+        return -1;
+    }
+
+       if (evhttp_bind_socket(http, addr, port) != 0) {
+        LOG(log_error, logtype_default, "rpc_setup: error in evhttp_new: %s", strerror(errno));
+        return -1;
+    }
+
+    rpcbase = evrpc_init(http);
+
+    EVRPC_REGISTER(rpcbase, lock_msg, lock_req, lock_rep, lock_msg_cb, NULL);
+
+       return 0;
+}
+
+static void rpc_teardown(struct evrpc_base *rpcbase)
+{
+       EVRPC_UNREGISTER(rpcbase, lock_msg);
+       evrpc_free(rpcbase);
+}
+
 int main(int ac, char **av)
 {
-    struct tevent_context *event_ctx;
-    sigset_t sigs;
     int ret;
 
     /* Default log setup: log to syslog */
@@ -113,36 +157,23 @@ int main(int ac, char **av)
         exit(0);
     }
 
-    if ((event_ctx = tevent_context_init(talloc_autofree_context())) == NULL) {
-        LOG(log_error, logtype_default, "Error initializing event lib");
-        exit(1);
-    }
-
     /* Setup signal stuff */
-    set_signal(event_ctx);
-
-    /* Setup listening socket */
-    struct tsocket_address *addr;
-    if (tsocket_address_inet_from_strings(event_ctx,
-                                          "ip",
-                                          "localhost",
-                                          4701,
-                                          &addr) != 0) {
-        LOG(log_error, logtype_default, "Error initializing socket");
+    set_signal();
+
+    /* Start listening */
+    if (rpc_setup("127.0.0.1", 4701) != 0) {
+        LOG(log_error, logtype_default, "main: rpc setup error");
         exit(1);
     }
-#if 0
-    ssize_t tsocket_address_bsd_sockaddr(const struct tsocket_address *addr,
-                                         struct sockaddr *sa,
-                                         size_t sa_socklen)
-#endif
 
     LOG(log_warning, logtype_default, "Running...");
 
     /* wait for events - this is where we sit for most of our life */
-    tevent_loop_wait(event_ctx);
+    event_base_dispatch(eventbase);
 
-    talloc_free(event_ctx);
+exit:
+    rpc_teardown(rpcbase);
+    evhttp_free(http);
 
     return 0;
 }
index 895a5e778b39b68094b7bf7771c67cf63c08dec9..4ee8385436cbec5213219bccb5d72809e7b024c4 100644 (file)
@@ -1,4 +1,4 @@
 Makefile
 Makefile.in
-.gitignore
 *.o
+lockrpc.gen.h
\ No newline at end of file
index 89b55f26900715bb7b177061a6a162d92f553718..57bf12137d5f76c26990b88016b577f3bc77a63a 100644 (file)
@@ -49,3 +49,10 @@ noinst_HEADERS = \
        dsi.h \
        ldapconfig.h \
        list.h
+
+BUILT_SOURCES = lockrpc.gen.h
+EXTRADIST = lockrpc.gen.h
+lockrpc.gen.h: $(top_srcdir)/libevent/event_rpcgen.py $(top_srcdir)/libatalk/rpc/lockrpc.rpc
+       cd $(top_srcdir)/libatalk/rpc/ \
+               && $(top_srcdir)/libevent/event_rpcgen.py lockrpc.rpc \
+               && mv lockrpc.gen.h $(top_srcdir)/include/atalk
\ No newline at end of file
index 4d5cdc030365067edda84ba592d251fa48cc53fd..52a5516983acedb5c3b2ad701fa7040318631b00 100644 (file)
@@ -1,7 +1,7 @@
 
 # Makefile.am for libatalk/
 
-SUBDIRS = acl adouble bstring compat cnid dsi talloc tdb tevent tsocket util unicode vfs
+SUBDIRS = acl adouble bstring compat cnid dsi rpc talloc tdb tevent tsocket util unicode vfs
 
 lib_LTLIBRARIES = libatalk.la
 
@@ -13,12 +13,13 @@ libatalk_la_LIBADD  = \
        bstring/libbstring.la \
        compat/libcompat.la     \
        dsi/libdsi.la           \
-       util/libutil.la         \
+       rpc/librpc.la           \
        talloc/libtalloc.la \
        tdb/libtdb.la       \
        tevent/libtevent.la \
        tsocket/libtsocket.la \
        unicode/libunicode.la \
+       util/libutil.la         \
        vfs/libvfs.la
 
 libatalk_la_DEPENDENCIES = \
@@ -27,12 +28,13 @@ libatalk_la_DEPENDENCIES = \
        bstring/libbstring.la \
        compat/libcompat.la     \
        dsi/libdsi.la           \
-       util/libutil.la         \
+       rpc/librpc.la           \
        talloc/libtalloc.la \
        tdb/libtdb.la       \
        tevent/libtevent.la \
        tsocket/libtsocket.la \
        unicode/libunicode.la \
+       util/libutil.la         \
        vfs/libvfs.la
 
 libatalk_la_LDFLAGS = -static
diff --git a/libatalk/rpc/.gitignore b/libatalk/rpc/.gitignore
new file mode 100644 (file)
index 0000000..3aabdda
--- /dev/null
@@ -0,0 +1,2 @@
+lockrpc.gen.c
+lockrpc.gen.h
\ No newline at end of file
diff --git a/libatalk/rpc/Makefile.am b/libatalk/rpc/Makefile.am
new file mode 100644 (file)
index 0000000..24a1eb7
--- /dev/null
@@ -0,0 +1,11 @@
+# Makefile.am for libatalk/rpc/
+
+noinst_LTLIBRARIES = librpc.la
+
+librpc_la_SOURCES = locking.c
+nodist_librpc_la_SOURCES = lockrpc.gen.c
+BUILT_SOURCES =  lockrpc.gen.c
+EXTRADIST = lockrpc.gen.c lockrpc.rpc
+lockrpc.gen.c: lockrpc.rpc $(top_srcdir)/libevent/event_rpcgen.py
+       $(top_srcdir)/libevent/event_rpcgen.py lockrpc.rpc || echo "RPC build failure or no Python installed"
+       cp  lockrpc.gen.h $(top_srcdir)/include/atalk
\ No newline at end of file
diff --git a/libatalk/rpc/locking.c b/libatalk/rpc/locking.c
new file mode 100644 (file)
index 0000000..6c36597
--- /dev/null
@@ -0,0 +1,3 @@
+static void dummy(void)
+{
+}
diff --git a/libatalk/rpc/lockrpc.rpc b/libatalk/rpc/lockrpc.rpc
new file mode 100644 (file)
index 0000000..ba5bbb2
--- /dev/null
@@ -0,0 +1,17 @@
+struct lock_req {
+       string req_filename = 1;
+       struct[lock] req_lock = 2;
+}
+
+struct lock_rep {
+       int result = 1;
+       int64 rangestart = 2;
+}
+
+struct lock {
+       int locktype = 1; /* LT_SHAREMODE or LT_BRL (brl means UNIX byterange lock) */
+       optional int sharemode = 2;
+       optional int brl_type = 3;
+       optional int64 brl_offset = 4;
+       optional int64 brl_length = 5;
+}
index 0a5ebd68ce08aaae90e4e7abdebc43b59bc8231a..0afd6fc8e961971ddfe8b785d05c3133df64c535 100644 (file)
@@ -2,8 +2,6 @@
 
 noinst_LTLIBRARIES = libutil.la
 
-AM_CFLAGS = -I$(top_srcdir)/sys
-
 libutil_la_SOURCES = \
        atalk_addr.c    \
        bprint.c        \