summaryrefslogtreecommitdiffhomepage
path: root/main.c
diff options
context:
space:
mode:
authorFelix Fietkau <nbd@openwrt.org>2011-10-15 19:06:28 +0200
committerFelix Fietkau <nbd@openwrt.org>2011-10-15 19:06:28 +0200
commit6b3f6f4466e5584f2bdefc55b3ca34186b65acb9 (patch)
treee604a886feccbd1a6017035470b8c0749b98050b /main.c
parent8c4dface377cf03de38c642b90940530e47296d3 (diff)
add support for tracking open file descriptors of modules and closing them for created child processes
Diffstat (limited to 'main.c')
-rw-r--r--main.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/main.c b/main.c
index 04d5648..6419fe9 100644
--- a/main.c
+++ b/main.c
@@ -14,7 +14,9 @@ unsigned int debug_mask = 0;
const char *main_path = DEFAULT_MAIN_PATH;
const char *resolv_conf = DEFAULT_RESOLV_CONF;
static char **global_argv;
+
static struct list_head process_list = LIST_HEAD_INIT(process_list);
+static struct list_head fds = LIST_HEAD_INIT(fds);
static void
netifd_process_cb(struct uloop_process *proc, int ret)
@@ -28,6 +30,7 @@ netifd_process_cb(struct uloop_process *proc, int ret)
int
netifd_start_process(const char **argv, char **env, struct netifd_process *proc)
{
+ struct netifd_fd *fd;
int pid;
netifd_kill_process(proc);
@@ -44,6 +47,14 @@ netifd_start_process(const char **argv, char **env, struct netifd_process *proc)
}
if (proc->dir_fd >= 0)
fchdir(proc->dir_fd);
+
+ /* close all non-essential fds */
+ list_for_each_entry(fd, &fds, list) {
+ if (fd->proc == proc)
+ continue;
+ close(fd->fd);
+ }
+
execvp(argv[0], (char **) argv);
exit(127);
}
@@ -70,6 +81,18 @@ netifd_kill_process(struct netifd_process *proc)
list_del(&proc->list);
}
+void
+netifd_fd_add(struct netifd_fd *fd)
+{
+ list_add_tail(&fd->list, &fds);
+}
+
+void
+netifd_fd_delete(struct netifd_fd *fd)
+{
+ list_del(&fd->list);
+}
+
static void netifd_do_restart(struct uloop_timeout *timeout)
{
execvp(global_argv[0], global_argv);