procd: service gets deleted when its last instance is freed
authorAlin Năstac <alin.nastac@gmail.com>
Mon, 27 Feb 2017 09:08:34 +0000 (10:08 +0100)
committerFelix Fietkau <nbd@nbd.name>
Sun, 5 Mar 2017 15:38:41 +0000 (16:38 +0100)
This fixes the following regression introduced in commit
961dc692aff7457f874bce61f8e766514edcf794:
 1) reboot using the following configuration
root@OpenWrt:~# uci show system.ntp
system.ntp=timeserver
system.ntp.enable_server='0'
system.ntp.use_dhcp='1'
system.ntp.dhcp_interface='wan'
root@OpenWrt:~# uci show network.wan
network.wan=interface
network.wan.proto='dhcp'
network.wan.ifname='eth4'
network.wan.reqopts='1 3 6 15 33 42 51 121 249'
 2) if obtained DHCP lease has an option 42 sysntpd service will have an
 instance
 3) run "ifup wan"
 4) although the same DHCP lease was obtained, sysntpd would be stopped

Because sysntpd service is deleted when last instance is freed, its triggers
will also be released. Without these triggers in place, sysntpd will not be
reloaded when a new DHCP lease containing option 42 will be received.

Signed-off-by: Alin Nastac <alin.nastac@gmail.com>
service/service.c
service/service.h

index 0584ee0..9675ba2 100644 (file)
@@ -140,6 +140,8 @@ service_update(struct service *s, struct blob_attr **tb, bool add)
                        vlist_flush(&s->instances);
        }
 
                        vlist_flush(&s->instances);
        }
 
+       s->deleted = false;
+
        rc(s->name, "running");
 
        return 0;
        rc(s->name, "running");
 
        return 0;
@@ -149,6 +151,7 @@ static void
 service_delete(struct service *s)
 {
        vlist_flush_all(&s->instances);
 service_delete(struct service *s)
 {
        vlist_flush_all(&s->instances);
+       s->deleted = true;
        service_stopped(s);
 }
 
        service_stopped(s);
 }
 
@@ -602,7 +605,7 @@ service_start_early(char *name, char *cmdline)
 
 void service_stopped(struct service *s)
 {
 
 void service_stopped(struct service *s)
 {
-       if (avl_is_empty(&s->instances.avl)) {
+       if (s->deleted && avl_is_empty(&s->instances.avl)) {
                service_event("service.stop", s->name, NULL);
                avl_delete(&services, &s->avl);
                trigger_del(s);
                service_event("service.stop", s->name, NULL);
                avl_delete(&services, &s->avl);
                trigger_del(s);
index d4f0a83..cc629b1 100644 (file)
@@ -40,6 +40,7 @@ struct validate {
 struct service {
        struct avl_node avl;
        const char *name;
 struct service {
        struct avl_node avl;
        const char *name;
+       bool deleted;
 
        struct blob_attr *trigger;
        struct vlist_tree instances;
 
        struct blob_attr *trigger;
        struct vlist_tree instances;