10Sstevel@tonic-gate /*
20Sstevel@tonic-gate * CDDL HEADER START
30Sstevel@tonic-gate *
40Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*6812Sraf * Common Development and Distribution License (the "License").
6*6812Sraf * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate *
80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate * See the License for the specific language governing permissions
110Sstevel@tonic-gate * and limitations under the License.
120Sstevel@tonic-gate *
130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate *
190Sstevel@tonic-gate * CDDL HEADER END
200Sstevel@tonic-gate */
21*6812Sraf
220Sstevel@tonic-gate /*
23*6812Sraf * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
240Sstevel@tonic-gate * Use is subject to license terms.
250Sstevel@tonic-gate */
260Sstevel@tonic-gate
270Sstevel@tonic-gate /* Copyright (c) 1988 AT&T */
280Sstevel@tonic-gate /* All Rights Reserved */
290Sstevel@tonic-gate
30*6812Sraf #pragma ident "%Z%%M% %I% %E% SMI"
310Sstevel@tonic-gate
320Sstevel@tonic-gate /*
330Sstevel@tonic-gate * execle(file, arg1, arg2, ..., 0, envp)
340Sstevel@tonic-gate */
350Sstevel@tonic-gate
36*6812Sraf #pragma weak _execle = execle
370Sstevel@tonic-gate
38*6812Sraf #include "lint.h"
390Sstevel@tonic-gate #include <sys/types.h>
400Sstevel@tonic-gate #include <alloca.h>
410Sstevel@tonic-gate #include <malloc.h>
420Sstevel@tonic-gate #include <stdarg.h>
430Sstevel@tonic-gate #include <unistd.h>
440Sstevel@tonic-gate
450Sstevel@tonic-gate /*VARARGS1*/
460Sstevel@tonic-gate int
execle(const char * file,const char * arg0,...)470Sstevel@tonic-gate execle(const char *file, const char *arg0, ...)
480Sstevel@tonic-gate {
490Sstevel@tonic-gate char **argp;
500Sstevel@tonic-gate va_list args;
510Sstevel@tonic-gate char **argvec;
520Sstevel@tonic-gate register char **environmentp;
530Sstevel@tonic-gate int err;
540Sstevel@tonic-gate int nargs = 0;
550Sstevel@tonic-gate char *nextarg;
560Sstevel@tonic-gate
570Sstevel@tonic-gate /*
580Sstevel@tonic-gate * count the number of arguments in the variable argument list
590Sstevel@tonic-gate * and allocate an argument vector for them on the stack,
600Sstevel@tonic-gate * adding space at the end for a terminating null pointer
610Sstevel@tonic-gate */
620Sstevel@tonic-gate
630Sstevel@tonic-gate va_start(args, arg0);
640Sstevel@tonic-gate while (va_arg(args, char *) != (char *)0) {
650Sstevel@tonic-gate nargs++;
660Sstevel@tonic-gate }
670Sstevel@tonic-gate
680Sstevel@tonic-gate /*
690Sstevel@tonic-gate * save the environment pointer, which is at the end of the
700Sstevel@tonic-gate * variable argument list
710Sstevel@tonic-gate */
720Sstevel@tonic-gate
730Sstevel@tonic-gate environmentp = va_arg(args, char **);
740Sstevel@tonic-gate va_end(args);
750Sstevel@tonic-gate
760Sstevel@tonic-gate /*
770Sstevel@tonic-gate * load the arguments in the variable argument list
780Sstevel@tonic-gate * into the argument vector, and add the terminating null pointer
790Sstevel@tonic-gate */
800Sstevel@tonic-gate
810Sstevel@tonic-gate va_start(args, arg0);
820Sstevel@tonic-gate /* workaround for bugid 1242839 */
830Sstevel@tonic-gate argvec = (char **)alloca((size_t)((nargs + 2) * sizeof (char *)));
840Sstevel@tonic-gate argp = argvec;
850Sstevel@tonic-gate *argp++ = (char *)arg0;
860Sstevel@tonic-gate while ((nextarg = va_arg(args, char *)) != (char *)0) {
870Sstevel@tonic-gate *argp++ = nextarg;
880Sstevel@tonic-gate }
890Sstevel@tonic-gate va_end(args);
900Sstevel@tonic-gate *argp = (char *)0;
910Sstevel@tonic-gate
920Sstevel@tonic-gate /*
930Sstevel@tonic-gate * call execve()
940Sstevel@tonic-gate */
950Sstevel@tonic-gate
960Sstevel@tonic-gate err = execve(file, argvec, environmentp);
970Sstevel@tonic-gate return (err);
980Sstevel@tonic-gate }
99