diff options
author | Yousong Zhou <yszhou4tech@gmail.com> | 2015-06-14 06:14:47 +0200 |
---|---|---|
committer | Felix Fietkau <nbd@openwrt.org> | 2015-06-14 18:30:59 +0200 |
commit | 46954a519259e1818117adee133c119dedbd4523 (patch) | |
tree | 5a994f9aee608f5070d0ccd5974c2aed0086cbbb /service | |
parent | 6a746e16105f5ad928d80f7584515f7e6ebb2005 (diff) | |
download | unitd-46954a519259e1818117adee133c119dedbd4523.tar unitd-46954a519259e1818117adee133c119dedbd4523.zip |
service: close instance pipe fd on restart.
Otherwise we hit max number of fd limit (1024) and instances fail to
start with the following errors in syslog
Sun Jun 14 01:27:38 2015 daemon.warn procd: pipe() failed: 24 (Too many open files)
Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
Diffstat (limited to 'service')
-rw-r--r-- | service/instance.c | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/service/instance.c b/service/instance.c index e89cbc6..29fb834 100644 --- a/service/instance.c +++ b/service/instance.c @@ -295,6 +295,8 @@ instance_run(struct service_instance *in, int _stdout, int _stderr) exit(127); } +static void instance_free_stdio(struct service_instance *in); + void instance_start(struct service_instance *in) { @@ -310,6 +312,7 @@ instance_start(struct service_instance *in) if (in->proc.pending) return; + instance_free_stdio(in); if (in->_stdout.fd.fd > -2) { if (pipe(opipe)) { ULOG_WARN("pipe() failed: %d (%s)\n", errno, strerror(errno)); @@ -820,19 +823,26 @@ instance_update(struct service_instance *in, struct service_instance *in_new) return true; } -void -instance_free(struct service_instance *in) +static void +instance_free_stdio(struct service_instance *in) { if (in->_stdout.fd.fd > -1) { ustream_free(&in->_stdout.stream); close(in->_stdout.fd.fd); + in->_stdout.fd.fd = -1; } if (in->_stderr.fd.fd > -1) { ustream_free(&in->_stderr.stream); close(in->_stderr.fd.fd); + in->_stderr.fd.fd = -1; } +} +void +instance_free(struct service_instance *in) +{ + instance_free_stdio(in); uloop_process_delete(&in->proc); uloop_timeout_cancel(&in->timeout); trigger_del(in); |