[PATCH 5/7] dhcp: switch globalvar to it's own device

Jean-Christophe PLAGNIOL-VILLARD plagnioj at jcrosoft.com
Fri Jan 25 18:55:30 EST 2013


Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj at jcrosoft.com>
---
 net/dhcp.c |   40 ++++++++--------------------------------
 1 file changed, 8 insertions(+), 32 deletions(-)

diff --git a/net/dhcp.c b/net/dhcp.c
index 768255e..486b407 100644
--- a/net/dhcp.c
+++ b/net/dhcp.c
@@ -81,31 +81,16 @@ static uint32_t dhcp_leasetime;
 static IPaddr_t net_dhcp_server_ip;
 static uint64_t dhcp_start;
 static char dhcp_tftpname[256];
+static struct device_d *dhcp_dev;
 
 static const char* dhcp_get_barebox_global(const char * var)
 {
-	char * var_global = asprintf("global.dhcp.%s", var);
-	const char *val;
-
-	if (!var_global)
-		return NULL;
-
-	val = getenv(var_global);
-	free(var_global);
-	return val;
+	return dev_get_param(dhcp_dev, var);
 }
 
 static int dhcp_set_barebox_global(const char * var, char *val)
 {
-	char * var_global = asprintf("global.dhcp.%s", var);
-	int ret;
-
-	if (!var_global)
-		return -ENOMEM;
-
-	ret = setenv(var_global, val);
-	free(var_global);
-	return ret;
+	return dev_set_param(dhcp_dev, var, val);
 }
 
 struct dhcp_opt {
@@ -663,30 +648,21 @@ static void dhcp_reset_env(void)
 	}
 }
 
-static void dhcp_global_add(const char *var)
-{
-	char * var_global = asprintf("dhcp.%s", var);
-
-	if (!var_global)
-		return;
-
-	globalvar_add_simple(var_global);
-	free(var_global);
-}
-
 static int dhcp_global_init(void)
 {
 	struct dhcp_opt *opt;
 	struct dhcp_param *param;
 	int i;
 
+	dhcp_dev = global_add_device("dhcp");
+
 	for (i = 0; i < ARRAY_SIZE(dhcp_options); i++) {
 		opt = &dhcp_options[i];
 
 		if (!opt->barebox_dhcp_global)
 			continue;
 
-		dhcp_global_add(opt->barebox_dhcp_global);
+		global_add_simple(dhcp_dev, opt->barebox_dhcp_global);
 	}
 
 	for (i = 0; i < ARRAY_SIZE(dhcp_params); i++) {
@@ -695,7 +671,7 @@ static int dhcp_global_init(void)
 		if (!param->barebox_dhcp_global)
 			continue;
 
-		dhcp_global_add(param->barebox_dhcp_global);
+		global_add_simple(dhcp_dev, param->barebox_dhcp_global);
 	}
 
 	return 0;
@@ -719,7 +695,7 @@ static int do_dhcp(int argc, char *argv[])
 
 	dhcp_reset_env();
 
-	dhcp_getenv_int("global.dhcp.retries", &retries);
+	dhcp_getenv_int("dhcp.retries", &retries);
 
 	while((opt = getopt(argc, argv, "H:v:c:u:U:r:")) > 0) {
 		switch(opt) {
-- 
1.7.10.4




More information about the barebox mailing list