Skip to content

Commit

Permalink
xspawn: Use _Fork() if available
Browse files Browse the repository at this point in the history
This completes the workaround for bfs_spawn() hanging on FreeBSD with
ASan enabled.

Link: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=280318
  • Loading branch information
tavianator committed Jul 27, 2024
1 parent c43d548 commit 085bb40
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions build/flags.mk
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ include build/exports.mk

# Conditionally-supported flags
AUTO_FLAGS := \
gen/flags/bind-now.mk \
gen/flags/deps.mk \
gen/flags/missing-var-decls.mk

Expand Down
8 changes: 8 additions & 0 deletions build/flags/bind-now.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Copyright © Tavian Barnes <tavianator@tavianator.com>
// SPDX-License-Identifier: 0BSD

/// _LDFLAGS += -Wl,-z,now

int main(void) {
return 0;
}
8 changes: 8 additions & 0 deletions build/has/_Fork.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Copyright © Tavian Barnes <tavianator@tavianator.com>
// SPDX-License-Identifier: 0BSD

#include <unistd.h>

int main(void) {
return _Fork();
}
1 change: 1 addition & 0 deletions build/header.mk
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ include build/exports.mk
# All header fragments we generate
HEADERS := \
gen/has/--st-birthtim.h \
gen/has/_Fork.h \
gen/has/acl-get-entry.h \
gen/has/acl-get-file.h \
gen/has/acl-get-tag-type.h \
Expand Down
4 changes: 4 additions & 0 deletions src/xspawn.c
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,11 @@ static pid_t bfs_fork_spawn(struct bfs_resolver *res, const struct bfs_spawn *ct
goto fail;
}

#if BFS_HAS__FORK
pid_t pid = _Fork();
#else
pid_t pid = fork();
#endif
if (pid == 0) {
// Child
bfs_spawn_exec(res, ctx, argv, envp, pipefd);
Expand Down

0 comments on commit 085bb40

Please sign in to comment.