1*5c51f124SMoriah Waterland /*
2*5c51f124SMoriah Waterland  * CDDL HEADER START
3*5c51f124SMoriah Waterland  *
4*5c51f124SMoriah Waterland  * The contents of this file are subject to the terms of the
5*5c51f124SMoriah Waterland  * Common Development and Distribution License (the "License").
6*5c51f124SMoriah Waterland  * You may not use this file except in compliance with the License.
7*5c51f124SMoriah Waterland  *
8*5c51f124SMoriah Waterland  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*5c51f124SMoriah Waterland  * or http://www.opensolaris.org/os/licensing.
10*5c51f124SMoriah Waterland  * See the License for the specific language governing permissions
11*5c51f124SMoriah Waterland  * and limitations under the License.
12*5c51f124SMoriah Waterland  *
13*5c51f124SMoriah Waterland  * When distributing Covered Code, include this CDDL HEADER in each
14*5c51f124SMoriah Waterland  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*5c51f124SMoriah Waterland  * If applicable, add the following below this CDDL HEADER, with the
16*5c51f124SMoriah Waterland  * fields enclosed by brackets "[]" replaced with your own identifying
17*5c51f124SMoriah Waterland  * information: Portions Copyright [yyyy] [name of copyright owner]
18*5c51f124SMoriah Waterland  *
19*5c51f124SMoriah Waterland  * CDDL HEADER END
20*5c51f124SMoriah Waterland  */
21*5c51f124SMoriah Waterland 
22*5c51f124SMoriah Waterland /*
23*5c51f124SMoriah Waterland  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
24*5c51f124SMoriah Waterland  * Use is subject to license terms.
25*5c51f124SMoriah Waterland  */
26*5c51f124SMoriah Waterland 
27*5c51f124SMoriah Waterland /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28*5c51f124SMoriah Waterland /* All Rights Reserved */
29*5c51f124SMoriah Waterland 
30*5c51f124SMoriah Waterland #include <stdio.h>
31*5c51f124SMoriah Waterland #include <errno.h>
32*5c51f124SMoriah Waterland #include <string.h>
33*5c51f124SMoriah Waterland #include <limits.h>
34*5c51f124SMoriah Waterland #include <stdlib.h>
35*5c51f124SMoriah Waterland #include <unistd.h>
36*5c51f124SMoriah Waterland #include <sys/types.h>
37*5c51f124SMoriah Waterland #include <locale.h>
38*5c51f124SMoriah Waterland #include <libintl.h>
39*5c51f124SMoriah Waterland #include <pkglib.h>
40*5c51f124SMoriah Waterland #include <install.h>
41*5c51f124SMoriah Waterland #include <libinst.h>
42*5c51f124SMoriah Waterland #include <libadm.h>
43*5c51f124SMoriah Waterland #include "installf.h"
44*5c51f124SMoriah Waterland 
45*5c51f124SMoriah Waterland void
removef(int argc,char * argv[])46*5c51f124SMoriah Waterland removef(int argc, char *argv[])
47*5c51f124SMoriah Waterland {
48*5c51f124SMoriah Waterland 	struct cfextra *new;
49*5c51f124SMoriah Waterland 	char	buf[PATH_MAX];
50*5c51f124SMoriah Waterland 	char	*path;
51*5c51f124SMoriah Waterland 	int	flag;
52*5c51f124SMoriah Waterland 	int	len;
53*5c51f124SMoriah Waterland 	int	max_eptnum;
54*5c51f124SMoriah Waterland 
55*5c51f124SMoriah Waterland 	flag = strcmp(argv[0], "-") == 0;
56*5c51f124SMoriah Waterland 
57*5c51f124SMoriah Waterland 	eptnum = 0;
58*5c51f124SMoriah Waterland 	max_eptnum = 64;	/* starting size of array */
59*5c51f124SMoriah Waterland 	extlist = malloc(max_eptnum * sizeof (struct cfextra *));
60*5c51f124SMoriah Waterland 
61*5c51f124SMoriah Waterland 	for (;;) {
62*5c51f124SMoriah Waterland 		if (flag) {
63*5c51f124SMoriah Waterland 			if (fgets(buf, PATH_MAX, stdin) == NULL)
64*5c51f124SMoriah Waterland 				break;
65*5c51f124SMoriah Waterland 
66*5c51f124SMoriah Waterland 			/* strip trailing new line */
67*5c51f124SMoriah Waterland 			len = strlen(buf);
68*5c51f124SMoriah Waterland 			if (buf[len - 1] == '\n')
69*5c51f124SMoriah Waterland 				buf[len - 1] = '\0';
70*5c51f124SMoriah Waterland 
71*5c51f124SMoriah Waterland 			path = buf;
72*5c51f124SMoriah Waterland 		} else {
73*5c51f124SMoriah Waterland 			if (argc-- <= 0)
74*5c51f124SMoriah Waterland 				break;
75*5c51f124SMoriah Waterland 			path = argv[argc];
76*5c51f124SMoriah Waterland 		}
77*5c51f124SMoriah Waterland 
78*5c51f124SMoriah Waterland 		/*
79*5c51f124SMoriah Waterland 		 * This strips the install root from the path using
80*5c51f124SMoriah Waterland 		 * a questionable algorithm. This should go away as
81*5c51f124SMoriah Waterland 		 * we define more precisely the command line syntax
82*5c51f124SMoriah Waterland 		 * with our '-R' option. - JST
83*5c51f124SMoriah Waterland 		 */
84*5c51f124SMoriah Waterland 		path = orig_path_ptr(path);
85*5c51f124SMoriah Waterland 
86*5c51f124SMoriah Waterland 		if (path == NULL) {
87*5c51f124SMoriah Waterland 			logerr(gettext("ERROR: no pathname was provided"));
88*5c51f124SMoriah Waterland 			warnflag++;
89*5c51f124SMoriah Waterland 			continue;
90*5c51f124SMoriah Waterland 		}
91*5c51f124SMoriah Waterland 
92*5c51f124SMoriah Waterland 		if (*path != '/') {
93*5c51f124SMoriah Waterland 			logerr(gettext(
94*5c51f124SMoriah Waterland 			    "WARNING: relative pathname <%s> ignored"), path);
95*5c51f124SMoriah Waterland 			warnflag++;
96*5c51f124SMoriah Waterland 			continue;
97*5c51f124SMoriah Waterland 		}
98*5c51f124SMoriah Waterland 
99*5c51f124SMoriah Waterland 		new = calloc(1, sizeof (struct cfextra));
100*5c51f124SMoriah Waterland 		if (new == NULL) {
101*5c51f124SMoriah Waterland 			progerr(strerror(errno));
102*5c51f124SMoriah Waterland 			quit(99);
103*5c51f124SMoriah Waterland 		}
104*5c51f124SMoriah Waterland 		new->cf_ent.ftype = '-';
105*5c51f124SMoriah Waterland 
106*5c51f124SMoriah Waterland 		(void) eval_path(&(new->server_path), &(new->client_path),
107*5c51f124SMoriah Waterland 		    &(new->map_path), path);
108*5c51f124SMoriah Waterland 
109*5c51f124SMoriah Waterland 		new->cf_ent.path = new->client_path;
110*5c51f124SMoriah Waterland 
111*5c51f124SMoriah Waterland 		extlist[eptnum++] = new;
112*5c51f124SMoriah Waterland 		if (eptnum >= max_eptnum) {
113*5c51f124SMoriah Waterland 			/* array size grows exponentially */
114*5c51f124SMoriah Waterland 			max_eptnum <<= 1;
115*5c51f124SMoriah Waterland 			extlist = realloc(extlist,
116*5c51f124SMoriah Waterland 			    max_eptnum * sizeof (struct cfextra *));
117*5c51f124SMoriah Waterland 			if (extlist == NULL) {
118*5c51f124SMoriah Waterland 				progerr(strerror(errno));
119*5c51f124SMoriah Waterland 				quit(99);
120*5c51f124SMoriah Waterland 			}
121*5c51f124SMoriah Waterland 		}
122*5c51f124SMoriah Waterland 	}
123*5c51f124SMoriah Waterland 	extlist[eptnum] = (struct cfextra *)NULL;
124*5c51f124SMoriah Waterland 
125*5c51f124SMoriah Waterland 	qsort((char *)extlist,
126*5c51f124SMoriah Waterland 	    (unsigned)eptnum, sizeof (struct cfextra *), cfentcmp);
127*5c51f124SMoriah Waterland }
128