diff options
author | Jo-Philipp Wich <jow@openwrt.org> | 2013-08-16 11:24:07 +0200 |
---|---|---|
committer | Jo-Philipp Wich <jow@openwrt.org> | 2013-08-16 11:24:07 +0200 |
commit | 85a5ce27f5f02e4ddab6916d69ba7f7375d289d4 (patch) | |
tree | bfafacc221e9e7bf36f946cb31509fb19548b706 | |
parent | 993b8f2f8a0e3683e6ade93f81e294a9b0899517 (diff) | |
download | unitd-85a5ce27f5f02e4ddab6916d69ba7f7375d289d4.tar unitd-85a5ce27f5f02e4ddab6916d69ba7f7375d289d4.zip |
service: terminate uloop after fork(), redirect stdin, out and err to /dev/null
-rw-r--r-- | instance.c | 14 |
1 files changed, 10 insertions, 4 deletions
@@ -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; } |