From: Vincent Bernat Date: Thu, 24 Sep 2009 08:13:27 +0000 (+0200) Subject: Use libtool convenience libraries for common files for lldpd and lldpctl. X-Git-Tag: 0.5.0~37^2~9 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=8e544ee42e4e394073795322c88b0e8e73b18ba2;p=thirdparty%2Flldpd.git Use libtool convenience libraries for common files for lldpd and lldpctl. 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. --- diff --git a/src/Makefile.am b/src/Makefile.am index 79e9d812..ac988ee2 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -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 index 00000000..8f45df67 --- /dev/null +++ b/src/ctl-server.c @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2008 Vincent Bernat + * + * 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 +#include +#include +#include +#include + +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; +} diff --git a/src/ctl.c b/src/ctl.c index 121faf1e..cba7c03e 100644 --- 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) { diff --git a/src/lldpd.h b/src/lldpd.h index e1c76679..51772413 100644 --- a/src/lldpd.h +++ b/src/lldpd.h @@ -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 *);