Re: [PATCH RFC] common: env: handle var="" not as var=NULL

2016-06-14 Thread Sascha Hauer
On Mon, Jun 13, 2016 at 12:51:52PM +0200, Alexander Aring wrote:
> This patch changes the behaviour which I think is used everywhere in
> barebox code. Currently var="" and var=NULL will end in the same
> behaviour.
> 
> New behaviour is:
> 
> setenv(name, "")  -> sets name to ""
> \-> getenv(name)  -> ""
> 
> setenv(name, NULL)-> deletes env
> \-> getenv(name)  -> NULL
> 
> It seems that barebox code already wants such behaviour, by run
> 
> $ grep -r "\"\"" | grep setenv
> 
> it finds most all related code sections which use "".
> 
> I detected the issue while commenting #ip="foo" in my env. The code
> part:
> 
> net/ifup.c:   setenv("ip", "");
> 
> Sets at first "ip" to "" but will end in the old behaviour as "delete".
> The getenv("ip") in ifup.c will not check on the NULL value and has a
> general handling for unknown ip env.
> 
> Note:
> Also check commit e7ed69d5 ("setenv: be robust against setenv(,
> NULL") which says that hush will handle "" and NULL as the same.
> 
> Another check would be:
> 
> $ grep -r "NULL" | grep setenv
> 
> which should show the behaviour in case of deleting env.
> 
> Signed-off-by: Alexander Aring 
> ---
> I test the ip env stuff only that barebox will not crash anymore but I
> think it will break some other setenv/getenv behaviour.
> 
> The question is "Shall we keep that "" and NULL ends in same behaviour"
> and fix the code which use it wrong, e.g. setenv("ip", ""); getenv("ip").

I'm not sure at the moment if a var="" should delete a variable or just
set it to an empty string. In any case we should fix net/ifup.c.
getenv() can return NULL and the code should be prepared for that.

Sascha

-- 
Pengutronix e.K.   | |
Industrial Linux Solutions | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0|
Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |

___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH RFC] common: env: handle var="" not as var=NULL

2016-06-13 Thread Alexander Aring
This patch changes the behaviour which I think is used everywhere in
barebox code. Currently var="" and var=NULL will end in the same
behaviour.

New behaviour is:

setenv(name, "")-> sets name to ""
\-> getenv(name)-> ""

setenv(name, NULL)  -> deletes env
\-> getenv(name)-> NULL

It seems that barebox code already wants such behaviour, by run

$ grep -r "\"\"" | grep setenv

it finds most all related code sections which use "".

I detected the issue while commenting #ip="foo" in my env. The code
part:

net/ifup.c: setenv("ip", "");

Sets at first "ip" to "" but will end in the old behaviour as "delete".
The getenv("ip") in ifup.c will not check on the NULL value and has a
general handling for unknown ip env.

Note:
Also check commit e7ed69d5 ("setenv: be robust against setenv(,
NULL") which says that hush will handle "" and NULL as the same.

Another check would be:

$ grep -r "NULL" | grep setenv

which should show the behaviour in case of deleting env.

Signed-off-by: Alexander Aring 
---
I test the ip env stuff only that barebox will not crash anymore but I
think it will break some other setenv/getenv behaviour.

The question is "Shall we keep that "" and NULL ends in same behaviour"
and fix the code which use it wrong, e.g. setenv("ip", ""); getenv("ip").

 common/env.c | 4 
 1 file changed, 4 deletions(-)

diff --git a/common/env.c b/common/env.c
index 6f736d5..4d8d446 100644
--- a/common/env.c
+++ b/common/env.c
@@ -210,10 +210,6 @@ int setenv(const char *_name, const char *value)
int ret = 0;
struct list_head *list;
 
-   if (value && !*value)
-   value = NULL;
-
-
if ((par = strchr(name, '.'))) {
struct device_d *dev;
 
-- 
2.8.3


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox