Print this page
5819 want dumpadm(1m) option to print estimated dump size
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/cmd/dumpadm/dconf.c
+++ new/usr/src/cmd/dumpadm/dconf.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/types.h>
26 27 #include <sys/stat.h>
27 28 #include <sys/swap.h>
28 29 #include <sys/dumpadm.h>
29 30 #include <sys/utsname.h>
30 31
31 32 #include <unistd.h>
32 33 #include <string.h>
33 34 #include <stdlib.h>
34 35 #include <stdio.h>
35 36 #include <fcntl.h>
36 37 #include <errno.h>
37 38 #include <libdiskmgt.h>
38 39 #include <libzfs.h>
39 40 #include <uuid/uuid.h>
40 41
41 42 #include "dconf.h"
42 43 #include "minfree.h"
43 44 #include "utils.h"
44 45 #include "swap.h"
45 46
46 47 typedef struct dc_token {
47 48 const char *tok_name;
48 49 int (*tok_parse)(dumpconf_t *, char *);
49 50 int (*tok_print)(const dumpconf_t *, FILE *);
50 51 } dc_token_t;
51 52
52 53
53 54 static int print_device(const dumpconf_t *, FILE *);
54 55 static int print_savdir(const dumpconf_t *, FILE *);
55 56 static int print_content(const dumpconf_t *, FILE *);
56 57 static int print_enable(const dumpconf_t *, FILE *);
57 58 static int print_csave(const dumpconf_t *, FILE *);
58 59
59 60 static const dc_token_t tokens[] = {
60 61 { "DUMPADM_DEVICE", dconf_str2device, print_device },
61 62 { "DUMPADM_SAVDIR", dconf_str2savdir, print_savdir },
62 63 { "DUMPADM_CONTENT", dconf_str2content, print_content },
63 64 { "DUMPADM_ENABLE", dconf_str2enable, print_enable },
64 65 { "DUMPADM_CSAVE", dconf_str2csave, print_csave },
65 66 { NULL, NULL, NULL }
66 67 };
67 68
68 69 static const char DC_STR_ON[] = "on"; /* On string */
69 70 static const char DC_STR_OFF[] = "off"; /* Off string */
70 71 static const char DC_STR_YES[] = "yes"; /* Enable on string */
71 72 static const char DC_STR_NO[] = "no"; /* Enable off string */
72 73 static const char DC_STR_SWAP[] = "swap"; /* Default dump device */
73 74 static const char DC_STR_NONE[] = "none";
74 75
75 76 /* The pages included in the dump */
76 77 static const char DC_STR_KERNEL[] = "kernel"; /* Kernel only */
77 78 static const char DC_STR_CURPROC[] = "curproc"; /* Kernel + current process */
78 79 static const char DC_STR_ALL[] = "all"; /* All pages */
79 80
80 81 /*
81 82 * Permissions and ownership for the configuration file:
82 83 */
83 84 #define DC_OWNER 0 /* Uid 0 (root) */
84 85 #define DC_GROUP 1 /* Gid 1 (other) */
85 86 #define DC_PERM (S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH) /* Mode 0644 */
86 87
87 88 static void
88 89 dconf_init(dumpconf_t *dcp, int dcmode)
89 90 {
90 91 struct utsname ut;
91 92
92 93 /*
93 94 * Default device for dumps is 'swap' (appropriate swap device),
94 95 * and default savecore directory is /var/crash/`uname -n`,
95 96 * which is compatible with pre-dumpadm behavior.
96 97 */
97 98 (void) strcpy(dcp->dc_device, DC_STR_SWAP);
98 99 (void) strcpy(dcp->dc_savdir, "/var/crash");
99 100
100 101 if (uname(&ut) != -1) {
101 102 (void) strcat(dcp->dc_savdir, "/");
102 103 (void) strcat(dcp->dc_savdir, ut.nodename);
103 104 }
104 105
105 106 /*
106 107 * Default is contents kernel, savecore enabled on reboot,
107 108 * savecore saves compressed core files.
108 109 */
109 110 dcp->dc_cflags = DUMP_KERNEL;
110 111 dcp->dc_enable = DC_ON;
111 112 dcp->dc_csave = DC_COMPRESSED;
112 113
113 114 dcp->dc_mode = dcmode;
114 115 dcp->dc_conf_fp = NULL;
115 116 dcp->dc_conf_fd = -1;
116 117 dcp->dc_dump_fd = -1;
117 118 dcp->dc_readonly = B_FALSE;
118 119 }
119 120
120 121 int
121 122 dconf_open(dumpconf_t *dcp, const char *dpath, const char *fpath, int dcmode)
122 123 {
123 124 char buf[BUFSIZ];
124 125 int line;
125 126 const char *fpmode = "r+";
126 127
127 128 dconf_init(dcp, dcmode);
128 129
129 130 if ((dcp->dc_dump_fd = open(dpath, O_RDWR)) == -1) {
130 131 warn(gettext("failed to open %s"), dpath);
131 132 return (-1);
132 133 }
133 134
134 135 if ((dcp->dc_conf_fd = open(fpath, O_RDWR | O_CREAT, DC_PERM)) == -1) {
135 136 /*
136 137 * Attempt to open the file read-only.
137 138 */
138 139 if ((dcp->dc_conf_fd = open(fpath, O_RDONLY)) == -1) {
139 140 warn(gettext("failed to open %s"), fpath);
140 141 return (-1);
141 142 }
142 143
143 144 dcp->dc_readonly = B_TRUE;
144 145 fpmode = "r";
145 146 }
146 147
147 148 if ((dcp->dc_conf_fp = fdopen(dcp->dc_conf_fd, fpmode)) == NULL) {
148 149 warn(gettext("failed to open stream for %s"), fpath);
149 150 return (-1);
150 151 }
151 152
152 153 /*
153 154 * If we're in override mode, the current kernel settings override the
154 155 * default settings and anything invalid in the configuration file.
155 156 */
156 157 if (dcmode == DC_OVERRIDE)
157 158 (void) dconf_getdev(dcp);
158 159
159 160 for (line = 1; fgets(buf, BUFSIZ, dcp->dc_conf_fp) != NULL; line++) {
160 161
161 162 char name[BUFSIZ], value[BUFSIZ];
162 163 const dc_token_t *tokp;
163 164 int len;
164 165
165 166 if (buf[0] == '#' || buf[0] == '\n')
166 167 continue;
167 168
168 169 /*
169 170 * Look for "name=value", with optional whitespace on either
170 171 * side, terminated by a newline, and consuming the whole line.
171 172 */
172 173 /* LINTED - unbounded string specifier */
173 174 if (sscanf(buf, " %[^=]=%s \n%n", name, value, &len) == 2 &&
174 175 name[0] != '\0' && value[0] != '\0' && len == strlen(buf)) {
175 176 /*
176 177 * Locate a matching token in the tokens[] table,
177 178 * and invoke its parsing function.
178 179 */
179 180 for (tokp = tokens; tokp->tok_name != NULL; tokp++) {
180 181 if (strcmp(name, tokp->tok_name) == 0) {
181 182 if (tokp->tok_parse(dcp, value) == -1) {
182 183 warn(gettext("\"%s\", line %d: "
183 184 "warning: invalid %s\n"),
184 185 fpath, line, name);
185 186 }
186 187 break;
187 188 }
188 189 }
189 190
190 191 /*
191 192 * If we hit the end of the tokens[] table,
192 193 * no matching token was found.
193 194 */
194 195 if (tokp->tok_name == NULL) {
195 196 warn(gettext("\"%s\", line %d: warning: "
196 197 "invalid token: %s\n"), fpath, line, name);
197 198 }
198 199
199 200 } else {
200 201 warn(gettext("\"%s\", line %d: syntax error\n"),
201 202 fpath, line);
202 203 }
203 204 }
204 205
205 206 /*
206 207 * If we're not in override mode, the current kernel settings
207 208 * override the settings read from the configuration file.
208 209 */
209 210 if (dcmode == DC_CURRENT)
210 211 return (dconf_getdev(dcp));
211 212
212 213 return (0);
213 214 }
214 215
215 216 int
216 217 dconf_getdev(dumpconf_t *dcp)
217 218 {
218 219 int status = 0;
219 220
220 221 if ((dcp->dc_cflags = ioctl(dcp->dc_dump_fd, DIOCGETCONF, 0)) == -1) {
221 222 warn(gettext("failed to get kernel dump settings"));
222 223 status = -1;
223 224 }
224 225
225 226 if (ioctl(dcp->dc_dump_fd, DIOCGETDEV, dcp->dc_device) == -1) {
226 227 if (errno != ENODEV) {
227 228 warn(gettext("failed to get dump device"));
228 229 status = -1;
229 230 } else
230 231 dcp->dc_device[0] = '\0';
231 232 }
232 233
233 234 return (status);
234 235 }
235 236
236 237 int
237 238 dconf_close(dumpconf_t *dcp)
238 239 {
239 240 if (fclose(dcp->dc_conf_fp) == 0) {
240 241 (void) close(dcp->dc_dump_fd);
241 242 return (0);
242 243 }
243 244 return (-1);
244 245 }
245 246
246 247 int
247 248 dconf_write(dumpconf_t *dcp)
248 249 {
249 250 const dc_token_t *tokp;
250 251
251 252 if (fseeko(dcp->dc_conf_fp, (off_t)0, SEEK_SET) == -1) {
252 253 warn(gettext("failed to seek config file"));
253 254 return (-1);
254 255 }
255 256
256 257 if (ftruncate(dcp->dc_conf_fd, (off_t)0) == -1) {
257 258 warn(gettext("failed to truncate config file"));
258 259 return (-1);
259 260 }
260 261
261 262 (void) fputs("#\n# dumpadm.conf\n#\n"
262 263 "# Configuration parameters for system crash dump.\n"
263 264 "# Do NOT edit this file by hand -- use dumpadm(1m) instead.\n"
264 265 "#\n", dcp->dc_conf_fp);
265 266
266 267 for (tokp = tokens; tokp->tok_name != NULL; tokp++) {
267 268 if (fprintf(dcp->dc_conf_fp, "%s=", tokp->tok_name) == -1 ||
268 269 tokp->tok_print(dcp, dcp->dc_conf_fp) == -1) {
269 270 warn(gettext("failed to write token"));
270 271 return (-1);
271 272 }
272 273 }
273 274
274 275 if (fflush(dcp->dc_conf_fp) != 0)
275 276 warn(gettext("warning: failed to flush config file"));
276 277
277 278 if (fsync(dcp->dc_conf_fd) == -1)
278 279 warn(gettext("warning: failed to sync config file to disk"));
279 280
280 281 if (fchmod(dcp->dc_conf_fd, DC_PERM) == -1)
281 282 warn(gettext("warning: failed to reset mode on config file"));
282 283
283 284 if (fchown(dcp->dc_conf_fd, DC_OWNER, DC_GROUP) == -1)
284 285 warn(gettext("warning: failed to reset owner on config file"));
285 286
286 287 return (0);
287 288 }
288 289
289 290 static int
290 291 open_stat64(const char *path, struct stat64 *stp)
291 292 {
292 293 int fd = open64(path, O_RDONLY);
293 294
294 295 if (fd >= 0) {
295 296 int status = fstat64(fd, stp);
296 297 (void) close(fd);
297 298 return (status);
298 299 }
299 300
300 301 return (-1);
301 302 }
302 303
303 304 static int
304 305 dconf_swap_compare(const swapent_t *s1, const swapent_t *s2)
305 306 {
306 307 struct stat64 st1, st2;
307 308
308 309 int prefer_s1 = -1; /* Return value to move s1 left (s1 < s2) */
309 310 int prefer_s2 = 1; /* Return value to move s2 left (s1 > s2) */
310 311
311 312 /*
312 313 * First try: open and fstat each swap entry. If either system
313 314 * call fails, arbitrarily prefer the other entry.
314 315 */
315 316 if (open_stat64(s1->ste_path, &st1) == -1)
316 317 return (prefer_s2);
317 318
318 319 if (open_stat64(s2->ste_path, &st2) == -1)
319 320 return (prefer_s1);
320 321
321 322 /*
322 323 * Second try: if both entries are block devices, or if
323 324 * neither is a block device, prefer the larger.
324 325 */
325 326 if (S_ISBLK(st1.st_mode) == S_ISBLK(st2.st_mode)) {
326 327 if (st2.st_size > st1.st_size)
327 328 return (prefer_s2);
328 329 return (prefer_s1);
329 330 }
330 331
331 332 /*
332 333 * Third try: prefer the entry that is a block device.
333 334 */
334 335 if (S_ISBLK(st2.st_mode))
335 336 return (prefer_s2);
336 337 return (prefer_s1);
337 338 }
338 339
339 340 static int
340 341 dconf_dev_ioctl(dumpconf_t *dcp, int cmd)
341 342 {
342 343 if (ioctl(dcp->dc_dump_fd, cmd, dcp->dc_device) == 0)
343 344 return (0);
344 345
345 346 switch (errno) {
346 347 case ENOTSUP:
347 348 warn(gettext("dumps not supported on %s\n"), dcp->dc_device);
348 349 break;
349 350 case EBUSY:
350 351 warn(gettext("device %s is already in use\n"), dcp->dc_device);
351 352 break;
352 353 case EBADR:
353 354 /* ZFS pool is too fragmented to support a dump device */
354 355 warn(gettext("device %s is too fragmented to be used as "
355 356 "a dump device\n"), dcp->dc_device);
356 357 break;
357 358 default:
358 359 /*
359 360 * NOTE: The stmsboot(1M) command's boot-up script parses this
360 361 * error to get the dump device name. If you change the format
361 362 * of this message, make sure that stmsboot(1M) is in sync.
362 363 */
363 364 warn(gettext("cannot use %s as dump device"), dcp->dc_device);
364 365 }
365 366 return (-1);
366 367 }
367 368
368 369 int
369 370 dconf_update(dumpconf_t *dcp, int checkinuse)
370 371 {
371 372 int oconf;
372 373 int error;
373 374 char *msg;
374 375
375 376 error = 0;
376 377
377 378 if (checkinuse && (dm_inuse(dcp->dc_device, &msg, DM_WHO_DUMP,
378 379 &error) || error)) {
379 380 if (error != 0) {
380 381 warn(gettext("failed to determine if %s is"
381 382 " in use"), dcp->dc_device);
382 383 } else {
383 384 warn(msg);
384 385 free(msg);
385 386 return (-1);
386 387 }
387 388 }
388 389
389 390 /*
390 391 * Save the existing dump configuration in case something goes wrong.
391 392 */
392 393 if ((oconf = ioctl(dcp->dc_dump_fd, DIOCGETCONF, 0)) == -1) {
393 394 warn(gettext("failed to get kernel dump configuration"));
394 395 return (-1);
395 396 }
396 397
397 398 oconf &= DUMP_CONTENT;
398 399 dcp->dc_cflags &= DUMP_CONTENT;
399 400
400 401 if (ioctl(dcp->dc_dump_fd, DIOCSETCONF, dcp->dc_cflags) == -1) {
401 402 warn(gettext("failed to update kernel dump configuration"));
402 403 return (-1);
403 404 }
404 405
405 406 if (strcmp(dcp->dc_device, DC_STR_SWAP) == 0) {
406 407 swaptbl_t *swt;
407 408 int i;
408 409
409 410 if ((swt = swap_list()) == NULL)
410 411 goto err;
411 412
412 413 if (swt->swt_n == 0) {
413 414 warn(gettext("no swap devices are available\n"));
414 415 free(swt);
415 416 goto err;
416 417 }
417 418
418 419 qsort(&swt->swt_ent[0], swt->swt_n, sizeof (swapent_t),
419 420 (int (*)(const void *, const void *))dconf_swap_compare);
420 421
421 422 /*
422 423 * Iterate through the prioritized list of swap entries,
423 424 * trying to configure one as the dump device.
424 425 */
425 426 for (i = 0; i < swt->swt_n; i++) {
426 427 if (ioctl(dcp->dc_dump_fd, DIOCSETDEV,
427 428 swt->swt_ent[i].ste_path) == 0) {
428 429 (void) strcpy(dcp->dc_device,
429 430 swt->swt_ent[i].ste_path);
430 431 break;
431 432 }
432 433 }
433 434
434 435 if (i == swt->swt_n) {
435 436 warn(gettext("no swap devices could be configured "
436 437 "as the dump device\n"));
437 438 free(swt);
438 439 goto err;
439 440 }
440 441 free(swt);
441 442
442 443 } else if (strcmp(dcp->dc_device, DC_STR_NONE) == 0) {
443 444 if (ioctl(dcp->dc_dump_fd, DIOCRMDEV, NULL) == -1) {
444 445 warn(gettext("failed to remove dump device"));
445 446 return (-1);
446 447 }
447 448 } else if (dcp->dc_device[0] != '\0') {
448 449 /*
449 450 * If we're not in forcible update mode, then fail the change
450 451 * if the selected device cannot be used as the dump device,
451 452 * or if it is not big enough to hold the dump.
452 453 */
453 454 if (dcp->dc_mode == DC_CURRENT) {
454 455 struct stat64 st;
455 456 uint64_t d;
456 457
457 458 if (dconf_dev_ioctl(dcp, DIOCTRYDEV) == -1)
458 459 goto err;
459 460
460 461 if (open_stat64(dcp->dc_device, &st) == -1) {
461 462 warn(gettext("failed to access %s"),
462 463 dcp->dc_device);
463 464 goto err;
464 465 }
465 466
466 467 if ((error = zvol_check_dump_config(
467 468 dcp->dc_device)) > 0)
468 469 goto err;
469 470 if (ioctl(dcp->dc_dump_fd, DIOCGETDUMPSIZE, &d) == -1) {
470 471 warn(gettext("failed to get kernel dump size"));
471 472 goto err;
472 473 }
473 474
474 475 if (st.st_size < d) {
475 476 warn(gettext("dump device %s is too small to "
476 477 "hold a system dump\ndump size %llu "
477 478 "bytes, device size %lld bytes\n"),
478 479 dcp->dc_device, d, st.st_size);
479 480 goto err;
480 481 }
481 482 }
482 483
483 484 if (dconf_dev_ioctl(dcp, DIOCSETDEV) == -1)
484 485 goto err;
485 486 }
486 487
487 488 /*
488 489 * Now that we've updated the dump device, we need to issue another
489 490 * ioctl to re-read the config flags to determine whether we
490 491 * obtained DUMP_EXCL access on our dump device.
491 492 */
492 493 if ((dcp->dc_cflags = ioctl(dcp->dc_dump_fd, DIOCGETCONF, 0)) == -1) {
493 494 warn(gettext("failed to re-read kernel dump configuration"));
494 495 return (-1);
495 496 }
496 497
497 498 return (0);
498 499
499 500 err:
500 501 (void) ioctl(dcp->dc_dump_fd, DIOCSETCONF, oconf);
501 502 return (-1);
502 503 }
503 504
504 505 int
505 506 dconf_write_uuid(dumpconf_t *dcp)
506 507 {
507 508 char uuidstr[36 + 1];
508 509 uuid_t uu;
509 510 int err;
510 511
511 512 uuid_generate(uu);
↓ open down ↓ |
479 lines elided |
↑ open up ↑ |
512 513 uuid_unparse(uu, uuidstr);
513 514
514 515 err = ioctl(dcp->dc_dump_fd, DIOCSETUUID, uuidstr);
515 516
516 517 if (err)
517 518 warn(gettext("kernel image uuid write failed"));
518 519
519 520 return (err == 0);
520 521 }
521 522
523 +int
524 +dconf_get_dumpsize(dumpconf_t *dcp)
525 +{
526 + char buf[32];
527 + uint64_t d;
528 +
529 + if (ioctl(dcp->dc_dump_fd, DIOCGETDUMPSIZE, &d) == -1) {
530 + warn(gettext("failed to get kernel dump size"));
531 + return (-1);
532 + }
533 +
534 + zfs_nicenum(d, buf, sizeof (buf));
535 +
536 + (void) printf(gettext("Estimated dump size: %s\n"), buf);
537 + return (0);
538 +}
539 +
522 540 void
523 541 dconf_print(dumpconf_t *dcp, FILE *fp)
524 542 {
525 543 u_longlong_t min;
526 544 char *content;
527 545
528 546 if (dcp->dc_cflags & DUMP_ALL)
529 547 content = gettext("all");
530 548 else if (dcp->dc_cflags & DUMP_CURPROC)
531 549 content = gettext("kernel and current process");
532 550 else
533 551 content = gettext("kernel");
534 552
535 553 (void) fprintf(fp, gettext(" Dump content: %s pages\n"), content);
536 554
537 555 if (dcp->dc_device[0] != '\0') {
538 556 (void) fprintf(fp, gettext(" Dump device: %s (%s)\n"),
539 557 dcp->dc_device, (dcp->dc_cflags & DUMP_EXCL) ?
540 558 gettext("dedicated") : gettext("swap"));
541 559 } else {
542 560 (void) fprintf(fp, gettext(" Dump device: none "
543 561 "(dumps disabled)\n"));
544 562 }
545 563
546 564 (void) fprintf(fp, gettext("Savecore directory: %s"), dcp->dc_savdir);
547 565
548 566 if (minfree_read(dcp->dc_savdir, &min) == 0) {
549 567 if (min < 1024 || (min % 1024) != 0)
550 568 (void) fprintf(fp, gettext(" (minfree = %lluKB)"), min);
551 569 else
552 570 (void) fprintf(fp, gettext(" (minfree = %lluMB)"),
553 571 min / 1024);
554 572 }
555 573
556 574 (void) fprintf(fp, gettext("\n"));
557 575
558 576 (void) fprintf(fp, gettext(" Savecore enabled: %s\n"),
559 577 (dcp->dc_enable == DC_OFF) ? gettext("no") : gettext("yes"));
560 578 (void) fprintf(fp, gettext(" Save compressed: %s\n"),
561 579 (dcp->dc_csave == DC_UNCOMPRESSED) ? gettext("off") :
562 580 gettext("on"));
563 581 }
564 582
565 583 int
566 584 dconf_str2device(dumpconf_t *dcp, char *buf)
567 585 {
568 586 if (strcasecmp(buf, DC_STR_SWAP) == 0) {
569 587 (void) strcpy(dcp->dc_device, DC_STR_SWAP);
570 588 return (0);
571 589 }
572 590
573 591 if (strcasecmp(buf, DC_STR_NONE) == 0) {
574 592 (void) strcpy(dcp->dc_device, DC_STR_NONE);
575 593 return (0);
576 594 }
577 595
578 596 if (valid_abspath(buf)) {
579 597 (void) strcpy(dcp->dc_device, buf);
580 598 return (0);
581 599 }
582 600
583 601 return (-1);
584 602 }
585 603
586 604 int
587 605 dconf_str2savdir(dumpconf_t *dcp, char *buf)
588 606 {
589 607 if (valid_abspath(buf)) {
590 608 (void) strcpy(dcp->dc_savdir, buf);
591 609 return (0);
592 610 }
593 611
594 612 return (-1);
595 613 }
596 614
597 615 int
598 616 dconf_str2content(dumpconf_t *dcp, char *buf)
599 617 {
600 618 if (strcasecmp(buf, DC_STR_KERNEL) == 0) {
601 619 dcp->dc_cflags = (dcp->dc_cflags & ~DUMP_CONTENT) | DUMP_KERNEL;
602 620 return (0);
603 621 }
604 622
605 623 if (strcasecmp(buf, DC_STR_CURPROC) == 0) {
606 624 dcp->dc_cflags = (dcp->dc_cflags & ~DUMP_CONTENT) |
607 625 DUMP_CURPROC;
608 626 return (0);
609 627 }
610 628
611 629 if (strcasecmp(buf, DC_STR_ALL) == 0) {
612 630 dcp->dc_cflags = (dcp->dc_cflags & ~DUMP_CONTENT) | DUMP_ALL;
613 631 return (0);
614 632 }
615 633
616 634 warn(gettext("invalid dump content type -- %s\n"), buf);
617 635 return (-1);
618 636 }
619 637
620 638 int
621 639 dconf_str2enable(dumpconf_t *dcp, char *buf)
622 640 {
623 641 if (strcasecmp(buf, DC_STR_YES) == 0) {
624 642 dcp->dc_enable = DC_ON;
625 643 return (0);
626 644 }
627 645
628 646 if (strcasecmp(buf, DC_STR_NO) == 0) {
629 647 dcp->dc_enable = DC_OFF;
630 648 return (0);
631 649 }
632 650
633 651 warn(gettext("invalid enable value -- %s\n"), buf);
634 652 return (-1);
635 653 }
636 654
637 655 int
638 656 dconf_str2csave(dumpconf_t *dcp, char *buf)
639 657 {
640 658 if (strcasecmp(buf, DC_STR_ON) == 0) {
641 659 dcp->dc_csave = DC_COMPRESSED;
642 660 return (0);
643 661 }
644 662
645 663 if (strcasecmp(buf, DC_STR_OFF) == 0) {
646 664 dcp->dc_csave = DC_UNCOMPRESSED;
647 665 return (0);
648 666 }
649 667
650 668 warn(gettext("invalid save compressed value -- %s\n"), buf);
651 669 return (-1);
652 670 }
653 671
654 672 static int
655 673 print_content(const dumpconf_t *dcp, FILE *fp)
656 674 {
657 675 const char *content;
658 676
659 677 if (dcp->dc_cflags & DUMP_ALL)
660 678 content = DC_STR_ALL;
661 679 else if (dcp->dc_cflags & DUMP_CURPROC)
662 680 content = DC_STR_CURPROC;
663 681 else
664 682 content = DC_STR_KERNEL;
665 683
666 684 return (fprintf(fp, "%s\n", content));
667 685 }
668 686
669 687 static int
670 688 print_device(const dumpconf_t *dcp, FILE *fp)
671 689 {
672 690 return (fprintf(fp, "%s\n", (dcp->dc_device[0] != '\0') ?
673 691 dcp->dc_device : DC_STR_SWAP));
674 692 }
675 693
676 694 static int
677 695 print_enable(const dumpconf_t *dcp, FILE *fp)
678 696 {
679 697 return (fprintf(fp, "%s\n", (dcp->dc_enable == DC_OFF) ?
680 698 DC_STR_NO : DC_STR_YES));
681 699 }
682 700
683 701 static int
684 702 print_csave(const dumpconf_t *dcp, FILE *fp)
685 703 {
686 704 return (fprintf(fp, "%s\n", (dcp->dc_csave == DC_COMPRESSED) ?
687 705 DC_STR_ON : DC_STR_OFF));
688 706 }
689 707
690 708 static int
691 709 print_savdir(const dumpconf_t *dcp, FILE *fp)
692 710 {
693 711 return (fprintf(fp, "%s\n", dcp->dc_savdir));
694 712 }
↓ open down ↓ |
163 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX