Module Name: src Committed By: christos Date: Sun Nov 7 14:34:30 UTC 2021
Modified Files: src/include: spawn.h src/lib/libc/gen: posix_spawn_fileactions.c Log Message: Commit the userland portion of the posix_spawn_chdir project by Piyush Sachdeva To generate a diff of this commit: cvs rdiff -u -r1.4 -r1.5 src/include/spawn.h cvs rdiff -u -r1.4 -r1.5 src/lib/libc/gen/posix_spawn_fileactions.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/include/spawn.h diff -u src/include/spawn.h:1.4 src/include/spawn.h:1.5 --- src/include/spawn.h:1.4 Wed Feb 22 12:51:01 2012 +++ src/include/spawn.h Sun Nov 7 09:34:30 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: spawn.h,v 1.4 2012/02/22 17:51:01 martin Exp $ */ +/* $NetBSD: spawn.h,v 1.5 2021/11/07 14:34:30 christos Exp $ */ /*- * Copyright (c) 2008 Ed Schouten <e...@freebsd.org> @@ -56,6 +56,10 @@ int posix_spawn_file_actions_addopen(pos int posix_spawn_file_actions_adddup2(posix_spawn_file_actions_t *, int, int); int posix_spawn_file_actions_addclose(posix_spawn_file_actions_t *, int); +int posix_spawn_file_actions_addchdir(posix_spawn_file_actions_t * __restrict, + const char * __restrict); +int posix_spawn_file_actions_addfchdir(posix_spawn_file_actions_t *, int); + /* * Spawn attributes */ Index: src/lib/libc/gen/posix_spawn_fileactions.c diff -u src/lib/libc/gen/posix_spawn_fileactions.c:1.4 src/lib/libc/gen/posix_spawn_fileactions.c:1.5 --- src/lib/libc/gen/posix_spawn_fileactions.c:1.4 Sun Feb 2 09:54:39 2014 +++ src/lib/libc/gen/posix_spawn_fileactions.c Sun Nov 7 09:34:30 2021 @@ -25,7 +25,7 @@ */ #include <sys/cdefs.h> -__RCSID("$NetBSD: posix_spawn_fileactions.c,v 1.4 2014/02/02 14:54:39 martin Exp $"); +__RCSID("$NetBSD: posix_spawn_fileactions.c,v 1.5 2021/11/07 14:34:30 christos Exp $"); #include "namespace.h" @@ -171,3 +171,47 @@ posix_spawn_file_actions_addclose(posix_ return 0; } + +int +posix_spawn_file_actions_addchdir(posix_spawn_file_actions_t * __restrict fa, + const char * __restrict path) +{ + char *dirpath; + unsigned int i; + int error; + + error = posix_spawn_file_actions_getentry(fa, &i); + if (error) + return error; + + dirpath = strdup(path); + if (dirpath == NULL) + return ENOMEM; + + fa->fae[i].fae_action = FAE_CHDIR; + fa->fae[i].fae_chdir_path = dirpath; + fa->fae[i].fae_fildes = -1; + fa->len++; + + return 0; +} + +int +posix_spawn_file_actions_addfchdir(posix_spawn_file_actions_t *fa, int fildes) +{ + unsigned int i; + int error; + + if (fildes < 0) + return EBADF; + + error = posix_spawn_file_actions_getentry(fa, &i); + if (error) + return error; + + fa->fae[i].fae_action = FAE_FCHDIR; + fa->fae[i].fae_fildes = fildes; + fa->len++; + + return 0; +}