xref: /onnv-gate/usr/src/cmd/svr4pkg/installf/removef.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 2008 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 #include <stdio.h>
31*9781SMoriah.Waterland@Sun.COM #include <errno.h>
32*9781SMoriah.Waterland@Sun.COM #include <string.h>
33*9781SMoriah.Waterland@Sun.COM #include <limits.h>
34*9781SMoriah.Waterland@Sun.COM #include <stdlib.h>
35*9781SMoriah.Waterland@Sun.COM #include <unistd.h>
36*9781SMoriah.Waterland@Sun.COM #include <sys/types.h>
37*9781SMoriah.Waterland@Sun.COM #include <locale.h>
38*9781SMoriah.Waterland@Sun.COM #include <libintl.h>
39*9781SMoriah.Waterland@Sun.COM #include <pkglib.h>
40*9781SMoriah.Waterland@Sun.COM #include <install.h>
41*9781SMoriah.Waterland@Sun.COM #include <libinst.h>
42*9781SMoriah.Waterland@Sun.COM #include <libadm.h>
43*9781SMoriah.Waterland@Sun.COM #include "installf.h"
44*9781SMoriah.Waterland@Sun.COM 
45*9781SMoriah.Waterland@Sun.COM void
removef(int argc,char * argv[])46*9781SMoriah.Waterland@Sun.COM removef(int argc, char *argv[])
47*9781SMoriah.Waterland@Sun.COM {
48*9781SMoriah.Waterland@Sun.COM 	struct cfextra *new;
49*9781SMoriah.Waterland@Sun.COM 	char	buf[PATH_MAX];
50*9781SMoriah.Waterland@Sun.COM 	char	*path;
51*9781SMoriah.Waterland@Sun.COM 	int	flag;
52*9781SMoriah.Waterland@Sun.COM 	int	len;
53*9781SMoriah.Waterland@Sun.COM 	int	max_eptnum;
54*9781SMoriah.Waterland@Sun.COM 
55*9781SMoriah.Waterland@Sun.COM 	flag = strcmp(argv[0], "-") == 0;
56*9781SMoriah.Waterland@Sun.COM 
57*9781SMoriah.Waterland@Sun.COM 	eptnum = 0;
58*9781SMoriah.Waterland@Sun.COM 	max_eptnum = 64;	/* starting size of array */
59*9781SMoriah.Waterland@Sun.COM 	extlist = malloc(max_eptnum * sizeof (struct cfextra *));
60*9781SMoriah.Waterland@Sun.COM 
61*9781SMoriah.Waterland@Sun.COM 	for (;;) {
62*9781SMoriah.Waterland@Sun.COM 		if (flag) {
63*9781SMoriah.Waterland@Sun.COM 			if (fgets(buf, PATH_MAX, stdin) == NULL)
64*9781SMoriah.Waterland@Sun.COM 				break;
65*9781SMoriah.Waterland@Sun.COM 
66*9781SMoriah.Waterland@Sun.COM 			/* strip trailing new line */
67*9781SMoriah.Waterland@Sun.COM 			len = strlen(buf);
68*9781SMoriah.Waterland@Sun.COM 			if (buf[len - 1] == '\n')
69*9781SMoriah.Waterland@Sun.COM 				buf[len - 1] = '\0';
70*9781SMoriah.Waterland@Sun.COM 
71*9781SMoriah.Waterland@Sun.COM 			path = buf;
72*9781SMoriah.Waterland@Sun.COM 		} else {
73*9781SMoriah.Waterland@Sun.COM 			if (argc-- <= 0)
74*9781SMoriah.Waterland@Sun.COM 				break;
75*9781SMoriah.Waterland@Sun.COM 			path = argv[argc];
76*9781SMoriah.Waterland@Sun.COM 		}
77*9781SMoriah.Waterland@Sun.COM 
78*9781SMoriah.Waterland@Sun.COM 		/*
79*9781SMoriah.Waterland@Sun.COM 		 * This strips the install root from the path using
80*9781SMoriah.Waterland@Sun.COM 		 * a questionable algorithm. This should go away as
81*9781SMoriah.Waterland@Sun.COM 		 * we define more precisely the command line syntax
82*9781SMoriah.Waterland@Sun.COM 		 * with our '-R' option. - JST
83*9781SMoriah.Waterland@Sun.COM 		 */
84*9781SMoriah.Waterland@Sun.COM 		path = orig_path_ptr(path);
85*9781SMoriah.Waterland@Sun.COM 
86*9781SMoriah.Waterland@Sun.COM 		if (path == NULL) {
87*9781SMoriah.Waterland@Sun.COM 			logerr(gettext("ERROR: no pathname was provided"));
88*9781SMoriah.Waterland@Sun.COM 			warnflag++;
89*9781SMoriah.Waterland@Sun.COM 			continue;
90*9781SMoriah.Waterland@Sun.COM 		}
91*9781SMoriah.Waterland@Sun.COM 
92*9781SMoriah.Waterland@Sun.COM 		if (*path != '/') {
93*9781SMoriah.Waterland@Sun.COM 			logerr(gettext(
94*9781SMoriah.Waterland@Sun.COM 			    "WARNING: relative pathname <%s> ignored"), path);
95*9781SMoriah.Waterland@Sun.COM 			warnflag++;
96*9781SMoriah.Waterland@Sun.COM 			continue;
97*9781SMoriah.Waterland@Sun.COM 		}
98*9781SMoriah.Waterland@Sun.COM 
99*9781SMoriah.Waterland@Sun.COM 		new = calloc(1, sizeof (struct cfextra));
100*9781SMoriah.Waterland@Sun.COM 		if (new == NULL) {
101*9781SMoriah.Waterland@Sun.COM 			progerr(strerror(errno));
102*9781SMoriah.Waterland@Sun.COM 			quit(99);
103*9781SMoriah.Waterland@Sun.COM 		}
104*9781SMoriah.Waterland@Sun.COM 		new->cf_ent.ftype = '-';
105*9781SMoriah.Waterland@Sun.COM 
106*9781SMoriah.Waterland@Sun.COM 		(void) eval_path(&(new->server_path), &(new->client_path),
107*9781SMoriah.Waterland@Sun.COM 		    &(new->map_path), path);
108*9781SMoriah.Waterland@Sun.COM 
109*9781SMoriah.Waterland@Sun.COM 		new->cf_ent.path = new->client_path;
110*9781SMoriah.Waterland@Sun.COM 
111*9781SMoriah.Waterland@Sun.COM 		extlist[eptnum++] = new;
112*9781SMoriah.Waterland@Sun.COM 		if (eptnum >= max_eptnum) {
113*9781SMoriah.Waterland@Sun.COM 			/* array size grows exponentially */
114*9781SMoriah.Waterland@Sun.COM 			max_eptnum <<= 1;
115*9781SMoriah.Waterland@Sun.COM 			extlist = realloc(extlist,
116*9781SMoriah.Waterland@Sun.COM 			    max_eptnum * sizeof (struct cfextra *));
117*9781SMoriah.Waterland@Sun.COM 			if (extlist == NULL) {
118*9781SMoriah.Waterland@Sun.COM 				progerr(strerror(errno));
119*9781SMoriah.Waterland@Sun.COM 				quit(99);
120*9781SMoriah.Waterland@Sun.COM 			}
121*9781SMoriah.Waterland@Sun.COM 		}
122*9781SMoriah.Waterland@Sun.COM 	}
123*9781SMoriah.Waterland@Sun.COM 	extlist[eptnum] = (struct cfextra *)NULL;
124*9781SMoriah.Waterland@Sun.COM 
125*9781SMoriah.Waterland@Sun.COM 	qsort((char *)extlist,
126*9781SMoriah.Waterland@Sun.COM 	    (unsigned)eptnum, sizeof (struct cfextra *), cfentcmp);
127*9781SMoriah.Waterland@Sun.COM }
128