git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: worley@alum.mit.edu (Dale R. Worley)
To: Junio C Hamano <gitster@pobox.com>
Cc: n1xim.email@gmail.com, trast@inf.ethz.ch, git@vger.kernel.org,
	fonseca@diku.dk
Subject: Re: [PATCH 1/2] git_mkstemps: correctly test return value of open()
Date: Thu, 18 Jul 2013 18:46:13 -0400	[thread overview]
Message-ID: <201307182246.r6IMkDiW021930@freeze.ariadne.com> (raw)
In-Reply-To: <CAPc5daVVDCHqjyDV3zYVV33EFYjea7ge84+CE=M=QXagxnHd-A@mail.gmail.com> (gitster@pobox.com)

> From: Junio C Hamano <gitster@pobox.com>
> 
> That's just a plain-vanilla part of POSIX shell behaviour, no?
> 
> http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_07_05

"Close standard input" is so weird I never thought it was Posix.  In
that case, we can eliminate the C helper program:

diff --git a/t/t0070-fundamental.sh b/t/t0070-fundamental.sh
index 986b2a8..d427f3a 100755
--- a/t/t0070-fundamental.sh
+++ b/t/t0070-fundamental.sh
@@ -25,6 +25,13 @@ test_expect_success POSIXPERM,SANITY 'mktemp to unwritable directory prints file
 	grep "cannotwrite/test" err
 '
 
+test_expect_success 'git_mkstemps_mode does not fail if fd 0 is not open' '
+	git init &&
+	echo Test. >test-file &&
+	git add test-file &&
+	git commit -m Message. <&-
+'
+
 test_expect_success 'check for a bug in the regex routines' '
 	# if this test fails, re-build git with NO_REGEX=1
 	test-regex
diff --git a/wrapper.c b/wrapper.c
index dd7ecbb..6a015de 100644
--- a/wrapper.c
+++ b/wrapper.c
@@ -322,7 +322,7 @@ int git_mkstemps_mode(char *pattern, int suffix_len, int mode)
 		template[5] = letters[v % num_letters]; v /= num_letters;
 
 		fd = open(pattern, O_CREAT | O_EXCL | O_RDWR, mode);
-		if (fd > 0)
+		if (fd >= 0)
 			return fd;
 		/*
 		 * Fatal error (EPERM, ENOSPC etc).

Is this a sensible place to put this test?

Dale

  reply	other threads:[~2013-07-18 22:46 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-07-12  8:58 [PATCH 0/2] open() error checking Thomas Rast
2013-07-12  8:58 ` [PATCH 1/2] git_mkstemps: correctly test return value of open() Thomas Rast
2013-07-16  9:37   ` Thomas Rast
2013-07-17 19:29     ` Junio C Hamano
2013-07-18 12:32       ` Drew Northup
2013-07-18 17:46         ` Junio C Hamano
2013-07-18 17:47           ` Junio C Hamano
2013-07-18 20:32           ` Dale R. Worley
2013-07-18 20:49             ` Eric Sunshine
2013-07-18 20:54             ` Junio C Hamano
2013-07-18 22:46               ` Dale R. Worley [this message]
2013-07-18 23:23                 ` Junio C Hamano
2013-07-18 23:29                   ` Dale R. Worley
2013-07-12  8:58 ` [PATCH 2/2] run-command: dup_devnull(): guard against syscalls failing Thomas Rast
2013-07-12 17:29 ` [PATCH 0/2] open() error checking Junio C Hamano
2013-07-16  9:25   ` Thomas Rast
2013-07-16  9:27   ` [PATCH 1/2] daemon/shell: refactor redirection of 0/1/2 from /dev/null Thomas Rast
2013-07-16  9:27     ` [PATCH 2/2] git: ensure 0/1/2 are open in main() Thomas Rast

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=201307182246.r6IMkDiW021930@freeze.ariadne.com \
    --to=worley@alum.mit.edu \
    --cc=fonseca@diku.dk \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=n1xim.email@gmail.com \
    --cc=trast@inf.ethz.ch \
    /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;
as well as URLs for NNTP newsgroup(s).