execvp.c revision 6a5408e613dc0b372f722907d6c0b18e99c182dd
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1988 AT&T */
/* All Rights Reserved */
/*
* execlp(name, arg,...,0) (like execl, but does path search)
* execvp(name, argv) (like execv, but does path search)
*/
#include "lint.h"
#include <unistd.h>
#include <string.h>
#include <alloca.h>
#include <errno.h>
#include <limits.h>
#include <stdarg.h>
#include <stdlib.h>
#include <paths.h>
static const char *execat(const char *, const char *, char *);
/*VARARGS1*/
int
{
char **argp;
char **argvec;
int err;
int nargs = 0;
char *nextarg;
/*
* count the number of arguments in the variable argument list
* and allocate an argument vector for them on the stack,
* adding space for a terminating null pointer at the end
* and one additional space for argv[0] which is no longer
* counted by the varargs loop.
*/
nargs++;
/*
* load the arguments in the variable argument list
* into the argument vector and add the terminating null pointer
*/
/* workaround for bugid 1242839 */
argp++;
}
*argp = (char *)0;
/*
* call execvp()
*/
return (err);
}
int
{
const char *pathstr;
char *newargs[256];
int i;
const char *cp;
unsigned etxtbsy = 1;
int eacces = 0;
if (*name == '\0') {
return (-1);
}
/*
* XPG4: pathstr is equivalent to CSPATH, except that
* with a colon when not root. Keep these paths in sync
* with CSPATH in confstr.c. Note that pathstr must end
* with a colon when not root so that when name doesn't
* contain '/', the last call to execat() will result in an
* attempt to execv name from the current directory.
*/
if (__xpg4 == 0) { /* not XPG4 */
}
} else {
if (__xpg4 == 0) { /* not XPG4 */
} else { /* XPG4 (CSPATH) */
}
}
}
do {
/*
* 4025035 and 4038378
* if a filename begins with a "-" prepend "./" so that
* the shell can't interpret it as an option
*/
if (*fname == '-') {
return (-1);
}
fname[0] = '.';
}
switch (errno) {
case ENOEXEC:
newargs[0] = "sh";
if (i >= 254) {
return (-1);
}
}
return (-1);
case ETXTBSY:
if (++etxtbsy > 5)
return (-1);
goto retry;
case EACCES:
++eacces;
break;
case ENOMEM:
case E2BIG:
case EFAULT:
return (-1);
}
} while (cp);
if (eacces)
return (-1);
}
static const char *
{
char *s;
s = si;
if (cnt > 0) {
*s++ = *s1++;
cnt--;
} else
s1++;
}
*s++ = '/';
cnt--;
}
*s++ = *s2++;
cnt--;
}
*s = '\0';
}