xinstall.c revision 1.54 1 /* $NetBSD: xinstall.c,v 1.54 2001/10/25 15:37:06 lukem Exp $ */
2
3 /*
4 * Copyright (c) 1987, 1993
5 * The Regents of the University of California. All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by the University of
18 * California, Berkeley and its contributors.
19 * 4. Neither the name of the University nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * SUCH DAMAGE.
34 */
35
36 #include <sys/cdefs.h>
37 #ifndef lint
38 __COPYRIGHT("@(#) Copyright (c) 1987, 1993\n\
39 The Regents of the University of California. All rights reserved.\n");
40 #endif /* not lint */
41
42 #ifndef lint
43 #if 0
44 static char sccsid[] = "@(#)xinstall.c 8.1 (Berkeley) 7/21/93";
45 #else
46 __RCSID("$NetBSD: xinstall.c,v 1.54 2001/10/25 15:37:06 lukem Exp $");
47 #endif
48 #endif /* not lint */
49
50 #include <sys/param.h>
51 #include <sys/wait.h>
52 #include <sys/mman.h>
53 #include <sys/stat.h>
54
55 #include <ctype.h>
56 #include <err.h>
57 #include <errno.h>
58 #include <fcntl.h>
59 #include <grp.h>
60 #include <paths.h>
61 #include <pwd.h>
62 #include <stdio.h>
63 #include <stdlib.h>
64 #include <string.h>
65 #include <unistd.h>
66 #include <vis.h>
67
68 #include "pathnames.h"
69 #include "stat_flags.h"
70
71 #define STRIP_ARGS_MAX 32
72 #define BACKUP_SUFFIX ".old"
73
74 int dobackup, docopy, dodir, dostrip, dolink, dopreserve, dorename,
75 dounpriv;
76 int numberedbackup;
77 int mode = S_IRWXU|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH;
78 char pathbuf[MAXPATHLEN];
79 uid_t uid;
80 gid_t gid;
81 char *group, *owner, *fflags, *tags;
82 FILE *metafp;
83 char *metafile;
84 u_long fileflags;
85 char *stripArgs;
86 char *suffix = BACKUP_SUFFIX;
87
88 #define LN_ABSOLUTE 0x01
89 #define LN_RELATIVE 0x02
90 #define LN_HARD 0x04
91 #define LN_SYMBOLIC 0x08
92 #define LN_MIXED 0x10
93
94 #define DIRECTORY 0x01 /* Tell install it's a directory. */
95 #define SETFLAGS 0x02 /* Tell install to set flags. */
96 #define HASUID 0x04 /* Tell install the uid was given */
97 #define HASGID 0x08 /* Tell install the gid was given */
98
99 void backup(const char *);
100 void copy(int, char *, int, char *, off_t);
101 void install(char *, char *, u_int);
102 void install_dir(char *, u_int);
103 int main(int, char *[]);
104 void makelink(char *, char *);
105 int parseid(char *, id_t *);
106 void strip(char *);
107 void metadata_log(const char *, mode_t, u_int, struct timeval *);
108 void usage(void);
109
110 int
111 main(int argc, char *argv[])
112 {
113 struct stat from_sb, to_sb;
114 void *set;
115 u_int iflags;
116 int ch, no_target;
117 char *p, *to_name;
118
119 setprogname(argv[0]);
120
121 iflags = 0;
122 while ((ch = getopt(argc, argv, "cbB:df:g:l:m:M:o:prsS:T:U")) != -1)
123 switch((char)ch) {
124 case 'B':
125 suffix = optarg;
126 numberedbackup = 0;
127 {
128 /* Check if given suffix really generates
129 different suffixes - catch e.g. ".%" */
130 char suffix_expanded0[FILENAME_MAX],
131 suffix_expanded1[FILENAME_MAX];
132 (void)snprintf(suffix_expanded0, FILENAME_MAX,
133 suffix, 0);
134 (void)snprintf(suffix_expanded1, FILENAME_MAX,
135 suffix, 1);
136 if (strcmp(suffix_expanded0, suffix_expanded1)
137 != 0)
138 numberedbackup = 1;
139 }
140 /* fall through; -B implies -b */
141 case 'b':
142 dobackup = 1;
143 break;
144 case 'c':
145 docopy = 1;
146 break;
147 case 'd':
148 dodir = 1;
149 break;
150 case 'f':
151 fflags = optarg;
152 break;
153 case 'g':
154 group = optarg;
155 break;
156 case 'l':
157 for (p = optarg; *p; p++)
158 switch (*p) {
159 case 's':
160 dolink &= ~(LN_HARD|LN_MIXED);
161 dolink |= LN_SYMBOLIC;
162 break;
163 case 'h':
164 dolink &= ~(LN_SYMBOLIC|LN_MIXED);
165 dolink |= LN_HARD;
166 break;
167 case 'm':
168 dolink &= ~(LN_SYMBOLIC|LN_HARD);
169 dolink |= LN_MIXED;
170 break;
171 case 'a':
172 dolink &= ~LN_RELATIVE;
173 dolink |= LN_ABSOLUTE;
174 break;
175 case 'r':
176 dolink &= ~LN_ABSOLUTE;
177 dolink |= LN_RELATIVE;
178 break;
179 default:
180 errx(1, "%c: invalid link type", *p);
181 break;
182 }
183 break;
184 case 'm':
185 if (!(set = setmode(optarg)))
186 errx(1, "%s: invalid file mode", optarg);
187 mode = getmode(set, 0);
188 free(set);
189 break;
190 case 'M':
191 metafile = optarg;
192 break;
193 case 'o':
194 owner = optarg;
195 break;
196 case 'p':
197 dopreserve = 1;
198 break;
199 case 'r':
200 dorename = 1;
201 break;
202 case 'S':
203 stripArgs = strdup(optarg);
204 if (stripArgs == NULL)
205 errx(1, "%s", strerror(ENOMEM));
206 /* fall through; -S implies -s */
207 case 's':
208 dostrip = 1;
209 break;
210 case 'T':
211 tags = optarg;
212 break;
213 case 'U':
214 dounpriv = 1;
215 break;
216 case '?':
217 default:
218 usage();
219 }
220 argc -= optind;
221 argv += optind;
222
223 /* strip and link options make no sense when creating directories */
224 if ((dostrip || dolink) && dodir)
225 usage();
226
227 /* strip and flags make no sense with links */
228 if ((dostrip || fflags) && dolink)
229 usage();
230
231 /* must have at least two arguments, except when creating directories */
232 if (argc < 2 && !dodir)
233 usage();
234
235 /* get group and owner id's */
236 if (group && !dounpriv) {
237 struct group *gp;
238
239 if ((gp = getgrnam(group)) != NULL)
240 gid = gp->gr_gid;
241 else if (! parseid(group, &gid))
242 errx(1, "unknown group %s", group);
243 iflags |= HASGID;
244 }
245 if (owner && !dounpriv) {
246 struct passwd *pp;
247
248 if ((pp = getpwnam(owner)) != NULL)
249 uid = pp->pw_uid;
250 else if (! parseid(owner, &uid))
251 errx(1, "unknown user %s", owner);
252 iflags |= HASUID;
253 }
254
255 if (fflags && !dounpriv) {
256 if (string_to_flags(&fflags, &fileflags, NULL))
257 errx(1, "%s: invalid flag", fflags);
258 iflags |= SETFLAGS;
259 }
260
261 if (metafile) {
262 if ((metafp = fopen(metafile, "a")) == NULL)
263 warn("open %s", metafile);
264 }
265
266 if (dodir) {
267 for (; *argv != NULL; ++argv)
268 install_dir(*argv, iflags);
269 exit (0);
270 }
271
272 no_target = stat(to_name = argv[argc - 1], &to_sb);
273 if (!no_target && S_ISDIR(to_sb.st_mode)) {
274 for (; *argv != to_name; ++argv)
275 install(*argv, to_name, iflags | DIRECTORY);
276 exit(0);
277 }
278
279 /* can't do file1 file2 directory/file */
280 if (argc != 2)
281 usage();
282
283 if (!no_target) {
284 if (stat(*argv, &from_sb))
285 err(1, "%s", *argv);
286 if (!S_ISREG(to_sb.st_mode))
287 errx(1, "%s: not a regular file", to_name);
288 if (!dolink && to_sb.st_dev == from_sb.st_dev &&
289 to_sb.st_ino == from_sb.st_ino)
290 errx(1, "%s and %s are the same file", *argv, to_name);
291 /*
292 * Unlink now... avoid ETXTBSY errors later. Try and turn
293 * off the append/immutable bits -- if we fail, go ahead,
294 * it might work.
295 */
296 #define NOCHANGEBITS (UF_IMMUTABLE | UF_APPEND | SF_IMMUTABLE | SF_APPEND)
297 if (to_sb.st_flags & NOCHANGEBITS)
298 (void)chflags(to_name,
299 to_sb.st_flags & ~(NOCHANGEBITS));
300 if (dobackup)
301 backup(to_name);
302 else if (!dorename)
303 (void)unlink(to_name);
304 }
305 install(*argv, to_name, iflags);
306 exit(0);
307 }
308
309 /*
310 * parseid --
311 * parse uid or gid from arg into id, returning non-zero if successful
312 */
313 int
314 parseid(char *name, id_t *id)
315 {
316 char *ep;
317
318 errno = 0;
319 *id = (id_t)strtoul(name, &ep, 10);
320 if (errno || *ep != '\0')
321 return (0);
322 return (1);
323 }
324
325 /*
326 * makelink --
327 * make a link from source to destination
328 */
329 void
330 makelink(char *from_name, char *to_name)
331 {
332 char src[MAXPATHLEN], dst[MAXPATHLEN], lnk[MAXPATHLEN];
333
334 /* Try hard links first */
335 if (dolink & (LN_HARD|LN_MIXED)) {
336 if (link(from_name, to_name) == -1) {
337 if ((dolink & LN_HARD) || errno != EXDEV)
338 err(1, "link %s -> %s", from_name, to_name);
339 }
340 else
341 return;
342 }
343
344 /* Symbolic links */
345 if (dolink & LN_ABSOLUTE) {
346 /* Convert source path to absolute */
347 if (realpath(from_name, src) == NULL)
348 err(1, "%s", src);
349 if (symlink(src, to_name) == -1)
350 err(1, "symlink %s -> %s", src, to_name);
351 return;
352 }
353
354 if (dolink & LN_RELATIVE) {
355 char *s, *d;
356
357 /* Resolve pathnames */
358 if (realpath(from_name, src) == NULL)
359 err(1, "%s", src);
360 if (realpath(to_name, dst) == NULL)
361 err(1, "%s", dst);
362
363 /* trim common path components */
364 for (s = src, d = dst; *s == *d; s++, d++)
365 continue;
366 while (*s != '/')
367 s--, d--;
368
369 /* count the number of directories we need to backtrack */
370 for (++d, lnk[0] = '\0'; *d; d++)
371 if (*d == '/')
372 (void) strcat(lnk, "../");
373
374 (void) strcat(lnk, ++s);
375
376 if (symlink(lnk, dst) == -1)
377 err(1, "symlink %s -> %s", lnk, dst);
378 return;
379 }
380
381 /*
382 * If absolute or relative was not specified,
383 * try the names the user provided
384 */
385 if (symlink(from_name, to_name) == -1)
386 err(1, "symlink %s -> %s", from_name, to_name);
387
388 }
389
390 /*
391 * install --
392 * build a path name and install the file
393 */
394 void
395 install(char *from_name, char *to_name, u_int flags)
396 {
397 struct stat from_sb, to_sb;
398 struct timeval tv[2];
399 int devnull, from_fd, to_fd, serrno;
400 char *p, tmpl[MAXPATHLEN], *oto_name;
401
402 /* If try to install NULL file to a directory, fails. */
403 if (flags & DIRECTORY || strcmp(from_name, _PATH_DEVNULL)) {
404 if (stat(from_name, &from_sb))
405 err(1, "%s", from_name);
406 if (!S_ISREG(from_sb.st_mode))
407 errx(1, "%s: not a regular file", to_name);
408 /* Build the target path. */
409 if (flags & DIRECTORY) {
410 (void)snprintf(pathbuf, sizeof(pathbuf), "%s/%s",
411 to_name,
412 (p = strrchr(from_name, '/')) ? ++p : from_name);
413 to_name = pathbuf;
414 }
415 devnull = 0;
416 } else {
417 from_sb.st_flags = 0; /* XXX */
418 devnull = 1;
419 }
420
421 /*
422 * Unlink now... avoid ETXTBSY errors later. Try and turn
423 * off the append/immutable bits -- if we fail, go ahead,
424 * it might work.
425 */
426 if (stat(to_name, &to_sb) == 0 &&
427 to_sb.st_flags & (NOCHANGEBITS))
428 (void)chflags(to_name, to_sb.st_flags & ~(NOCHANGEBITS));
429 if (dorename) {
430 char *ptr, c, *dir;
431
432 if ((ptr = strrchr(to_name, '/')) != NULL) {
433 c = *++ptr;
434 *ptr = '\0';
435 dir = to_name;
436 } else {
437 c = '\0'; /* pacify gcc */
438 dir = tmpl;
439 *dir = '\0';
440 }
441 (void)snprintf(tmpl, sizeof(tmpl), "%sinst.XXXXXX", dir);
442 if (ptr)
443 *ptr = c;
444 oto_name = to_name;
445 to_name = tmpl;
446
447 } else {
448 oto_name = NULL; /* pacify gcc */
449 if (dobackup)
450 backup(to_name);
451 else
452 (void)unlink(to_name);
453 }
454
455 if (dolink) {
456 makelink(from_name, to_name);
457 return;
458 }
459
460 /* Create target. */
461 if (dorename) {
462 if ((to_fd = mkstemp(to_name)) == -1)
463 err(1, "%s", to_name);
464 } else {
465 if ((to_fd = open(to_name,
466 O_CREAT | O_WRONLY | O_TRUNC, S_IRUSR | S_IWUSR)) < 0)
467 err(1, "%s", to_name);
468 }
469 if (!devnull) {
470 if ((from_fd = open(from_name, O_RDONLY, 0)) < 0) {
471 (void)unlink(to_name);
472 err(1, "%s", from_name);
473 }
474 copy(from_fd, from_name, to_fd, to_name, from_sb.st_size);
475 (void)close(from_fd);
476 }
477
478 if (dostrip) {
479 strip(to_name);
480
481 /*
482 * Re-open our fd on the target, in case we used a strip
483 * that does not work in-place -- like gnu binutils strip.
484 */
485 close(to_fd);
486 if ((to_fd = open(to_name, O_RDONLY, S_IRUSR | S_IWUSR)) < 0)
487 err(1, "stripping %s", to_name);
488 }
489
490 /*
491 * Set owner, group, mode for target; do the chown first,
492 * chown may lose the setuid bits.
493 */
494 if (!dounpriv &&
495 (flags & (HASUID | HASGID)) && fchown(to_fd, uid, gid) == -1) {
496 serrno = errno;
497 (void)unlink(to_name);
498 errx(1, "%s: chown/chgrp: %s", to_name, strerror(serrno));
499 }
500 if (!dounpriv && fchmod(to_fd, mode) == -1) {
501 serrno = errno;
502 (void)unlink(to_name);
503 errx(1, "%s: chmod: %s", to_name, strerror(serrno));
504 }
505
506 /*
507 * Preserve the date of the source file.
508 */
509 if (dopreserve) {
510 #ifdef BSD4_4
511 TIMESPEC_TO_TIMEVAL(&tv[0], &from_sb.st_atimespec);
512 TIMESPEC_TO_TIMEVAL(&tv[1], &from_sb.st_mtimespec);
513 #else
514 tv[0].tv_sec = from_sb.st_atime;
515 tv[0].tv_usec = 0;
516 tv[1].tv_sec = from_sb.st_mtime;
517 tv[1].tv_usec = 0;
518 #endif
519 if (!dounpriv && futimes(to_fd, tv) == -1)
520 warn("%s: futimes", to_name);
521 }
522
523 (void)close(to_fd);
524
525 if (dorename) {
526 if (rename(to_name, oto_name) == -1)
527 err(1, "%s: rename", to_name);
528 to_name = oto_name;
529 }
530
531 if (!docopy && !devnull && unlink(from_name))
532 err(1, "%s", from_name);
533
534 /*
535 * If provided a set of flags, set them, otherwise, preserve the
536 * flags, except for the dump flag.
537 */
538 if (!dounpriv && chflags(to_name,
539 flags & SETFLAGS ? fileflags : from_sb.st_flags & ~UF_NODUMP) == -1)
540 {
541 if (errno != EOPNOTSUPP || (from_sb.st_flags & ~UF_NODUMP) != 0)
542 warn("%s: chflags", to_name);
543 }
544
545 metadata_log(to_name, S_IFREG, flags, dopreserve ? tv : NULL);
546 }
547
548 /*
549 * copy --
550 * copy from one file to another
551 */
552 void
553 copy(int from_fd, char *from_name, int to_fd, char *to_name, off_t size)
554 {
555 ssize_t nr, nw;
556 int serrno;
557 char *p;
558 char buf[MAXBSIZE];
559
560 /*
561 * There's no reason to do anything other than close the file
562 * now if it's empty, so let's not bother.
563 */
564 if (size > 0) {
565
566 /*
567 * Mmap and write if less than 8M (the limit is so we
568 * don't totally trash memory on big files). This is
569 * really a minor hack, but it wins some CPU back.
570 */
571
572 if (size <= 8 * 1048576) {
573 if ((p = mmap(NULL, (size_t)size, PROT_READ,
574 MAP_FILE|MAP_SHARED, from_fd, (off_t)0))
575 == MAP_FAILED) {
576 goto mmap_failed;
577 }
578 #ifdef MADV_SEQUENTIAL
579 if (madvise(p, (size_t)size, MADV_SEQUENTIAL) == -1
580 && errno != EOPNOTSUPP)
581 warnx("madvise: %s", strerror(errno));
582 #endif
583
584 if (write(to_fd, p, size) != size) {
585 serrno = errno;
586 (void)unlink(to_name);
587 errx(1, "%s: %s",
588 to_name, strerror(serrno));
589 }
590 } else {
591 mmap_failed:
592 while ((nr = read(from_fd, buf, sizeof(buf))) > 0) {
593 if ((nw = write(to_fd, buf, nr)) != nr) {
594 serrno = errno;
595 (void)unlink(to_name);
596 errx(1, "%s: %s", to_name,
597 strerror(nw > 0 ? EIO : serrno));
598 }
599 }
600 if (nr != 0) {
601 serrno = errno;
602 (void)unlink(to_name);
603 errx(1, "%s: %s", from_name, strerror(serrno));
604 }
605 }
606 }
607 }
608
609 /*
610 * strip --
611 * use strip(1) to strip the target file
612 */
613 void
614 strip(char *to_name)
615 {
616 int serrno, status;
617 char *stripprog;
618
619 switch (vfork()) {
620 case -1:
621 serrno = errno;
622 (void)unlink(to_name);
623 errx(1, "vfork: %s", strerror(serrno));
624 case 0:
625 stripprog = getenv("STRIP");
626 if (stripprog == NULL)
627 stripprog = _PATH_STRIP;
628
629 if (stripArgs) {
630 /*
631 * build up a command line and let /bin/sh
632 * parse the arguments
633 */
634 char* cmd = (char*)malloc(sizeof(char)*
635 (3+strlen(stripprog)+
636 strlen(stripArgs)+
637 strlen(to_name)));
638
639 if (cmd == NULL)
640 errx(1, "%s", strerror(ENOMEM));
641
642 sprintf(cmd, "%s %s %s", stripprog, stripArgs, to_name);
643
644 execl(_PATH_BSHELL, "sh", "-c", cmd, NULL);
645 } else
646 execlp(stripprog, "strip", to_name, NULL);
647
648 warn("%s", stripprog);
649 _exit(1);
650 default:
651 if (wait(&status) == -1 || status)
652 (void)unlink(to_name);
653 }
654 }
655
656 /*
657 * backup file "to_name" to to_name.suffix
658 * if suffix contains a "%", it's taken as a printf(3) pattern
659 * used for a numbered backup.
660 */
661 void
662 backup(const char *to_name)
663 {
664 char backup[FILENAME_MAX];
665
666 if (numberedbackup) {
667 /* Do numbered backup */
668 int cnt;
669 char suffix_expanded[FILENAME_MAX];
670
671 cnt=0;
672 do {
673 (void)snprintf(suffix_expanded, FILENAME_MAX, suffix,
674 cnt);
675 (void)snprintf(backup, FILENAME_MAX, "%s%s",
676 to_name, suffix_expanded);
677 cnt++;
678 } while (access(backup, F_OK)==0);
679 } else {
680 /* Do simple backup */
681 (void)snprintf(backup, FILENAME_MAX, "%s%s", to_name, suffix);
682 }
683
684 (void)rename(to_name, backup);
685 }
686
687 /*
688 * install_dir --
689 * build directory hierarchy
690 */
691 void
692 install_dir(char *path, u_int flags)
693 {
694 char *p;
695 struct stat sb;
696 int ch;
697
698 for (p = path;; ++p)
699 if (!*p || (p != path && *p == '/')) {
700 ch = *p;
701 *p = '\0';
702 if (stat(path, &sb)) {
703 if (errno != ENOENT || mkdir(path, 0777) < 0) {
704 err(1, "%s", path);
705 /* NOTREACHED */
706 }
707 }
708 if (!(*p = ch))
709 break;
710 }
711
712 if (!dounpriv && (
713 ((flags & (HASUID | HASGID)) && chown(path, uid, gid) == -1)
714 || chmod(path, mode) == -1 )) {
715 warn("%s", path);
716 }
717 metadata_log(path, S_IFDIR, flags & ~SETFLAGS, NULL);
718 }
719
720 /*
721 * metadata_log --
722 * if metafp is not NULL, output mtree(8) full path name and settings to
723 * metafp, to allow permissions to be set correctly by other tools.
724 */
725 void
726 metadata_log(const char *path, mode_t type, u_int flags, struct timeval *tv)
727 {
728 const char extra[] = { ' ', '\t', '\n', '\\', '#', '\0' };
729 char *buf;
730
731 if (!metafp)
732 return;
733 buf = (char *)malloc(4 * strlen(path) + 1); /* buf for strsvis(3) */
734 if (buf == NULL) {
735 warnx("%s", strerror(ENOMEM));
736 return;
737 }
738 if (flock(fileno(metafp), LOCK_EX) == -1) { /* lock log file */
739 warn("can't lock %s", metafile);
740 return;
741 }
742
743 strsvis(buf, path, VIS_CSTYLE, extra); /* encode name */
744 fprintf(metafp, ".%s%s type=%s mode=%#o", /* print details */
745 buf[0] == '/' ? "" : "/", buf,
746 S_ISDIR(type) ? "dir" : "file", mode);
747 if (owner)
748 fprintf(metafp, " uname=%s", owner);
749 if (group)
750 fprintf(metafp, " gname=%s", group);
751 if (fflags)
752 fprintf(metafp, " flags=%s", fflags);
753 if (tags)
754 fprintf(metafp, " tags=%s", tags);
755 if (tv != NULL)
756 fprintf(metafp, " time=%ld.%ld", tv[1].tv_sec, tv[1].tv_usec);
757 fputc('\n', metafp);
758 fflush(metafp); /* flush output */
759 if (flock(fileno(metafp), LOCK_UN) == -1) { /* unlock log file */
760 warn("can't unlock %s", metafile);
761 }
762 free(buf);
763 }
764
765
766
767 /*
768 * usage --
769 * print a usage message and die
770 */
771 void
772 usage(void)
773 {
774
775 (void)fprintf(stderr, "\
776 usage: install [-Ubcprs] [-M log] [-T tags] [-B suffix] [-f flags] [-m mode]\n\
777 [-o owner] [-g group] [-l linkflags] [-S stripflags] file1 file2\n\
778 install [-Ubcprs] [-M log] [-T tags] [-B suffix] [-f flags] [-m mode]\n\
779 [-o owner] [-g group] [-l linkflags] [-S stripflags]\n\
780 file1 ... fileN directory\n\
781 install [-Up] [-M log] [-T tags] -d [-m mode]\n\
782 [-o owner] [-g group] directory ...\n");
783 exit(1);
784 }
785