lib: spawn(): Fix fd leak and stupid error handlinglab6-exercise5
commit68ad100e38d21945dec59b4cdddd80284c43659c
authorLuiz Fernando N. Capitulino <lcapitulino@gmail.com>
Sun, 9 Dec 2007 21:30:53 +0000 (9 19:30 -0200)
committerLuiz Fernando N. Capitulino <lcapitulino@gmail.com>
Sun, 9 Dec 2007 21:33:34 +0000 (9 19:33 -0200)
tree285934d5b531917779f0a95e52b706aa365df8db
parent3416245107753fbd4f45593a24e8628c14ace828
lib: spawn(): Fix fd leak and stupid error handling

if init_stack() fails, the error handling code will only call
sys_env_destroy() and continue! Yes, it'll go ahead and try to
setup the just created child...

Also, we're leaking the binary file's file descriptor in the child
because sys_exofork() and copy_shared_pages() will duplicate the
(still valid) fd's mapping into the child.

In order to fix both problems, this change introduces a new error
handling code, calls sys_exofork() before calling open() and closes
the file descriptor before calling copy_shared_pages().

Signed-off-by: Luiz Fernando N. Capitulino <lcapitulino@gmail.com>
src/lib/spawn.c