[PATCH v2] edit: Return error when save_file failed
Sascha Hauer
s.hauer at pengutronix.de
Wed Nov 4 05:30:53 PST 2015
On Wed, Nov 04, 2015 at 03:23:21PM +0300, Antony Pavlov wrote:
> On Wed, 4 Nov 2015 12:03:24 +0100
> Enrico Jorns <ejo at pengutronix.de> wrote:
>
> > When writing a file failed (e.g. due to a read-only file system), no
> > error was reported by the 'edit' tool. To be valid (and to not confuse
> > the poor user) at least '1' should be returned to indicate an error.
> >
> > Signed-off-by: Enrico Jorns <ejo at pengutronix.de>
> > ---
> > commands/edit.c | 5 +++--
> > 1 file changed, 3 insertions(+), 2 deletions(-)
> >
> > diff --git a/commands/edit.c b/commands/edit.c
> > index b28e2b9..3b653b7 100644
> > --- a/commands/edit.c
> > +++ b/commands/edit.c
> > @@ -375,6 +375,7 @@ static int do_edit(int argc, char *argv[])
> > int i;
> > int linepos;
> > int c;
> > + int ret = 0;
>
> Can we use COMMAND_SUCCESS insted of 0?
>
>
> >
> > if (argc != 2)
> > return COMMAND_ERROR_USAGE;
> > @@ -533,7 +534,7 @@ static int do_edit(int argc, char *argv[])
> > }
> > break;
> > case 4:
> > - save_file(argv[1]);
> > + ret = save_file(argv[1]);
>
> Actually save_file() returns open()'s error. We have to convert it to COMMAND_ERROR, e.g.:
If we return an error code from a command then the caller will print the
corresponding error string to the console which might be what we want
here.
>
> if (save_file(argv[1]) != 0)
> ret = COMMAND_ERROR;
>
> Also save_file() does not check write()'s error.
Indeed, this could be fixed while touching this code.
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-5555 |
More information about the barebox
mailing list