Skip to content

Commit e350625

Browse files
committed
Merge branch 'bw/forking-and-threading' into maint
The "run-command" API implementation has been made more robust against dead-locking in a threaded environment. * bw/forking-and-threading: usage.c: drop set_error_handle() run-command: restrict PATH search to executable files run-command: expose is_executable function run-command: block signals between fork and execve run-command: add note about forking and threading run-command: handle dup2 and close errors in child run-command: eliminate calls to error handling functions in child run-command: don't die in child when duping /dev/null run-command: prepare child environment before forking string-list: add string_list_remove function run-command: use the async-signal-safe execv instead of execvp run-command: prepare command before forking t0061: run_command executes scripts without a #! line t5550: use write_script to generate post-update hook
2 parents 7a190a2 + e3f43ce commit e350625

File tree

9 files changed

+449
-134
lines changed

9 files changed

+449
-134
lines changed

git-compat-util.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,6 @@ extern void (*get_error_routine(void))(const char *err, va_list params);
445445
extern void set_warn_routine(void (*routine)(const char *warn, va_list params));
446446
extern void (*get_warn_routine(void))(const char *warn, va_list params);
447447
extern void set_die_is_recursing_routine(int (*routine)(void));
448-
extern void set_error_handle(FILE *);
449448

450449
extern int starts_with(const char *str, const char *prefix);
451450

help.c

Lines changed: 1 addition & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "cache.h"
22
#include "builtin.h"
33
#include "exec_cmd.h"
4+
#include "run-command.h"
45
#include "levenshtein.h"
56
#include "help.h"
67
#include "common-cmds.h"
@@ -96,48 +97,6 @@ static void pretty_print_cmdnames(struct cmdnames *cmds, unsigned int colopts)
9697
string_list_clear(&list, 0);
9798
}
9899

99-
static int is_executable(const char *name)
100-
{
101-
struct stat st;
102-
103-
if (stat(name, &st) || /* stat, not lstat */
104-
!S_ISREG(st.st_mode))
105-
return 0;
106-
107-
#if defined(GIT_WINDOWS_NATIVE)
108-
/*
109-
* On Windows there is no executable bit. The file extension
110-
* indicates whether it can be run as an executable, and Git
111-
* has special-handling to detect scripts and launch them
112-
* through the indicated script interpreter. We test for the
113-
* file extension first because virus scanners may make
114-
* it quite expensive to open many files.
115-
*/
116-
if (ends_with(name, ".exe"))
117-
return S_IXUSR;
118-
119-
{
120-
/*
121-
* Now that we know it does not have an executable extension,
122-
* peek into the file instead.
123-
*/
124-
char buf[3] = { 0 };
125-
int n;
126-
int fd = open(name, O_RDONLY);
127-
st.st_mode &= ~S_IXUSR;
128-
if (fd >= 0) {
129-
n = read(fd, buf, 2);
130-
if (n == 2)
131-
/* look for a she-bang */
132-
if (!strcmp(buf, "#!"))
133-
st.st_mode |= S_IXUSR;
134-
close(fd);
135-
}
136-
}
137-
#endif
138-
return st.st_mode & S_IXUSR;
139-
}
140-
141100
static void list_commands_in_dir(struct cmdnames *cmds,
142101
const char *path,
143102
const char *prefix)

0 commit comments

Comments
 (0)