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