1*fcf3ce44SJohn Forte /*
2*fcf3ce44SJohn Forte * CDDL HEADER START
3*fcf3ce44SJohn Forte *
4*fcf3ce44SJohn Forte * The contents of this file are subject to the terms of the
5*fcf3ce44SJohn Forte * Common Development and Distribution License (the "License").
6*fcf3ce44SJohn Forte * You may not use this file except in compliance with the License.
7*fcf3ce44SJohn Forte *
8*fcf3ce44SJohn Forte * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*fcf3ce44SJohn Forte * or http://www.opensolaris.org/os/licensing.
10*fcf3ce44SJohn Forte * See the License for the specific language governing permissions
11*fcf3ce44SJohn Forte * and limitations under the License.
12*fcf3ce44SJohn Forte *
13*fcf3ce44SJohn Forte * When distributing Covered Code, include this CDDL HEADER in each
14*fcf3ce44SJohn Forte * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*fcf3ce44SJohn Forte * If applicable, add the following below this CDDL HEADER, with the
16*fcf3ce44SJohn Forte * fields enclosed by brackets "[]" replaced with your own identifying
17*fcf3ce44SJohn Forte * information: Portions Copyright [yyyy] [name of copyright owner]
18*fcf3ce44SJohn Forte *
19*fcf3ce44SJohn Forte * CDDL HEADER END
20*fcf3ce44SJohn Forte */
21*fcf3ce44SJohn Forte /*
22*fcf3ce44SJohn Forte * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
23*fcf3ce44SJohn Forte * Use is subject to license terms.
24*fcf3ce44SJohn Forte */
25*fcf3ce44SJohn Forte
26*fcf3ce44SJohn Forte #include <stdio.h>
27*fcf3ce44SJohn Forte #include <sys/types.h>
28*fcf3ce44SJohn Forte #include <sys/wait.h>
29*fcf3ce44SJohn Forte #include <sys/vtoc.h>
30*fcf3ce44SJohn Forte #include <sys/stat.h>
31*fcf3ce44SJohn Forte #include <stdio.h>
32*fcf3ce44SJohn Forte #include <sys/mnttab.h>
33*fcf3ce44SJohn Forte #include <errno.h>
34*fcf3ce44SJohn Forte #include <limits.h>
35*fcf3ce44SJohn Forte #include <fcntl.h>
36*fcf3ce44SJohn Forte #include <string.h>
37*fcf3ce44SJohn Forte #include <strings.h>
38*fcf3ce44SJohn Forte #include <stdlib.h>
39*fcf3ce44SJohn Forte #include <unistd.h>
40*fcf3ce44SJohn Forte #include <time.h>
41*fcf3ce44SJohn Forte
42*fcf3ce44SJohn Forte #include <locale.h>
43*fcf3ce44SJohn Forte #include <langinfo.h>
44*fcf3ce44SJohn Forte #include <libintl.h>
45*fcf3ce44SJohn Forte #include <stdarg.h>
46*fcf3ce44SJohn Forte #include <netdb.h>
47*fcf3ce44SJohn Forte #include <ctype.h>
48*fcf3ce44SJohn Forte #include <assert.h>
49*fcf3ce44SJohn Forte
50*fcf3ce44SJohn Forte #include <sys/nsctl/cfg_impl.h>
51*fcf3ce44SJohn Forte #include <sys/nsctl/cfg.h>
52*fcf3ce44SJohn Forte
53*fcf3ce44SJohn Forte #include <sys/unistat/spcs_s.h>
54*fcf3ce44SJohn Forte #include <sys/unistat/spcs_s_u.h>
55*fcf3ce44SJohn Forte #include <sys/unistat/spcs_errors.h>
56*fcf3ce44SJohn Forte
57*fcf3ce44SJohn Forte #ifdef DEBUG
58*fcf3ce44SJohn Forte #include <sys/nsctl/dsw.h>
59*fcf3ce44SJohn Forte #endif
60*fcf3ce44SJohn Forte
61*fcf3ce44SJohn Forte #define DEFAULT_PARSER_LOC "/etc/dscfg_format"
62*fcf3ce44SJohn Forte
63*fcf3ce44SJohn Forte int Cflg;
64*fcf3ce44SJohn Forte int Dflg;
65*fcf3ce44SJohn Forte int Lflg;
66*fcf3ce44SJohn Forte int aflg;
67*fcf3ce44SJohn Forte int iflg;
68*fcf3ce44SJohn Forte int lflg;
69*fcf3ce44SJohn Forte int nflg;
70*fcf3ce44SJohn Forte int pflg;
71*fcf3ce44SJohn Forte int rflg;
72*fcf3ce44SJohn Forte int sflg;
73*fcf3ce44SJohn Forte int uflg;
74*fcf3ce44SJohn Forte
75*fcf3ce44SJohn Forte int verbose;
76*fcf3ce44SJohn Forte int noflags;
77*fcf3ce44SJohn Forte int errflg;
78*fcf3ce44SJohn Forte int mustcommit;
79*fcf3ce44SJohn Forte char *locname; /* config location from cfg_location */
80*fcf3ce44SJohn Forte char *cmdname;
81*fcf3ce44SJohn Forte
82*fcf3ce44SJohn Forte #define MAX_FILENAME 80
83*fcf3ce44SJohn Forte
84*fcf3ce44SJohn Forte char output_file[MAX_FILENAME]; /* specified output file */
85*fcf3ce44SJohn Forte char altroot[MAX_FILENAME]; /* specifed root location */
86*fcf3ce44SJohn Forte char config_file[MAX_FILENAME]; /* specified configuration file */
87*fcf3ce44SJohn Forte char input_file[MAX_FILENAME]; /* specified input file */
88*fcf3ce44SJohn Forte char logical_host[MAX_FILENAME]; /* specified cluster node */
89*fcf3ce44SJohn Forte char device_group[MAX_FILENAME]; /* specified device group name */
90*fcf3ce44SJohn Forte
91*fcf3ce44SJohn Forte #define IS_NOT_CLUSTER 1
92*fcf3ce44SJohn Forte #define IS_CLUSTER 2
93*fcf3ce44SJohn Forte
94*fcf3ce44SJohn Forte void cfg_invalidate_hsizes(int, const char *);
95*fcf3ce44SJohn Forte static int check_cluster();
96*fcf3ce44SJohn Forte
97*fcf3ce44SJohn Forte void
usage(char * errmsg)98*fcf3ce44SJohn Forte usage(char *errmsg)
99*fcf3ce44SJohn Forte {
100*fcf3ce44SJohn Forte if (errmsg)
101*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdname, errmsg);
102*fcf3ce44SJohn Forte (void) fprintf(stderr,
103*fcf3ce44SJohn Forte gettext("dscfg \t\t\t\tDisplay location of "
104*fcf3ce44SJohn Forte "local configuration database\n"));
105*fcf3ce44SJohn Forte (void) fprintf(stderr, gettext("dscfg -l -s path\t\t"
106*fcf3ce44SJohn Forte "List contents of configuration database\n"));
107*fcf3ce44SJohn Forte (void) fprintf(stderr, gettext(
108*fcf3ce44SJohn Forte "\t\t\t\tlocated at path specified\n"));
109*fcf3ce44SJohn Forte (void) fprintf(stderr, gettext("dscfg -i\t\t\t"
110*fcf3ce44SJohn Forte "Initialize configuration database\n"));
111*fcf3ce44SJohn Forte (void) fprintf(stderr,
112*fcf3ce44SJohn Forte gettext("dscfg -i -p "
113*fcf3ce44SJohn Forte #ifdef DEBUG
114*fcf3ce44SJohn Forte "[-n] "
115*fcf3ce44SJohn Forte #endif
116*fcf3ce44SJohn Forte "/etc/dscfg_format\tFormat configuration database\n"));
117*fcf3ce44SJohn Forte (void) fprintf(stderr,
118*fcf3ce44SJohn Forte gettext("dscfg -a file\t\t\tRestore configuration "
119*fcf3ce44SJohn Forte "database from file\n"));
120*fcf3ce44SJohn Forte (void) fprintf(stderr, gettext("\t\t\t\tspecified\n"));
121*fcf3ce44SJohn Forte (void) fprintf(stderr,
122*fcf3ce44SJohn Forte gettext("dscfg -l\t\t\tList contents of configuration database"
123*fcf3ce44SJohn Forte "\n"));
124*fcf3ce44SJohn Forte (void) fprintf(stderr,
125*fcf3ce44SJohn Forte gettext("dscfg -L\t\t\tDisplay configuration database's\n"));
126*fcf3ce44SJohn Forte (void) fprintf(stderr, gettext("\t\t\t\tlock status\n"));
127*fcf3ce44SJohn Forte (void) fprintf(stderr, gettext("dscfg -h\t\t\tUsage message\n"));
128*fcf3ce44SJohn Forte if (check_cluster() != IS_NOT_CLUSTER) {
129*fcf3ce44SJohn Forte (void) fprintf(stderr, gettext("\nSun Cluster Usage\n"));
130*fcf3ce44SJohn Forte (void) fprintf(stderr, gettext("******************\n"));
131*fcf3ce44SJohn Forte (void) fprintf(stderr,
132*fcf3ce44SJohn Forte gettext("dscfg -s path\t\t\tSet cluster "
133*fcf3ce44SJohn Forte "configuration database at DID\n"));
134*fcf3ce44SJohn Forte (void) fprintf(stderr, gettext("\t\t\t\tpath specified\n"));
135*fcf3ce44SJohn Forte (void) fprintf(stderr, gettext("dscfg -D device_group\t\t"
136*fcf3ce44SJohn Forte "Check status of cluster device group\n"));
137*fcf3ce44SJohn Forte (void) fprintf(stderr, gettext("dscfg -C -\t\t\t"
138*fcf3ce44SJohn Forte "Display location of cluster configuration\n"));
139*fcf3ce44SJohn Forte (void) fprintf(stderr, gettext("\t\t\t\tdatabase\n"));
140*fcf3ce44SJohn Forte (void) fprintf(stderr, gettext("dscfg -l -s DID_device\t\tList "
141*fcf3ce44SJohn Forte "the contents of cluster configuration\n"));
142*fcf3ce44SJohn Forte (void) fprintf(stderr, gettext("\t\t\t\tdatabase\n"));
143*fcf3ce44SJohn Forte (void) fprintf(stderr, gettext("dscfg -C - -i\t\t\tInitialize "
144*fcf3ce44SJohn Forte "cluster configuration database\n"));
145*fcf3ce44SJohn Forte (void) fprintf(stderr, gettext("dscfg -C - -i -p "
146*fcf3ce44SJohn Forte "/etc/dscfg_format Format cluster configuration database\n"));
147*fcf3ce44SJohn Forte (void) fprintf(stderr, gettext("dscfg -C - -a file\t\t"
148*fcf3ce44SJohn Forte "Restore cluster configuration database from\n"));
149*fcf3ce44SJohn Forte (void) fprintf(stderr, gettext("\t\t\t\tfile specified\n"));
150*fcf3ce44SJohn Forte (void) fprintf(stderr, gettext("dscfg -C - -l\t\t\t"
151*fcf3ce44SJohn Forte "List contents of local configuration database\n"));
152*fcf3ce44SJohn Forte (void) fprintf(stderr, gettext("dscfg -C device_group -l\t"
153*fcf3ce44SJohn Forte "List configuration database by device group\n"));
154*fcf3ce44SJohn Forte (void) fprintf(stderr, gettext("dscfg -C \"-\" -l\t\t\t"
155*fcf3ce44SJohn Forte "List configuration database excluding\n"));
156*fcf3ce44SJohn Forte (void) fprintf(stderr, gettext("\t\t\t\tdevice groups\n"));
157*fcf3ce44SJohn Forte }
158*fcf3ce44SJohn Forte }
159*fcf3ce44SJohn Forte
160*fcf3ce44SJohn Forte int
parse_parse_config(CFGFILE * cfg)161*fcf3ce44SJohn Forte parse_parse_config(CFGFILE *cfg)
162*fcf3ce44SJohn Forte {
163*fcf3ce44SJohn Forte FILE *fp;
164*fcf3ce44SJohn Forte char inbuf[CFG_MAX_BUF];
165*fcf3ce44SJohn Forte char *buff;
166*fcf3ce44SJohn Forte int rc;
167*fcf3ce44SJohn Forte
168*fcf3ce44SJohn Forte /*
169*fcf3ce44SJohn Forte * Open parser config file, use default if none specified
170*fcf3ce44SJohn Forte */
171*fcf3ce44SJohn Forte buff = (input_file[0]) ? input_file : DEFAULT_PARSER_LOC;
172*fcf3ce44SJohn Forte if ((fp = fopen(buff, "r")) == NULL) {
173*fcf3ce44SJohn Forte (void) fprintf(stderr,
174*fcf3ce44SJohn Forte gettext("parser config file (%s) not found\n"), buff);
175*fcf3ce44SJohn Forte return (-1);
176*fcf3ce44SJohn Forte }
177*fcf3ce44SJohn Forte
178*fcf3ce44SJohn Forte /*
179*fcf3ce44SJohn Forte * start at begining of configration database
180*fcf3ce44SJohn Forte */
181*fcf3ce44SJohn Forte cfg_rewind(cfg, CFG_SEC_ALL);
182*fcf3ce44SJohn Forte
183*fcf3ce44SJohn Forte while (((buff = fgets(inbuf, (sizeof (inbuf) - 1), fp)) != NULL)) {
184*fcf3ce44SJohn Forte if (*buff == '#' || *buff == '%')
185*fcf3ce44SJohn Forte continue;
186*fcf3ce44SJohn Forte /* overwrite newline */
187*fcf3ce44SJohn Forte buff[strlen(buff) - 1] = '\0';
188*fcf3ce44SJohn Forte rc = cfg_update_parser_config(cfg, buff, CFG_PARSE_CONF);
189*fcf3ce44SJohn Forte if (rc < 0) {
190*fcf3ce44SJohn Forte (void) fprintf(stderr,
191*fcf3ce44SJohn Forte gettext("update parser config rc %d key %s\n"),
192*fcf3ce44SJohn Forte rc, buff);
193*fcf3ce44SJohn Forte (void) fclose(fp);
194*fcf3ce44SJohn Forte return (-1);
195*fcf3ce44SJohn Forte }
196*fcf3ce44SJohn Forte }
197*fcf3ce44SJohn Forte (void) fclose(fp);
198*fcf3ce44SJohn Forte return (1);
199*fcf3ce44SJohn Forte }
200*fcf3ce44SJohn Forte
201*fcf3ce44SJohn Forte void
parse_text_config(CFGFILE * cfg)202*fcf3ce44SJohn Forte parse_text_config(CFGFILE *cfg)
203*fcf3ce44SJohn Forte {
204*fcf3ce44SJohn Forte FILE *fp;
205*fcf3ce44SJohn Forte char inbuf[CFG_MAX_BUF];
206*fcf3ce44SJohn Forte char *buff;
207*fcf3ce44SJohn Forte char *key;
208*fcf3ce44SJohn Forte char *p;
209*fcf3ce44SJohn Forte int rc;
210*fcf3ce44SJohn Forte
211*fcf3ce44SJohn Forte if ((fp = fopen(input_file, "r")) == NULL) {
212*fcf3ce44SJohn Forte (void) fprintf(stderr,
213*fcf3ce44SJohn Forte gettext("Unable to open text config %s\n"),
214*fcf3ce44SJohn Forte input_file);
215*fcf3ce44SJohn Forte exit(2);
216*fcf3ce44SJohn Forte }
217*fcf3ce44SJohn Forte bzero(inbuf, sizeof (inbuf));
218*fcf3ce44SJohn Forte cfg_rewind(cfg, CFG_SEC_CONF);
219*fcf3ce44SJohn Forte while (((buff = fgets(inbuf, (sizeof (inbuf) - 1), fp)) != NULL)) {
220*fcf3ce44SJohn Forte if (*buff == '#')
221*fcf3ce44SJohn Forte continue;
222*fcf3ce44SJohn Forte /* overwrite newline */
223*fcf3ce44SJohn Forte buff[strlen(buff) - 1] = '\0';
224*fcf3ce44SJohn Forte key = strtok(buff, ":");
225*fcf3ce44SJohn Forte if (!key) {
226*fcf3ce44SJohn Forte continue;
227*fcf3ce44SJohn Forte }
228*fcf3ce44SJohn Forte p = &buff[strlen(key)+2];
229*fcf3ce44SJohn Forte while (*p && isspace(*p)) {
230*fcf3ce44SJohn Forte ++p;
231*fcf3ce44SJohn Forte }
232*fcf3ce44SJohn Forte if (!*p) {
233*fcf3ce44SJohn Forte continue;
234*fcf3ce44SJohn Forte }
235*fcf3ce44SJohn Forte rc = cfg_put_cstring(cfg, key, p, strlen(p));
236*fcf3ce44SJohn Forte if (rc < 0) {
237*fcf3ce44SJohn Forte (void) fprintf(stderr,
238*fcf3ce44SJohn Forte gettext("update text config failed rc %d key %s"),
239*fcf3ce44SJohn Forte rc, buff);
240*fcf3ce44SJohn Forte return;
241*fcf3ce44SJohn Forte }
242*fcf3ce44SJohn Forte bzero(inbuf, sizeof (inbuf));
243*fcf3ce44SJohn Forte }
244*fcf3ce44SJohn Forte (void) fclose(fp);
245*fcf3ce44SJohn Forte }
246*fcf3ce44SJohn Forte void
dump_status(CFGFILE * cfg)247*fcf3ce44SJohn Forte dump_status(CFGFILE *cfg)
248*fcf3ce44SJohn Forte {
249*fcf3ce44SJohn Forte cfp_t *cfp = FP_SUN_CLUSTER(cfg);
250*fcf3ce44SJohn Forte
251*fcf3ce44SJohn Forte /*
252*fcf3ce44SJohn Forte * WARNING will robinson
253*fcf3ce44SJohn Forte * The following is using a non-exported internal interface
254*fcf3ce44SJohn Forte * to libcfg
255*fcf3ce44SJohn Forte * You may not use any of the following fields in MS software
256*fcf3ce44SJohn Forte */
257*fcf3ce44SJohn Forte if (!locname)
258*fcf3ce44SJohn Forte exit(2);
259*fcf3ce44SJohn Forte if (!verbose)
260*fcf3ce44SJohn Forte (void) printf("%s\n", locname);
261*fcf3ce44SJohn Forte else {
262*fcf3ce44SJohn Forte #ifdef DEBUG
263*fcf3ce44SJohn Forte (void) printf(gettext("Configuration location: %s\n"), locname);
264*fcf3ce44SJohn Forte (void) printf(
265*fcf3ce44SJohn Forte gettext("Header info:\n\t\t\tmagic: %x\tstate: %x\n"),
266*fcf3ce44SJohn Forte cfp->cf_head->h_magic, cfp->cf_head->h_state);
267*fcf3ce44SJohn Forte (void) printf(
268*fcf3ce44SJohn Forte gettext("Parser section:\t\t"
269*fcf3ce44SJohn Forte "Start: %x\tsize: %d offset: %d\n"),
270*fcf3ce44SJohn Forte cfp->cf_mapped, cfp->cf_head->h_parsesize,
271*fcf3ce44SJohn Forte cfp->cf_head->h_parseoff);
272*fcf3ce44SJohn Forte (void) printf(
273*fcf3ce44SJohn Forte gettext("Config section:\t\t"
274*fcf3ce44SJohn Forte "Start: %x\tsize:%d\tacsize: %d\n"),
275*fcf3ce44SJohn Forte cfp->cf_head->h_cparse, cfp->cf_head->h_csize,
276*fcf3ce44SJohn Forte cfp->cf_head->h_acsize);
277*fcf3ce44SJohn Forte (void) printf("\t\t\tccopy1: %s\tccopy2: %s\n",
278*fcf3ce44SJohn Forte cfp->cf_head->h_ccopy1,
279*fcf3ce44SJohn Forte cfp->cf_head->h_ccopy2);
280*fcf3ce44SJohn Forte (void) printf(
281*fcf3ce44SJohn Forte gettext("Sequence:\t\tseq1: %d\t\tseq2: %d\n"),
282*fcf3ce44SJohn Forte cfp->cf_head->h_seq1, cfp->cf_head->h_seq2);
283*fcf3ce44SJohn Forte #endif
284*fcf3ce44SJohn Forte }
285*fcf3ce44SJohn Forte }
286*fcf3ce44SJohn Forte
287*fcf3ce44SJohn Forte void
dump_lockstat(CFGFILE * cfg)288*fcf3ce44SJohn Forte dump_lockstat(CFGFILE *cfg)
289*fcf3ce44SJohn Forte {
290*fcf3ce44SJohn Forte pid_t pid;
291*fcf3ce44SJohn Forte CFGLOCK lock;
292*fcf3ce44SJohn Forte char ps_str[1024];
293*fcf3ce44SJohn Forte
294*fcf3ce44SJohn Forte if (cfg_get_lock(cfg, &lock, &pid) == TRUE) {
295*fcf3ce44SJohn Forte (void) printf("%s %ld\n",
296*fcf3ce44SJohn Forte lock == CFG_RDLOCK ?
297*fcf3ce44SJohn Forte gettext("Read locked by process id") :
298*fcf3ce44SJohn Forte gettext("Write locked by process id"),
299*fcf3ce44SJohn Forte pid);
300*fcf3ce44SJohn Forte (void) sprintf(ps_str, "ps -p %ld", pid);
301*fcf3ce44SJohn Forte system(ps_str);
302*fcf3ce44SJohn Forte } else
303*fcf3ce44SJohn Forte (void) printf("%s\n", gettext("Not locked."));
304*fcf3ce44SJohn Forte }
305*fcf3ce44SJohn Forte
306*fcf3ce44SJohn Forte
307*fcf3ce44SJohn Forte /*
308*fcf3ce44SJohn Forte * dump current configuration section to stdout
309*fcf3ce44SJohn Forte */
310*fcf3ce44SJohn Forte
311*fcf3ce44SJohn Forte void
print_config(CFGFILE * cfg)312*fcf3ce44SJohn Forte print_config(CFGFILE *cfg)
313*fcf3ce44SJohn Forte {
314*fcf3ce44SJohn Forte time_t tloc = 0;
315*fcf3ce44SJohn Forte int set = 0;
316*fcf3ce44SJohn Forte char pconfig[CFG_MAX_BUF];
317*fcf3ce44SJohn Forte char key[CFG_MAX_KEY];
318*fcf3ce44SJohn Forte char buf[CFG_MAX_BUF];
319*fcf3ce44SJohn Forte char *cp, pbuf[CFG_MAX_BUF];
320*fcf3ce44SJohn Forte FILE *fp;
321*fcf3ce44SJohn Forte int rc;
322*fcf3ce44SJohn Forte int end;
323*fcf3ce44SJohn Forte
324*fcf3ce44SJohn Forte (void) snprintf(pconfig, sizeof (pconfig),
325*fcf3ce44SJohn Forte "%s%s", altroot, DEFAULT_PARSER_LOC);
326*fcf3ce44SJohn Forte if ((fp = fopen(pconfig, "r")) == NULL) {
327*fcf3ce44SJohn Forte (void) fprintf(stderr,
328*fcf3ce44SJohn Forte gettext("dscfg: unable to open "
329*fcf3ce44SJohn Forte "parser configuration (%s): %s\n"),
330*fcf3ce44SJohn Forte pconfig, strerror(errno));
331*fcf3ce44SJohn Forte exit(1);
332*fcf3ce44SJohn Forte }
333*fcf3ce44SJohn Forte
334*fcf3ce44SJohn Forte (void) time(&tloc);
335*fcf3ce44SJohn Forte (void) printf(gettext("# Consolidated Dataservice Configuration\n"));
336*fcf3ce44SJohn Forte (void) printf(gettext("# Do not edit out whitespace or dashes\n"));
337*fcf3ce44SJohn Forte (void) printf(gettext("# File created on: %s"), ctime(&tloc));
338*fcf3ce44SJohn Forte
339*fcf3ce44SJohn Forte while (fgets(pbuf, (sizeof (pbuf) - 1), fp) != NULL) {
340*fcf3ce44SJohn Forte if (pbuf[0] == '#') {
341*fcf3ce44SJohn Forte /* comment */
342*fcf3ce44SJohn Forte continue;
343*fcf3ce44SJohn Forte }
344*fcf3ce44SJohn Forte /* force a NULL terminator */
345*fcf3ce44SJohn Forte pbuf[sizeof (pbuf) - 1] = '\0';
346*fcf3ce44SJohn Forte
347*fcf3ce44SJohn Forte if (pbuf[0] == '%') {
348*fcf3ce44SJohn Forte /*
349*fcf3ce44SJohn Forte * descriptive text
350*fcf3ce44SJohn Forte * - print it (with comment leader) and move on
351*fcf3ce44SJohn Forte */
352*fcf3ce44SJohn Forte (void) printf("#%s", &pbuf[1]);
353*fcf3ce44SJohn Forte continue;
354*fcf3ce44SJohn Forte }
355*fcf3ce44SJohn Forte
356*fcf3ce44SJohn Forte /*
357*fcf3ce44SJohn Forte * truncate the parser config in pbuf[] to just the tag
358*fcf3ce44SJohn Forte */
359*fcf3ce44SJohn Forte cp = strchr(pbuf, '.');
360*fcf3ce44SJohn Forte if (cp != NULL) {
361*fcf3ce44SJohn Forte *cp = '\0';
362*fcf3ce44SJohn Forte }
363*fcf3ce44SJohn Forte
364*fcf3ce44SJohn Forte set = 1;
365*fcf3ce44SJohn Forte /*CONSTCOND*/
366*fcf3ce44SJohn Forte while (1) {
367*fcf3ce44SJohn Forte bzero(buf, CFG_MAX_BUF);
368*fcf3ce44SJohn Forte (void) snprintf(key,
369*fcf3ce44SJohn Forte sizeof (key), "%s.set%d", pbuf, set);
370*fcf3ce44SJohn Forte rc = cfg_get_cstring(cfg, key, buf, CFG_MAX_BUF);
371*fcf3ce44SJohn Forte if (rc < 0) {
372*fcf3ce44SJohn Forte break;
373*fcf3ce44SJohn Forte }
374*fcf3ce44SJohn Forte /* trim trailing space if necessary */
375*fcf3ce44SJohn Forte end = strlen(buf) - 1;
376*fcf3ce44SJohn Forte if (buf[end] == ' ')
377*fcf3ce44SJohn Forte buf[end] = '\0';
378*fcf3ce44SJohn Forte
379*fcf3ce44SJohn Forte (void) printf("%s:%s\n", pbuf, buf);
380*fcf3ce44SJohn Forte set++;
381*fcf3ce44SJohn Forte }
382*fcf3ce44SJohn Forte }
383*fcf3ce44SJohn Forte
384*fcf3ce44SJohn Forte (void) fclose(fp);
385*fcf3ce44SJohn Forte }
386*fcf3ce44SJohn Forte
387*fcf3ce44SJohn Forte int
make_new_config(const char * fileloc)388*fcf3ce44SJohn Forte make_new_config(const char *fileloc)
389*fcf3ce44SJohn Forte {
390*fcf3ce44SJohn Forte int fd;
391*fcf3ce44SJohn Forte int rc;
392*fcf3ce44SJohn Forte int skip;
393*fcf3ce44SJohn Forte
394*fcf3ce44SJohn Forte char buf[CFG_MAX_BUF];
395*fcf3ce44SJohn Forte /*CONSTCOND*/
396*fcf3ce44SJohn Forte assert((sizeof (buf) % 512) == 0);
397*fcf3ce44SJohn Forte
398*fcf3ce44SJohn Forte bzero(buf, CFG_MAX_BUF);
399*fcf3ce44SJohn Forte
400*fcf3ce44SJohn Forte if ((fd = open(fileloc, O_RDWR | O_CREAT, 0640)) == -1) {
401*fcf3ce44SJohn Forte return (-1);
402*fcf3ce44SJohn Forte }
403*fcf3ce44SJohn Forte
404*fcf3ce44SJohn Forte /* if this is a device, we may have to skip the vtoc */
405*fcf3ce44SJohn Forte if ((skip = cfg_shldskip_vtoc(fd, fileloc)) == -1) {
406*fcf3ce44SJohn Forte (void) fprintf(stderr,
407*fcf3ce44SJohn Forte gettext("dscfg: unable to read vtoc on (%s)\n"),
408*fcf3ce44SJohn Forte fileloc);
409*fcf3ce44SJohn Forte return (-1);
410*fcf3ce44SJohn Forte } else if (skip) {
411*fcf3ce44SJohn Forte do {
412*fcf3ce44SJohn Forte rc = lseek(fd, CFG_VTOC_SKIP, SEEK_SET);
413*fcf3ce44SJohn Forte } while (rc == -1 && errno == EINTR);
414*fcf3ce44SJohn Forte
415*fcf3ce44SJohn Forte if (rc == -1) {
416*fcf3ce44SJohn Forte (void) fprintf(stderr, gettext("dscfg: seek error"));
417*fcf3ce44SJohn Forte return (-1);
418*fcf3ce44SJohn Forte }
419*fcf3ce44SJohn Forte }
420*fcf3ce44SJohn Forte
421*fcf3ce44SJohn Forte do {
422*fcf3ce44SJohn Forte rc = write(fd, buf, sizeof (buf));
423*fcf3ce44SJohn Forte } while (rc == -1 && errno == EINTR);
424*fcf3ce44SJohn Forte
425*fcf3ce44SJohn Forte close(fd);
426*fcf3ce44SJohn Forte
427*fcf3ce44SJohn Forte return ((rc < 0) ? 0 : 1);
428*fcf3ce44SJohn Forte }
429*fcf3ce44SJohn Forte
430*fcf3ce44SJohn Forte /*
431*fcf3ce44SJohn Forte * dscfg
432*fcf3ce44SJohn Forte * configure or return dataservice persistent configuration
433*fcf3ce44SJohn Forte *
434*fcf3ce44SJohn Forte * options
435*fcf3ce44SJohn Forte * -i initialize file for first time
436*fcf3ce44SJohn Forte * -l dump current configuration to stdout in ascii
437*fcf3ce44SJohn Forte * -a add
438*fcf3ce44SJohn Forte * -C node Set resource filter
439*fcf3ce44SJohn Forte * -p parser config specified input file
440*fcf3ce44SJohn Forte * -s set partition location or filename in default location
441*fcf3ce44SJohn Forte * -L print configuration lock status
442*fcf3ce44SJohn Forte * -u upgrade
443*fcf3ce44SJohn Forte * -r prepend bootdir to beginning of path for cfg_open
444*fcf3ce44SJohn Forte * no options status
445*fcf3ce44SJohn Forte *
446*fcf3ce44SJohn Forte *
447*fcf3ce44SJohn Forte */
448*fcf3ce44SJohn Forte #ifdef lint
449*fcf3ce44SJohn Forte int
dscfg_lintmain(int argc,char * argv[])450*fcf3ce44SJohn Forte dscfg_lintmain(int argc, char *argv[])
451*fcf3ce44SJohn Forte #else
452*fcf3ce44SJohn Forte int
453*fcf3ce44SJohn Forte main(int argc, char *argv[])
454*fcf3ce44SJohn Forte #endif
455*fcf3ce44SJohn Forte {
456*fcf3ce44SJohn Forte CFGFILE *cfg;
457*fcf3ce44SJohn Forte extern char *optarg;
458*fcf3ce44SJohn Forte char *loc;
459*fcf3ce44SJohn Forte int offset = 0;
460*fcf3ce44SJohn Forte int rc;
461*fcf3ce44SJohn Forte char c;
462*fcf3ce44SJohn Forte int local;
463*fcf3ce44SJohn Forte int action_counts = 0;
464*fcf3ce44SJohn Forte
465*fcf3ce44SJohn Forte bzero(input_file, sizeof (input_file));
466*fcf3ce44SJohn Forte (void) setlocale(LC_ALL, "");
467*fcf3ce44SJohn Forte (void) textdomain("dscfg");
468*fcf3ce44SJohn Forte logical_host[0] = '\0';
469*fcf3ce44SJohn Forte cmdname = argv[0];
470*fcf3ce44SJohn Forte #ifdef DEBUG
471*fcf3ce44SJohn Forte while ((c = getopt(argc, argv, "a:C:dD:ilLp:r:s:hvn")) != EOF) {
472*fcf3ce44SJohn Forte #else
473*fcf3ce44SJohn Forte while ((c = getopt(argc, argv, "a:C:dD:ilLp:r:s:h")) != EOF) {
474*fcf3ce44SJohn Forte #endif
475*fcf3ce44SJohn Forte switch (c) {
476*fcf3ce44SJohn Forte case 'a':
477*fcf3ce44SJohn Forte aflg++;
478*fcf3ce44SJohn Forte strcpy(input_file, optarg);
479*fcf3ce44SJohn Forte mustcommit++;
480*fcf3ce44SJohn Forte action_counts++;
481*fcf3ce44SJohn Forte break;
482*fcf3ce44SJohn Forte case 'C':
483*fcf3ce44SJohn Forte Cflg++;
484*fcf3ce44SJohn Forte strcpy(logical_host, optarg);
485*fcf3ce44SJohn Forte if (logical_host && *logical_host == '-')
486*fcf3ce44SJohn Forte if (argc == 3)
487*fcf3ce44SJohn Forte action_counts++;
488*fcf3ce44SJohn Forte break;
489*fcf3ce44SJohn Forte case 'D':
490*fcf3ce44SJohn Forte Dflg++;
491*fcf3ce44SJohn Forte strcpy(device_group, optarg);
492*fcf3ce44SJohn Forte action_counts++;
493*fcf3ce44SJohn Forte break;
494*fcf3ce44SJohn Forte case 'i':
495*fcf3ce44SJohn Forte iflg++;
496*fcf3ce44SJohn Forte mustcommit++;
497*fcf3ce44SJohn Forte action_counts++;
498*fcf3ce44SJohn Forte break;
499*fcf3ce44SJohn Forte case 'l':
500*fcf3ce44SJohn Forte lflg++;
501*fcf3ce44SJohn Forte action_counts++;
502*fcf3ce44SJohn Forte break;
503*fcf3ce44SJohn Forte case 'L':
504*fcf3ce44SJohn Forte Lflg++;
505*fcf3ce44SJohn Forte action_counts++;
506*fcf3ce44SJohn Forte break;
507*fcf3ce44SJohn Forte case 'p':
508*fcf3ce44SJohn Forte pflg++;
509*fcf3ce44SJohn Forte strcpy(input_file, optarg);
510*fcf3ce44SJohn Forte mustcommit++;
511*fcf3ce44SJohn Forte break;
512*fcf3ce44SJohn Forte case 's':
513*fcf3ce44SJohn Forte sflg++;
514*fcf3ce44SJohn Forte strcpy(config_file, optarg);
515*fcf3ce44SJohn Forte action_counts++;
516*fcf3ce44SJohn Forte break;
517*fcf3ce44SJohn Forte case 'h':
518*fcf3ce44SJohn Forte usage(NULL);
519*fcf3ce44SJohn Forte exit(0);
520*fcf3ce44SJohn Forte /*NOTREACHED*/
521*fcf3ce44SJohn Forte #ifdef DEBUG
522*fcf3ce44SJohn Forte case 'v':
523*fcf3ce44SJohn Forte verbose++;
524*fcf3ce44SJohn Forte action_counts++;
525*fcf3ce44SJohn Forte break;
526*fcf3ce44SJohn Forte #endif
527*fcf3ce44SJohn Forte #ifdef UPGRADE
528*fcf3ce44SJohn Forte case 'u':
529*fcf3ce44SJohn Forte uflg++;
530*fcf3ce44SJohn Forte action_counts++;
531*fcf3ce44SJohn Forte break;
532*fcf3ce44SJohn Forte #endif
533*fcf3ce44SJohn Forte
534*fcf3ce44SJohn Forte case 'r':
535*fcf3ce44SJohn Forte rflg++;
536*fcf3ce44SJohn Forte strcpy(altroot, optarg);
537*fcf3ce44SJohn Forte break;
538*fcf3ce44SJohn Forte
539*fcf3ce44SJohn Forte case 'n':
540*fcf3ce44SJohn Forte nflg++;
541*fcf3ce44SJohn Forte break;
542*fcf3ce44SJohn Forte
543*fcf3ce44SJohn Forte default:
544*fcf3ce44SJohn Forte usage(NULL);
545*fcf3ce44SJohn Forte exit(1);
546*fcf3ce44SJohn Forte break;
547*fcf3ce44SJohn Forte };
548*fcf3ce44SJohn Forte }
549*fcf3ce44SJohn Forte
550*fcf3ce44SJohn Forte switch (action_counts) {
551*fcf3ce44SJohn Forte case 0:
552*fcf3ce44SJohn Forte if (argc > 1) {
553*fcf3ce44SJohn Forte if (pflg)
554*fcf3ce44SJohn Forte usage(gettext(
555*fcf3ce44SJohn Forte "-p option must be used in conjunction with -i"));
556*fcf3ce44SJohn Forte else
557*fcf3ce44SJohn Forte usage(gettext("must specify an action flag"));
558*fcf3ce44SJohn Forte exit(1);
559*fcf3ce44SJohn Forte }
560*fcf3ce44SJohn Forte break;
561*fcf3ce44SJohn Forte case 1:
562*fcf3ce44SJohn Forte break;
563*fcf3ce44SJohn Forte case 2:
564*fcf3ce44SJohn Forte if (lflg && sflg)
565*fcf3ce44SJohn Forte break;
566*fcf3ce44SJohn Forte else {
567*fcf3ce44SJohn Forte usage(gettext("too many action flags"));
568*fcf3ce44SJohn Forte exit(1);
569*fcf3ce44SJohn Forte break;
570*fcf3ce44SJohn Forte }
571*fcf3ce44SJohn Forte default:
572*fcf3ce44SJohn Forte usage(gettext("too many action flags"));
573*fcf3ce44SJohn Forte exit(1);
574*fcf3ce44SJohn Forte break;
575*fcf3ce44SJohn Forte }
576*fcf3ce44SJohn Forte
577*fcf3ce44SJohn Forte if (argc == 1 || (argc == 2 && verbose) || (argc == 3 && (rflg|Cflg)))
578*fcf3ce44SJohn Forte noflags++;
579*fcf3ce44SJohn Forte
580*fcf3ce44SJohn Forte if (Dflg) {
581*fcf3ce44SJohn Forte /*
582*fcf3ce44SJohn Forte * Determine if the value specified is a device group
583*fcf3ce44SJohn Forte * that is active on this node
584*fcf3ce44SJohn Forte */
585*fcf3ce44SJohn Forte char *other_node;
586*fcf3ce44SJohn Forte if ((cfg_issuncluster() > 0) && (strlen(device_group) > 0)) {
587*fcf3ce44SJohn Forte local = cfg_dgname_islocal(device_group, &other_node);
588*fcf3ce44SJohn Forte if (local == 0)
589*fcf3ce44SJohn Forte (void) fprintf(stderr, gettext(
590*fcf3ce44SJohn Forte "Device group %s active on %s\n"),
591*fcf3ce44SJohn Forte device_group, other_node);
592*fcf3ce44SJohn Forte else if (local == 1)
593*fcf3ce44SJohn Forte (void) fprintf(stderr, gettext(
594*fcf3ce44SJohn Forte "Device group %s active on this node\n"),
595*fcf3ce44SJohn Forte device_group);
596*fcf3ce44SJohn Forte else
597*fcf3ce44SJohn Forte (void) fprintf(stderr, gettext(
598*fcf3ce44SJohn Forte "Device group %s not found\n"), device_group);
599*fcf3ce44SJohn Forte return (local);
600*fcf3ce44SJohn Forte } else {
601*fcf3ce44SJohn Forte (void) fprintf(stderr, gettext(
602*fcf3ce44SJohn Forte "dscfg -D is only allowed in "
603*fcf3ce44SJohn Forte "Sun Cluster OE\n"));
604*fcf3ce44SJohn Forte return (0);
605*fcf3ce44SJohn Forte }
606*fcf3ce44SJohn Forte }
607*fcf3ce44SJohn Forte
608*fcf3ce44SJohn Forte if (sflg && !lflg) {
609*fcf3ce44SJohn Forte /*
610*fcf3ce44SJohn Forte * Only allow setting location on a non-sun cluster system
611*fcf3ce44SJohn Forte * if the cluster reference file is already present.
612*fcf3ce44SJohn Forte */
613*fcf3ce44SJohn Forte struct stat dscfg_stat = {0};
614*fcf3ce44SJohn Forte if (cfg_issuncluster() <= 0) {
615*fcf3ce44SJohn Forte if (stat(CFG_CLUSTER_LOCATION, &dscfg_stat) != 0) {
616*fcf3ce44SJohn Forte if (dscfg_stat.st_blocks == 0) {
617*fcf3ce44SJohn Forte (void) fprintf(stderr, gettext(
618*fcf3ce44SJohn Forte "dscfg -s is only allowed in "
619*fcf3ce44SJohn Forte "Sun Cluster OE\n"));
620*fcf3ce44SJohn Forte exit(1);
621*fcf3ce44SJohn Forte }
622*fcf3ce44SJohn Forte }
623*fcf3ce44SJohn Forte }
624*fcf3ce44SJohn Forte
625*fcf3ce44SJohn Forte spcs_log("dscfg", NULL, gettext("dscfg -s %s"), config_file);
626*fcf3ce44SJohn Forte locname = cfg_location(config_file, CFG_LOC_SET_CLUSTER,
627*fcf3ce44SJohn Forte rflg ? altroot : NULL);
628*fcf3ce44SJohn Forte if (locname == NULL) {
629*fcf3ce44SJohn Forte (void) fprintf(stderr, gettext("dscfg: %s\n"),
630*fcf3ce44SJohn Forte cfg_error(NULL));
631*fcf3ce44SJohn Forte exit(1);
632*fcf3ce44SJohn Forte } else
633*fcf3ce44SJohn Forte exit(0);
634*fcf3ce44SJohn Forte
635*fcf3ce44SJohn Forte } else if (sflg && lflg) {
636*fcf3ce44SJohn Forte /* s used with l for temporarily peeking at a dscfg database */
637*fcf3ce44SJohn Forte loc = config_file;
638*fcf3ce44SJohn Forte } else {
639*fcf3ce44SJohn Forte locname = cfg_location(NULL,
640*fcf3ce44SJohn Forte Cflg ? CFG_LOC_GET_CLUSTER : CFG_LOC_GET_LOCAL,
641*fcf3ce44SJohn Forte rflg ? altroot : NULL);
642*fcf3ce44SJohn Forte if (Cflg && (locname == NULL)) {
643*fcf3ce44SJohn Forte (void) fprintf(stderr, gettext(
644*fcf3ce44SJohn Forte "dscfg: cluster config not set: %s\n"),
645*fcf3ce44SJohn Forte cfg_error(NULL));
646*fcf3ce44SJohn Forte return (1);
647*fcf3ce44SJohn Forte }
648*fcf3ce44SJohn Forte loc = rflg ? locname : NULL;
649*fcf3ce44SJohn Forte }
650*fcf3ce44SJohn Forte
651*fcf3ce44SJohn Forte /*
652*fcf3ce44SJohn Forte * the following hack forces the configuration file to initialize
653*fcf3ce44SJohn Forte */
654*fcf3ce44SJohn Forte if (iflg && !pflg) {
655*fcf3ce44SJohn Forte int fild;
656*fcf3ce44SJohn Forte int c;
657*fcf3ce44SJohn Forte char buf[CFG_MAX_BUF] = {0};
658*fcf3ce44SJohn Forte cfp_t *cfp;
659*fcf3ce44SJohn Forte
660*fcf3ce44SJohn Forte if (!nflg) {
661*fcf3ce44SJohn Forte (void) printf(
662*fcf3ce44SJohn Forte gettext("WARNING: This option will erase your "
663*fcf3ce44SJohn Forte "Availability Suite configuration\n"));
664*fcf3ce44SJohn Forte (void) printf(
665*fcf3ce44SJohn Forte gettext("Do you want to continue? (Y/N) [N] "));
666*fcf3ce44SJohn Forte
667*fcf3ce44SJohn Forte c = getchar();
668*fcf3ce44SJohn Forte switch (c) {
669*fcf3ce44SJohn Forte case 'y':
670*fcf3ce44SJohn Forte case 'Y': break;
671*fcf3ce44SJohn Forte case 'n':
672*fcf3ce44SJohn Forte case 'N':
673*fcf3ce44SJohn Forte case '\n':
674*fcf3ce44SJohn Forte (void) fprintf(stderr, gettext(
675*fcf3ce44SJohn Forte "dscfg: configuration not initialized\n"));
676*fcf3ce44SJohn Forte exit(1);
677*fcf3ce44SJohn Forte default:
678*fcf3ce44SJohn Forte (void) fprintf(stderr, gettext(
679*fcf3ce44SJohn Forte "dscfg: %d is not a valid response\n"), c);
680*fcf3ce44SJohn Forte exit(1);
681*fcf3ce44SJohn Forte }
682*fcf3ce44SJohn Forte }
683*fcf3ce44SJohn Forte
684*fcf3ce44SJohn Forte spcs_log("dscfg", NULL, gettext("dscfg -i"));
685*fcf3ce44SJohn Forte
686*fcf3ce44SJohn Forte if ((cfg = cfg_open(loc)) == NULL) {
687*fcf3ce44SJohn Forte /* this is not a good config, or non-existent so.. */
688*fcf3ce44SJohn Forte if (!make_new_config(locname)) {
689*fcf3ce44SJohn Forte (void) fprintf(stderr, gettext("dscfg: %s\n"),
690*fcf3ce44SJohn Forte cfg_error(NULL));
691*fcf3ce44SJohn Forte exit(1);
692*fcf3ce44SJohn Forte }
693*fcf3ce44SJohn Forte if ((cfg = cfg_open(loc)) == NULL) {
694*fcf3ce44SJohn Forte (void) fprintf(stderr, gettext("dscfg: %s\n"),
695*fcf3ce44SJohn Forte cfg_error(NULL));
696*fcf3ce44SJohn Forte exit(1);
697*fcf3ce44SJohn Forte }
698*fcf3ce44SJohn Forte }
699*fcf3ce44SJohn Forte
700*fcf3ce44SJohn Forte /*
701*fcf3ce44SJohn Forte * Set cluster node if specified
702*fcf3ce44SJohn Forte */
703*fcf3ce44SJohn Forte if (Cflg)
704*fcf3ce44SJohn Forte cfg_resource(cfg, logical_host);
705*fcf3ce44SJohn Forte
706*fcf3ce44SJohn Forte if (cfg_is_cfg(cfg) != 1) {
707*fcf3ce44SJohn Forte if (!make_new_config(locname)) {
708*fcf3ce44SJohn Forte (void) fprintf(stderr, gettext("dscfg: unable "
709*fcf3ce44SJohn Forte " to create new config \n"));
710*fcf3ce44SJohn Forte exit(1);
711*fcf3ce44SJohn Forte }
712*fcf3ce44SJohn Forte }
713*fcf3ce44SJohn Forte
714*fcf3ce44SJohn Forte if (!cfg_lock(cfg, CFG_WRLOCK)) {
715*fcf3ce44SJohn Forte (void) fprintf(stderr, gettext("dscfg: %s\n"),
716*fcf3ce44SJohn Forte cfg_error(NULL));
717*fcf3ce44SJohn Forte exit(1);
718*fcf3ce44SJohn Forte }
719*fcf3ce44SJohn Forte
720*fcf3ce44SJohn Forte cfp = FP_SUN_CLUSTER(cfg);
721*fcf3ce44SJohn Forte if ((fild = cfp->cf_fd) == 0) {
722*fcf3ce44SJohn Forte (void) fprintf(stderr,
723*fcf3ce44SJohn Forte gettext("dscfg: failure to access %s "
724*fcf3ce44SJohn Forte "configuration database: %s\n"),
725*fcf3ce44SJohn Forte (Cflg) ? gettext("cluster") : gettext("local"),
726*fcf3ce44SJohn Forte cfg_error(NULL));
727*fcf3ce44SJohn Forte exit(1);
728*fcf3ce44SJohn Forte }
729*fcf3ce44SJohn Forte
730*fcf3ce44SJohn Forte if (cfg_shldskip_vtoc(fild, locname) > 0)
731*fcf3ce44SJohn Forte offset += CFG_VTOC_SKIP;
732*fcf3ce44SJohn Forte
733*fcf3ce44SJohn Forte lseek(fild, offset, SEEK_SET);
734*fcf3ce44SJohn Forte write(fild, buf, sizeof (buf));
735*fcf3ce44SJohn Forte cfg_invalidate_hsizes(fild, locname);
736*fcf3ce44SJohn Forte
737*fcf3ce44SJohn Forte cfg_close(cfg);
738*fcf3ce44SJohn Forte exit(0);
739*fcf3ce44SJohn Forte }
740*fcf3ce44SJohn Forte
741*fcf3ce44SJohn Forte if (pflg && !iflg) {
742*fcf3ce44SJohn Forte usage(gettext("-p option must be used in conjunction with -i"));
743*fcf3ce44SJohn Forte exit(1);
744*fcf3ce44SJohn Forte
745*fcf3ce44SJohn Forte }
746*fcf3ce44SJohn Forte
747*fcf3ce44SJohn Forte if (uflg) {
748*fcf3ce44SJohn Forte char cmd[CFG_MAX_BUF];
749*fcf3ce44SJohn Forte if (rflg)
750*fcf3ce44SJohn Forte (void) snprintf(cmd, sizeof (cmd),
751*fcf3ce44SJohn Forte "%s/usr/sbin/dscfg -r %s -l >"
752*fcf3ce44SJohn Forte " %s/var/tmp/.dscfg.bak", altroot,
753*fcf3ce44SJohn Forte altroot, altroot);
754*fcf3ce44SJohn Forte else
755*fcf3ce44SJohn Forte (void) snprintf(cmd, sizeof (cmd),
756*fcf3ce44SJohn Forte "/usr/sbin/dscfg -l >"
757*fcf3ce44SJohn Forte " /var/tmp/.dscfg.bak");
758*fcf3ce44SJohn Forte
759*fcf3ce44SJohn Forte if (system(cmd) != 0) {
760*fcf3ce44SJohn Forte (void) fprintf(stderr,
761*fcf3ce44SJohn Forte "dscfg: unable to create backup\n");
762*fcf3ce44SJohn Forte exit(1);
763*fcf3ce44SJohn Forte }
764*fcf3ce44SJohn Forte
765*fcf3ce44SJohn Forte if ((cfg = cfg_open(loc)) == NULL) {
766*fcf3ce44SJohn Forte (void) fprintf(stderr, gettext("dscfg: %s\n"),
767*fcf3ce44SJohn Forte cfg_error(NULL));
768*fcf3ce44SJohn Forte exit(2);
769*fcf3ce44SJohn Forte }
770*fcf3ce44SJohn Forte
771*fcf3ce44SJohn Forte if (!cfg_lock(cfg, CFG_UPGRADE)) {
772*fcf3ce44SJohn Forte (void) fprintf(stderr,
773*fcf3ce44SJohn Forte gettext("dscfg: upgrade failed\n"));
774*fcf3ce44SJohn Forte cfg_close(cfg);
775*fcf3ce44SJohn Forte exit(1);
776*fcf3ce44SJohn Forte }
777*fcf3ce44SJohn Forte
778*fcf3ce44SJohn Forte cfg_close(cfg);
779*fcf3ce44SJohn Forte exit(0);
780*fcf3ce44SJohn Forte }
781*fcf3ce44SJohn Forte
782*fcf3ce44SJohn Forte if ((cfg = cfg_open(loc)) == NULL) {
783*fcf3ce44SJohn Forte (void) fprintf(stderr, gettext("dscfg: %s\n"), cfg_error(NULL));
784*fcf3ce44SJohn Forte exit(2);
785*fcf3ce44SJohn Forte }
786*fcf3ce44SJohn Forte
787*fcf3ce44SJohn Forte /*
788*fcf3ce44SJohn Forte * Set cluster node if specified
789*fcf3ce44SJohn Forte */
790*fcf3ce44SJohn Forte if (Cflg)
791*fcf3ce44SJohn Forte cfg_resource(cfg, logical_host);
792*fcf3ce44SJohn Forte
793*fcf3ce44SJohn Forte if ((!pflg) && (!noflags)) {
794*fcf3ce44SJohn Forte if (cfg_is_cfg(cfg) != 1) {
795*fcf3ce44SJohn Forte (void) fprintf(stderr,
796*fcf3ce44SJohn Forte gettext("dscfg: %s\n"), cfg_error(NULL));
797*fcf3ce44SJohn Forte cfg_close(cfg);
798*fcf3ce44SJohn Forte exit(1);
799*fcf3ce44SJohn Forte }
800*fcf3ce44SJohn Forte }
801*fcf3ce44SJohn Forte
802*fcf3ce44SJohn Forte if (Lflg) {
803*fcf3ce44SJohn Forte dump_lockstat(cfg);
804*fcf3ce44SJohn Forte cfg_close(cfg);
805*fcf3ce44SJohn Forte exit(0);
806*fcf3ce44SJohn Forte }
807*fcf3ce44SJohn Forte
808*fcf3ce44SJohn Forte if (noflags) {
809*fcf3ce44SJohn Forte dump_status(cfg);
810*fcf3ce44SJohn Forte cfg_close(cfg);
811*fcf3ce44SJohn Forte exit(0);
812*fcf3ce44SJohn Forte }
813*fcf3ce44SJohn Forte
814*fcf3ce44SJohn Forte if (!cfg_lock(cfg, mustcommit? CFG_WRLOCK : CFG_RDLOCK)) {
815*fcf3ce44SJohn Forte (void) fprintf(stderr, gettext("cfg_lock: lock failed\n"));
816*fcf3ce44SJohn Forte cfg_close(cfg);
817*fcf3ce44SJohn Forte exit(1);
818*fcf3ce44SJohn Forte }
819*fcf3ce44SJohn Forte
820*fcf3ce44SJohn Forte if (lflg) {
821*fcf3ce44SJohn Forte print_config(cfg);
822*fcf3ce44SJohn Forte cfg_close(cfg);
823*fcf3ce44SJohn Forte exit(0);
824*fcf3ce44SJohn Forte }
825*fcf3ce44SJohn Forte
826*fcf3ce44SJohn Forte /*
827*fcf3ce44SJohn Forte * initialize configuration
828*fcf3ce44SJohn Forte */
829*fcf3ce44SJohn Forte if (iflg) {
830*fcf3ce44SJohn Forte spcs_log("dscfg", NULL, gettext("dscfg -i -p %s"), input_file);
831*fcf3ce44SJohn Forte
832*fcf3ce44SJohn Forte if (!pflg) {
833*fcf3ce44SJohn Forte (void) fprintf(stderr,
834*fcf3ce44SJohn Forte gettext("dscfg: cannot init without "
835*fcf3ce44SJohn Forte "parser configuration file\n"));
836*fcf3ce44SJohn Forte cfg_close(cfg);
837*fcf3ce44SJohn Forte exit(1);
838*fcf3ce44SJohn Forte } else if (parse_parse_config(cfg) < 0) {
839*fcf3ce44SJohn Forte (void) fprintf(stderr, gettext("dscfg: cannot load "
840*fcf3ce44SJohn Forte "parser configuration file\n"));
841*fcf3ce44SJohn Forte cfg_close(cfg);
842*fcf3ce44SJohn Forte exit(1);
843*fcf3ce44SJohn Forte }
844*fcf3ce44SJohn Forte }
845*fcf3ce44SJohn Forte
846*fcf3ce44SJohn Forte /*
847*fcf3ce44SJohn Forte * read asci config file and write
848*fcf3ce44SJohn Forte */
849*fcf3ce44SJohn Forte if (aflg) {
850*fcf3ce44SJohn Forte spcs_log("dscfg", NULL, gettext("dscfg -a %s"), input_file);
851*fcf3ce44SJohn Forte parse_text_config(cfg);
852*fcf3ce44SJohn Forte }
853*fcf3ce44SJohn Forte
854*fcf3ce44SJohn Forte if (mustcommit) {
855*fcf3ce44SJohn Forte rc = cfg_commit(cfg);
856*fcf3ce44SJohn Forte if (rc < 0) {
857*fcf3ce44SJohn Forte int sev = 0;
858*fcf3ce44SJohn Forte (void) fprintf(stderr, gettext("dscfg: %s\n"),
859*fcf3ce44SJohn Forte cfg_error(&sev));
860*fcf3ce44SJohn Forte if (sev == CFG_EFATAL) {
861*fcf3ce44SJohn Forte cfg_close(cfg);
862*fcf3ce44SJohn Forte exit(2);
863*fcf3ce44SJohn Forte }
864*fcf3ce44SJohn Forte }
865*fcf3ce44SJohn Forte }
866*fcf3ce44SJohn Forte
867*fcf3ce44SJohn Forte cfg_close(cfg);
868*fcf3ce44SJohn Forte return (0);
869*fcf3ce44SJohn Forte }
870*fcf3ce44SJohn Forte
871*fcf3ce44SJohn Forte static int
872*fcf3ce44SJohn Forte check_cluster()
873*fcf3ce44SJohn Forte {
874*fcf3ce44SJohn Forte static int is_cluster = -1;
875*fcf3ce44SJohn Forte int rc;
876*fcf3ce44SJohn Forte
877*fcf3ce44SJohn Forte if (is_cluster != -1)
878*fcf3ce44SJohn Forte return (is_cluster);
879*fcf3ce44SJohn Forte rc = cfg_iscluster();
880*fcf3ce44SJohn Forte if (rc > 0) {
881*fcf3ce44SJohn Forte is_cluster = IS_CLUSTER;
882*fcf3ce44SJohn Forte return (is_cluster);
883*fcf3ce44SJohn Forte } else if (rc == 0) {
884*fcf3ce44SJohn Forte is_cluster = IS_NOT_CLUSTER;
885*fcf3ce44SJohn Forte return (is_cluster);
886*fcf3ce44SJohn Forte } else {
887*fcf3ce44SJohn Forte (void) fprintf(stderr,
888*fcf3ce44SJohn Forte gettext("dscfg: unable to determin environment\n"));
889*fcf3ce44SJohn Forte /*NOTREACHED*/
890*fcf3ce44SJohn Forte }
891*fcf3ce44SJohn Forte
892*fcf3ce44SJohn Forte /* gcc */
893*fcf3ce44SJohn Forte return (is_cluster);
894*fcf3ce44SJohn Forte }
895