| 1 |
(* pexecute.def provides an interface to libiberty pexecute.c |
| 2 |
|
| 3 |
Copyright (C) 2001-2025 Free Software Foundation, Inc. |
| 4 |
Contributed by Gaius Mulley <[email protected]>. |
| 5 |
|
| 6 |
This file is part of GNU Modula-2. |
| 7 |
|
| 8 |
GNU Modula-2 is free software; you can redistribute it and/or modify |
| 9 |
it under the terms of the GNU General Public License as published by |
| 10 |
the Free Software Foundation; either version 3, or (at your option) |
| 11 |
any later version. |
| 12 |
|
| 13 |
GNU Modula-2 is distributed in the hope that it will be useful, but |
| 14 |
WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 16 |
General Public License for more details. |
| 17 |
|
| 18 |
You should have received a copy of the GNU General Public License |
| 19 |
along with GNU Modula-2; see the file COPYING3. If not see |
| 20 |
<http://www.gnu.org/licenses/>. *) |
| 21 |
|
| 22 |
DEFINITION MODULE FOR "C" pexecute ; |
| 23 |
|
| 24 |
FROM SYSTEM IMPORT ADDRESS ; |
| 25 |
|
| 26 |
EXPORT UNQUALIFIED pexecute ; |
| 27 |
|
| 28 |
(* |
| 29 |
PROGRAM and ARGV are the arguments to execv/execvp. |
| 30 |
|
| 31 |
THIS_PNAME is name of the calling program (i.e. argv[0]). |
| 32 |
|
| 33 |
TEMP_BASE is the path name, sans suffix, of a temporary file to use |
| 34 |
if needed. This is currently only needed for MSDOS ports that dont use |
| 35 |
GO32 (do any still exist?). Ports that dont need it can pass NULL. |
| 36 |
|
| 37 |
(FLAGS & PEXECUTE_SEARCH) is non-zero if $PATH should be searched |
| 38 |
(??? Its not clear that GCC passes this flag correctly). |
| 39 |
(FLAGS & PEXECUTE_FIRST) is nonzero for the first process in chain. |
| 40 |
(FLAGS & PEXECUTE_FIRST) is nonzero for the last process in chain. |
| 41 |
FIRST_LAST could be simplified to only mark the last of a chain of processes |
| 42 |
but that requires the caller to always mark the last one (and not give up |
| 43 |
early if some error occurs). Its more robust to require the caller to |
| 44 |
mark both ends of the chain. |
| 45 |
|
| 46 |
The result is the pid on systems like Unix where we fork/exec and on systems |
| 47 |
like WIN32 and OS2 where we use spawn. It is up to the caller to wait for |
| 48 |
the child. |
| 49 |
|
| 50 |
The result is the WEXITSTATUS on systems like MSDOS where we spawn and wait |
| 51 |
for the child here. |
| 52 |
|
| 53 |
Upon failure, ERRMSG_FMT and ERRMSG_ARG are set to the text of the error |
| 54 |
message with an optional argument (if not needed, ERRMSG_ARG is set to |
| 55 |
NULL), and -1 is returned. errno is available to the caller to use. |
| 56 |
|
| 57 |
pwait: cover function for wait. |
| 58 |
|
| 59 |
PID is the process id of the task to wait for. |
| 60 |
STATUS is the status argument to wait. |
| 61 |
FLAGS is currently unused (allows future enhancement without breaking |
| 62 |
upward compatibility). Pass 0 for now. |
| 63 |
|
| 64 |
The result is the pid of the child reaped, |
| 65 |
or -1 for failure (errno says why). |
| 66 |
|
| 67 |
On systems that dont support waiting for a particular child, PID is |
| 68 |
ignored. On systems like MSDOS that dont really multitask pwait |
| 69 |
is just a mechanism to provide a consistent interface for the caller. |
| 70 |
|
| 71 |
pfinish: finish generation of script |
| 72 |
|
| 73 |
pfinish is necessary for systems like MPW where a script is generated that |
| 74 |
runs the requested programs. |
| 75 |
*) |
| 76 |
|
| 77 |
PROCEDURE pexecute (program: ADDRESS; argv: ADDRESS; this_pname: ADDRESS; |
| 78 |
temp_base: ADDRESS; |
| 79 |
VAR errmsg_fmt, errmsg_arg: ADDRESS; flags: CARDINAL) : INTEGER ; |
| 80 |
|
| 81 |
|
| 82 |
END pexecute. |