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]
22 * Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved.
23 * Copyright 2015 Nexenta Systems, Inc. All rights reserved.
37 static const char USAGE
[] = "\
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";
42 static const char OPTS
[] = "einuyc:d:m:s:r:z:";
44 static const char PATH_DEVICE
[] = "/dev/dump";
45 static const char PATH_CONFIG
[] = "/etc/dumpadm.conf";
48 main(int argc
, char *argv
[])
50 const char *pname
= getpname(argv
[0]);
55 int dflag
= 0; /* for checking in use during -d ops */
56 int eflag
= 0; /* print estimated dump size */
57 int dcmode
= DC_CURRENT
; /* kernel settings override unless -u */
58 int modified
= 0; /* have we modified the dump config? */
59 char *minfstr
= NULL
; /* string value of -m argument */
60 dumpconf_t dc
; /* current configuration */
64 (void) setlocale(LC_ALL
, "");
65 (void) textdomain(TEXT_DOMAIN
);
68 * Take an initial lap through argv hunting for -r root-dir,
69 * so that we can chroot before opening the configuration file.
70 * We also handle -u and any bad options at this point.
72 while (optind
< argc
) {
73 while ((c
= getopt(argc
, argv
, OPTS
)) != (int)EOF
) {
74 if (c
== 'r' && ++chrooted
&& chroot(optarg
) == -1)
75 die(gettext("failed to chroot to %s"), optarg
);
79 (void) fprintf(stderr
, gettext(USAGE
), pname
);
85 warn(gettext("illegal argument -- %s\n"), argv
[optind
]);
86 (void) fprintf(stderr
, gettext(USAGE
), pname
);
92 die(gettext("you must be root to use %s\n"), pname
);
95 * If no config file exists yet, we're going to create an empty one,
96 * so set the modified flag to force writing out the file.
98 if (access(PATH_CONFIG
, F_OK
) == -1)
102 * Now open and read in the initial values from the config file.
103 * If it doesn't exist, we create an empty file and dc is
104 * initialized with the default values.
106 if (dconf_open(&dc
, PATH_DEVICE
, PATH_CONFIG
, dcmode
) == -1)
110 * Take another lap through argv, processing options and
111 * modifying the dumpconf_t as appropriate.
113 for (optind
= 1; optind
< argc
; optind
++) {
114 while ((c
= getopt(argc
, argv
, OPTS
)) != (int)EOF
) {
117 if (dconf_str2content(&dc
, optarg
) == -1)
122 if (dconf_str2device(&dc
, optarg
) == -1)
131 /* undocumented option */
133 warn(gettext("-i and -r cannot be "
145 dc
.dc_enable
= DC_OFF
;
150 if (stat(optarg
, &st
) == -1 ||
151 !S_ISDIR(st
.st_mode
)) {
152 warn(gettext("%s is missing or not a "
153 "directory\n"), optarg
);
157 if (dconf_str2savdir(&dc
, optarg
) == -1)
163 dc
.dc_enable
= DC_ON
;
168 if (dconf_str2csave(&dc
, optarg
) == -1)
177 if (argc
== 2 && argv
[1][0] == '-' && argv
[1][1] == 'e' &&
179 return (dconf_get_dumpsize(&dc
) ? E_SUCCESS
: E_ERROR
);
181 die(gettext("-e cannot be used with other options\n"));
185 return (dconf_write_uuid(&dc
) ? E_SUCCESS
: E_ERROR
);
187 if (minfstr
!= NULL
) {
188 if (minfree_compute(dc
.dc_savdir
, minfstr
, &minf
) == -1)
190 if (minfree_write(dc
.dc_savdir
, minf
) == -1)
194 if (dcmode
== DC_OVERRIDE
) {
196 * In override mode, we try to force an update. If this
197 * fails, we re-load the kernel configuration and write that
198 * out to the file in order to force the file in sync.
200 * We allow the file to be read-only but print a warning to the
201 * user that indicates it hasn't been updated.
203 if (dconf_update(&dc
, 0) == -1)
204 (void) dconf_getdev(&dc
);
206 warn(gettext("kernel settings updated, but "
207 "%s is read-only\n"), PATH_CONFIG
);
208 else if (dconf_write(&dc
) == -1)
211 } else if (modified
) {
213 * If we're modifying the configuration, then try
214 * to update it, and write out the file if successful.
216 if (dc
.dc_readonly
) {
217 warn(gettext("failed to update settings: %s is "
218 "read-only\n"), PATH_CONFIG
);
222 if (dconf_update(&dc
, dflag
) == -1 ||
223 dconf_write(&dc
) == -1)
227 if (dcmode
== DC_CURRENT
)
228 dconf_print(&dc
, stdout
);
230 if (dconf_close(&dc
) == -1)
231 warn(gettext("failed to close configuration file"));