mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Antony Pavlov <antonynpavlov@gmail.com>
To: Enrico Jorns <ejo@pengutronix.de>
Cc: barebox@lists.infradead.org
Subject: Re: [PATCH v2] edit: Return error when save_file failed
Date: Wed, 4 Nov 2015 15:23:21 +0300	[thread overview]
Message-ID: <20151104152321.1f2d9e673c1b259c8373148c@gmail.com> (raw)
In-Reply-To: <1446635004-26896-1-git-send-email-ejo@pengutronix.de>

On Wed,  4 Nov 2015 12:03:24 +0100
Enrico Jorns <ejo@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@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 (save_file(argv[1]) != 0)
	ret = COMMAND_ERROR;

Also save_file() does not check write()'s error.

>  			goto out;
>  		case 3:
>  			goto out;
> @@ -546,7 +547,7 @@ out:
>  	free_buffer();
>  	printf("%c[2J%c[r", 27, 27);
>  	printf("\n");
> -	return 0;
> +	return ret;
>  }
>  
>  static const char *edit_aliases[] = { "sedit", NULL};
> -- 
> 2.6.1
> 
> 
> _______________________________________________
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox


-- 
-- 
Best regards,
  Antony Pavlov

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

  reply	other threads:[~2015-11-04 12:00 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-03 16:19 [PATCH] " Enrico Jorns
2015-11-04 11:03 ` [PATCH v2] " Enrico Jorns
2015-11-04 12:23   ` Antony Pavlov [this message]
2015-11-04 13:30     ` Sascha Hauer
2015-11-04 14:48       ` Antony Pavlov
2015-11-05  8:17         ` Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20151104152321.1f2d9e673c1b259c8373148c@gmail.com \
    --to=antonynpavlov@gmail.com \
    --cc=barebox@lists.infradead.org \
    --cc=ejo@pengutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox