Print this page
4027 remove CLOSED_BUILD
4028 remove CLOSED_IS_PRESENT
4029 remove tonic build bits
Reviewed by: Andy Stormont <andyjstormont@gmail.com>
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/tools/install.bin/install.bin.c
+++ new/usr/src/tools/install.bin/install.bin.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21 /*
22 22 * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
23 23 */
24 24
25 25
26 26 #include <stdio.h>
27 27 #include <stdlib.h>
28 28 #include <strings.h>
29 29 #include <sys/param.h>
30 30 #include <fcntl.h>
31 31 #include <sys/errno.h>
32 32 #include <sys/types.h>
33 33 #include <sys/uio.h>
34 34 #include <unistd.h>
35 35 #include <sys/stat.h>
36 36 #include <errno.h>
37 37 #include <libgen.h>
↓ open down ↓ |
37 lines elided |
↑ open up ↑ |
38 38 #include "stdusers.h"
39 39
40 40
41 41 #define FILE_BUFF 40960
42 42
43 43 static int suppress = 0;
44 44
45 45 static void usage(void);
46 46 static void file_copy(char *src_file, char *dest_file);
47 47 static void chown_file(const char *file, const char *group, const char *owner);
48 -static void formclosed(char *root, char *closedroot);
49 48 static char *find_basename(const char *str);
50 49 static int creatdir(char *fn);
51 50
52 51
53 52 void
54 53 usage(void)
55 54 {
56 55 (void) fprintf(stderr,
57 - "usage: install [-sdO][-m mode][-g group][-u owner] "
56 + "usage: install [-sd][-m mode][-g group][-u owner] "
58 57 "-f dir file ...\n");
59 58 }
60 59
61 60 void
62 61 file_copy(char *src_file, char *dest_file)
63 62 {
64 63 int src_fd;
65 64 int dest_fd;
66 65 int count;
67 66 static char file_buff[FILE_BUFF];
68 67
69 68 if ((src_fd = open(src_file, O_RDONLY)) == -1) {
70 69 (void) fprintf(stderr, "install:file_copy: %s failed "
71 70 "(%d): %s\n", src_file, errno, strerror(errno));
72 71 exit(1);
73 72 }
74 73
75 74 if ((dest_fd = open(dest_file, O_CREAT|O_WRONLY|O_TRUNC, 0755)) == -1) {
76 75 (void) fprintf(stderr, "install:file_copy: %s failed "
77 76 "(%d): %s\n", dest_file, errno, strerror(errno));
78 77 exit(1);
79 78 }
80 79
81 80 while ((count = read(src_fd, file_buff, FILE_BUFF)) > 0) {
82 81 (void) write(dest_fd, file_buff, count);
83 82 }
84 83
85 84 if (count == -1) {
86 85 (void) fprintf(stderr, "install:file_copy:read failed "
87 86 "(%d): %s\n", errno, strerror(errno));
88 87 exit(1);
89 88 }
90 89
91 90 if (!suppress)
92 91 (void) printf("%s installed as %s\n", src_file, dest_file);
93 92
94 93 (void) close(src_fd);
95 94 (void) close(dest_fd);
96 95 }
97 96
98 97
99 98 void
100 99 chown_file(const char *file, const char *group, const char *owner)
101 100 {
102 101 gid_t grp = (gid_t)-1;
103 102 uid_t own = (uid_t)-1;
104 103
105 104 if (group) {
106 105 grp = stdfind(group, groupnames);
107 106 if (grp < 0)
108 107 (void) fprintf(stderr, "unknown group(%s)\n", group);
109 108 }
110 109
111 110 if (owner) {
112 111 own = stdfind(owner, usernames);
113 112 if (own < 0) {
114 113 (void) fprintf(stderr, "unknown owner(%s)\n", owner);
115 114 exit(1);
116 115 }
117 116
↓ open down ↓ |
50 lines elided |
↑ open up ↑ |
118 117 }
119 118
120 119 if (chown(file, own, grp) == -1) {
121 120 (void) fprintf(stderr, "install:chown_file: failed "
122 121 "(%d): %s\n", errno, strerror(errno));
123 122 exit(1);
124 123 }
125 124 }
126 125
127 126
128 -void
129 -formclosed(char *root, char *closedroot)
130 -{
131 - int wholelen, residlen;
132 - char *temp;
133 -
134 - wholelen = strlen(root);
135 - temp = strstr(strstr(root, "proto/root_"), "/");
136 - temp++;
137 - temp = strstr(temp, "/");
138 - residlen = strlen(temp);
139 - (void) strlcpy(closedroot, root, wholelen - residlen + 1);
140 - (void) strlcat(closedroot, "-closed", MAXPATHLEN);
141 - (void) strlcat(closedroot, temp, MAXPATHLEN);
142 -}
143 -
144 -
145 127 char *
146 128 find_basename(const char *str)
147 129 {
148 130 int i;
149 131 int len;
150 132
151 133 len = strlen(str);
152 134
153 135 for (i = len-1; i >= 0; i--)
154 136 if (str[i] == '/')
155 137 return ((char *)(str + i + 1));
156 138 return ((char *)str);
157 139 }
158 140
159 141 int
160 142 creatdir(char *fn) {
161 143
162 144 errno = 0;
163 145
164 146 if (mkdirp(fn, 0755) == -1) {
165 147 if (errno != EEXIST)
166 148 return (errno);
167 149 } else if (!suppress) {
168 150 (void) printf("directory %s created\n", fn);
169 151 }
170 152 return (0);
171 153 }
172 154
173 155
174 156 int
175 157 main(int argc, char **argv)
↓ open down ↓ |
21 lines elided |
↑ open up ↑ |
176 158 {
177 159 int c;
178 160 int errflg = 0;
179 161 int dirflg = 0;
180 162 char *group = NULL;
181 163 char *owner = NULL;
182 164 char *dirb = NULL;
183 165 char *ins_file = NULL;
184 166 int mode = -1;
185 167 char dest_file[MAXPATHLEN];
186 - char shadow_dest[MAXPATHLEN];
187 - char shadow_dirb[MAXPATHLEN];
188 - int tonic = 0;
189 168 int rv = 0;
190 169
191 - while ((c = getopt(argc, argv, "f:sm:du:g:O")) != EOF) {
170 + while ((c = getopt(argc, argv, "f:sm:du:g:")) != EOF) {
192 171 switch (c) {
193 172 case 'f':
194 173 dirb = optarg;
195 174 break;
196 175 case 'g':
197 176 group = optarg;
198 177 break;
199 178 case 'u':
200 179 owner = optarg;
201 180 break;
202 181 case 'd':
203 182 dirflg = 1;
204 183 break;
205 184 case 'm':
206 185 mode = strtol(optarg, NULL, 8);
207 186 break;
208 187 case 's':
209 188 suppress = 1;
210 189 break;
211 - case 'O':
212 - tonic = 1;
213 - break;
214 190 case '?':
215 191 errflg++;
216 192 break;
217 193 }
218 194 }
219 195
220 196 if (errflg) {
221 197 usage();
222 198 return (1);
223 199 }
224 200
225 201 if (argc == optind) {
226 202 usage();
227 203 return (1);
228 204 }
229 205
↓ open down ↓ |
6 lines elided |
↑ open up ↑ |
230 206 if (!dirflg && (dirb == NULL)) {
231 207 (void) fprintf(stderr,
232 208 "install: no destination directory specified.\n");
233 209 return (1);
234 210 }
235 211
236 212 for (c = optind; c < argc; c++) {
237 213 ins_file = argv[c];
238 214
239 215 if (dirflg) {
240 - if (tonic) {
241 - formclosed(ins_file, shadow_dest);
242 - rv = creatdir(shadow_dest);
243 - if (rv) {
244 - (void) fprintf(stderr,
245 - "install: tonic creatdir "
246 - "%s (%d): (%s)\n",
247 - shadow_dest, errno,
248 - strerror(errno));
249 - return (rv);
250 - }
251 - }
252 216 rv = creatdir(ins_file);
253 217 if (rv) {
254 218 (void) fprintf(stderr,
255 219 "install: creatdir %s (%d): %s\n",
256 220 ins_file, errno, strerror(errno));
257 221 return (rv);
258 222 }
259 223 (void) strlcpy(dest_file, ins_file, MAXPATHLEN);
260 224
261 225 } else {
262 226 (void) strcat(strcat(strcpy(dest_file, dirb), "/"),
263 227 find_basename(ins_file));
264 228 file_copy(ins_file, dest_file);
265 -
266 - if (tonic) {
267 - formclosed(dirb, shadow_dirb);
268 - /*
269 - * The standard directories in the proto
270 - * area are created as part of "make setup",
271 - * but that doesn't create them in the
272 - * closed proto area. So if the target
273 - * directory doesn't exist, we need to
274 - * create it now.
275 - */
276 - rv = creatdir(shadow_dirb);
277 - if (rv) {
278 - (void) fprintf(stderr,
279 - "install: tonic creatdir(f) "
280 - "%s (%d): %s\n",
281 - shadow_dirb, errno,
282 - strerror(errno));
283 - return (rv);
284 - }
285 - (void) strcat(strcat(strcpy(shadow_dest,
286 - shadow_dirb), "/"),
287 - find_basename(ins_file));
288 - file_copy(ins_file, shadow_dest);
289 - }
290 229 }
291 230
292 - if (group || owner) {
231 + if (group || owner)
293 232 chown_file(dest_file, group, owner);
294 - if (tonic)
295 - chown_file(shadow_dest, group, owner);
296 - }
233 +
297 234 if (mode != -1) {
298 235 (void) umask(0);
299 236 if (chmod(dest_file, mode) == -1) {
300 237 (void) fprintf(stderr,
301 238 "install: chmod of %s to mode %o failed "
302 239 "(%d): %s\n",
303 240 dest_file, mode, errno, strerror(errno));
304 241 return (1);
305 242 }
306 - if (tonic) {
307 - if (chmod(shadow_dest, mode) == -1) {
308 - (void) fprintf(stderr,
309 - "install: tonic chmod of %s "
310 - "to mode %o failed (%d): %s\n",
311 - shadow_dest, mode,
312 - errno, strerror(errno));
313 - return (1);
314 - }
315 - }
316 243 }
317 244 }
318 245 return (0);
319 246 }
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX