Skip to content

Commit 085bb40

Browse files
committed
xspawn: Use _Fork() if available
This completes the workaround for bfs_spawn() hanging on FreeBSD with ASan enabled. Link: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=280318
1 parent c43d548 commit 085bb40

File tree

5 files changed

+22
-0
lines changed

5 files changed

+22
-0
lines changed

build/flags.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ include build/exports.mk
105105

106106
# Conditionally-supported flags
107107
AUTO_FLAGS := \
108+
gen/flags/bind-now.mk \
108109
gen/flags/deps.mk \
109110
gen/flags/missing-var-decls.mk
110111

build/flags/bind-now.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// Copyright © Tavian Barnes <[email protected]>
2+
// SPDX-License-Identifier: 0BSD
3+
4+
/// _LDFLAGS += -Wl,-z,now
5+
6+
int main(void) {
7+
return 0;
8+
}

build/has/_Fork.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// Copyright © Tavian Barnes <[email protected]>
2+
// SPDX-License-Identifier: 0BSD
3+
4+
#include <unistd.h>
5+
6+
int main(void) {
7+
return _Fork();
8+
}

build/header.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ include build/exports.mk
1313
# All header fragments we generate
1414
HEADERS := \
1515
gen/has/--st-birthtim.h \
16+
gen/has/_Fork.h \
1617
gen/has/acl-get-entry.h \
1718
gen/has/acl-get-file.h \
1819
gen/has/acl-get-tag-type.h \

src/xspawn.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,11 @@ static pid_t bfs_fork_spawn(struct bfs_resolver *res, const struct bfs_spawn *ct
612612
goto fail;
613613
}
614614

615+
#if BFS_HAS__FORK
616+
pid_t pid = _Fork();
617+
#else
615618
pid_t pid = fork();
619+
#endif
616620
if (pid == 0) {
617621
// Child
618622
bfs_spawn_exec(res, ctx, argv, envp, pipefd);

0 commit comments

Comments
 (0)