]> git.ipfire.org Git - thirdparty/lldpd.git/commitdiff
debian: provide an upstart job
authorVincent Bernat <bernat@luffy.cx>
Sun, 6 Jan 2013 23:24:31 +0000 (00:24 +0100)
committerVincent Bernat <bernat@luffy.cx>
Sun, 6 Jan 2013 23:33:04 +0000 (00:33 +0100)
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.

debian/lldpd.init.d
debian/lldpd.upstart [new file with mode: 0644]
src/daemon/event.c
src/daemon/lldpd.c

index c2654ea6b4153a033c27f2058f2bb9924ac8b108..ca5d4569c9922f532868788a47bb9afcbf4a931b 100644 (file)
@@ -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 (file)
index 0000000..19c8528
--- /dev/null
@@ -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
index 7bbebc98c5af07515bd9a8464fd751fc2c5d2f3c..1c7844a6f4adf262adc2ee57dc5761fe649d830a 100644 (file)
@@ -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);
index 1c0d81e0f3b45cb05d6a2433fe93c2963e0b3da5..3038e60827685e774e1db60d969060513aa19bc2 100644 (file)
@@ -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");