Implement reload option for includes to decide whether includes should get reloaded...
authorJo-Philipp Wich <jow@openwrt.org>
Thu, 14 Mar 2013 13:48:37 +0000 (14:48 +0100)
committerJo-Philipp Wich <jow@openwrt.org>
Thu, 14 Mar 2013 13:48:37 +0000 (14:48 +0100)
includes.c
includes.h
main.c
options.h

index 4221def04407e57feda25111417b39b2cb7b9106..23cfda0f4f73f7e4d99183d84144336763e08237 100644 (file)
@@ -25,6 +25,7 @@ const struct fw3_option fw3_include_opts[] = {
        FW3_OPT("path",                string,         include,     path),
        FW3_OPT("type",                include_type,   include,     type),
        FW3_OPT("family",              family,         include,     family),
+       FW3_OPT("reload",              bool,           include,     reload),
 
        { }
 };
@@ -82,7 +83,7 @@ fw3_load_includes(struct fw3_state *state, struct uci_package *p)
 
 
 static void
-print_include(enum fw3_family family, struct fw3_include *include)
+print_include(struct fw3_include *include, enum fw3_family family)
 {
        FILE *f;
        char line[1024];
@@ -105,13 +106,18 @@ print_include(enum fw3_family family, struct fw3_include *include)
 }
 
 void
-fw3_print_includes(enum fw3_family family, struct fw3_state *state)
+fw3_print_includes(struct fw3_state *state, enum fw3_family family, bool reload)
 {
        struct fw3_include *include;
 
        list_for_each_entry(include, &state->includes, list)
+       {
+               if (reload && !include->reload)
+                       continue;
+
                if (include->type == FW3_INC_TYPE_RESTORE)
-                       print_include(family, include);
+                       print_include(include, family);
+       }
 }
 
 
@@ -144,11 +150,16 @@ run_include(struct fw3_include *include)
 }
 
 void
-fw3_run_includes(struct fw3_state *state)
+fw3_run_includes(struct fw3_state *state, bool reload)
 {
        struct fw3_include *include;
 
        list_for_each_entry(include, &state->includes, list)
+       {
+               if (reload && !include->reload)
+                       continue;
+
                if (include->type == FW3_INC_TYPE_SCRIPT)
                        run_include(include);
+       }
 }
index 5c091b743fd5844a96f24481a0f70e987eda6c07..cd48edefaa6bfd9480ceeb35f15302060d359e55 100644 (file)
 extern const struct fw3_option fw3_include_opts[];
 
 void fw3_load_includes(struct fw3_state *state, struct uci_package *p);
-void fw3_print_includes(enum fw3_family family, struct fw3_state *state);
-void fw3_run_includes(struct fw3_state *state);
+
+void fw3_print_includes(struct fw3_state *state, enum fw3_family family,
+                        bool reload);
+
+void fw3_run_includes(struct fw3_state *state, bool reload);
 
 #define fw3_free_include(include) \
        fw3_free_object(include, fw3_include_opts)
diff --git a/main.c b/main.c
index 3c2b4eb1e6e4ea645c977bb98ec9a987c0518fea..90ef8202a71c15563c48d352ab4e898f0ccff70f 100644 (file)
--- a/main.c
+++ b/main.c
@@ -293,8 +293,7 @@ start(struct fw3_state *state, bool reload)
                        fw3_pr("COMMIT\n");
                }
 
-               if (!reload)
-                       fw3_print_includes(family, state);
+               fw3_print_includes(state, family, reload);
 
                fw3_command_close();
                family_set(state, family, true);
@@ -308,9 +307,7 @@ start(struct fw3_state *state, bool reload)
 
                if (!print_rules)
                {
-                       if (!reload)
-                               fw3_run_includes(state);
-
+                       fw3_run_includes(state, reload);
                        fw3_hotplug_zones(true, state);
                        fw3_write_statefile(state);
                }
index bb98fb68ae63fd745313bec4fbe46496ad70820a..33224b8383e9d790322486256994fb9178141c77 100644 (file)
--- a/options.h
+++ b/options.h
@@ -417,6 +417,8 @@ struct fw3_include
 
        const char *path;
        enum fw3_include_type type;
+
+       bool reload;
 };
 
 struct fw3_state