Print this page
6110 dumpadm usage string should mention '-d none'
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/cmd/dumpadm/main.c
+++ new/usr/src/cmd/dumpadm/main.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) 1998, 2010, Oracle and/or its affiliates. All rights reserved.
23 23 * Copyright 2015 Nexenta Systems, Inc. All rights reserved.
24 24 */
25 25
26 26 #include <sys/stat.h>
27 27 #include <locale.h>
↓ open down ↓ |
27 lines elided |
↑ open up ↑ |
28 28 #include <unistd.h>
29 29 #include <stdlib.h>
30 30 #include <stdio.h>
31 31 #include <string.h>
32 32
33 33 #include "dconf.h"
34 34 #include "minfree.h"
35 35 #include "utils.h"
36 36
37 37 static const char USAGE[] = "\
38 -Usage: %s [-enuy] [-c kernel | curproc | all ] [-d dump-device | swap ]\n\
39 - [-m min {k|m|%%} ] [-s savecore-dir] [-r root-dir] [-z on|off]\n";
38 +Usage: %s [-enuy] [-c kernel | curproc | all ]\n\
39 + [-d dump-device | swap | none ] [-m min {k|m|%%} ] [-s savecore-dir]\n\
40 + [-r root-dir] [-z on|off]\n";
40 41
41 42 static const char OPTS[] = "einuyc:d:m:s:r:z:";
42 43
43 44 static const char PATH_DEVICE[] = "/dev/dump";
44 45 static const char PATH_CONFIG[] = "/etc/dumpadm.conf";
45 46
46 47 int
47 48 main(int argc, char *argv[])
48 49 {
49 50 const char *pname = getpname(argv[0]);
50 51
51 52 u_longlong_t minf;
52 53 struct stat st;
53 54 int c;
54 55 int dflag = 0; /* for checking in use during -d ops */
55 56 int eflag = 0; /* print estimated dump size */
56 57 int dcmode = DC_CURRENT; /* kernel settings override unless -u */
57 58 int modified = 0; /* have we modified the dump config? */
58 59 char *minfstr = NULL; /* string value of -m argument */
59 60 dumpconf_t dc; /* current configuration */
60 61 int chrooted = 0;
61 62 int douuid = 0;
62 63
63 64 (void) setlocale(LC_ALL, "");
64 65 (void) textdomain(TEXT_DOMAIN);
65 66
66 67 /*
67 68 * Take an initial lap through argv hunting for -r root-dir,
68 69 * so that we can chroot before opening the configuration file.
69 70 * We also handle -u and any bad options at this point.
70 71 */
71 72 while (optind < argc) {
72 73 while ((c = getopt(argc, argv, OPTS)) != (int)EOF) {
73 74 if (c == 'r' && ++chrooted && chroot(optarg) == -1)
74 75 die(gettext("failed to chroot to %s"), optarg);
75 76 else if (c == 'u')
76 77 dcmode = DC_OVERRIDE;
77 78 else if (c == '?') {
78 79 (void) fprintf(stderr, gettext(USAGE), pname);
79 80 return (E_USAGE);
80 81 }
81 82 }
82 83
83 84 if (optind < argc) {
84 85 warn(gettext("illegal argument -- %s\n"), argv[optind]);
85 86 (void) fprintf(stderr, gettext(USAGE), pname);
86 87 return (E_USAGE);
87 88 }
88 89 }
89 90
90 91 if (geteuid() != 0)
91 92 die(gettext("you must be root to use %s\n"), pname);
92 93
93 94 /*
94 95 * If no config file exists yet, we're going to create an empty one,
95 96 * so set the modified flag to force writing out the file.
96 97 */
97 98 if (access(PATH_CONFIG, F_OK) == -1)
98 99 modified++;
99 100
100 101 /*
101 102 * Now open and read in the initial values from the config file.
102 103 * If it doesn't exist, we create an empty file and dc is
103 104 * initialized with the default values.
104 105 */
105 106 if (dconf_open(&dc, PATH_DEVICE, PATH_CONFIG, dcmode) == -1)
106 107 return (E_ERROR);
107 108
108 109 /*
109 110 * Take another lap through argv, processing options and
110 111 * modifying the dumpconf_t as appropriate.
111 112 */
112 113 for (optind = 1; optind < argc; optind++) {
113 114 while ((c = getopt(argc, argv, OPTS)) != (int)EOF) {
114 115 switch (c) {
115 116 case 'c':
116 117 if (dconf_str2content(&dc, optarg) == -1)
117 118 return (E_USAGE);
118 119 modified++;
119 120 break;
120 121 case 'd':
121 122 if (dconf_str2device(&dc, optarg) == -1)
122 123 return (E_USAGE);
123 124 dflag++;
124 125 modified++;
125 126 break;
126 127 case 'e':
127 128 eflag++;
128 129 break;
129 130 case 'i':
130 131 /* undocumented option */
131 132 if (chrooted) {
132 133 warn(gettext("-i and -r cannot be "
133 134 "used together\n"));
134 135 return (E_USAGE);
135 136 }
136 137 douuid++;
137 138 break;
138 139
139 140 case 'm':
140 141 minfstr = optarg;
141 142 break;
142 143
143 144 case 'n':
144 145 dc.dc_enable = DC_OFF;
145 146 modified++;
146 147 break;
147 148
148 149 case 's':
149 150 if (stat(optarg, &st) == -1 ||
150 151 !S_ISDIR(st.st_mode)) {
151 152 warn(gettext("%s is missing or not a "
152 153 "directory\n"), optarg);
153 154 return (E_USAGE);
154 155 }
155 156
156 157 if (dconf_str2savdir(&dc, optarg) == -1)
157 158 return (E_USAGE);
158 159 modified++;
159 160 break;
160 161
161 162 case 'y':
162 163 dc.dc_enable = DC_ON;
163 164 modified++;
164 165 break;
165 166
166 167 case 'z':
167 168 if (dconf_str2csave(&dc, optarg) == -1)
168 169 return (E_USAGE);
169 170 modified++;
170 171 break;
171 172 }
172 173 }
173 174 }
174 175
175 176 if (eflag) {
176 177 if (argc == 2 && argv[1][0] == '-' && argv[1][1] == 'e' &&
177 178 !argv[1][2])
178 179 return (dconf_get_dumpsize(&dc) ? E_SUCCESS : E_ERROR);
179 180 else
180 181 die(gettext("-e cannot be used with other options\n"));
181 182 }
182 183
183 184 if (douuid)
184 185 return (dconf_write_uuid(&dc) ? E_SUCCESS : E_ERROR);
185 186
186 187 if (minfstr != NULL) {
187 188 if (minfree_compute(dc.dc_savdir, minfstr, &minf) == -1)
188 189 return (E_USAGE);
189 190 if (minfree_write(dc.dc_savdir, minf) == -1)
190 191 return (E_ERROR);
191 192 }
192 193
193 194 if (dcmode == DC_OVERRIDE) {
194 195 /*
195 196 * In override mode, we try to force an update. If this
196 197 * fails, we re-load the kernel configuration and write that
197 198 * out to the file in order to force the file in sync.
198 199 *
199 200 * We allow the file to be read-only but print a warning to the
200 201 * user that indicates it hasn't been updated.
201 202 */
202 203 if (dconf_update(&dc, 0) == -1)
203 204 (void) dconf_getdev(&dc);
204 205 if (dc.dc_readonly)
205 206 warn(gettext("kernel settings updated, but "
206 207 "%s is read-only\n"), PATH_CONFIG);
207 208 else if (dconf_write(&dc) == -1)
208 209 return (E_ERROR);
209 210
210 211 } else if (modified) {
211 212 /*
212 213 * If we're modifying the configuration, then try
213 214 * to update it, and write out the file if successful.
214 215 */
215 216 if (dc.dc_readonly) {
216 217 warn(gettext("failed to update settings: %s is "
217 218 "read-only\n"), PATH_CONFIG);
218 219 return (E_ERROR);
219 220 }
220 221
221 222 if (dconf_update(&dc, dflag) == -1 ||
222 223 dconf_write(&dc) == -1)
223 224 return (E_ERROR);
224 225 }
225 226
226 227 if (dcmode == DC_CURRENT)
227 228 dconf_print(&dc, stdout);
228 229
229 230 if (dconf_close(&dc) == -1)
230 231 warn(gettext("failed to close configuration file"));
231 232
232 233 return (E_SUCCESS);
233 234 }
↓ open down ↓ |
184 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX