Re: [PATCH] Don't ignore write failure from git-diff, git-log, etc.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Jim Meyering <jim@xxxxxxxxxxxx> writes:

> ...
> Also, to be consistent with e.g., write_or_die, do not
> diagnose EPIPE write failures.
>
> Signed-off-by: Jim Meyering <jim@xxxxxxxxxxxx>
> ---
>  git.c |   19 ++++++++++++++++++-
>  1 files changed, 18 insertions(+), 1 deletions(-)
>
> diff --git a/git.c b/git.c
> index 29b55a1..8258885 100644
> --- a/git.c
> +++ b/git.c
> @@ -308,6 +308,7 @@ static void handle_internal_command(int argc, const char **argv, char **envp)
>  	for (i = 0; i < ARRAY_SIZE(commands); i++) {
>  		struct cmd_struct *p = commands+i;
>  		const char *prefix;
> +		int status;
>  		if (strcmp(p->cmd, cmd))
>  			continue;
>
> @@ -321,7 +322,23 @@ static void handle_internal_command(int argc, const char **argv, char **envp)
>  			die("%s must be run in a work tree", cmd);
>  		trace_argv_printf(argv, argc, "trace: built-in: git");
>
> -		exit(p->fn(argc, argv, prefix));
> +		status = p->fn(argc, argv, prefix);
> +
> +		/* Close stdout if necessary, and diagnose any failure
> +		   other than EPIPE.  */
> +		if (fcntl(fileno (stdout), F_GETFD) >= 0) {
> +			errno = 0;
> +			if ((ferror(stdout) || fclose(stdout))
> +			    && errno != EPIPE) {
> +				if (errno == 0)
> +					die("write failure on standard output");
> +				else
> +					die("write failure on standard output"
> +					    ": %s", strerror(errno));
> +			}

This makes the final write failure trump the breakage p->fn()
already diagnosed, doesn't it?  Maybe if (fcntrl(...) >=0 )
should read if (!status && fcntrl(...) >= 0).

> +		}
> +
> +		exit(status);
>  	}
>  }
>
> --
> 1.5.2.73.g18bece

-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux