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