mirror of
https://github.com/adtools/clib2.git
synced 2025-12-08 14:59:05 +00:00
- execve() no longer directly calls exit(), but a function which can be
replaced by the user. If that function __execve_exit() does not call exit but just returns to the caller without doing anything, execve() will return the caller with the return code of the RunCommand() function. git-svn-id: file:///Users/olsen/Code/migration-svn-zu-git/logical-line-staging/clib2/trunk@15122 87f5fb63-7c3d-0410-a384-fd976d0f7a62
This commit is contained in:
@ -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 \
|
||||
|
||||
@ -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 \
|
||||
|
||||
@ -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 */
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
49
library/unistd_execve_exit.c
Normal file
49
library/unistd_execve_exit.c
Normal file
@ -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 <olsen (at) sourcery.han.de>
|
||||
* 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);
|
||||
}
|
||||
Reference in New Issue
Block a user