]> git.ipfire.org Git - thirdparty/lldpd.git/commitdiff
Use libtool convenience libraries for common files for lldpd and lldpctl.
authorVincent Bernat <bernat@luffy.cx>
Thu, 24 Sep 2009 08:13:27 +0000 (10:13 +0200)
committerVincent Bernat <bernat@luffy.cx>
Tue, 29 Sep 2009 14:44:58 +0000 (16:44 +0200)
Instead of directly linking common files, we use another libtool
convenience library (libcommon.la). We also separate server part of
ctl.c into a separate file to avoid -DCLIENT_ONLY flag which was
causing recompilation of most files.

We also move compatibility objects (like strcpy() function) into
libcommon.la.

src/Makefile.am
src/ctl-server.c [new file with mode: 0644]
src/ctl.c
src/lldpd.h

index 79e9d81200feb06a91db8829db61393c734c1f6c..ac988ee296b26d76f140f72f25dbe7e00f868913 100644 (file)
@@ -1,19 +1,25 @@
 sbin_PROGRAMS = lldpd lldpctl
-noinst_LTLIBRARIES = liblldpd.la
+noinst_LTLIBRARIES = liblldpd.la libcommon.la
 
-COMMON = log.c ctl.c lldpd.h lldp.h cdp.h compat.h sonmp.h edp.h
-liblldpd_la_SOURCES = frame.h frame.c lldpd.c lldp.c cdp.c sonmp.c edp.c interfaces.c client.c priv.c privsep_fdpass.c dmi.c $(COMMON)
-lldpctl_SOURCES = lldpctl.c $(COMMON)
+## Shared by all executables
+libcommon_la_SOURCES = log.c ctl.c lldpd.h lldp.h cdp.h compat.h sonmp.h edp.h
+libcommon_la_LIBADD = @LTLIBOBJS@ 
 
-liblldpd_la_LIBADD = @LTLIBOBJS@
-lldpctl_LDADD = @LIBOBJS@
-lldpctl_CFLAGS = -DCLIENT_ONLY
+## Used for lldpd and tests
+liblldpd_la_SOURCES = frame.h frame.c lldpd.c lldp.c cdp.c sonmp.c edp.c \
+       interfaces.c client.c priv.c privsep_fdpass.c dmi.c ctl-server.c
+liblldpd_la_LIBADD = libcommon.la
 
+## lldpd
 lldpd_SOURCES = main.c
 lldpd_LDADD = liblldpd.la
 
+## lldpctl
+lldpctl_SOURCES = lldpctl.c
+lldpctl_LDADD = libcommon.la
+
+## With SNMP...
 if USE_SNMP
 liblldpd_la_SOURCES += agent.c agent_priv.c
 lldpd_LDADD += @NETSNMP_LIB@
 endif
-
diff --git a/src/ctl-server.c b/src/ctl-server.c
new file mode 100644 (file)
index 0000000..8f45df6
--- /dev/null
@@ -0,0 +1,64 @@
+/*
+ * Copyright (c) 2008 Vincent Bernat <bernat@luffy.cx>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include "lldpd.h"
+
+#include <unistd.h>
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+
+static void
+ctl_callback(struct lldpd *cfg, struct lldpd_callback *callback)
+{
+       char *buffer;
+       int n;
+
+       if ((buffer = (char *)malloc(MAX_HMSGSIZE)) ==
+           NULL) {
+               LLOG_WARN("failed to alloc reception buffer");
+               return;
+       }
+       if ((n = recv(callback->fd, buffer,
+                   MAX_HMSGSIZE, 0)) == -1) {
+               LLOG_WARN("error while receiving message");
+               free(buffer);
+               return;
+       }
+       if (n > 0)
+               client_handle_client(cfg, callback, buffer, n);
+       else {
+               close(callback->fd);
+               lldpd_callback_del(cfg, callback->fd, ctl_callback);
+       }
+       free(buffer);
+}
+
+void
+ctl_accept(struct lldpd *cfg, struct lldpd_callback *callback)
+{
+       int s;
+       if ((s = accept(callback->fd, NULL, NULL)) == -1) {
+               LLOG_WARN("unable to accept connection from socket");
+               return;
+       }
+       if (lldpd_callback_add(cfg, s, ctl_callback, NULL) != 0) {
+               LLOG_WARN("unable to add callback for new client");
+               close(s);
+       }
+       return;
+}
index 121faf1e9de443d53e302e9b70e235c86cf6270c..cba7c03e403ae742f424dbff83bd4d4b3c988e27 100644 (file)
--- a/src/ctl.c
+++ b/src/ctl.c
@@ -63,49 +63,6 @@ ctl_connect(char *name)
        return s;
 }
 
-#ifndef CLIENT_ONLY
-static void
-ctl_callback(struct lldpd *cfg, struct lldpd_callback *callback)
-{
-       char *buffer;
-       int n;
-
-       if ((buffer = (char *)malloc(MAX_HMSGSIZE)) ==
-           NULL) {
-               LLOG_WARN("failed to alloc reception buffer");
-               return;
-       }
-       if ((n = recv(callback->fd, buffer,
-                   MAX_HMSGSIZE, 0)) == -1) {
-               LLOG_WARN("error while receiving message");
-               free(buffer);
-               return;
-       }
-       if (n > 0)
-               client_handle_client(cfg, callback, buffer, n);
-       else {
-               close(callback->fd);
-               lldpd_callback_del(cfg, callback->fd, ctl_callback);
-       }
-       free(buffer);
-}
-
-void
-ctl_accept(struct lldpd *cfg, struct lldpd_callback *callback)
-{
-       int s;
-       if ((s = accept(callback->fd, NULL, NULL)) == -1) {
-               LLOG_WARN("unable to accept connection from socket");
-               return;
-       }
-       if (lldpd_callback_add(cfg, s, ctl_callback, NULL) != 0) {
-               LLOG_WARN("unable to add callback for new client");
-               close(s);
-       }
-       return;
-}
-#endif
-
 void
 ctl_msg_init(struct hmsg *t, enum hmsg_type type)
 {
index e1c76679812f26aad3c1e77786c31f3f0a9d9226..51772413142102ee2a6a5a4363e28f7b736faf80 100644 (file)
@@ -384,9 +384,7 @@ int  edp_decode(PROTO_DECODE_SIG);
 int     ctl_create(char *);
 int     ctl_connect(char *);
 void    ctl_cleanup(char *);
-#ifndef CLIENT_ONLY
 void    ctl_accept(struct lldpd *, struct lldpd_callback *);
-#endif
 void    ctl_msg_init(struct hmsg *, enum hmsg_type);
 int     ctl_msg_send(int, struct hmsg *);
 int     ctl_msg_recv(int, struct hmsg *);