procd: instance: Support deleting stopped instances
[project/procd.git] / service / instance.c
index 917b003b3907c5e06014129db9e9ca95bdf17100..3512f66b313c89f40fd293921327d0273ee2725d 100644 (file)
@@ -469,18 +469,20 @@ instance_stdio(struct ustream *s, int prio, struct service_instance *in)
        ulog_open(ULOG_SYSLOG, LOG_DAEMON, ident);
 
        do {
-               str = ustream_get_read_buf(s, NULL);
+               str = ustream_get_read_buf(s, &len);
                if (!str)
                        break;
 
-               newline = strchr(str, '\n');
-               if (!newline)
+               newline = memchr(str, '\n', len);
+               if (!newline && (s->r.buffer_len != len))
                        break;
 
-               *newline = 0;
+               if (newline) {
+                       *newline = 0;
+                       len = newline + 1 - str;
+               }
                ulog(prio, "%s\n", str);
 
-               len = newline + 1 - str;
                ustream_consume(s, len);
        } while (1);
 
@@ -516,6 +518,16 @@ instance_timeout(struct uloop_timeout *t)
                instance_start(in);
 }
 
+static void
+instance_delete(struct service_instance *in)
+{
+       struct service *s = in->srv;
+
+       avl_delete(&s->instances.avl, &in->node.avl);
+       instance_free(in);
+       service_stopped(s);
+}
+
 static void
 instance_exit(struct uloop_process *p, int ret)
 {
@@ -537,13 +549,8 @@ instance_exit(struct uloop_process *p, int ret)
                instance_removepid(in);
                if (in->restart)
                        instance_start(in);
-               else {
-                       struct service *s = in->srv;
-
-                       avl_delete(&s->instances.avl, &in->node.avl);
-                       instance_free(in);
-                       service_stopped(s);
-               }
+               else
+                       instance_delete(in);
        } else if (in->restart) {
                instance_start(in);
        } else if (in->respawn) {
@@ -567,8 +574,11 @@ instance_exit(struct uloop_process *p, int ret)
 void
 instance_stop(struct service_instance *in, bool halt)
 {
-       if (!in->proc.pending)
+       if (!in->proc.pending) {
+               if (halt)
+                       instance_delete(in);
                return;
+       }
        in->halt = halt;
        in->restart = in->respawn = false;
        kill(in->proc.pid, SIGTERM);
@@ -637,6 +647,11 @@ instance_config_changed(struct service_instance *in, struct service_instance *in
        if (in->respawn_timeout != in_new->respawn_timeout)
                return true;
 
+       if ((!in->seccomp && in_new->seccomp) ||
+           (in->seccomp && !in_new->seccomp) ||
+           (in->seccomp && in_new->seccomp && strcmp(in->seccomp, in_new->seccomp)))
+               return true;
+
        if (!blobmsg_list_equal(&in->limits, &in_new->limits))
                return true;
 
@@ -957,6 +972,7 @@ instance_config_move(struct service_instance *in, struct service_instance *in_sr
        in->respawn_timeout = in_src->respawn_timeout;
        in->name = in_src->name;
        in->trace = in_src->trace;
+       in->seccomp = in_src->seccomp;
        in->node.avl.key = in_src->node.avl.key;
 
        free(in->config);