afpd_LDADD = \
$(top_builddir)/libatalk/cnid/libcnid.la \
$(top_builddir)/libatalk/libatalk.la \
+ $(top_builddir)/libevent/libevent.la \
@QUOTA_LIBS@ @SLP_LIBS@ @WRAP_LIBS@ @LIBADD_DL@ @ACL_LIBS@ @ZEROCONF_LIBS@ @PTHREAD_LIBS@
-afpd_LDFLAGS = -export-dynamic
+afpd_LDFLAGS = -export-dynamic -static
afpd_CFLAGS = \
-I$(top_srcdir)/include \
#include <stdlib.h>
#include <string.h>
#include <signal.h>
-
#include <sys/param.h>
#include <sys/uio.h>
-#include <atalk/logger.h>
#include <sys/time.h>
#include <sys/socket.h>
-
#include <errno.h>
+#include <atalk/logger.h>
#include <atalk/adouble.h>
-
#include <netatalk/at.h>
#include <atalk/compat.h>
#include <atalk/dsi.h>
#include <atalk/util.h>
#include <atalk/server_child.h>
#include <atalk/server_ipc.h>
+#include <atalk/errchk.h>
+#include <atalk/locking.h>
+
+#include "event2/event.h"
+#include "event2/http.h"
+#include "event2/rpc.h"
#include "globals.h"
#include "afp_config.h"
unsigned char nologin = 0;
struct afp_options default_options;
+
static AFPConfig *configs;
static server_child *server_children;
static fd_set save_rfds;
}
pthread_sigmask(SIG_UNBLOCK, &sigs, NULL);
- /* Register CNID */
+ /* Initialize */
cnid_init();
-
+ if (rpc_init("127.0.0.1", 4701) != 0)
+ afp_exit(EXITERR_SYS);
+
/* watch atp, dsi sockets and ipc parent/child file descriptor. */
if ((ipc = server_ipc_create())) {
Ipc_fd = server_ipc_parent(ipc);
#include <atalk/logger.h>
#include <atalk/paths.h>
#include <atalk/util.h>
+#include <atalk/compat.h>
#include "event2/event.h"
#include "event2/http.h"
EVRPC_REQUEST_DONE(rpc);
}
+static void ev_log_cb(int severity, const char *msg)
+{
+ LOG(log_warning, logtype_default, (char *)msg);
+}
+
static int rpc_setup(const char *addr, uint16_t port)
{
eventbase = event_base_new();
-
+ event_set_log_callback(ev_log_cb);
+
if ((http = evhttp_new(eventbase)) == NULL) {
LOG(log_error, logtype_default, "rpc_setup: error in evhttp_new: %s", strerror(errno));
return -1;
evrpc_free(rpcbase);
}
-int main(int ac, char **av)
+int main(int argc, char **argv)
{
int ret;
/* Default log setup: log to syslog */
set_processname("netalockd");
- setuplog("default log_note");
/* Check lockfile and daemonize */
switch(server_lock("netalockd", _PATH_NETALOCKD_LOCK, 0)) {
exit(0);
}
+ char c;
+ static char logconfig[MAXPATHLEN + 21 + 1] = "default log_note";
+ char *loglevel, *logfile;
+ while ((c = getopt(argc, argv, "l:f:")) != -1 ) {
+ switch (c) {
+ case 'l':
+ loglevel = strdup(optarg);
+ break;
+ case 'f':
+ logfile = strdup(optarg);
+ break;
+ }
+ }
+
+ /* Setup logging */
+ if (loglevel) {
+ strlcpy(logconfig + 8, loglevel, 13);
+ free(loglevel);
+ strcat(logconfig, " ");
+ }
+ if (logfile) {
+ strlcat(logconfig, logfile, MAXPATHLEN);
+ free(logfile);
+ }
+ setuplog(logconfig);
+
/* Setup signal stuff */
set_signal();
afp.h \
vfs.h \
cnid.h \
+ locking.h \
logger.h \
paths.h \
unicode.h \
extern u_int16_t ad_openforks (struct adouble * /*adp*/, u_int16_t);
extern int ad_excl_lock (struct adouble * /*adp*/, const u_int32_t /*eid*/);
+#if 0
#define ad_lock ad_fcntl_lock
#define ad_tmplock ad_fcntl_tmplock
#define ad_unlock ad_fcntl_unlock
+#endif
+
+#define ad_lock rpc_lock
+#define ad_tmplock rpc_tmplock
+#define ad_unlock rpc_unlock
+
/* ad_open.c */
extern const char *oflags2logstr(int oflags);
--- /dev/null
+/*
+ * Copyright (c) 2010 Frank Lahm
+ * All Rights Reserved. See COPYRIGHT.
+ */
+
+#ifndef ATALK_LOCKING_H
+#define ATALK_LOCKING_H
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <sys/types.h>
+#include <inttypes.h>
+
+#include <atalk/adouble.h>
+#include <atalk/lockrpc.gen.h>
+
+#include "event2/event.h"
+#include "event2/http.h"
+#include "event2/rpc.h"
+
+extern int rpc_init(const char *addr, unsigned short port);
+extern int rpc_lock(struct adouble *, uint32_t eid, int type, off_t off, off_t len, int user);
+extern void rpc_unlock(struct adouble *, int user);
+extern int rpc_tmplock(struct adouble *, uint32_t eid, int type, off_t off, off_t len, int user);
+
+
+#endif /* ATALK_LOCKING_H */
tsocket/libtsocket.la \
unicode/libunicode.la \
util/libutil.la \
- vfs/libvfs.la
+ vfs/libvfs.la \
+ $(top_builddir)/libevent/libevent.la
libatalk_la_DEPENDENCIES = \
acl/libacl.la \
tsocket/libtsocket.la \
unicode/libunicode.la \
util/libutil.la \
- vfs/libvfs.la
+ vfs/libvfs.la \
+ $(top_builddir)/libevent/libevent.la
libatalk_la_LDFLAGS = -static
-static void dummy(void)
+/*
+ * Copyright (c) 2010 Frank Lahm
+ * All Rights Reserved. See COPYRIGHT.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif /* HAVE_CONFIG_H */
+
+#include <sys/queue.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+
+#include "event2/event-config.h"
+
+#include "event2/event.h"
+#include "event2/http.h"
+#include "event2/rpc.h"
+#include "event2/rpc_struct.h"
+
+#include <atalk/logger.h>
+#include <atalk/errchk.h>
+#include <atalk/locking.h>
+#include <atalk/adouble.h>
+#include <atalk/bstrlib.h>
+#include <atalk/bstradd.h>
+
+EVRPC_HEADER(lock_msg, lock_req, lock_rep)
+EVRPC_GENERATE(lock_msg, lock_req, lock_rep)
+
+static struct evrpc_pool *rpc_pool;
+static struct event_base *ev_base;
+
+static void ev_log_cb(int severity, const char *msg)
{
+ LOG(log_warning, logtype_default, (char *)msg);
+}
+
+static void msg_rep_cb(struct evrpc_status *status,
+ struct lock_req *req,
+ struct lock_rep *rep,
+ void *arg)
+{
+ if (status->error != EVRPC_STATUS_ERR_NONE)
+ goto done;
+
+done:
+ event_base_loopexit(ev_base, NULL);
+}
+
+static void rpc_dummy(const char *name)
+{
+ struct lock_req *lock_req = NULL;
+ struct lock_rep *lock_rep = NULL;
+
+ lock_req = lock_req_new();
+ lock_rep = lock_rep_new();
+
+ EVTAG_ASSIGN(lock_req, req_filename, name);
+
+ EVRPC_MAKE_REQUEST(lock_msg, rpc_pool, lock_req, lock_rep, msg_rep_cb, NULL);
+
+ event_base_dispatch(ev_base);
+}
+
+int rpc_lock(struct adouble *ad, uint32_t eid, int type, off_t off, off_t len, int user)
+{
+ rpc_dummy(cfrombstr(ad->ad_fullpath));
+ return 0;
+}
+
+void rpc_unlock(struct adouble *ad, int user)
+{
+ rpc_dummy(cfrombstr(ad->ad_fullpath));
+}
+
+int rpc_tmplock(struct adouble *ad, uint32_t eid, int type, off_t off, off_t len, int user)
+{
+ rpc_dummy(cfrombstr(ad->ad_fullpath));
+ return 0;
+}
+
+/**************************************************************************************
+ * Public functions
+ **************************************************************************************/
+
+int rpc_init(const char *addr, unsigned short port)
+{
+ EC_INIT;
+ struct evhttp_connection *evcon;
+
+ EC_NULL_LOG(ev_base = event_base_new());
+ event_set_log_callback(ev_log_cb);
+ EC_NULL_LOG(rpc_pool = evrpc_pool_new(ev_base));
+ EC_NULL_LOG(evcon = evhttp_connection_base_new(NULL, NULL, addr, port));
+
+ evrpc_pool_add_connection(rpc_pool, evcon);
+
+EC_CLEANUP:
+ EC_EXIT;
}