Index: newlib/libc/posix/posix_spawn.c |
diff --git a/newlib/libc/posix/posix_spawn.c b/newlib/libc/posix/posix_spawn.c |
index bc0e033725a8acc01c7d7e3667921d971319b7d6..7f13c7188b8d076a9b737e8de11131087e103821 100644 |
--- a/newlib/libc/posix/posix_spawn.c |
+++ b/newlib/libc/posix/posix_spawn.c |
@@ -91,13 +91,11 @@ Supporting OS subroutines required: <<_close>>, <<dup2>>, <<_fcntl>>, |
#include <sys/cdefs.h> |
#include <sys/signal.h> |
-#include <sys/queue.h> |
#include <sys/wait.h> |
#include <_syslist.h> |
#include <errno.h> |
#include <fcntl.h> |
-#include <sched.h> |
#include <spawn.h> |
#include <signal.h> |
#include <stdlib.h> |
@@ -109,46 +107,12 @@ Supporting OS subroutines required: <<_close>>, <<dup2>>, <<_fcntl>>, |
'environ'. */ |
static char ***p_environ = &environ; |
-struct __posix_spawnattr { |
- short sa_flags; |
- pid_t sa_pgroup; |
- struct sched_param sa_schedparam; |
- int sa_schedpolicy; |
- sigset_t sa_sigdefault; |
- sigset_t sa_sigmask; |
-}; |
- |
-struct __posix_spawn_file_actions { |
- STAILQ_HEAD(, __posix_spawn_file_actions_entry) fa_list; |
-}; |
- |
-typedef struct __posix_spawn_file_actions_entry { |
- STAILQ_ENTRY(__posix_spawn_file_actions_entry) fae_list; |
- enum { FAE_OPEN, FAE_DUP2, FAE_CLOSE } fae_action; |
- |
- int fae_fildes; |
- union { |
- struct { |
- char *path; |
-#define fae_path fae_data.open.path |
- int oflag; |
-#define fae_oflag fae_data.open.oflag |
- mode_t mode; |
-#define fae_mode fae_data.open.mode |
- } open; |
- struct { |
- int newfildes; |
-#define fae_newfildes fae_data.dup2.newfildes |
- } dup2; |
- } fae_data; |
-} posix_spawn_file_actions_entry_t; |
- |
/* |
* Spawn routines |
*/ |
static int |
-process_spawnattr(_CONST posix_spawnattr_t sa) |
+process_spawnattr(_CONST posix_spawnattr_t* sa) |
{ |
struct sigaction sigact = { .sa_flags = 0, .sa_handler = SIG_DFL }; |
int i; |
@@ -241,7 +205,7 @@ process_file_actions_entry(posix_spawn_file_actions_entry_t *fae) |
} |
static int |
-process_file_actions(_CONST posix_spawn_file_actions_t fa) |
+process_file_actions(_CONST posix_spawn_file_actions_t* fa) |
{ |
posix_spawn_file_actions_entry_t *fae; |
int error; |
@@ -270,12 +234,12 @@ do_posix_spawn(pid_t *pid, _CONST char *path, |
return (errno); |
case 0: |
if (sa != NULL) { |
- error = process_spawnattr(*sa); |
+ error = process_spawnattr(sa); |
if (error) |
_exit(127); |
} |
if (fa != NULL) { |
- error = process_file_actions(*fa); |
+ error = process_file_actions(fa); |
if (error) |
_exit(127); |
} |
@@ -318,261 +282,4 @@ _DEFUN(posix_spawnp, (pid, path, fa, sa, argv, envp), |
return do_posix_spawn(pid, path, fa, sa, argv, envp, 1); |
} |
-/* |
- * File descriptor actions |
- */ |
- |
-int |
-_DEFUN(posix_spawn_file_actions_init, (ret), |
- posix_spawn_file_actions_t *ret) |
-{ |
- posix_spawn_file_actions_t fa; |
- |
- fa = malloc(sizeof(struct __posix_spawn_file_actions)); |
- if (fa == NULL) |
- return (-1); |
- |
- STAILQ_INIT(&fa->fa_list); |
- *ret = fa; |
- return (0); |
-} |
- |
-int |
-_DEFUN(posix_spawn_file_actions_destroy, (fa), |
- posix_spawn_file_actions_t *fa) |
-{ |
- posix_spawn_file_actions_entry_t *fae; |
- |
- while ((fae = STAILQ_FIRST(&(*fa)->fa_list)) != NULL) { |
- /* Remove file action entry from the queue */ |
- STAILQ_REMOVE_HEAD(&(*fa)->fa_list, fae_list); |
- |
- /* Deallocate file action entry */ |
- if (fae->fae_action == FAE_OPEN) |
- free(fae->fae_path); |
- free(fae); |
- } |
- |
- free(*fa); |
- return (0); |
-} |
- |
-int |
-_DEFUN(posix_spawn_file_actions_addopen, (fa, fildes, path, oflag, mode), |
- posix_spawn_file_actions_t * __restrict fa _AND |
- int fildes _AND |
- _CONST char * __restrict path _AND |
- int oflag _AND |
- mode_t mode) |
-{ |
- posix_spawn_file_actions_entry_t *fae; |
- int error; |
- |
- if (fildes < 0) |
- return (EBADF); |
- |
- /* Allocate object */ |
- fae = malloc(sizeof(posix_spawn_file_actions_entry_t)); |
- if (fae == NULL) |
- return (errno); |
- |
- /* Set values and store in queue */ |
- fae->fae_action = FAE_OPEN; |
- fae->fae_path = strdup(path); |
- if (fae->fae_path == NULL) { |
- error = errno; |
- free(fae); |
- return (error); |
- } |
- fae->fae_fildes = fildes; |
- fae->fae_oflag = oflag; |
- fae->fae_mode = mode; |
- |
- STAILQ_INSERT_TAIL(&(*fa)->fa_list, fae, fae_list); |
- return (0); |
-} |
- |
-int |
-_DEFUN(posix_spawn_file_actions_adddup2, (fa, fildes, newfildes), |
- posix_spawn_file_actions_t *fa _AND |
- int fildes _AND |
- int newfildes) |
-{ |
- posix_spawn_file_actions_entry_t *fae; |
- |
- if (fildes < 0 || newfildes < 0) |
- return (EBADF); |
- |
- /* Allocate object */ |
- fae = malloc(sizeof(posix_spawn_file_actions_entry_t)); |
- if (fae == NULL) |
- return (errno); |
- |
- /* Set values and store in queue */ |
- fae->fae_action = FAE_DUP2; |
- fae->fae_fildes = fildes; |
- fae->fae_newfildes = newfildes; |
- |
- STAILQ_INSERT_TAIL(&(*fa)->fa_list, fae, fae_list); |
- return (0); |
-} |
- |
-int |
-_DEFUN(posix_spawn_file_actions_addclose, (fa, fildes), |
- posix_spawn_file_actions_t *fa _AND |
- int fildes) |
-{ |
- posix_spawn_file_actions_entry_t *fae; |
- |
- if (fildes < 0) |
- return (EBADF); |
- |
- /* Allocate object */ |
- fae = malloc(sizeof(posix_spawn_file_actions_entry_t)); |
- if (fae == NULL) |
- return (errno); |
- |
- /* Set values and store in queue */ |
- fae->fae_action = FAE_CLOSE; |
- fae->fae_fildes = fildes; |
- |
- STAILQ_INSERT_TAIL(&(*fa)->fa_list, fae, fae_list); |
- return (0); |
-} |
- |
-/* |
- * Spawn attributes |
- */ |
- |
-int |
-_DEFUN(posix_spawnattr_init, (ret), |
- posix_spawnattr_t *ret) |
-{ |
- posix_spawnattr_t sa; |
- |
- sa = calloc(1, sizeof(struct __posix_spawnattr)); |
- if (sa == NULL) |
- return (errno); |
- |
- /* Set defaults as specified by POSIX, cleared above */ |
- *ret = sa; |
- return (0); |
-} |
- |
-int |
-_DEFUN(posix_spawnattr_destroy, (sa), |
- posix_spawnattr_t *sa) |
-{ |
- free(*sa); |
- return (0); |
-} |
- |
-int |
-_DEFUN(posix_spawnattr_getflags, (sa, flags), |
- _CONST posix_spawnattr_t * __restrict sa _AND |
- short * __restrict flags) |
-{ |
- *flags = (*sa)->sa_flags; |
- return (0); |
-} |
- |
-int |
-_DEFUN(posix_spawnattr_getpgroup, (sa, pgroup), |
- _CONST posix_spawnattr_t * __restrict sa _AND |
- pid_t * __restrict pgroup) |
-{ |
- *pgroup = (*sa)->sa_pgroup; |
- return (0); |
-} |
- |
-int |
-_DEFUN(posix_spawnattr_getschedparam, (sa, schedparam), |
- _CONST posix_spawnattr_t * __restrict sa _AND |
- struct sched_param * __restrict schedparam) |
-{ |
- *schedparam = (*sa)->sa_schedparam; |
- return (0); |
-} |
- |
-int |
-_DEFUN(posix_spawnattr_getschedpolicy, (sa, schedpolicy), |
- _CONST posix_spawnattr_t * __restrict sa _AND |
- int * __restrict schedpolicy) |
-{ |
- *schedpolicy = (*sa)->sa_schedpolicy; |
- return (0); |
-} |
- |
-int |
-_DEFUN(posix_spawnattr_getsigdefault, (sa, sigdefault), |
- _CONST posix_spawnattr_t * __restrict sa _AND |
- sigset_t * __restrict sigdefault) |
-{ |
- *sigdefault = (*sa)->sa_sigdefault; |
- return (0); |
-} |
- |
-int |
-_DEFUN(posix_spawnattr_getsigmask, (sa, sigmask), |
- _CONST posix_spawnattr_t * __restrict sa _AND |
- sigset_t * __restrict sigmask) |
-{ |
- *sigmask = (*sa)->sa_sigmask; |
- return (0); |
-} |
- |
-int |
-_DEFUN(posix_spawnattr_setflags, (sa, flags), |
- posix_spawnattr_t *sa _AND |
- short flags) |
-{ |
- (*sa)->sa_flags = flags; |
- return (0); |
-} |
- |
-int |
-_DEFUN(posix_spawnattr_setpgroup, (sa, pgroup), |
- posix_spawnattr_t *sa _AND |
- pid_t pgroup) |
-{ |
- (*sa)->sa_pgroup = pgroup; |
- return (0); |
-} |
- |
-int |
-_DEFUN(posix_spawnattr_setschedparam, (sa, schedparam), |
- posix_spawnattr_t * __restrict sa _AND |
- _CONST struct sched_param * __restrict schedparam) |
-{ |
- (*sa)->sa_schedparam = *schedparam; |
- return (0); |
-} |
- |
-int |
-_DEFUN(posix_spawnattr_setschedpolicy, (sa, schedpolicy), |
- posix_spawnattr_t *sa _AND |
- int schedpolicy) |
-{ |
- (*sa)->sa_schedpolicy = schedpolicy; |
- return (0); |
-} |
- |
-int |
-_DEFUN(posix_spawnattr_setsigdefault, (sa, sigdefault), |
- posix_spawnattr_t * __restrict sa _AND |
- _CONST sigset_t * __restrict sigdefault) |
-{ |
- (*sa)->sa_sigdefault = *sigdefault; |
- return (0); |
-} |
- |
-int |
-_DEFUN(posix_spawnattr_setsigmask, (sa, sigmask), |
- posix_spawnattr_t * __restrict sa _AND |
- _CONST sigset_t * __restrict sigmask) |
-{ |
- (*sa)->sa_sigmask = *sigmask; |
- return (0); |
-} |
- |
#endif /* !_NO_POSIX_SPAWN */ |