service: terminate uloop after fork(), redirect stdin, out and err to /dev/null
authorJo-Philipp Wich <jow@openwrt.org>
Fri, 16 Aug 2013 09:24:07 +0000 (11:24 +0200)
committerJo-Philipp Wich <jow@openwrt.org>
Fri, 16 Aug 2013 09:24:07 +0000 (11:24 +0200)
instance.c

index 28e5c94d5611a539ac6dcbb5055bcbecf4fa0a2a..d61bb332e2c7047b99f5d3d069576df63e224557 100644 (file)
@@ -63,7 +63,7 @@ instance_run(struct service_instance *in)
        struct blob_attr *cur;
        char **argv;
        int argc = 1; /* NULL terminated */
-       int rem;
+       int rem, fd;
 
        if (in->nice)
                setpriority(PRIO_PROCESS, 0, in->nice);
@@ -81,9 +81,14 @@ instance_run(struct service_instance *in)
                argv[argc++] = blobmsg_data(cur);
 
        argv[argc] = NULL;
-       close(STDIN_FILENO);
-       close(STDOUT_FILENO);
-       close(STDERR_FILENO);
+       fd = open("/dev/null", O_RDWR);
+       if (fd > -1) {
+               dup2(fd, STDIN_FILENO);
+               dup2(fd, STDOUT_FILENO);
+               dup2(fd, STDERR_FILENO);
+               if (fd > STDERR_FILENO)
+                       close(fd);
+       }
        execvp(argv[0], argv);
        exit(127);
 }
@@ -105,6 +110,7 @@ instance_start(struct service_instance *in)
                return;
 
        if (!pid) {
+               uloop_done();
                instance_run(in);
                return;
        }