summaryrefslogtreecommitdiff
path: root/shell.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2013-07-22 11:23:35 -0700
committerJunio C Hamano <gitster@pobox.com>2013-07-22 11:23:35 -0700
commitcb29dfde484e459e4329281151b05ef1c5ad462c (patch)
tree7d99f8e0d925b8369757793d6a9f65d27691a4a5 /shell.c
parent5701c3d701d3932d853ffb9f75ee8745fae21209 (diff)
parenta11c39646c14600d588ca55fcfe3c244b66047c7 (diff)
downloadgit-cb29dfde484e459e4329281151b05ef1c5ad462c.tar.gz
Merge branch 'tr/protect-low-3-fds'
When "git" is spawned in such a way that any of the low 3 file descriptors is closed, our first open() may yield file descriptor 2, and writing error message to it would screw things up in a big way. * tr/protect-low-3-fds: git: ensure 0/1/2 are open in main() daemon/shell: refactor redirection of 0/1/2 from /dev/null
Diffstat (limited to 'shell.c')
-rw-r--r--shell.c12
1 files changed, 3 insertions, 9 deletions
diff --git a/shell.c b/shell.c
index 1429870a8f..66350b220c 100644
--- a/shell.c
+++ b/shell.c
@@ -147,7 +147,6 @@ int main(int argc, char **argv)
char *prog;
const char **user_argv;
struct commands *cmd;
- int devnull_fd;
int count;
git_setup_gettext();
@@ -156,15 +155,10 @@ int main(int argc, char **argv)
/*
* 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.
+ * in die(). It also avoids 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_errno("opening /dev/null failed");
- close (devnull_fd);
+ sanitize_stdfds();
/*
* Special hack to pretend to be a CVS server