From: Vincent Bernat Date: Sun, 6 Jan 2013 23:24:31 +0000 (+0100) Subject: debian: provide an upstart job X-Git-Tag: 0.7.1~18 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=2591639f6f8128f53624453ed7261dc315c097f6;p=thirdparty%2Flldpd.git debian: provide an upstart job lldpd daemonization seems to confuse upstart (I think this is because it also forks the monitor process, otherwise the daemonization is pretty classic). Therefore, when we detect we are run by upstart (because of UPSTART_JOB variable), we raise the SIGSTOP signal instead of daemonizing. Upstart notices it and will resume us and consider we are ready. No more misleading fork. Also, ignore SIGHUP which is used for reload. --- diff --git a/debian/lldpd.init.d b/debian/lldpd.init.d index c2654ea6..ca5d4569 100644 --- a/debian/lldpd.init.d +++ b/debian/lldpd.init.d @@ -6,9 +6,9 @@ # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: LLDP daemon -# Description: This script controls lldpd, a 802.1ab -# implementation. lldpd also supports CDP, -# EDP and various other protocols. +# Description: lldpd is a 802.1AB implementation, a L2 network +# discovery protocol. It also supports CDP, EDP and +# various other protocols. ### END INIT INFO # Do NOT "set -e" diff --git a/debian/lldpd.upstart b/debian/lldpd.upstart new file mode 100644 index 00000000..19c85288 --- /dev/null +++ b/debian/lldpd.upstart @@ -0,0 +1,24 @@ +# lldpd - LLDP daemon +# +# lldpd is a 802.1AB implementation, a L2 network discovery +# protocol. It also supports CDP, EDP and various other protocols. + +description "LLDP daemon" + +start on net-device-up IFACE=lo +stop on runlevel [06] + +expect stop +respawn + +pre-start script + CHROOT=/var/run/lldpd + [ -d $CHROOT/etc ] || mkdir -p $CHROOT/etc + [ -f $CHROOT/etc/localtime ] || [ ! -f /etc/localtime ] || \ + cp /etc/localtime $CHROOT/etc/localtime +end script + +script + . /etc/default/lldpd + exec lldpd $DAEMON_ARGS +end script diff --git a/src/daemon/event.c b/src/daemon/event.c index 7bbebc98..1c7844a6 100644 --- a/src/daemon/event.c +++ b/src/daemon/event.c @@ -459,12 +459,10 @@ levent_init(struct lldpd *cfg) /* Signals */ log_debug("event", "register signals"); + sigignore(SIGHUP); evsignal_add(evsignal_new(cfg->g_base, SIGUSR1, levent_dump, cfg->g_base), NULL); - evsignal_add(evsignal_new(cfg->g_base, SIGHUP, - levent_stop, cfg->g_base), - NULL); evsignal_add(evsignal_new(cfg->g_base, SIGINT, levent_stop, cfg->g_base), NULL); diff --git a/src/daemon/lldpd.c b/src/daemon/lldpd.c index 1c0d81e0..3038e608 100644 --- a/src/daemon/lldpd.c +++ b/src/daemon/lldpd.c @@ -1020,6 +1020,20 @@ static const struct intint filters[] = { { -1, 0 } }; +/** + * Tell if we have been started by upstart. + */ +static int +lldpd_started_by_upstart() +{ + const char *upstartjob = getenv("UPSTART_JOB"); + if (!(upstartjob && !strcmp(upstartjob, "lldpd"))) + return 0; + log_debug("main", "running with upstart, don't fork but stop"); + raise(SIGSTOP); + return 1; +} + int lldpd_main(int argc, char *argv[]) { @@ -1191,8 +1205,8 @@ lldpd_main(int argc, char *argv[]) /* Disable SIGPIPE */ signal(SIGPIPE, SIG_IGN); - /* Detach if needed */ - if (!debug) { + /* Daemonization, unless started by upstart or debug */ + if (!lldpd_started_by_upstart() && !debug) { int pid; char *spid; log_debug("main", "daemonize");