xref: /titanic_44/usr/src/lib/libast/common/obsolete/spawn.c (revision 3e14f97f673e8a630f076077de35afdd43dc1587)
1 /***********************************************************************
2 *                                                                      *
3 *               This software is part of the ast package               *
4 *          Copyright (c) 1985-2010 AT&T Intellectual Property          *
5 *                      and is licensed under the                       *
6 *                  Common Public License, Version 1.0                  *
7 *                    by AT&T Intellectual Property                     *
8 *                                                                      *
9 *                A copy of the License is available at                 *
10 *            http://www.opensource.org/licenses/cpl1.0.txt             *
11 *         (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9)         *
12 *                                                                      *
13 *              Information and Software Systems Research               *
14 *                            AT&T Research                             *
15 *                           Florham Park NJ                            *
16 *                                                                      *
17 *                 Glenn Fowler <gsf@research.att.com>                  *
18 *                  David Korn <dgk@research.att.com>                   *
19 *                   Phong Vo <kpv@research.att.com>                    *
20 *                                                                      *
21 ***********************************************************************/
22 #pragma prototyped
23 
24 /*
25  * OBSOLETE 20030321 -- use spawnveg()
26  */
27 
28 #include <ast_lib.h>
29 
30 #if !_lib_spawnve
31 #define spawnve		______spawnve
32 #endif
33 #if !_lib_spawnvpe
34 #define spawnvpe	______spawnvpe
35 #endif
36 #if !_lib_spawnvp
37 #define spawnvp		______spawnvp
38 #endif
39 #if !_lib_spawnlp
40 #define spawnlp		______spawnlp
41 #endif
42 
43 #include <ast.h>
44 #include <error.h>
45 
46 #if !_lib_spawnve
47 #undef	spawnve
48 #endif
49 #if !_lib_spawnvpe
50 #undef	spawnvpe
51 #endif
52 #if !_lib_spawnvp
53 #undef	spawnvp
54 #endif
55 #if !_lib_spawnlp
56 #undef	spawnlp
57 #endif
58 
59 #if defined(__EXPORT__)
60 #define extern	__EXPORT__
61 #endif
62 
63 #if _lib_spawnve
64 
65 NoN(spawnve)
66 
67 #else
68 
69 extern pid_t
70 spawnve(const char* cmd, char* const argv[], char* const envv[])
71 {
72 	return spawnveg(cmd, argv, envv, 0);
73 }
74 
75 #endif
76 
77 #if _lib_spawnvpe
78 
79 NoN(spawnvpe)
80 
81 #else
82 
83 extern pid_t
84 spawnvpe(const char* name, char* const argv[], char* const envv[])
85 {
86 	register const char*	path = name;
87 	pid_t			pid;
88 	char			buffer[PATH_MAX];
89 
90 	if (*path != '/')
91 		path = pathpath(buffer, name, NULL, PATH_REGULAR|PATH_EXECUTE);
92 	if ((pid = spawnve(path, argv, envv)) >= 0)
93 		return pid;
94 	if (errno == ENOEXEC)
95 	{
96 		register char**	newargv;
97 		register char**	ov;
98 		register char**	nv;
99 
100 		for (ov = (char**)argv; *ov++;);
101 		if (newargv = newof(0, char*, ov + 1 - (char**)argv, 0))
102 		{
103 			nv = newargv;
104 			*nv++ = "sh";
105 			*nv++ = (char*)path;
106 			ov = (char**)argv;
107 			while (*nv++ = *++ov);
108 			path = pathshell();
109 			pid = spawnve(path, newargv, environ);
110 			free(newargv);
111 		}
112 		else
113 			errno = ENOMEM;
114 	}
115 	return pid;
116 }
117 
118 #endif
119 
120 #if _lib_spawnvp
121 
122 NoN(spawnvp)
123 
124 #else
125 
126 extern pid_t
127 spawnvp(const char* name, char* const argv[])
128 {
129 	return spawnvpe(name, argv, environ);
130 }
131 
132 #endif
133 
134 #if _lib_spawnlp
135 
136 NoN(spawnlp)
137 
138 #else
139 
140 extern pid_t
141 spawnlp(const char* name, const char* arg, ...)
142 {
143 	va_list	ap;
144 	pid_t	pid;
145 
146 	va_start(ap, arg);
147 	pid = spawnvp(name, (char* const*)&arg);
148 	va_end(ap);
149 	return pid;
150 }
151 
152 #endif
153