/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#include <stdio.h>
#include <stdio.h>
#include <errno.h>
#include <limits.h>
#include <fcntl.h>
#include <string.h>
#include <strings.h>
#include <stdlib.h>
#include <unistd.h>
#include <time.h>
#include <locale.h>
#include <langinfo.h>
#include <libintl.h>
#include <stdarg.h>
#include <netdb.h>
#include <ctype.h>
#include <assert.h>
#ifdef DEBUG
#endif
int Cflg;
int Dflg;
int Lflg;
int aflg;
int iflg;
int lflg;
int nflg;
int pflg;
int rflg;
int sflg;
int uflg;
int verbose;
int noflags;
int errflg;
int mustcommit;
char *cmdname;
void cfg_invalidate_hsizes(int, const char *);
static int check_cluster();
void
{
if (errmsg)
gettext("dscfg \t\t\t\tDisplay location of "
"local configuration database\n"));
"List contents of configuration database\n"));
"\t\t\t\tlocated at path specified\n"));
"Initialize configuration database\n"));
gettext("dscfg -i -p "
#ifdef DEBUG
"[-n] "
#endif
"/etc/dscfg_format\tFormat configuration database\n"));
gettext("dscfg -a file\t\t\tRestore configuration "
"database from file\n"));
gettext("dscfg -l\t\t\tList contents of configuration database"
"\n"));
gettext("dscfg -L\t\t\tDisplay configuration database's\n"));
if (check_cluster() != IS_NOT_CLUSTER) {
gettext("dscfg -s path\t\t\tSet cluster "
"configuration database at DID\n"));
"Check status of cluster device group\n"));
"Display location of cluster configuration\n"));
"the contents of cluster configuration\n"));
"cluster configuration database\n"));
"/etc/dscfg_format Format cluster configuration database\n"));
"Restore cluster configuration database from\n"));
"List contents of local configuration database\n"));
"List configuration database by device group\n"));
"List configuration database excluding\n"));
}
}
int
{
char *buff;
int rc;
/*
* Open parser config file, use default if none specified
*/
return (-1);
}
/*
* start at begining of configration database
*/
continue;
/* overwrite newline */
if (rc < 0) {
gettext("update parser config rc %d key %s\n"),
return (-1);
}
}
return (1);
}
void
{
char *buff;
char *key;
char *p;
int rc;
gettext("Unable to open text config %s\n"),
exit(2);
}
if (*buff == '#')
continue;
/* overwrite newline */
if (!key) {
continue;
}
while (*p && isspace(*p)) {
++p;
}
if (!*p) {
continue;
}
if (rc < 0) {
gettext("update text config failed rc %d key %s"),
return;
}
}
}
void
{
/*
* WARNING will robinson
* The following is using a non-exported internal interface
* to libcfg
* You may not use any of the following fields in MS software
*/
if (!locname)
exit(2);
if (!verbose)
else {
#ifdef DEBUG
(void) printf(
gettext("Header info:\n\t\t\tmagic: %x\tstate: %x\n"),
(void) printf(
gettext("Parser section:\t\t"
"Start: %x\tsize: %d offset: %d\n"),
(void) printf(
gettext("Config section:\t\t"
"Start: %x\tsize:%d\tacsize: %d\n"),
(void) printf("\t\t\tccopy1: %s\tccopy2: %s\n",
(void) printf(
gettext("Sequence:\t\tseq1: %d\t\tseq2: %d\n"),
#endif
}
}
void
{
(void) printf("%s %ld\n",
lock == CFG_RDLOCK ?
gettext("Read locked by process id") :
gettext("Write locked by process id"),
pid);
} else
}
/*
* dump current configuration section to stdout
*/
void
{
int set = 0;
int rc;
int end;
gettext("dscfg: unable to open "
"parser configuration (%s): %s\n"),
exit(1);
}
if (pbuf[0] == '#') {
/* comment */
continue;
}
/* force a NULL terminator */
if (pbuf[0] == '%') {
/*
* descriptive text
* - print it (with comment leader) and move on
*/
continue;
}
/*
* truncate the parser config in pbuf[] to just the tag
*/
*cp = '\0';
}
set = 1;
/*CONSTCOND*/
while (1) {
if (rc < 0) {
break;
}
/* trim trailing space if necessary */
set++;
}
}
}
int
{
int fd;
int rc;
int skip;
/*CONSTCOND*/
return (-1);
}
/* if this is a device, we may have to skip the vtoc */
gettext("dscfg: unable to read vtoc on (%s)\n"),
fileloc);
return (-1);
} else if (skip) {
do {
if (rc == -1) {
return (-1);
}
}
do {
return ((rc < 0) ? 0 : 1);
}
/*
* dscfg
* configure or return dataservice persistent configuration
*
* options
* -i initialize file for first time
* -l dump current configuration to stdout in ascii
* -a add
* -C node Set resource filter
* -p parser config specified input file
* -s set partition location or filename in default location
* -L print configuration lock status
* -u upgrade
* -r prepend bootdir to beginning of path for cfg_open
* no options status
*
*
*/
#ifdef lint
int
#else
int
#endif
{
extern char *optarg;
char *loc;
int offset = 0;
int rc;
char c;
int local;
int action_counts = 0;
(void) textdomain("dscfg");
logical_host[0] = '\0';
#ifdef DEBUG
#else
#endif
switch (c) {
case 'a':
aflg++;
mustcommit++;
break;
case 'C':
Cflg++;
if (argc == 3)
break;
case 'D':
Dflg++;
break;
case 'i':
iflg++;
mustcommit++;
break;
case 'l':
lflg++;
break;
case 'L':
Lflg++;
break;
case 'p':
pflg++;
mustcommit++;
break;
case 's':
sflg++;
break;
case 'h':
exit(0);
/*NOTREACHED*/
#ifdef DEBUG
case 'v':
verbose++;
break;
#endif
#ifdef UPGRADE
case 'u':
uflg++;
break;
#endif
case 'r':
rflg++;
break;
case 'n':
nflg++;
break;
default:
exit(1);
break;
};
}
switch (action_counts) {
case 0:
if (argc > 1) {
if (pflg)
"-p option must be used in conjunction with -i"));
else
exit(1);
}
break;
case 1:
break;
case 2:
break;
else {
exit(1);
break;
}
default:
exit(1);
break;
}
noflags++;
if (Dflg) {
/*
* Determine if the value specified is a device group
* that is active on this node
*/
char *other_node;
if (local == 0)
"Device group %s active on %s\n"),
else if (local == 1)
"Device group %s active on this node\n"),
else
"Device group %s not found\n"), device_group);
return (local);
} else {
"dscfg -D is only allowed in "
"Sun Cluster OE\n"));
return (0);
}
}
/*
* Only allow setting location on a non-sun cluster system
* if the cluster reference file is already present.
*/
if (cfg_issuncluster() <= 0) {
if (dscfg_stat.st_blocks == 0) {
"dscfg -s is only allowed in "
"Sun Cluster OE\n"));
exit(1);
}
}
}
exit(1);
} else
exit(0);
/* s used with l for temporarily peeking at a dscfg database */
loc = config_file;
} else {
"dscfg: cluster config not set: %s\n"),
return (1);
}
}
/*
* the following hack forces the configuration file to initialize
*/
int fild;
int c;
if (!nflg) {
(void) printf(
gettext("WARNING: This option will erase your "
"Availability Suite configuration\n"));
(void) printf(
gettext("Do you want to continue? (Y/N) [N] "));
c = getchar();
switch (c) {
case 'y':
case 'Y': break;
case 'n':
case 'N':
case '\n':
"dscfg: configuration not initialized\n"));
exit(1);
default:
"dscfg: %d is not a valid response\n"), c);
exit(1);
}
}
/* this is not a good config, or non-existent so.. */
if (!make_new_config(locname)) {
exit(1);
}
exit(1);
}
}
/*
* Set cluster node if specified
*/
if (Cflg)
if (!make_new_config(locname)) {
" to create new config \n"));
exit(1);
}
}
exit(1);
}
gettext("dscfg: failure to access %s "
"configuration database: %s\n"),
exit(1);
}
offset += CFG_VTOC_SKIP;
exit(0);
}
exit(1);
}
if (uflg) {
if (rflg)
else
"dscfg: unable to create backup\n");
exit(1);
}
exit(2);
}
gettext("dscfg: upgrade failed\n"));
exit(1);
}
exit(0);
}
exit(2);
}
/*
* Set cluster node if specified
*/
if (Cflg)
exit(1);
}
}
if (Lflg) {
exit(0);
}
if (noflags) {
exit(0);
}
exit(1);
}
if (lflg) {
exit(0);
}
/*
* initialize configuration
*/
if (iflg) {
if (!pflg) {
gettext("dscfg: cannot init without "
"parser configuration file\n"));
exit(1);
} else if (parse_parse_config(cfg) < 0) {
"parser configuration file\n"));
exit(1);
}
}
/*
* read asci config file and write
*/
if (aflg) {
}
if (mustcommit) {
if (rc < 0) {
int sev = 0;
if (sev == CFG_EFATAL) {
exit(2);
}
}
}
return (0);
}
static int
{
int rc;
if (is_cluster != -1)
return (is_cluster);
rc = cfg_iscluster();
if (rc > 0) {
return (is_cluster);
} else if (rc == 0) {
return (is_cluster);
} else {
gettext("dscfg: unable to determin environment\n"));
/*NOTREACHED*/
}
/* gcc */
return (is_cluster);
}