Andrew's git
/
gitweb.git
/ diff
summary
|
log
|
commit
| diff |
tree
commit
grep
author
committer
pickaxe
?
re
run-command: don't die in child when duping /dev/null
author
Brandon Williams
<bmwill@google.com>
Wed, 19 Apr 2017 23:13:23 +0000
(16:13 -0700)
committer
Junio C Hamano
<gitster@pobox.com>
Fri, 21 Apr 2017 00:55:32 +0000
(17:55 -0700)
Signed-off-by: Brandon Williams <bmwill@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
run-command.c
patch
|
blob
|
history
raw
|
patch
|
inline
| side by side (parent:
ae25394
)
diff --git
a/run-command.c
b/run-command.c
index 15e2e74a7eb270085fd256d50ef0e05f20d682a1..b3a35dd82db18590bfad48f557873e7a47a3761d 100644
(file)
--- a/
run-command.c
+++ b/
run-command.c
@@
-117,18
+117,6
@@
static inline void close_pair(int fd[2])
close(fd[1]);
}
close(fd[1]);
}
-#ifndef GIT_WINDOWS_NATIVE
-static inline void dup_devnull(int to)
-{
- int fd = open("/dev/null", O_RDWR);
- if (fd < 0)
- die_errno(_("open /dev/null failed"));
- if (dup2(fd, to) < 0)
- die_errno(_("dup2(%d,%d) failed"), fd, to);
- close(fd);
-}
-#endif
-
static char *locate_in_PATH(const char *file)
{
const char *p = getenv("PATH");
static char *locate_in_PATH(const char *file)
{
const char *p = getenv("PATH");
@@
-444,12
+432,20
@@
int start_command(struct child_process *cmd)
#ifndef GIT_WINDOWS_NATIVE
{
int notify_pipe[2];
#ifndef GIT_WINDOWS_NATIVE
{
int notify_pipe[2];
+ int null_fd = -1;
char **childenv;
struct argv_array argv = ARGV_ARRAY_INIT;
if (pipe(notify_pipe))
notify_pipe[0] = notify_pipe[1] = -1;
char **childenv;
struct argv_array argv = ARGV_ARRAY_INIT;
if (pipe(notify_pipe))
notify_pipe[0] = notify_pipe[1] = -1;
+ if (cmd->no_stdin || cmd->no_stdout || cmd->no_stderr) {
+ null_fd = open("/dev/null", O_RDWR | O_CLOEXEC);
+ if (null_fd < 0)
+ die_errno(_("open /dev/null failed"));
+ set_cloexec(null_fd);
+ }
+
prepare_cmd(&argv, cmd);
childenv = prep_childenv(cmd->env);
prepare_cmd(&argv, cmd);
childenv = prep_childenv(cmd->env);
@@
-473,7
+469,7
@@
int start_command(struct child_process *cmd)
atexit(notify_parent);
if (cmd->no_stdin)
atexit(notify_parent);
if (cmd->no_stdin)
- dup
_devnull(
0);
+ dup
2(null_fd,
0);
else if (need_in) {
dup2(fdin[0], 0);
close_pair(fdin);
else if (need_in) {
dup2(fdin[0], 0);
close_pair(fdin);
@@
-483,7
+479,7
@@
int start_command(struct child_process *cmd)
}
if (cmd->no_stderr)
}
if (cmd->no_stderr)
- dup
_devnull(
2);
+ dup
2(null_fd,
2);
else if (need_err) {
dup2(fderr[1], 2);
close_pair(fderr);
else if (need_err) {
dup2(fderr[1], 2);
close_pair(fderr);
@@
-493,7
+489,7
@@
int start_command(struct child_process *cmd)
}
if (cmd->no_stdout)
}
if (cmd->no_stdout)
- dup
_devnull(
1);
+ dup
2(null_fd,
1);
else if (cmd->stdout_to_stderr)
dup2(2, 1);
else if (need_out) {
else if (cmd->stdout_to_stderr)
dup2(2, 1);
else if (need_out) {
@@
-553,6
+549,8
@@
int start_command(struct child_process *cmd)
}
close(notify_pipe[0]);
}
close(notify_pipe[0]);
+ if (null_fd >= 0)
+ close(null_fd);
argv_array_clear(&argv);
free(childenv);
}
argv_array_clear(&argv);
free(childenv);
}