summaryrefslogtreecommitdiff
path: root/shell.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2008-08-29 00:16:39 -0700
committerJunio C Hamano <gitster@pobox.com>2008-08-29 00:16:39 -0700
commit445cac18c015809a7fcb4a570d3c6571b1ddaf7d (patch)
tree89eeb8e6618d9eb582ea5bd1a2cf781625ebc001 /shell.c
parente990501312e22cfa910d88dc7143bc4eb3632ae1 (diff)
parent53d1589ff6bd336e3ece39e0a963a3d2a537cf96 (diff)
downloadgit-445cac18c015809a7fcb4a570d3c6571b1ddaf7d.tar.gz
Merge branch 'maint'
* maint: tutorial: gentler illustration of Alice/Bob workflow using gitk pretty=format: respect date format options make git-shell paranoid about closed stdin/stdout/stderr Document gitk --argscmd flag. Fix '--dirstat' with cross-directory renaming for-each-ref: Allow a trailing slash in the patterns
Diffstat (limited to 'shell.c')
-rw-r--r--shell.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/shell.c b/shell.c
index 0f6a727a8c..e3393690dd 100644
--- a/shell.c
+++ b/shell.c
@@ -48,6 +48,19 @@ int main(int argc, char **argv)
{
char *prog;
struct commands *cmd;
+ int devnull_fd;
+
+ /*
+ * Always open file descriptors 0/1/2 to avoid clobbering files
+ * in die(). It also avoids not messing up when the pipes are
+ * dup'ed onto stdin/stdout/stderr in the child processes we spawn.
+ */
+ devnull_fd = open("/dev/null", O_RDWR);
+ while (devnull_fd >= 0 && devnull_fd <= 2)
+ devnull_fd = dup(devnull_fd);
+ if (devnull_fd == -1)
+ die("opening /dev/null failed (%s)", strerror(errno));
+ close (devnull_fd);
/*
* Special hack to pretend to be a CVS server