fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * CDDL HEADER START
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * The contents of this file are subject to the terms of the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Common Development and Distribution License (the "License").
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * You may not use this file except in compliance with the License.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * or http://www.opensolaris.org/os/licensing.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * See the License for the specific language governing permissions
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and limitations under the License.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * When distributing Covered Code, include this CDDL HEADER in each
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If applicable, add the following below this CDDL HEADER, with the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * fields enclosed by brackets "[]" replaced with your own identifying
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * information: Portions Copyright [yyyy] [name of copyright owner]
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * CDDL HEADER END
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Use is subject to license terms.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <stdio.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/types.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/wait.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/vtoc.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/stat.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <stdio.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/mnttab.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <errno.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <limits.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <fcntl.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <string.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <strings.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <stdlib.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <unistd.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <time.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <locale.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <langinfo.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <libintl.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <stdarg.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <netdb.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <ctype.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <assert.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/nsctl/cfg_impl.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/nsctl/cfg.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/unistat/spcs_s.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/unistat/spcs_s_u.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/unistat/spcs_errors.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/nsctl/dsw.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define DEFAULT_PARSER_LOC "/etc/dscfg_format"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint Cflg;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint Dflg;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint Lflg;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint aflg;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint iflg;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint lflg;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint nflg;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint pflg;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint rflg;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint sflg;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint uflg;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint verbose;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint noflags;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint errflg;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint mustcommit;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortechar *locname; /* config location from cfg_location */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortechar *cmdname;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define MAX_FILENAME 80
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortechar output_file[MAX_FILENAME]; /* specified output file */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortechar altroot[MAX_FILENAME]; /* specifed root location */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortechar config_file[MAX_FILENAME]; /* specified configuration file */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortechar input_file[MAX_FILENAME]; /* specified input file */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortechar logical_host[MAX_FILENAME]; /* specified cluster node */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortechar device_group[MAX_FILENAME]; /* specified device group name */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define IS_NOT_CLUSTER 1
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define IS_CLUSTER 2
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid cfg_invalidate_hsizes(int, const char *);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int check_cluster();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteusage(char *errmsg)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (errmsg)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdname, errmsg);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("dscfg \t\t\t\tDisplay location of "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "local configuration database\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr, gettext("dscfg -l -s path\t\t"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "List contents of configuration database\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr, gettext(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "\t\t\t\tlocated at path specified\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr, gettext("dscfg -i\t\t\t"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "Initialize configuration database\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("dscfg -i -p "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte"[-n] "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "/etc/dscfg_format\tFormat configuration database\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("dscfg -a file\t\t\tRestore configuration "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "database from file\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr, gettext("\t\t\t\tspecified\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("dscfg -l\t\t\tList contents of configuration database"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("dscfg -L\t\t\tDisplay configuration database's\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr, gettext("\t\t\t\tlock status\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr, gettext("dscfg -h\t\t\tUsage message\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (check_cluster() != IS_NOT_CLUSTER) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr, gettext("\nSun Cluster Usage\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr, gettext("******************\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("dscfg -s path\t\t\tSet cluster "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "configuration database at DID\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr, gettext("\t\t\t\tpath specified\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr, gettext("dscfg -D device_group\t\t"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "Check status of cluster device group\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr, gettext("dscfg -C -\t\t\t"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "Display location of cluster configuration\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr, gettext("\t\t\t\tdatabase\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr, gettext("dscfg -l -s DID_device\t\tList "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "the contents of cluster configuration\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr, gettext("\t\t\t\tdatabase\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr, gettext("dscfg -C - -i\t\t\tInitialize "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "cluster configuration database\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr, gettext("dscfg -C - -i -p "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "/etc/dscfg_format Format cluster configuration database\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr, gettext("dscfg -C - -a file\t\t"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "Restore cluster configuration database from\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr, gettext("\t\t\t\tfile specified\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr, gettext("dscfg -C - -l\t\t\t"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "List contents of local configuration database\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr, gettext("dscfg -C device_group -l\t"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "List configuration database by device group\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr, gettext("dscfg -C \"-\" -l\t\t\t"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "List configuration database excluding\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr, gettext("\t\t\t\tdevice groups\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteparse_parse_config(CFGFILE *cfg)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte FILE *fp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char inbuf[CFG_MAX_BUF];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *buff;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Open parser config file, use default if none specified
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte buff = (input_file[0]) ? input_file : DEFAULT_PARSER_LOC;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((fp = fopen(buff, "r")) == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("parser config file (%s) not found\n"), buff);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * start at begining of configration database
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cfg_rewind(cfg, CFG_SEC_ALL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (((buff = fgets(inbuf, (sizeof (inbuf) - 1), fp)) != NULL)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (*buff == '#' || *buff == '%')
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* overwrite newline */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte buff[strlen(buff) - 1] = '\0';
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = cfg_update_parser_config(cfg, buff, CFG_PARSE_CONF);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rc < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("update parser config rc %d key %s\n"),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc, buff);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fclose(fp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fclose(fp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteparse_text_config(CFGFILE *cfg)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte FILE *fp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char inbuf[CFG_MAX_BUF];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *buff;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *key;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *p;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((fp = fopen(input_file, "r")) == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("Unable to open text config %s\n"),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte input_file);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(2);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bzero(inbuf, sizeof (inbuf));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cfg_rewind(cfg, CFG_SEC_CONF);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (((buff = fgets(inbuf, (sizeof (inbuf) - 1), fp)) != NULL)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (*buff == '#')
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* overwrite newline */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte buff[strlen(buff) - 1] = '\0';
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte key = strtok(buff, ":");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!key) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p = &buff[strlen(key)+2];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (*p && isspace(*p)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ++p;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!*p) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = cfg_put_cstring(cfg, key, p, strlen(p));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rc < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("update text config failed rc %d key %s"),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc, buff);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bzero(inbuf, sizeof (inbuf));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fclose(fp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortedump_status(CFGFILE *cfg)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cfp_t *cfp = FP_SUN_CLUSTER(cfg);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * WARNING will robinson
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * The following is using a non-exported internal interface
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * to libcfg
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * You may not use any of the following fields in MS software
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!locname)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(2);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!verbose)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) printf("%s\n", locname);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) printf(gettext("Configuration location: %s\n"), locname);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) printf(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("Header info:\n\t\t\tmagic: %x\tstate: %x\n"),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cfp->cf_head->h_magic, cfp->cf_head->h_state);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) printf(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("Parser section:\t\t"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "Start: %x\tsize: %d offset: %d\n"),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cfp->cf_mapped, cfp->cf_head->h_parsesize,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cfp->cf_head->h_parseoff);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) printf(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("Config section:\t\t"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "Start: %x\tsize:%d\tacsize: %d\n"),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cfp->cf_head->h_cparse, cfp->cf_head->h_csize,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cfp->cf_head->h_acsize);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) printf("\t\t\tccopy1: %s\tccopy2: %s\n",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cfp->cf_head->h_ccopy1,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cfp->cf_head->h_ccopy2);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) printf(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("Sequence:\t\tseq1: %d\t\tseq2: %d\n"),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cfp->cf_head->h_seq1, cfp->cf_head->h_seq2);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortedump_lockstat(CFGFILE *cfg)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pid_t pid;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte CFGLOCK lock;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char ps_str[1024];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cfg_get_lock(cfg, &lock, &pid) == TRUE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) printf("%s %ld\n",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lock == CFG_RDLOCK ?
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("Read locked by process id") :
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("Write locked by process id"),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pid);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) sprintf(ps_str, "ps -p %ld", pid);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte system(ps_str);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) printf("%s\n", gettext("Not locked."));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * dump current configuration section to stdout
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteprint_config(CFGFILE *cfg)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte time_t tloc = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int set = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char pconfig[CFG_MAX_BUF];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char key[CFG_MAX_KEY];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char buf[CFG_MAX_BUF];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *cp, pbuf[CFG_MAX_BUF];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte FILE *fp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int end;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) snprintf(pconfig, sizeof (pconfig),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "%s%s", altroot, DEFAULT_PARSER_LOC);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((fp = fopen(pconfig, "r")) == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("dscfg: unable to open "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "parser configuration (%s): %s\n"),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pconfig, strerror(errno));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) time(&tloc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) printf(gettext("# Consolidated Dataservice Configuration\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) printf(gettext("# Do not edit out whitespace or dashes\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) printf(gettext("# File created on: %s"), ctime(&tloc));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (fgets(pbuf, (sizeof (pbuf) - 1), fp) != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (pbuf[0] == '#') {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* comment */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* force a NULL terminator */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pbuf[sizeof (pbuf) - 1] = '\0';
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (pbuf[0] == '%') {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * descriptive text
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * - print it (with comment leader) and move on
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) printf("#%s", &pbuf[1]);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * truncate the parser config in pbuf[] to just the tag
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cp = strchr(pbuf, '.');
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cp != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *cp = '\0';
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte set = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*CONSTCOND*/
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bzero(buf, CFG_MAX_BUF);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) snprintf(key,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (key), "%s.set%d", pbuf, set);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = cfg_get_cstring(cfg, key, buf, CFG_MAX_BUF);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rc < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* trim trailing space if necessary */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte end = strlen(buf) - 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (buf[end] == ' ')
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte buf[end] = '\0';
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) printf("%s:%s\n", pbuf, buf);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte set++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fclose(fp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortemake_new_config(const char *fileloc)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int fd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int skip;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char buf[CFG_MAX_BUF];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*CONSTCOND*/
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte assert((sizeof (buf) % 512) == 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bzero(buf, CFG_MAX_BUF);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((fd = open(fileloc, O_RDWR | O_CREAT, 0640)) == -1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* if this is a device, we may have to skip the vtoc */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((skip = cfg_shldskip_vtoc(fd, fileloc)) == -1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("dscfg: unable to read vtoc on (%s)\n"),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fileloc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (skip) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte do {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = lseek(fd, CFG_VTOC_SKIP, SEEK_SET);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } while (rc == -1 && errno == EINTR);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rc == -1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr, gettext("dscfg: seek error"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte do {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = write(fd, buf, sizeof (buf));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } while (rc == -1 && errno == EINTR);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte close(fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return ((rc < 0) ? 0 : 1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * dscfg
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * configure or return dataservice persistent configuration
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * options
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * -i initialize file for first time
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * -l dump current configuration to stdout in ascii
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * -a add
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * -C node Set resource filter
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * -p parser config specified input file
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * -s set partition location or filename in default location
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * -L print configuration lock status
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * -u upgrade
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * -r prepend bootdir to beginning of path for cfg_open
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * no options status
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef lint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortedscfg_lintmain(int argc, char *argv[])
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortemain(int argc, char *argv[])
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte CFGFILE *cfg;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte extern char *optarg;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *loc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int offset = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char c;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int local;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int action_counts = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bzero(input_file, sizeof (input_file));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) setlocale(LC_ALL, "");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) textdomain("dscfg");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte logical_host[0] = '\0';
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmdname = argv[0];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while ((c = getopt(argc, argv, "a:C:dD:ilLp:r:s:hvn")) != EOF) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while ((c = getopt(argc, argv, "a:C:dD:ilLp:r:s:h")) != EOF) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte switch (c) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case 'a':
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte aflg++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte strcpy(input_file, optarg);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mustcommit++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte action_counts++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case 'C':
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte Cflg++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte strcpy(logical_host, optarg);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (logical_host && *logical_host == '-')
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (argc == 3)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte action_counts++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case 'D':
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte Dflg++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte strcpy(device_group, optarg);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte action_counts++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case 'i':
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iflg++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mustcommit++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte action_counts++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case 'l':
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lflg++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte action_counts++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case 'L':
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte Lflg++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte action_counts++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case 'p':
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pflg++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte strcpy(input_file, optarg);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mustcommit++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case 's':
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sflg++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte strcpy(config_file, optarg);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte action_counts++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case 'h':
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte usage(NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*NOTREACHED*/
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case 'v':
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte verbose++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte action_counts++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef UPGRADE
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case 'u':
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uflg++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte action_counts++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case 'r':
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rflg++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte strcpy(altroot, optarg);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case 'n':
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nflg++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte default:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte usage(NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte };
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte switch (action_counts) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case 0:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (argc > 1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (pflg)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte usage(gettext(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "-p option must be used in conjunction with -i"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte usage(gettext("must specify an action flag"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case 1:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case 2:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (lflg && sflg)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte usage(gettext("too many action flags"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte default:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte usage(gettext("too many action flags"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (argc == 1 || (argc == 2 && verbose) || (argc == 3 && (rflg|Cflg)))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte noflags++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (Dflg) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Determine if the value specified is a device group
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * that is active on this node
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *other_node;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((cfg_issuncluster() > 0) && (strlen(device_group) > 0)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte local = cfg_dgname_islocal(device_group, &other_node);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (local == 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr, gettext(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "Device group %s active on %s\n"),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte device_group, other_node);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else if (local == 1)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr, gettext(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "Device group %s active on this node\n"),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte device_group);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr, gettext(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "Device group %s not found\n"), device_group);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (local);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr, gettext(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "dscfg -D is only allowed in "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "Sun Cluster OE\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (sflg && !lflg) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Only allow setting location on a non-sun cluster system
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * if the cluster reference file is already present.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct stat dscfg_stat = {0};
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cfg_issuncluster() <= 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (stat(CFG_CLUSTER_LOCATION, &dscfg_stat) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (dscfg_stat.st_blocks == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr, gettext(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "dscfg -s is only allowed in "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "Sun Cluster OE\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_log("dscfg", NULL, gettext("dscfg -s %s"), config_file);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte locname = cfg_location(config_file, CFG_LOC_SET_CLUSTER,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rflg ? altroot : NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (locname == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr, gettext("dscfg: %s\n"),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cfg_error(NULL));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (sflg && lflg) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* s used with l for temporarily peeking at a dscfg database */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte loc = config_file;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte locname = cfg_location(NULL,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte Cflg ? CFG_LOC_GET_CLUSTER : CFG_LOC_GET_LOCAL,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rflg ? altroot : NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (Cflg && (locname == NULL)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr, gettext(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "dscfg: cluster config not set: %s\n"),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cfg_error(NULL));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte loc = rflg ? locname : NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the following hack forces the configuration file to initialize
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (iflg && !pflg) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int fild;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int c;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char buf[CFG_MAX_BUF] = {0};
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cfp_t *cfp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!nflg) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) printf(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("WARNING: This option will erase your "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "Availability Suite configuration\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) printf(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("Do you want to continue? (Y/N) [N] "));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte c = getchar();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte switch (c) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case 'y':
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case 'Y': break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case 'n':
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case 'N':
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case '\n':
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr, gettext(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "dscfg: configuration not initialized\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte default:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr, gettext(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "dscfg: %d is not a valid response\n"), c);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_log("dscfg", NULL, gettext("dscfg -i"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((cfg = cfg_open(loc)) == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* this is not a good config, or non-existent so.. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!make_new_config(locname)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr, gettext("dscfg: %s\n"),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cfg_error(NULL));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((cfg = cfg_open(loc)) == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr, gettext("dscfg: %s\n"),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cfg_error(NULL));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Set cluster node if specified
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (Cflg)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cfg_resource(cfg, logical_host);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cfg_is_cfg(cfg) != 1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!make_new_config(locname)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr, gettext("dscfg: unable "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte " to create new config \n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!cfg_lock(cfg, CFG_WRLOCK)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr, gettext("dscfg: %s\n"),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cfg_error(NULL));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cfp = FP_SUN_CLUSTER(cfg);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((fild = cfp->cf_fd) == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("dscfg: failure to access %s "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "configuration database: %s\n"),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (Cflg) ? gettext("cluster") : gettext("local"),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cfg_error(NULL));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cfg_shldskip_vtoc(fild, locname) > 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte offset += CFG_VTOC_SKIP;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lseek(fild, offset, SEEK_SET);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte write(fild, buf, sizeof (buf));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cfg_invalidate_hsizes(fild, locname);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cfg_close(cfg);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (pflg && !iflg) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte usage(gettext("-p option must be used in conjunction with -i"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (uflg) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char cmd[CFG_MAX_BUF];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rflg)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) snprintf(cmd, sizeof (cmd),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "%s/usr/sbin/dscfg -r %s -l >"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte " %s/var/tmp/.dscfg.bak", altroot,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte altroot, altroot);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) snprintf(cmd, sizeof (cmd),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "/usr/sbin/dscfg -l >"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte " /var/tmp/.dscfg.bak");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (system(cmd) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "dscfg: unable to create backup\n");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((cfg = cfg_open(loc)) == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr, gettext("dscfg: %s\n"),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cfg_error(NULL));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(2);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!cfg_lock(cfg, CFG_UPGRADE)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("dscfg: upgrade failed\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cfg_close(cfg);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cfg_close(cfg);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((cfg = cfg_open(loc)) == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr, gettext("dscfg: %s\n"), cfg_error(NULL));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(2);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Set cluster node if specified
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (Cflg)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cfg_resource(cfg, logical_host);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((!pflg) && (!noflags)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cfg_is_cfg(cfg) != 1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("dscfg: %s\n"), cfg_error(NULL));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cfg_close(cfg);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (Lflg) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dump_lockstat(cfg);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cfg_close(cfg);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (noflags) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dump_status(cfg);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cfg_close(cfg);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!cfg_lock(cfg, mustcommit? CFG_WRLOCK : CFG_RDLOCK)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr, gettext("cfg_lock: lock failed\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cfg_close(cfg);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (lflg) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte print_config(cfg);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cfg_close(cfg);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * initialize configuration
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (iflg) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_log("dscfg", NULL, gettext("dscfg -i -p %s"), input_file);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!pflg) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("dscfg: cannot init without "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "parser configuration file\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cfg_close(cfg);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (parse_parse_config(cfg) < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr, gettext("dscfg: cannot load "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "parser configuration file\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cfg_close(cfg);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * read asci config file and write
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (aflg) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_log("dscfg", NULL, gettext("dscfg -a %s"), input_file);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte parse_text_config(cfg);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (mustcommit) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = cfg_commit(cfg);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rc < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int sev = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr, gettext("dscfg: %s\n"),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cfg_error(&sev));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (sev == CFG_EFATAL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cfg_close(cfg);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(2);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cfg_close(cfg);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortecheck_cluster()
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte static int is_cluster = -1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (is_cluster != -1)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (is_cluster);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = cfg_iscluster();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rc > 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte is_cluster = IS_CLUSTER;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (is_cluster);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (rc == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte is_cluster = IS_NOT_CLUSTER;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (is_cluster);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("dscfg: unable to determin environment\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*NOTREACHED*/
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* gcc */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (is_cluster);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}