From 5ad44e1ce236a2c1145d541f00d67ce21be3cce6 Mon Sep 17 00:00:00 2001 From: verhaegs Date: Sat, 4 Feb 2012 00:06:40 +0000 Subject: [PATCH] compiler/clib: refactoring; moved some of fdesc handling code from __exec.c to __fdesc.c git-svn-id: https://svn.aros.org/svn/aros/trunk/AROS@43838 fb15a70f-31f2-0310-bbcc-cdcc74a49acc --- compiler/clib/__exec.c | 24 +++--------------------- compiler/clib/__fdesc.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ compiler/clib/__fdesc.h | 6 +++++- compiler/clib/__vfork.c | 9 +++------ 4 files changed, 55 insertions(+), 28 deletions(-) diff --git a/compiler/clib/__exec.c b/compiler/clib/__exec.c index bfbe9d93ba..cee1d2b092 100644 --- a/compiler/clib/__exec.c +++ b/compiler/clib/__exec.c @@ -34,7 +34,6 @@ static char *escape(const char *str); static char *appendarg(char *argptr, int *argptrsize, const char *arg, APTR pool); static char *appendargs(char *argptr, int *argptrsize, char *const args[], APTR pool); static void __exec_cleanup(struct aroscbase *aroscbase); -static void close_on_exec(struct aroscbase *aroscbase); /* Public functions */ /********************/ @@ -179,6 +178,8 @@ APTR __exec_prepare(const char *filename, int searchpath, char *const argv[], ch { D(bug("__exec_prepare: Continue child immediately on error\n")); Signal(udata->child, 1 << udata->child_signal); + + return NULL; } D(bug("__exec_prepare: Exiting from forked __exec_prepare id=%x, errno=%d\n", @@ -413,7 +414,7 @@ void __exec_do(APTR id) D(bug("[__exec_do] PRETEND_CHILD\n")); - close_on_exec(aroscbase); + __close_on_exec_fdescs(); D(bug("Notify child to call __exec_do\n")); @@ -645,22 +646,3 @@ static void __exec_cleanup(struct aroscbase *aroscbase) aroscbase->acb_exec_seglist = (BPTR)NULL; } } - -static void close_on_exec(struct aroscbase *aroscbase) -{ - int i; - fdesc *fd; - - for (i = __getfdslots() - 1; i >= 0; i--) - { - if ((fd = __getfdesc(i)) != NULL) - { - D(bug("close_on_exec: checking fd %d\n", i)); - if (fd->fdflags & FD_CLOEXEC) - { - D(bug("close_on_exec: closing fd %d\n", i)); - assert(close(i) == 0); - } - } - } -} diff --git a/compiler/clib/__fdesc.c b/compiler/clib/__fdesc.c index 486e934e5c..4048d0da6d 100644 --- a/compiler/clib/__fdesc.c +++ b/compiler/clib/__fdesc.c @@ -28,6 +28,29 @@ static struct SignalSemaphore __fdsem; static struct MinList __fdreglist; +void __getfdarray(APTR *arrayptr, int *slotsptr) +{ + struct aroscbase *aroscbase = __GM_GetBase(); + + *arrayptr = aroscbase->acb_fd_array; + *slotsptr = aroscbase->acb_numslots; +} + +void __setfdarray(APTR array, int slots) +{ + struct aroscbase *aroscbase = __GM_GetBase(); + aroscbase->acb_fd_array = array; + aroscbase->acb_numslots = slots; +} + +void __setfdarraybase(struct aroscbase *aroscbase2) +{ + struct aroscbase *aroscbase = __GM_GetBase(); + + aroscbase->acb_fd_array = aroscbase2->acb_fd_array; + aroscbase->acb_numslots = aroscbase2->acb_numslots; +} + int __getfdslots(void) { struct aroscbase *aroscbase = __GM_GetBase(); @@ -499,6 +522,27 @@ void __exit_fd(struct aroscbase *aroscbase) DeletePool(aroscbase->acb_fd_mempool); } +void __close_on_exec_fdescs(void) +{ + struct aroscbase *aroscbase = __GM_GetBase(); + + int i; + fdesc *fd; + + for (i = aroscbase->acb_numslots - 1; i >= 0; i--) + { + if ((fd = __getfdesc(i)) != NULL) + { + D(bug("__close_fdesc_on_exec: checking fd %d\n", i)); + if (fd->fdflags & FD_CLOEXEC) + { + D(bug("__close_fdesc_on_exec: closing fd %d\n", i)); + close(i); + } + } + } +} + #include void __updatestdio(void) diff --git a/compiler/clib/__fdesc.h b/compiler/clib/__fdesc.h index 64cbf66567..612bc05c9e 100644 --- a/compiler/clib/__fdesc.h +++ b/compiler/clib/__fdesc.h @@ -2,7 +2,7 @@ #define ___FDESC_H /* - Copyright © 1995-2011, The AROS Development Team. All rights reserved. + Copyright © 1995-2012, The AROS Development Team. All rights reserved. $Id$ Desc: file descriptors handling internals - header file @@ -34,6 +34,9 @@ typedef struct _fdesc struct aroscbase; int __register_init_fdarray(struct aroscbase *base); int __getfdslots(void); +void __getfdarray(APTR *arrayptr, int *slotsptr); +void __setfdarray(APTR array, int slots); +void __setfdarraybase(struct aroscbase *base); fdesc *__getfdesc(register int fd); void __setfdesc(register int fd, fdesc *fdesc); int __getfdslot(int wanted_fd); @@ -43,5 +46,6 @@ void __updatestdio(void); LONG __oflags2amode(int flags); fdesc *__alloc_fdesc(void); void __free_fdesc(fdesc *fdesc); +void __close_on_exec_fdescs(void); #endif /* ___FDESC_H */ diff --git a/compiler/clib/__vfork.c b/compiler/clib/__vfork.c index a774eae465..bcc860b716 100644 --- a/compiler/clib/__vfork.c +++ b/compiler/clib/__vfork.c @@ -336,10 +336,8 @@ static void parent_enterpretendchild(struct vfork_data *udata) /* Remember and switch fd descriptor table */ udata->parent_fd_mempool = aroscbase->acb_fd_mempool; aroscbase->acb_fd_mempool = udata->child_aroscbase->acb_fd_mempool; - udata->parent_numslots = aroscbase->acb_numslots; - aroscbase->acb_numslots = udata->child_aroscbase->acb_numslots; - udata->parent_fd_array = aroscbase->acb_fd_array; - aroscbase->acb_fd_array = udata->child_aroscbase->acb_fd_array; + __getfdarray((APTR *)&udata->parent_fd_array, &udata->parent_numslots); + __setfdarraybase(udata->child_aroscbase); /* Remember and switch chdir fields */ udata->parent_cd_changed = aroscbase->acb_cd_changed; @@ -380,8 +378,7 @@ static void parent_leavepretendchild(struct vfork_data *udata) /* Restore parent's old fd_array */ aroscbase->acb_fd_mempool = udata->parent_fd_mempool; - aroscbase->acb_numslots = udata->parent_numslots; - aroscbase->acb_fd_array = udata->parent_fd_array; + __setfdarray(udata->parent_fd_array, udata->parent_numslots); /* Switch to currentdir from before vfork() call */ aroscbase->acb_cd_changed = udata->parent_cd_changed; -- 2.11.4.GIT