Remove the RCSID macro
[openafs.git] / src / procmgmt / procmgmt_unix.c
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  * 
5  * This software has been released under the terms of the IBM Public
6  * License.  For details, see the LICENSE file in the top-level source
7  * directory or online at http://www.openafs.org/dl/license10.html
8  */
9
10 #include <afsconfig.h>
11 #include <afs/param.h>
12
13
14 #include <afs/stds.h>
15
16 #include <stddef.h>
17 #include <stdlib.h>
18 #include <errno.h>
19
20 #include "procmgmt.h"
21 #include "pmgtprivate.h"
22
23
24 /* -----------------  Processes  ---------------- */
25
26
27 /*
28  * pmgt_ProcessSpawnVE() -- Spawn a process (Unix fork()/execve() semantics)
29  *
30  *     Returns pid of the child process ((pid_t)-1 on failure with errno set).
31  *
32  *     Notes: A senvp value of NULL results in Unix fork()/execv() semantics.
33  *            Open files are not inherited, except stdin, stdout, and stderr.
34  *            If child fails to exec() spath, its exit code is estatus.
35  *
36  * ASSUMPTIONS: sargv[0] is the same as spath (or its last component).
37  */
38 pid_t
39 pmgt_ProcessSpawnVE(const char *spath, char *sargv[], char *senvp[],
40                     int estatus)
41 {
42     pid_t pid;
43
44     /* create child process to exec spath */
45     if ((pid = fork()) == 0) {
46         /* child process */
47         int i;
48
49         /* close random fd's above stderr */
50         for (i = 3; i < 64; i++) {
51             close(i);
52         }
53
54         if (senvp) {
55             execve(spath, sargv, senvp);
56         } else {
57             execv(spath, sargv);
58         }
59
60         /* this point is only reached if exec() failed */
61         exit(estatus);
62     } else {
63         /* parent process */
64         return pid;
65     }
66 }