git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Jeff King <peff@peff.net>
To: Johannes Sixt <j6t@kdbg.org>
Cc: "Trygve Aaberge" <trygveaa@gmail.com>,
	"Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>,
	git@vger.kernel.org
Subject: [PATCH 2/3] execv_dashed_external: stop exiting with negative code
Date: Fri, 6 Jan 2017 20:17:48 -0500	[thread overview]
Message-ID: <20170107011748.l25a6ofofjiuvpgk@sigill.intra.peff.net> (raw)
In-Reply-To: <20170107011445.3e4fv6vdtimrwhgv@sigill.intra.peff.net>

When we try to exec a git sub-command, we pass along the
status code from run_command(). But that may return -1 if we
ran into an error with pipe() or execve(). This tends to
work (and end up as 255 due to twos-complement wraparound
and truncation), but in general it's probably a good idea to
avoid negative exit codes for portability.

We can easily translate to the normal generic "128" code we
get when syscalls cause us to die.

Signed-off-by: Jeff King <peff@peff.net>
---
I know that negative exit codes were a problem once upon a time on
Windows, but I think that is fine since 47e3de0e79 (MinGW: truncate
exit()'s argument to lowest 8 bits, 2009-07-05). Still, I think it's a
weird portability thing that we are better off avoiding (and certainly I
wouldn't be surprised if some callers assume everything >128 is a
signal).

 git.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/git.c b/git.c
index d0e04d5c97..bc2f2a7ec9 100644
--- a/git.c
+++ b/git.c
@@ -593,12 +593,16 @@ static void execv_dashed_external(const char **argv)
 	trace_argv_printf(cmd.args.argv, "trace: exec:");
 
 	/*
-	 * if we fail because the command is not found, it is
-	 * OK to return. Otherwise, we just pass along the status code.
+	 * If we fail because the command is not found, it is
+	 * OK to return. Otherwise, we just pass along the status code,
+	 * or our usual generic code if we were not even able to exec
+	 * the program.
 	 */
 	status = run_command(&cmd);
-	if (status >= 0 || errno != ENOENT)
+	if (status >= 0)
 		exit(status);
+	else if (errno != ENOENT)
+		exit(128);
 }
 
 static int run_argv(int *argcp, const char ***argv)
-- 
2.11.0.527.gfef230ca76


  parent reply	other threads:[~2017-01-07  1:17 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-05 14:25 Regression: Ctrl-c from the pager in an alias exits it Trygve Aaberge
2017-01-06  6:40 ` Jeff King
2017-01-06  6:47   ` Jeff King
2017-01-06  7:26     ` Jeff King
2017-01-06  7:32       ` Jeff King
2017-01-06 13:19         ` Trygve Aaberge
2017-01-06 14:39         ` Johannes Sixt
2017-01-06 19:41           ` Jeff King
2017-01-06 22:42             ` Johannes Sixt
2017-01-06 23:20               ` Jeff King
2017-01-07  1:14                 ` [PATCH 0/3] fix ^C killing pager when running alias Jeff King
2017-01-07  1:16                   ` [PATCH 1/3] execv_dashed_external: use child_process struct Jeff King
2017-01-07  1:17                   ` Jeff King [this message]
2017-01-07  1:22                   ` [PATCH 3/3] execv_dashed_external: wait for child on signal death Jeff King
2017-01-07  7:28                     ` Johannes Sixt
2017-01-07  7:34                       ` Jeff King
2017-01-07  9:07                     ` Duy Nguyen
2017-01-07 23:26                   ` [PATCH 0/3] fix ^C killing pager when running alias Jacob Keller
2017-01-07 23:27                     ` Jacob Keller

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

  List information: http://vger.kernel.org/majordomo-info.html

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

  git send-email \
    --in-reply-to=20170107011748.l25a6ofofjiuvpgk@sigill.intra.peff.net \
    --to=peff@peff.net \
    --cc=git@vger.kernel.org \
    --cc=j6t@kdbg.org \
    --cc=pclouds@gmail.com \
    --cc=trygveaa@gmail.com \
    /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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).