1 From 7ec30bf273cbdf5f0ae335684939a883182e493e Mon Sep 17 00:00:00 2001
2 From: Andreas Oberritter <obi@opendreambox.org>
3 Date: Mon, 23 Apr 2012 22:08:39 +0200
4 Subject: [PATCH 5/6] ifupdown: improve compatibility with Debian
6 Set environment variable 'PHASE'.
7 Treat post-up and pre-down as aliases for up and down.
8 Uses the same logic as ifupdown.nw from ifupdown-0.6.16.
9 Makes it possible to execute Debian's ifupdown script for
12 Signed-off-by: Andreas Oberritter <obi@opendreambox.org>
13 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
15 networking/ifupdown.c | 20 ++++++++++++--------
16 1 file changed, 12 insertions(+), 8 deletions(-)
18 diff --git a/networking/ifupdown.c b/networking/ifupdown.c
19 index 9f49619..5c3dcec 100644
20 --- a/networking/ifupdown.c
21 +++ b/networking/ifupdown.c
22 @@ -140,8 +140,6 @@ static const char keywords_up_down[] ALIGN1 =
31 @@ -895,6 +893,11 @@ static struct interfaces_file_t *read_interfaces(const char *filename)
32 if (rest_of_line[0] == '\0')
33 bb_error_msg_and_die("option with empty value \"%s\"", buf);
35 + if (strcmp(first_word, "post-up") == 0)
36 + first_word += 5; /* "up" */
37 + else if (strcmp(first_word, "pre-down") == 0)
38 + first_word += 4; /* "down" */
40 /* If not one of "up", "down",... words... */
41 if (index_in_strings(keywords_up_down, first_word) < 0) {
43 @@ -963,7 +966,7 @@ static char *setlocalenv(const char *format, const char *name, const char *value
47 -static void set_environ(struct interface_defn_t *iface, const char *mode)
48 +static void set_environ(struct interface_defn_t *iface, const char *mode, const char *opt)
52 @@ -976,7 +979,7 @@ static void set_environ(struct interface_defn_t *iface, const char *mode)
55 /* note: last element will stay NULL: */
56 - G.my_environ = xzalloc(sizeof(char *) * (iface->n_options + 6));
57 + G.my_environ = xzalloc(sizeof(char *) * (iface->n_options + 7));
60 for (i = 0; i < iface->n_options; i++) {
61 @@ -990,6 +993,7 @@ static void set_environ(struct interface_defn_t *iface, const char *mode)
62 *pp++ = setlocalenv("%s=%s", "ADDRFAM", iface->address_family->name);
63 *pp++ = setlocalenv("%s=%s", "METHOD", iface->method->name);
64 *pp++ = setlocalenv("%s=%s", "MODE", mode);
65 + *pp++ = setlocalenv("%s=%s", "PHASE", opt);
67 *pp++ = setlocalenv("%s=%s", "PATH", G.startup_PATH);
69 @@ -1044,21 +1048,21 @@ static int check(char *str)
70 static int iface_up(struct interface_defn_t *iface)
72 if (!iface->method->up(iface, check)) return -1;
73 - set_environ(iface, "start");
74 + set_environ(iface, "start", "pre-up");
75 if (!execute_all(iface, "pre-up")) return 0;
76 if (!iface->method->up(iface, doit)) return 0;
77 + set_environ(iface, "start", "post-up");
78 if (!execute_all(iface, "up")) return 0;
79 - if (!execute_all(iface, "post-up")) return 0;
83 static int iface_down(struct interface_defn_t *iface)
85 if (!iface->method->down(iface,check)) return -1;
86 - set_environ(iface, "stop");
87 - if (!execute_all(iface, "pre-down")) return 0;
88 + set_environ(iface, "stop", "pre-down");
89 if (!execute_all(iface, "down")) return 0;
90 if (!iface->method->down(iface, doit)) return 0;
91 + set_environ(iface, "stop", "post-down");
92 if (!execute_all(iface, "post-down")) return 0;