diff options
author | Tavian Barnes <tavianator@tavianator.com> | 2023-11-10 22:22:01 -0500 |
---|---|---|
committer | Tavian Barnes <tavianator@tavianator.com> | 2023-11-10 22:22:01 -0500 |
commit | 640fa83406bb8c08d971be68b32b7e222e92e286 (patch) | |
tree | d6151f9dea6ffd02f68acca03a2696b0dd5bc712 /src/xspawn.c | |
parent | e44e07a6bff0dd21a3fb08f28cd161e03360328b (diff) | |
download | bfs-640fa83406bb8c08d971be68b32b7e222e92e286.tar.xz |
Initial support for Cosmopolitan Libc
Diffstat (limited to 'src/xspawn.c')
-rw-r--r-- | src/xspawn.c | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/src/xspawn.c b/src/xspawn.c index 01f21e9..6a2ebba 100644 --- a/src/xspawn.c +++ b/src/xspawn.c @@ -174,15 +174,38 @@ int bfs_spawn_addfchdir(struct bfs_spawn *ctx, int fd) { int bfs_spawn_addsetrlimit(struct bfs_spawn *ctx, int resource, const struct rlimit *rl) { struct bfs_spawn_action *action = bfs_spawn_action(BFS_SPAWN_SETRLIMIT); if (!action) { - return -1; + goto fail; + } + +#ifdef POSIX_SPAWN_SETRLIMIT + short flags; + errno = posix_spawnattr_getflags(&ctx->attr, &flags); + if (errno != 0) { + goto fail; + } + + flags |= POSIX_SPAWN_SETRLIMIT; + errno = posix_spawnattr_setflags(&ctx->attr, flags); + if (errno != 0) { + goto fail; } + errno = posix_spawnattr_setrlimit(&ctx->attr, resource, rl); + if (errno != 0) { + goto fail; + } +#else ctx->flags &= ~BFS_SPAWN_USE_POSIX; +#endif action->resource = resource; action->rlimit = *rl; SLIST_APPEND(ctx, action); return 0; + +fail: + free(action); + return -1; } /** bfs_spawn() implementation using posix_spawn(). */ |