diff --git a/library/GNUmakefile.68k b/library/GNUmakefile.68k index 8fd6c90..15ae356 100644 --- a/library/GNUmakefile.68k +++ b/library/GNUmakefile.68k @@ -1,5 +1,5 @@ # -# $Id: GNUmakefile.68k,v 1.92 2006-08-02 08:00:27 obarthel Exp $ +# $Id: GNUmakefile.68k,v 1.93 2006-08-06 08:15:42 obarthel Exp $ # # :ts=8 # @@ -537,6 +537,7 @@ UNIX_LIB = \ unistd_execve.o \ unistd_execve_env_exit.o \ unistd_execve_env_init.o \ + unistd_execve_exit.o \ unistd_execvp.o \ unistd_fpathconf.o \ unistd_getcwd.o \ diff --git a/library/GNUmakefile.os4 b/library/GNUmakefile.os4 index 7d4d96a..1f7d5ab 100644 --- a/library/GNUmakefile.os4 +++ b/library/GNUmakefile.os4 @@ -1,5 +1,5 @@ # -# $Id: GNUmakefile.os4,v 1.105 2006-08-02 08:00:27 obarthel Exp $ +# $Id: GNUmakefile.os4,v 1.106 2006-08-06 08:15:42 obarthel Exp $ # # :ts=8 # @@ -580,6 +580,7 @@ UNIX_LIB = \ unistd_execve.o \ unistd_execve_env_exit.o \ unistd_execve_env_init.o \ + unistd_execve_exit.o \ unistd_execvp.o \ unistd_fpathconf.o \ unistd_getcwd.o \ diff --git a/library/include/dos.h b/library/include/dos.h index 7ed427e..f40ff36 100644 --- a/library/include/dos.h +++ b/library/include/dos.h @@ -1,5 +1,5 @@ /* - * $Id: dos.h,v 1.23 2006-08-02 08:00:30 obarthel Exp $ + * $Id: dos.h,v 1.24 2006-08-06 08:15:42 obarthel Exp $ * * :ts=4 * @@ -527,6 +527,19 @@ extern void __execve_environ_exit(char * const envp[]); /****************************************************************************/ +/* + * The __execve_exit() function is called by execve() if the command + * executed correctly and control should be returned to the shell. The + * default behaviour is to eventually call exit(). You can, however, + * replace __execve_exit() with a stub which does nothing at all. In + * that case the execve() function will return control to the caller + * instead. + */ + +extern void __execve_exit(int return_code); + +/****************************************************************************/ + #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/library/unistd_execve.c b/library/unistd_execve.c index 308f190..f750eec 100644 --- a/library/unistd_execve.c +++ b/library/unistd_execve.c @@ -1,5 +1,5 @@ /* - * $Id: unistd_execve.c,v 1.6 2006-08-02 14:44:01 obarthel Exp $ + * $Id: unistd_execve.c,v 1.7 2006-08-06 08:15:42 obarthel Exp $ * * :ts=4 * @@ -535,7 +535,9 @@ get_arg_string_length(char *const argv[]) size_t i,len; char * s; - for(i = 0 ; argv[i] != NULL ; i++) + /* The first argv[] element is skipped; it does not contain part of + the command line but holds the name of the program to be run. */ + for(i = 1 ; argv[i] != NULL ; i++) { s = (char *)argv[i]; @@ -571,7 +573,9 @@ build_arg_string(char *const argv[],char * arg_string) size_t i,j,len; char * s; - for(i = 0 ; argv[i] != NULL ; i++) + /* The first argv[] element is skipped; it does not contain part of + the command line but holds the name of the program to be run. */ + for(i = 1 ; argv[i] != NULL ; i++) { s = (char *)argv[i]; @@ -785,14 +789,12 @@ execve(const char *path, char *const argv[], char *const envp[]) if(pi != NULL) free_program_info(pi); - /* If things went well, we can actually quit now. */ - if(success) - exit(result); - if(arg_string != NULL) free(arg_string); - /* This function only returns control to the caller - if something went wrong... */ - return(-1); + /* If things went well, we can actually quit now. */ + if(success) + __execve_exit(result); + + return(result); } diff --git a/library/unistd_execve_exit.c b/library/unistd_execve_exit.c new file mode 100644 index 0000000..5560468 --- /dev/null +++ b/library/unistd_execve_exit.c @@ -0,0 +1,49 @@ +/* + * $Id: unistd_execve_exit.c,v 1.1 2006-08-06 08:15:42 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2006 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _UNISTD_HEADERS_H +#include "unistd_headers.h" +#endif /* _UNISTD_HEADERS_H */ + +/****************************************************************************/ + +/* This is a stub which you may need to override with your own implementation. + It is supposed to perform any cleanup duties for the currently running + program and then return control to the shell. However, it is perfectly + safe not to call exit() here and merely return immediately. In this case + the execve() function will simply return to the caller of the function. */ +void +__execve_exit(int return_code) +{ + exit(return_code); +}