+typedef void (*script_dump_cb)(const char *name, json_object *obj);
+
+static int
+netifd_dir_push(int fd)
+{
+ int prev_fd = open(".", O_RDONLY | O_DIRECTORY);
+ system_fd_set_cloexec(prev_fd);
+ if (fd >= 0)
+ fchdir(fd);
+ return prev_fd;
+}
+
+static void
+netifd_dir_pop(int prev_fd)
+{
+ fchdir(prev_fd);
+ close(prev_fd);
+}
+
+static int
+netifd_open_subdir(const char *name)
+{
+ int prev_dir;
+ int ret = -1;
+
+ prev_dir = netifd_dir_push(-1);
+ if (chdir(main_path)) {
+ perror("chdir(main path)");
+ goto out;
+ }
+
+ ret = open(name, O_RDONLY | O_DIRECTORY);
+ if (ret >= 0)
+ system_fd_set_cloexec(ret);
+
+out:
+ netifd_dir_pop(prev_dir);
+ return ret;
+}
+
+static void
+netifd_init_script_handler(const char *name, script_dump_cb cb)