8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / cmd / svr4pkg / pkgtrans / main.c
blobb13920c2a1f2d009ff94566d2f1636724ae7e478
1 /*
2 * CDDL HEADER START
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.
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.
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]
19 * CDDL HEADER END
23 * Copyright (c) 2017 Peter Tribble.
27 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
28 * Use is subject to license terms.
31 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
32 /* All Rights Reserved */
35 * Copyright 2010 Nexenta Systems, Inc. All rights reserved.
38 #include <locale.h>
39 #include <libintl.h>
40 #include <stdio.h>
41 #include <signal.h>
42 #include <stdlib.h>
43 #include <unistd.h>
44 #include <string.h>
45 #include <pkgtrans.h>
46 #include <pkglib.h>
47 #include <pkglocs.h>
48 #include <libadm.h>
49 #include <libinst.h>
50 #include <messages.h>
52 static int options;
54 static void usage(void);
55 static void trap(int signo);
57 int
58 main(int argc, char *argv[])
60 int c;
61 void (*func)();
62 extern int optind;
63 int ret;
65 (void) setlocale(LC_ALL, "");
67 #if !defined(TEXT_DOMAIN) /* Should be defined by cc -D */
68 #define TEXT_DOMAIN "SYS_TEST"
69 #endif
70 (void) textdomain(TEXT_DOMAIN);
72 (void) set_prog_name(argv[0]);
74 while ((c = getopt(argc, argv, "snio?")) != EOF) {
75 switch (c) {
76 case 'n':
77 options |= PT_RENAME;
78 break;
80 case 'i':
81 options |= PT_INFO_ONLY;
82 break;
84 case 'o':
85 options |= PT_OVERWRITE;
86 break;
88 case 's':
89 options |= PT_ODTSTREAM;
90 break;
92 default:
93 usage();
94 return (1);
97 func = signal(SIGINT, trap);
98 if (func != SIG_DFL)
99 (void) signal(SIGINT, func);
100 (void) signal(SIGHUP, trap);
101 (void) signal(SIGQUIT, trap);
102 (void) signal(SIGTERM, trap);
103 (void) signal(SIGPIPE, trap);
104 (void) signal(SIGPWR, trap);
106 if ((argc-optind) < 2) {
107 usage();
108 return (1);
111 ret = pkgtrans(flex_device(argv[optind], 1),
112 flex_device(argv[optind+1], 1), &argv[optind+2], options);
114 quit(ret);
115 /*NOTREACHED*/
118 void
119 quit(int retcode)
121 (void) signal(SIGINT, SIG_IGN);
122 (void) signal(SIGHUP, SIG_IGN);
123 (void) ds_close(1);
124 (void) pkghead(NULL);
125 exit(retcode);
128 static void
129 trap(int signo)
131 (void) signal(SIGINT, SIG_IGN);
132 (void) signal(SIGHUP, SIG_IGN);
134 if (signo == SIGINT) {
135 progerr(gettext("aborted at user request.\n"));
136 quit(3);
138 progerr(gettext("aborted by signal %d\n"), signo);
139 quit(1);
142 static void
143 usage(void)
145 (void) fprintf(stderr,
146 gettext("usage: %s [-ions] srcdev dstdev [pkg [pkg...]]\n"),
147 get_prog_name());