[PATCH] ifupdown: set environment variable 'PHASE'

Andreas Oberritter obi at opendreambox.org
Thu Apr 12 01:25:15 UTC 2012


* Improves compatibility with Debian's ifupdown.

Signed-off-by: Andreas Oberritter <obi at opendreambox.org>
---
 networking/ifupdown.c |   24 +++++++++++++-----------
 1 files changed, 13 insertions(+), 11 deletions(-)

diff --git a/networking/ifupdown.c b/networking/ifupdown.c
index dfda206..02b5ca3 100644
--- a/networking/ifupdown.c
+++ b/networking/ifupdown.c
@@ -963,7 +963,7 @@ static char *setlocalenv(const char *format, const char *name, const char *value
 	return result;
 }
 
-static void set_environ(struct interface_defn_t *iface, const char *mode)
+static void set_environ(struct interface_defn_t *iface, const char *mode, const char *opt)
 {
 	int i;
 	char **pp;
@@ -976,7 +976,7 @@ static void set_environ(struct interface_defn_t *iface, const char *mode)
 	}
 
 	/* note: last element will stay NULL: */
-	G.my_environ = xzalloc(sizeof(char *) * (iface->n_options + 6));
+	G.my_environ = xzalloc(sizeof(char *) * (iface->n_options + 7));
 	pp = G.my_environ;
 
 	for (i = 0; i < iface->n_options; i++) {
@@ -990,6 +990,7 @@ static void set_environ(struct interface_defn_t *iface, const char *mode)
 	*pp++ = setlocalenv("%s=%s", "ADDRFAM", iface->address_family->name);
 	*pp++ = setlocalenv("%s=%s", "METHOD", iface->method->name);
 	*pp++ = setlocalenv("%s=%s", "MODE", mode);
+	*pp++ = setlocalenv("%s=%s", "PHASE", opt);
 	if (G.startup_PATH)
 		*pp++ = setlocalenv("%s=%s", "PATH", G.startup_PATH);
 }
@@ -1019,10 +1020,13 @@ static int doit(char *str)
 	return 1;
 }
 
-static int execute_all(struct interface_defn_t *ifd, const char *opt)
+static int execute_all(struct interface_defn_t *ifd, const char *mode, const char *opt)
 {
 	int i;
 	char *buf;
+
+	set_environ(ifd, mode, opt);
+
 	for (i = 0; i < ifd->n_options; i++) {
 		if (strcmp(ifd->option[i].name, opt) == 0) {
 			if (!doit(ifd->option[i].value)) {
@@ -1044,22 +1048,20 @@ static int check(char *str)
 static int iface_up(struct interface_defn_t *iface)
 {
 	if (!iface->method->up(iface, check)) return -1;
-	set_environ(iface, "start");
-	if (!execute_all(iface, "pre-up")) return 0;
+	if (!execute_all(iface, "start", "pre-up")) return 0;
 	if (!iface->method->up(iface, doit)) return 0;
-	if (!execute_all(iface, "up")) return 0;
-	if (!execute_all(iface, "post-up")) return 0;
+	if (!execute_all(iface, "start", "up")) return 0;
+	if (!execute_all(iface, "start", "post-up")) return 0;
 	return 1;
 }
 
 static int iface_down(struct interface_defn_t *iface)
 {
 	if (!iface->method->down(iface,check)) return -1;
-	set_environ(iface, "stop");
-	if (!execute_all(iface, "pre-down")) return 0;
-	if (!execute_all(iface, "down")) return 0;
+	if (!execute_all(iface, "stop", "pre-down")) return 0;
+	if (!execute_all(iface, "stop", "down")) return 0;
 	if (!iface->method->down(iface, doit)) return 0;
-	if (!execute_all(iface, "post-down")) return 0;
+	if (!execute_all(iface, "stop", "post-down")) return 0;
 	return 1;
 }
 
-- 
1.7.5.4



More information about the busybox mailing list