Skip to content

Commit 83b9ef8

Browse files
authored
Merge pull request #213 from bgamari/wip/refactor
Various fixes for `posix_spawn` refactoring
2 parents 78b0a7f + 278746a commit 83b9ef8

File tree

5 files changed

+44
-10
lines changed

5 files changed

+44
-10
lines changed

cbits/posix/find_executable.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
#include "common.h"
1313

14-
// the below is only necessary when we don't have execvpe.
14+
// the below is only necessary when we need to emulate execvpe.
1515
#if !defined(HAVE_execvpe)
1616

1717
/* Return true if the given file exists and is an executable. */
@@ -28,7 +28,16 @@ static char *find_in_search_path(char *search_path, const char *filename) {
2828
char *tokbuf;
2929
char *path = strtok_r(search_path, ":", &tokbuf);
3030
while (path != NULL) {
31+
// N.B. gcc 6.3.0, used by Debian 9, inexplicably warns that `path`
32+
// may not be initialised with -Wall. Silence this warning. See #210.
33+
#if defined(__GNUC__) && __GNUC__ == 6 && __GNUC_MINOR__ == 3
34+
#pragma GCC diagnostic push
35+
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
36+
#endif
3137
const int tmp_len = filename_len + 1 + strlen(path) + 1;
38+
#if defined(__GNUC__) && __GNUC__ == 6 && __GNUC_MINOR__ == 3
39+
#pragma GCC diagnostic pop
40+
#endif
3241
char *tmp = malloc(tmp_len);
3342
snprintf(tmp, tmp_len, "%s/%s", path, filename);
3443
if (is_executable(tmp)) {

cbits/posix/fork_exec.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ setup_std_handle_fork(int fd,
6262
case STD_HANDLE_CLOSE:
6363
if (close(fd) == -1) {
6464
child_failed(pipe, "close");
65-
return -1;
6665
}
6766
return 0;
6867

@@ -84,7 +83,12 @@ setup_std_handle_fork(int fd,
8483
if (close(b->use_pipe.parent_end) == -1) {
8584
child_failed(pipe, "close(parent_end)");
8685
}
87-
break;
86+
return 0;
87+
88+
default:
89+
// N.B. this should be unreachable but some compilers apparently can't
90+
// see this.
91+
child_failed(pipe, "setup_std_handle_fork(invalid behavior)");
8892
}
8993
}
9094

@@ -219,7 +223,7 @@ do_spawn_fork (char *const args[],
219223

220224
/* Reset the SIGINT/SIGQUIT signal handlers in the child, if requested
221225
*/
222-
if (flags & RESET_INT_QUIT_HANDLERS != 0) {
226+
if ((flags & RESET_INT_QUIT_HANDLERS) != 0) {
223227
struct sigaction dfl;
224228
(void)sigemptyset(&dfl.sa_mask);
225229
dfl.sa_flags = 0;

cbits/posix/posix_spawn.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,13 @@ setup_std_handle_spawn (int fd,
6464
return -1;
6565
}
6666
return 0;
67+
68+
default:
69+
// N.B. this should be unreachable
70+
// but some compilers apparently can't
71+
// see this.
72+
*failed_doing = "posix_spawn_file_actions_addclose(invalid behavior)";
73+
return -1;
6774
}
6875
}
6976

@@ -143,11 +150,13 @@ do_spawn_posix (char *const args[],
143150
#endif
144151
}
145152

146-
#if defined(HAVE_POSIX_SPAWN_SETPGROUP)
147153
if ((flags & RUN_PROCESS_IN_NEW_GROUP) != 0) {
154+
#if defined(HAVE_POSIX_SPAWN_SETPGROUP)
148155
spawn_flags |= POSIX_SPAWN_SETPGROUP;
149-
}
156+
#else
157+
goto not_supported;
150158
#endif
159+
}
151160

152161
if (setup_std_handle_spawn(STDIN_FILENO, stdInHdl, &fa, failed_doing) != 0) {
153162
goto fail;

configure.ac

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,18 @@ AC_CHECK_FUNCS([execvpe])
1818

1919
# posix_spawn checks
2020
AC_CHECK_HEADERS([spawn.h])
21-
AC_CHECK_FUNCS([posix_spawnp posix_spawn_file_actions_addchdir])
22-
AC_CHECK_DECLS([POSIX_SPAWN_SETSID, POSIX_SPAWN_SETSID_NP])
23-
AC_CHECK_DECLS([POSIX_SPAWN_SETPGROUP])
21+
AC_CHECK_FUNCS([posix_spawnp posix_spawn_file_actions_addchdir],[],[],[
22+
#define _GNU_SOURCE
23+
#include <spawn.h>
24+
])
25+
AC_CHECK_DECLS([POSIX_SPAWN_SETSID, POSIX_SPAWN_SETSID_NP],[],[],[
26+
#define _GNU_SOURCE
27+
#include <spawn.h>
28+
])
29+
AC_CHECK_DECLS([POSIX_SPAWN_SETPGROUP],[],[],[
30+
#define _GNU_SOURCE
31+
#include <spawn.h>
32+
])
2433

2534
FP_CHECK_CONSTS([SIG_DFL SIG_IGN])
2635

tests/all.T

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@ test('T3994', [only_ways(['threaded1','threaded2']),
3838
test('T4889', normal, compile_and_run, [''])
3939
4040
test('process009', when(opsys('mingw32'), skip), compile_and_run, [''])
41-
test('process010', normalise_exec, compile_and_run, [''])
41+
test('process010', [
42+
normalise_fun(lambda s: s.replace('illegal operation (Inappropriate ioctl for device)', 'does not exist (No such file or directory)')),
43+
normalise_exec
44+
], compile_and_run, [''])
4245
test('process011', when(opsys('mingw32'), skip), compile_and_run, [''])
4346
4447
test('T8343', normal, compile_and_run, [''])

0 commit comments

Comments
 (0)