xref: /onnv-gate/usr/src/lib/libpkg/common/pkgexecl.c (revision 9781:ccf49524d5dc)
1*9781SMoriah.Waterland@Sun.COM /*
2*9781SMoriah.Waterland@Sun.COM  * CDDL HEADER START
3*9781SMoriah.Waterland@Sun.COM  *
4*9781SMoriah.Waterland@Sun.COM  * The contents of this file are subject to the terms of the
5*9781SMoriah.Waterland@Sun.COM  * Common Development and Distribution License (the "License").
6*9781SMoriah.Waterland@Sun.COM  * You may not use this file except in compliance with the License.
7*9781SMoriah.Waterland@Sun.COM  *
8*9781SMoriah.Waterland@Sun.COM  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*9781SMoriah.Waterland@Sun.COM  * or http://www.opensolaris.org/os/licensing.
10*9781SMoriah.Waterland@Sun.COM  * See the License for the specific language governing permissions
11*9781SMoriah.Waterland@Sun.COM  * and limitations under the License.
12*9781SMoriah.Waterland@Sun.COM  *
13*9781SMoriah.Waterland@Sun.COM  * When distributing Covered Code, include this CDDL HEADER in each
14*9781SMoriah.Waterland@Sun.COM  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*9781SMoriah.Waterland@Sun.COM  * If applicable, add the following below this CDDL HEADER, with the
16*9781SMoriah.Waterland@Sun.COM  * fields enclosed by brackets "[]" replaced with your own identifying
17*9781SMoriah.Waterland@Sun.COM  * information: Portions Copyright [yyyy] [name of copyright owner]
18*9781SMoriah.Waterland@Sun.COM  *
19*9781SMoriah.Waterland@Sun.COM  * CDDL HEADER END
20*9781SMoriah.Waterland@Sun.COM  */
21*9781SMoriah.Waterland@Sun.COM 
22*9781SMoriah.Waterland@Sun.COM /*
23*9781SMoriah.Waterland@Sun.COM  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
24*9781SMoriah.Waterland@Sun.COM  * Use is subject to license terms.
25*9781SMoriah.Waterland@Sun.COM  */
26*9781SMoriah.Waterland@Sun.COM 
27*9781SMoriah.Waterland@Sun.COM /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28*9781SMoriah.Waterland@Sun.COM /* All Rights Reserved */
29*9781SMoriah.Waterland@Sun.COM 
30*9781SMoriah.Waterland@Sun.COM 
31*9781SMoriah.Waterland@Sun.COM #include <stdio.h>
32*9781SMoriah.Waterland@Sun.COM #include <errno.h>
33*9781SMoriah.Waterland@Sun.COM #include <string.h>
34*9781SMoriah.Waterland@Sun.COM #include <stdlib.h>
35*9781SMoriah.Waterland@Sun.COM #include <unistd.h>
36*9781SMoriah.Waterland@Sun.COM #include <stdarg.h>
37*9781SMoriah.Waterland@Sun.COM #include <wait.h>
38*9781SMoriah.Waterland@Sun.COM #include <signal.h>
39*9781SMoriah.Waterland@Sun.COM #include <sys/types.h>
40*9781SMoriah.Waterland@Sun.COM #include <sys/stat.h>
41*9781SMoriah.Waterland@Sun.COM #include <pwd.h>
42*9781SMoriah.Waterland@Sun.COM #include <grp.h>
43*9781SMoriah.Waterland@Sun.COM #include <fcntl.h>
44*9781SMoriah.Waterland@Sun.COM #include "pkglocale.h"
45*9781SMoriah.Waterland@Sun.COM #include "pkglibmsgs.h"
46*9781SMoriah.Waterland@Sun.COM #include "pkglib.h"
47*9781SMoriah.Waterland@Sun.COM 
48*9781SMoriah.Waterland@Sun.COM #define	MAXARGS	64
49*9781SMoriah.Waterland@Sun.COM 
50*9781SMoriah.Waterland@Sun.COM /*VARARGS4*/
51*9781SMoriah.Waterland@Sun.COM int
pkgexecl(char * filein,char * fileout,char * uname,char * gname,...)52*9781SMoriah.Waterland@Sun.COM pkgexecl(char *filein, char *fileout, char *uname, char *gname, ...)
53*9781SMoriah.Waterland@Sun.COM {
54*9781SMoriah.Waterland@Sun.COM 	char		*arg[MAXARGS+1];
55*9781SMoriah.Waterland@Sun.COM 	char		*pt;
56*9781SMoriah.Waterland@Sun.COM 	int		n;
57*9781SMoriah.Waterland@Sun.COM 	va_list		ap;
58*9781SMoriah.Waterland@Sun.COM 
59*9781SMoriah.Waterland@Sun.COM 	/* construct arg[] array from varargs passed in */
60*9781SMoriah.Waterland@Sun.COM 
61*9781SMoriah.Waterland@Sun.COM 	va_start(ap, gname);
62*9781SMoriah.Waterland@Sun.COM 
63*9781SMoriah.Waterland@Sun.COM 	n = 0;
64*9781SMoriah.Waterland@Sun.COM 	while ((pt = va_arg(ap, char *)) != NULL) {
65*9781SMoriah.Waterland@Sun.COM 		if (n >= MAXARGS) {
66*9781SMoriah.Waterland@Sun.COM 			va_end(ap);
67*9781SMoriah.Waterland@Sun.COM 			progerr(pkg_gt(ERR_TOO_MANY_ARGS),
68*9781SMoriah.Waterland@Sun.COM 				arg[0] ? arg[0] : "??");
69*9781SMoriah.Waterland@Sun.COM 			return (-1);
70*9781SMoriah.Waterland@Sun.COM 		}
71*9781SMoriah.Waterland@Sun.COM 		arg[n++] = pt;
72*9781SMoriah.Waterland@Sun.COM 	}
73*9781SMoriah.Waterland@Sun.COM 
74*9781SMoriah.Waterland@Sun.COM 	arg[n] = NULL;
75*9781SMoriah.Waterland@Sun.COM 	va_end(ap);
76*9781SMoriah.Waterland@Sun.COM 
77*9781SMoriah.Waterland@Sun.COM 	/* return results of executing command based on arg[] list */
78*9781SMoriah.Waterland@Sun.COM 
79*9781SMoriah.Waterland@Sun.COM 	return (pkgexecv(filein, fileout, uname, gname, arg));
80*9781SMoriah.Waterland@Sun.COM }
81