summaryrefslogtreecommitdiff
path: root/shell.c
diff options
context:
space:
mode:
authorThomas Rast <trast@inf.ethz.ch>2013-07-16 09:27:36 (GMT)
committerJunio C Hamano <gitster@pobox.com>2013-07-17 19:50:34 (GMT)
commit1d999ddd1daa6da2779d21b293ea9b275780bff8 (patch)
tree4c179cf554418c4acf3249a64b021225a5ec6361 /shell.c
parent62e91efafd2030b7dc33ac6450b4e9a316e6ecc6 (diff)
downloadgit-1d999ddd1daa6da2779d21b293ea9b275780bff8.zip
git-1d999ddd1daa6da2779d21b293ea9b275780bff8.tar.gz
git-1d999ddd1daa6da2779d21b293ea9b275780bff8.tar.bz2
daemon/shell: refactor redirection of 0/1/2 from /dev/null
Both daemon.c and shell.c contain logic to open FDs 0/1/2 from /dev/null if they are not already open. Move the function in daemon.c to setup.c and use it in shell.c, too. While there, remove a 'not' that inverted the meaning of the comment. The point is indeed to *avoid* messing up. Signed-off-by: Thomas Rast <trast@inf.ethz.ch> Signed-off-by: Junio C Hamano <gitster@pobox.com>
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 84b237f..d6fb9f0 100644
--- a/shell.c
+++ b/shell.c
@@ -134,7 +134,6 @@ int main(int argc, char **argv)
char *prog;
const char **user_argv;
struct commands *cmd;
- int devnull_fd;
int count;
git_setup_gettext();
@@ -143,15 +142,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