mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] common: env: make error message more verbose
@ 2015-04-28 10:32 Steffen Trumtrar
  2015-05-04  7:32 ` Sascha Hauer
  0 siblings, 1 reply; 3+ messages in thread
From: Steffen Trumtrar @ 2015-04-28 10:32 UTC (permalink / raw)
  To: barebox; +Cc: Steffen Trumtrar

Change the setenv error message from

	set parameter: Invalid argument

to a more helpful

	net: cannot set parameter 'nameserver': Invalid argument

Signed-off-by: Steffen Trumtrar <s.trumtrar@pengutronix.de>
---
 common/env.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/common/env.c b/common/env.c
index 2e33eb35856b..434170a7468b 100644
--- a/common/env.c
+++ b/common/env.c
@@ -225,8 +225,10 @@ int setenv(const char *_name, const char *value)
 
 		errno = -ret;
 
-		if (ret < 0)
-			perror("set parameter");
+		if (ret < 0) {
+			dev_err(dev, "cannot set parameter '%s'", par);
+			perror("");
+		}
 
 		goto out;
 	}
-- 
2.1.4


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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] common: env: make error message more verbose
  2015-04-28 10:32 [PATCH] common: env: make error message more verbose Steffen Trumtrar
@ 2015-05-04  7:32 ` Sascha Hauer
  2015-05-04  7:43   ` Steffen Trumtrar
  0 siblings, 1 reply; 3+ messages in thread
From: Sascha Hauer @ 2015-05-04  7:32 UTC (permalink / raw)
  To: Steffen Trumtrar; +Cc: barebox

On Tue, Apr 28, 2015 at 12:32:27PM +0200, Steffen Trumtrar wrote:
> Change the setenv error message from
> 
> 	set parameter: Invalid argument
> 
> to a more helpful
> 
> 	net: cannot set parameter 'nameserver': Invalid argument
> 
> Signed-off-by: Steffen Trumtrar <s.trumtrar@pengutronix.de>
> ---
>  common/env.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/common/env.c b/common/env.c
> index 2e33eb35856b..434170a7468b 100644
> --- a/common/env.c
> +++ b/common/env.c
> @@ -225,8 +225,10 @@ int setenv(const char *_name, const char *value)
>  
>  		errno = -ret;
>  
> -		if (ret < 0)
> -			perror("set parameter");
> +		if (ret < 0) {
> +			dev_err(dev, "cannot set parameter '%s'", par);
> +			perror("");
> +		}

dev may be invalid here, so you shouldn't use dev_err.

After we talked about the missing informations in the setenv failure
path I created the following patch. I applied this one now.

Sascha

------------------------8<---------------------------

From 6d4afd96fc94a3f2d256ef4e8d7c9687a145a701 Mon Sep 17 00:00:00 2001
From: Sascha Hauer <s.hauer@pengutronix.de>
Date: Tue, 28 Apr 2015 12:43:02 +0200
Subject: [PATCH] setenv: Be more informative when device parameter setting
 fails

When setting a device parameter fails not only the error code
is of interest, but also what the parameter name is, what the
device name is and whether a device was found for this name.
Add this information to the error message.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 common/env.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/common/env.c b/common/env.c
index 2e33eb3..c98ed73 100644
--- a/common/env.c
+++ b/common/env.c
@@ -218,16 +218,18 @@ int setenv(const char *_name, const char *value)
 
 		*par++ = 0;
 		dev = get_device_by_name(name);
-		if (dev)
+		if (dev) {
 			ret = dev_set_param(dev, par, value);
-		else
+			if (ret)
+				eprintf("%s: set parameter %s: %s\n",
+						dev_name(dev), par, strerror(-ret));
+		} else {
 			ret = -ENODEV;
+			eprintf("set parameter: no such device %s\n", name);
+		}
 
 		errno = -ret;
 
-		if (ret < 0)
-			perror("set parameter");
-
 		goto out;
 	}
 
-- 
2.1.4

-- 
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-5555 |

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] common: env: make error message more verbose
  2015-05-04  7:32 ` Sascha Hauer
@ 2015-05-04  7:43   ` Steffen Trumtrar
  0 siblings, 0 replies; 3+ messages in thread
From: Steffen Trumtrar @ 2015-05-04  7:43 UTC (permalink / raw)
  To: Sascha Hauer; +Cc: barebox

Hi!

On Mon, May 04, 2015 at 09:32:19AM +0200, Sascha Hauer wrote:
> On Tue, Apr 28, 2015 at 12:32:27PM +0200, Steffen Trumtrar wrote:
> > Change the setenv error message from
> > 
> > 	set parameter: Invalid argument
> > 
> > to a more helpful
> > 
> > 	net: cannot set parameter 'nameserver': Invalid argument
> > 
> > Signed-off-by: Steffen Trumtrar <s.trumtrar@pengutronix.de>
> > ---
> >  common/env.c | 6 ++++--
> >  1 file changed, 4 insertions(+), 2 deletions(-)
> > 
> > diff --git a/common/env.c b/common/env.c
> > index 2e33eb35856b..434170a7468b 100644
> > --- a/common/env.c
> > +++ b/common/env.c
> > @@ -225,8 +225,10 @@ int setenv(const char *_name, const char *value)
> >  
> >  		errno = -ret;
> >  
> > -		if (ret < 0)
> > -			perror("set parameter");
> > +		if (ret < 0) {
> > +			dev_err(dev, "cannot set parameter '%s'", par);
> > +			perror("");
> > +		}
> 
> dev may be invalid here, so you shouldn't use dev_err.
> 

Argh, yeah, of course *facepalm*.

> After we talked about the missing informations in the setenv failure
> path I created the following patch. I applied this one now.

Thanks for fixing.
Steffen

-- 
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-5555 |

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-05-04  7:44 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-04-28 10:32 [PATCH] common: env: make error message more verbose Steffen Trumtrar
2015-05-04  7:32 ` Sascha Hauer
2015-05-04  7:43   ` Steffen Trumtrar

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox