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