#include <string.h>
#include <stdlib.h>
#include <stdio.h>
-#include <glob.h>
#include <unistd.h>
-#include <fcntl.h>
#include <signal.h>
#include <arpa/inet.h>
#include <netinet/in.h>
-#include <libubox/blobmsg_json.h>
#include "netifd.h"
#include "interface.h"
#include "interface-ip.h"
#include "proto.h"
#include "system.h"
+#include "handler.h"
static int proto_fd = -1;
struct proto_shell_handler {
struct list_head list;
struct proto_handler proto;
- struct config_param_list config;
+ struct uci_blob_param_list config;
char *config_buf;
bool init_available;
char script_name[];
{
struct proto_shell_dependency *pdep;
- if (ev != IFEV_UP)
+ if (ev != IFEV_UP && ev != IFEV_UPDATE)
return;
pdep = container_of(dep, struct proto_shell_dependency, dep);
struct proto_shell_dependency *pdep;
struct proto_shell_state *state;
- if (ev == IFEV_UP)
+ if (ev == IFEV_UP || ev == IFEV_UPDATE)
return;
pdep = container_of(dep, struct proto_shell_dependency, dep);
}
static char *
-proto_shell_parse_config(struct config_param_list *config, json_object *obj)
+proto_shell_parse_config(struct uci_blob_param_list *config, json_object *obj)
{
struct blobmsg_policy *attrs;
char *str_buf, *str_cur;
add_proto_handler(proto);
}
-static void proto_shell_add_script(const char *name)
-{
- struct json_tokener *tok = NULL;
- json_object *obj;
- static char buf[512];
- char *start, *cmd;
- FILE *f;
- int len;
-
-#define DUMP_SUFFIX " '' dump"
-
- cmd = alloca(strlen(name) + 1 + sizeof(DUMP_SUFFIX));
- sprintf(cmd, "%s" DUMP_SUFFIX, name);
-
- f = popen(cmd, "r");
- if (!f)
- return;
-
- do {
- start = fgets(buf, sizeof(buf), f);
- if (!start)
- continue;
-
- len = strlen(start);
-
- if (!tok)
- tok = json_tokener_new();
-
- obj = json_tokener_parse_ex(tok, start, len);
- if (!is_error(obj)) {
- proto_shell_add_handler(name, obj);
- json_object_put(obj);
- json_tokener_free(tok);
- tok = NULL;
- } else if (start[len - 1] == '\n') {
- json_tokener_free(tok);
- tok = NULL;
- }
- } while (!feof(f) && !ferror(f));
-
- if (tok)
- json_tokener_free(tok);
-
- pclose(f);
-}
-
static void __init proto_shell_init(void)
{
- glob_t g;
- int main_fd;
- int i;
-
- main_fd = open(".", O_RDONLY | O_DIRECTORY);
- if (main_fd < 0)
- return;
-
- if (chdir(main_path)) {
- perror("chdir(main path)");
- goto close_cur;
- }
-
- if (chdir("./proto"))
- goto close_cur;
-
- proto_fd = open(".", O_RDONLY | O_DIRECTORY);
+ proto_fd = netifd_open_subdir("proto");
if (proto_fd < 0)
- goto close_cur;
-
- system_fd_set_cloexec(proto_fd);
- glob("./*.sh", 0, NULL, &g);
- for (i = 0; i < g.gl_pathc; i++)
- proto_shell_add_script(g.gl_pathv[i]);
+ return;
-close_cur:
- fchdir(main_fd);
- close(main_fd);
+ netifd_init_script_handlers(proto_fd, proto_shell_add_handler);
}