17836SJohn.Forte@Sun.COM /*
27836SJohn.Forte@Sun.COM * CDDL HEADER START
37836SJohn.Forte@Sun.COM *
47836SJohn.Forte@Sun.COM * The contents of this file are subject to the terms of the
57836SJohn.Forte@Sun.COM * Common Development and Distribution License (the "License").
67836SJohn.Forte@Sun.COM * You may not use this file except in compliance with the License.
77836SJohn.Forte@Sun.COM *
87836SJohn.Forte@Sun.COM * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97836SJohn.Forte@Sun.COM * or http://www.opensolaris.org/os/licensing.
107836SJohn.Forte@Sun.COM * See the License for the specific language governing permissions
117836SJohn.Forte@Sun.COM * and limitations under the License.
127836SJohn.Forte@Sun.COM *
137836SJohn.Forte@Sun.COM * When distributing Covered Code, include this CDDL HEADER in each
147836SJohn.Forte@Sun.COM * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157836SJohn.Forte@Sun.COM * If applicable, add the following below this CDDL HEADER, with the
167836SJohn.Forte@Sun.COM * fields enclosed by brackets "[]" replaced with your own identifying
177836SJohn.Forte@Sun.COM * information: Portions Copyright [yyyy] [name of copyright owner]
187836SJohn.Forte@Sun.COM *
197836SJohn.Forte@Sun.COM * CDDL HEADER END
207836SJohn.Forte@Sun.COM */
21*11576SSurya.Prakki@Sun.COM
227836SJohn.Forte@Sun.COM /*
23*11576SSurya.Prakki@Sun.COM * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
247836SJohn.Forte@Sun.COM * Use is subject to license terms.
257836SJohn.Forte@Sun.COM */
267836SJohn.Forte@Sun.COM
277836SJohn.Forte@Sun.COM #include <sys/types.h>
287836SJohn.Forte@Sun.COM #include <stdio.h>
297836SJohn.Forte@Sun.COM #include <sys/mnttab.h>
307836SJohn.Forte@Sun.COM #include <errno.h>
317836SJohn.Forte@Sun.COM #include <limits.h>
327836SJohn.Forte@Sun.COM #include <fcntl.h>
337836SJohn.Forte@Sun.COM #include <strings.h>
347836SJohn.Forte@Sun.COM #include <stdlib.h>
357836SJohn.Forte@Sun.COM #include <unistd.h>
367836SJohn.Forte@Sun.COM #include <sys/stat.h>
377836SJohn.Forte@Sun.COM #include <signal.h>
387836SJohn.Forte@Sun.COM
397836SJohn.Forte@Sun.COM #include <locale.h>
407836SJohn.Forte@Sun.COM #include <langinfo.h>
417836SJohn.Forte@Sun.COM #include <libintl.h>
427836SJohn.Forte@Sun.COM #include <stdarg.h>
437836SJohn.Forte@Sun.COM #include <sys/nsctl/rdc_io.h>
447836SJohn.Forte@Sun.COM #include <sys/nsctl/rdc_ioctl.h>
457836SJohn.Forte@Sun.COM #include <sys/nsctl/rdc_prot.h>
467836SJohn.Forte@Sun.COM
477836SJohn.Forte@Sun.COM #include <sys/nsctl/cfg.h>
487836SJohn.Forte@Sun.COM
497836SJohn.Forte@Sun.COM #include <sys/unistat/spcs_s.h>
507836SJohn.Forte@Sun.COM #include <sys/unistat/spcs_s_u.h>
517836SJohn.Forte@Sun.COM #include <sys/unistat/spcs_errors.h>
527836SJohn.Forte@Sun.COM
537836SJohn.Forte@Sun.COM #include "rdcadm.h"
547836SJohn.Forte@Sun.COM
557836SJohn.Forte@Sun.COM
567836SJohn.Forte@Sun.COM int maxqfbas = MAXQFBAS;
577836SJohn.Forte@Sun.COM int maxqitems = MAXQITEMS;
587836SJohn.Forte@Sun.COM int autosync = AUTOSYNC;
597836SJohn.Forte@Sun.COM int asyncthr = ASYNCTHR;
607836SJohn.Forte@Sun.COM int qblock = QBLOCK;
617836SJohn.Forte@Sun.COM
627836SJohn.Forte@Sun.COM int
mounted(char * device)637836SJohn.Forte@Sun.COM mounted(char *device)
647836SJohn.Forte@Sun.COM {
657836SJohn.Forte@Sun.COM char target[NSC_MAXPATH];
667836SJohn.Forte@Sun.COM struct mnttab mntref;
677836SJohn.Forte@Sun.COM struct mnttab mntent;
687836SJohn.Forte@Sun.COM FILE *mntfp;
697836SJohn.Forte@Sun.COM int rdsk;
707836SJohn.Forte@Sun.COM char *s;
717836SJohn.Forte@Sun.COM int i;
727836SJohn.Forte@Sun.COM
737836SJohn.Forte@Sun.COM rdsk = i = 0;
747836SJohn.Forte@Sun.COM for (s = target; i < NSC_MAXPATH && (*s = *device++); i++) {
757836SJohn.Forte@Sun.COM if (*s == 'r' && rdsk == 0 && strncmp(device, "dsk/", 4) == 0)
767836SJohn.Forte@Sun.COM rdsk = 1;
777836SJohn.Forte@Sun.COM else
787836SJohn.Forte@Sun.COM s++;
797836SJohn.Forte@Sun.COM }
807836SJohn.Forte@Sun.COM *s = '\0';
817836SJohn.Forte@Sun.COM
827836SJohn.Forte@Sun.COM mntref.mnt_special = target;
837836SJohn.Forte@Sun.COM mntref.mnt_mountp = NULL;
847836SJohn.Forte@Sun.COM mntref.mnt_fstype = NULL;
857836SJohn.Forte@Sun.COM mntref.mnt_mntopts = NULL;
867836SJohn.Forte@Sun.COM mntref.mnt_time = NULL;
877836SJohn.Forte@Sun.COM
887836SJohn.Forte@Sun.COM mntfp = fopen(MNTTAB, "r");
897836SJohn.Forte@Sun.COM
907836SJohn.Forte@Sun.COM if (mntfp == NULL) {
917836SJohn.Forte@Sun.COM rdc_warn(NULL,
927836SJohn.Forte@Sun.COM gettext("can not check volume %s against mount table"),
937836SJohn.Forte@Sun.COM mntref.mnt_special);
947836SJohn.Forte@Sun.COM /* Assume the worst, that it is mounted */
957836SJohn.Forte@Sun.COM return (1);
967836SJohn.Forte@Sun.COM }
977836SJohn.Forte@Sun.COM
987836SJohn.Forte@Sun.COM if (getmntany(mntfp, &mntent, &mntref) != -1) {
997836SJohn.Forte@Sun.COM /* found something before EOF */
1007836SJohn.Forte@Sun.COM (void) fclose(mntfp);
1017836SJohn.Forte@Sun.COM return (1);
1027836SJohn.Forte@Sun.COM }
1037836SJohn.Forte@Sun.COM
1047836SJohn.Forte@Sun.COM (void) fclose(mntfp);
1057836SJohn.Forte@Sun.COM return (0);
1067836SJohn.Forte@Sun.COM }
1077836SJohn.Forte@Sun.COM
1087836SJohn.Forte@Sun.COM
1097836SJohn.Forte@Sun.COM /* Needs to match parsing code in rdcboot.c and rdcadm.c */
1107836SJohn.Forte@Sun.COM char *
rdc_decode_flag(int flag,int options)1117836SJohn.Forte@Sun.COM rdc_decode_flag(int flag, int options)
1127836SJohn.Forte@Sun.COM {
1137836SJohn.Forte@Sun.COM static char str[32];
1147836SJohn.Forte@Sun.COM
1157836SJohn.Forte@Sun.COM switch (flag) {
1167836SJohn.Forte@Sun.COM case (RDC_CMD_COPY):
1177836SJohn.Forte@Sun.COM if (options & RDC_OPT_FULL)
118*11576SSurya.Prakki@Sun.COM (void) strcpy(str, "-m");
1197836SJohn.Forte@Sun.COM else
120*11576SSurya.Prakki@Sun.COM (void) strcpy(str, "-u");
1217836SJohn.Forte@Sun.COM if (options & RDC_OPT_REVERSE)
122*11576SSurya.Prakki@Sun.COM (void) strcat(str, " -r");
1237836SJohn.Forte@Sun.COM break;
1247836SJohn.Forte@Sun.COM
1257836SJohn.Forte@Sun.COM case (RDC_CMD_DISABLE):
126*11576SSurya.Prakki@Sun.COM (void) strcpy(str, "-d");
1277836SJohn.Forte@Sun.COM break;
1287836SJohn.Forte@Sun.COM
1297836SJohn.Forte@Sun.COM case (RDC_CMD_ENABLE):
1307836SJohn.Forte@Sun.COM if (options & RDC_OPT_SETBMP)
131*11576SSurya.Prakki@Sun.COM (void) strcpy(str, "-e");
1327836SJohn.Forte@Sun.COM else
133*11576SSurya.Prakki@Sun.COM (void) strcpy(str, "-E");
1347836SJohn.Forte@Sun.COM break;
1357836SJohn.Forte@Sun.COM
1367836SJohn.Forte@Sun.COM case (RDC_CMD_LOG):
137*11576SSurya.Prakki@Sun.COM (void) strcpy(str, "-l");
1387836SJohn.Forte@Sun.COM break;
1397836SJohn.Forte@Sun.COM
1407836SJohn.Forte@Sun.COM case (RDC_CMD_HEALTH):
141*11576SSurya.Prakki@Sun.COM (void) strcpy(str, "-H");
1427836SJohn.Forte@Sun.COM break;
1437836SJohn.Forte@Sun.COM
1447836SJohn.Forte@Sun.COM case (RDC_CMD_WAIT):
145*11576SSurya.Prakki@Sun.COM (void) strcpy(str, "-w");
1467836SJohn.Forte@Sun.COM break;
1477836SJohn.Forte@Sun.COM
1487836SJohn.Forte@Sun.COM case (RDC_CMD_RECONFIG):
149*11576SSurya.Prakki@Sun.COM (void) strcpy(str, "-R ...");
1507836SJohn.Forte@Sun.COM break;
1517836SJohn.Forte@Sun.COM
1527836SJohn.Forte@Sun.COM case (RDC_CMD_TUNABLE):
153*11576SSurya.Prakki@Sun.COM (void) strcpy(str, "");
1547836SJohn.Forte@Sun.COM if (maxqfbas != MAXQFBAS)
155*11576SSurya.Prakki@Sun.COM (void) strcat(str, " -F");
1567836SJohn.Forte@Sun.COM if (maxqitems != MAXQITEMS)
157*11576SSurya.Prakki@Sun.COM (void) strcat(str, " -W");
1587836SJohn.Forte@Sun.COM if (autosync != AUTOSYNC)
159*11576SSurya.Prakki@Sun.COM (void) strcat(str, " -a");
1607836SJohn.Forte@Sun.COM if (asyncthr != ASYNCTHR)
161*11576SSurya.Prakki@Sun.COM (void) strcat(str, " -A");
1627836SJohn.Forte@Sun.COM if (qblock != QBLOCK)
163*11576SSurya.Prakki@Sun.COM (void) strcat(str, " -D");
1647836SJohn.Forte@Sun.COM break;
1657836SJohn.Forte@Sun.COM
1667836SJohn.Forte@Sun.COM case (RDC_CMD_SUSPEND):
167*11576SSurya.Prakki@Sun.COM (void) strcpy(str, "-s");
1687836SJohn.Forte@Sun.COM break;
1697836SJohn.Forte@Sun.COM
1707836SJohn.Forte@Sun.COM case (RDC_CMD_RESUME):
171*11576SSurya.Prakki@Sun.COM (void) strcpy(str, "-r");
1727836SJohn.Forte@Sun.COM break;
1737836SJohn.Forte@Sun.COM
1747836SJohn.Forte@Sun.COM case (RDC_CMD_RESET):
175*11576SSurya.Prakki@Sun.COM (void) strcpy(str, "-R");
1767836SJohn.Forte@Sun.COM break;
1777836SJohn.Forte@Sun.COM
1787836SJohn.Forte@Sun.COM case (RDC_CMD_ADDQ):
179*11576SSurya.Prakki@Sun.COM (void) strcpy(str, "-q a");
1807836SJohn.Forte@Sun.COM break;
1817836SJohn.Forte@Sun.COM
1827836SJohn.Forte@Sun.COM case (RDC_CMD_REMQ):
183*11576SSurya.Prakki@Sun.COM (void) strcpy(str, "-q d");
1847836SJohn.Forte@Sun.COM break;
1857836SJohn.Forte@Sun.COM
1867836SJohn.Forte@Sun.COM case (RDC_CMD_REPQ):
187*11576SSurya.Prakki@Sun.COM (void) strcpy(str, "-q r");
1887836SJohn.Forte@Sun.COM break;
1897836SJohn.Forte@Sun.COM
1907836SJohn.Forte@Sun.COM default:
191*11576SSurya.Prakki@Sun.COM (void) strcpy(str, gettext("unknown"));
1927836SJohn.Forte@Sun.COM break;
1937836SJohn.Forte@Sun.COM }
1947836SJohn.Forte@Sun.COM
1957836SJohn.Forte@Sun.COM return (str);
1967836SJohn.Forte@Sun.COM }
1977836SJohn.Forte@Sun.COM
1987836SJohn.Forte@Sun.COM
1997836SJohn.Forte@Sun.COM static void
rdc_msg(char * prefix,spcs_s_info_t * status,char * string,va_list ap)2007836SJohn.Forte@Sun.COM rdc_msg(char *prefix, spcs_s_info_t *status, char *string, va_list ap)
2017836SJohn.Forte@Sun.COM {
2027836SJohn.Forte@Sun.COM if (status) {
2037836SJohn.Forte@Sun.COM (void) fprintf(stderr, "Remote Mirror: %s\n", prefix);
2047836SJohn.Forte@Sun.COM spcs_s_report(*status, stderr);
2057836SJohn.Forte@Sun.COM } else {
2067836SJohn.Forte@Sun.COM (void) fprintf(stderr, "%s: %s: ", program, prefix);
2077836SJohn.Forte@Sun.COM }
2087836SJohn.Forte@Sun.COM
2097836SJohn.Forte@Sun.COM if (string && *string != '\0') {
2107836SJohn.Forte@Sun.COM (void) vfprintf(stderr, string, ap);
2117836SJohn.Forte@Sun.COM }
2127836SJohn.Forte@Sun.COM
2137836SJohn.Forte@Sun.COM (void) fprintf(stderr, "\n");
2147836SJohn.Forte@Sun.COM }
2157836SJohn.Forte@Sun.COM
2167836SJohn.Forte@Sun.COM void
rdc_err(spcs_s_info_t * status,char * string,...)2177836SJohn.Forte@Sun.COM rdc_err(spcs_s_info_t *status, char *string, ...)
2187836SJohn.Forte@Sun.COM {
2197836SJohn.Forte@Sun.COM va_list ap;
2207836SJohn.Forte@Sun.COM va_start(ap, string);
2217836SJohn.Forte@Sun.COM
2227836SJohn.Forte@Sun.COM rdc_msg(gettext("Error"), status, string, ap);
2237836SJohn.Forte@Sun.COM
2247836SJohn.Forte@Sun.COM va_end(ap);
2257836SJohn.Forte@Sun.COM exit(1);
2267836SJohn.Forte@Sun.COM }
2277836SJohn.Forte@Sun.COM
2287836SJohn.Forte@Sun.COM void
rdc_warn(spcs_s_info_t * status,char * string,...)2297836SJohn.Forte@Sun.COM rdc_warn(spcs_s_info_t *status, char *string, ...)
2307836SJohn.Forte@Sun.COM {
2317836SJohn.Forte@Sun.COM va_list ap;
2327836SJohn.Forte@Sun.COM va_start(ap, string);
2337836SJohn.Forte@Sun.COM
2347836SJohn.Forte@Sun.COM rdc_msg(gettext("warning"), status, string, ap);
2357836SJohn.Forte@Sun.COM
2367836SJohn.Forte@Sun.COM va_end(ap);
2377836SJohn.Forte@Sun.COM }
2387836SJohn.Forte@Sun.COM
2397836SJohn.Forte@Sun.COM int
rdc_get_maxsets(void)2407836SJohn.Forte@Sun.COM rdc_get_maxsets(void)
2417836SJohn.Forte@Sun.COM {
2427836SJohn.Forte@Sun.COM rdc_status_t rdc_status;
2437836SJohn.Forte@Sun.COM spcs_s_info_t ustatus;
2447836SJohn.Forte@Sun.COM int rc;
2457836SJohn.Forte@Sun.COM
2467836SJohn.Forte@Sun.COM rdc_status.nset = 0;
2477836SJohn.Forte@Sun.COM ustatus = spcs_s_ucreate();
2487836SJohn.Forte@Sun.COM
2497836SJohn.Forte@Sun.COM rc = RDC_IOCTL(RDC_STATUS, &rdc_status, 0, 0, 0, 0, ustatus);
2507836SJohn.Forte@Sun.COM if (rc == SPCS_S_ERROR) {
2517836SJohn.Forte@Sun.COM rdc_err(&ustatus, gettext("statistics error"));
2527836SJohn.Forte@Sun.COM }
2537836SJohn.Forte@Sun.COM
2547836SJohn.Forte@Sun.COM spcs_s_ufree(&ustatus);
2557836SJohn.Forte@Sun.COM return (rdc_status.maxsets);
2567836SJohn.Forte@Sun.COM }
2577836SJohn.Forte@Sun.COM
2587836SJohn.Forte@Sun.COM /*
2597836SJohn.Forte@Sun.COM * Look up a set in libcfg to find the setnumber.
2607836SJohn.Forte@Sun.COM *
2617836SJohn.Forte@Sun.COM * ASSUMPTIONS:
2627836SJohn.Forte@Sun.COM * - a valid cfg handle
2637836SJohn.Forte@Sun.COM *
2647836SJohn.Forte@Sun.COM * INPUTS:
2657836SJohn.Forte@Sun.COM * cfg - cfg handle
2667836SJohn.Forte@Sun.COM * tohost - secondary hostname
2677836SJohn.Forte@Sun.COM * tofile - secondary volume
2687836SJohn.Forte@Sun.COM *
2697836SJohn.Forte@Sun.COM * OUTPUTS:
2707836SJohn.Forte@Sun.COM * set number if found, otherwise -1 for an error
2717836SJohn.Forte@Sun.COM */
2727836SJohn.Forte@Sun.COM int
find_setnumber_in_libcfg(CFGFILE * cfg,char * ctag,char * tohost,char * tofile)2737836SJohn.Forte@Sun.COM find_setnumber_in_libcfg(CFGFILE *cfg, char *ctag, char *tohost, char *tofile)
2747836SJohn.Forte@Sun.COM {
2757836SJohn.Forte@Sun.COM int setnumber;
2767836SJohn.Forte@Sun.COM int entries, rc;
2777836SJohn.Forte@Sun.COM char *buf, *secondary, *shost;
2787836SJohn.Forte@Sun.COM char **entry;
2797836SJohn.Forte@Sun.COM char *cnode;
2807836SJohn.Forte@Sun.COM int offset = 0;
2817836SJohn.Forte@Sun.COM
2827836SJohn.Forte@Sun.COM if (cfg == NULL) {
2837836SJohn.Forte@Sun.COM #ifdef DEBUG
2847836SJohn.Forte@Sun.COM rdc_warn(NULL, "cfg is NULL while looking up set number");
2857836SJohn.Forte@Sun.COM #endif
2867836SJohn.Forte@Sun.COM return (-1);
2877836SJohn.Forte@Sun.COM }
2887836SJohn.Forte@Sun.COM
2897836SJohn.Forte@Sun.COM entries = cfg_get_section(cfg, &entry, "sndr");
2907836SJohn.Forte@Sun.COM
2917836SJohn.Forte@Sun.COM rc = -1;
2927836SJohn.Forte@Sun.COM for (setnumber = 1; setnumber <= entries; setnumber++) {
2937836SJohn.Forte@Sun.COM buf = entry[setnumber - 1];
2947836SJohn.Forte@Sun.COM
2957836SJohn.Forte@Sun.COM (void) strtok(buf, " "); /* phost */
2967836SJohn.Forte@Sun.COM (void) strtok(NULL, " "); /* primary */
2977836SJohn.Forte@Sun.COM (void) strtok(NULL, " "); /* pbitmap */
2987836SJohn.Forte@Sun.COM shost = strtok(NULL, " ");
2997836SJohn.Forte@Sun.COM secondary = strtok(NULL, " ");
3007836SJohn.Forte@Sun.COM
3017836SJohn.Forte@Sun.COM if (ctag && *ctag) {
3027836SJohn.Forte@Sun.COM (void) strtok(NULL, " "); /* sbitmap */
3037836SJohn.Forte@Sun.COM (void) strtok(NULL, " "); /* type */
3047836SJohn.Forte@Sun.COM (void) strtok(NULL, " "); /* mode */
3057836SJohn.Forte@Sun.COM (void) strtok(NULL, " "); /* group */
3067836SJohn.Forte@Sun.COM cnode = strtok(NULL, " ");
3077836SJohn.Forte@Sun.COM
3087836SJohn.Forte@Sun.COM if (ctag && strcmp(cnode, ctag) != 0) {
3097836SJohn.Forte@Sun.COM /* filter this out */
3107836SJohn.Forte@Sun.COM ++offset;
3117836SJohn.Forte@Sun.COM continue;
3127836SJohn.Forte@Sun.COM }
3137836SJohn.Forte@Sun.COM }
3147836SJohn.Forte@Sun.COM
3157836SJohn.Forte@Sun.COM /* Check secondary volume name first, will get less hits */
3167836SJohn.Forte@Sun.COM if (strcmp(secondary, tofile) != 0) {
3177836SJohn.Forte@Sun.COM free(buf);
3187836SJohn.Forte@Sun.COM continue;
3197836SJohn.Forte@Sun.COM }
3207836SJohn.Forte@Sun.COM
3217836SJohn.Forte@Sun.COM if (strcmp(shost, tohost) == 0) {
3227836SJohn.Forte@Sun.COM free(buf);
3237836SJohn.Forte@Sun.COM rc = setnumber - offset;
3247836SJohn.Forte@Sun.COM break;
3257836SJohn.Forte@Sun.COM }
3267836SJohn.Forte@Sun.COM
3277836SJohn.Forte@Sun.COM free(buf);
3287836SJohn.Forte@Sun.COM }
3297836SJohn.Forte@Sun.COM
3307836SJohn.Forte@Sun.COM while (setnumber < entries)
3317836SJohn.Forte@Sun.COM free(entry[setnumber++]);
3327836SJohn.Forte@Sun.COM if (entries)
3337836SJohn.Forte@Sun.COM free(entry);
3347836SJohn.Forte@Sun.COM
3357836SJohn.Forte@Sun.COM return (rc);
3367836SJohn.Forte@Sun.COM }
3377836SJohn.Forte@Sun.COM
3387836SJohn.Forte@Sun.COM void
get_group_diskq(CFGFILE * cfg,char * group,char * diskq)3397836SJohn.Forte@Sun.COM get_group_diskq(CFGFILE *cfg, char *group, char *diskq)
3407836SJohn.Forte@Sun.COM {
3417836SJohn.Forte@Sun.COM int i;
3427836SJohn.Forte@Sun.COM char key[CFG_MAX_KEY];
3437836SJohn.Forte@Sun.COM char buf[CFG_MAX_BUF];
3447836SJohn.Forte@Sun.COM
3457836SJohn.Forte@Sun.COM if (*group == '\0')
3467836SJohn.Forte@Sun.COM return;
3477836SJohn.Forte@Sun.COM for (i = 1; ; i++) {
3487836SJohn.Forte@Sun.COM bzero(&key, sizeof (key));
3497836SJohn.Forte@Sun.COM bzero(&buf, sizeof (buf));
3507836SJohn.Forte@Sun.COM (void) sprintf(key, "sndr.set%d.group", i);
3517836SJohn.Forte@Sun.COM if (cfg_get_cstring(cfg, key, &buf, sizeof (buf)) < 0)
3527836SJohn.Forte@Sun.COM break;
3537836SJohn.Forte@Sun.COM if (strncmp(group, buf, sizeof (buf)) == 0) {
3547836SJohn.Forte@Sun.COM (void) sprintf(key, "sndr.set%d.diskq", i);
3557836SJohn.Forte@Sun.COM if (cfg_get_cstring(cfg, key, diskq, CFG_MAX_BUF) < 0) {
3567836SJohn.Forte@Sun.COM rdc_warn(NULL, gettext("unable to retrieve "
3577836SJohn.Forte@Sun.COM "group %s's disk queue"), group);
3587836SJohn.Forte@Sun.COM }
3597836SJohn.Forte@Sun.COM }
3607836SJohn.Forte@Sun.COM }
3617836SJohn.Forte@Sun.COM }
3627836SJohn.Forte@Sun.COM
3637836SJohn.Forte@Sun.COM int
get_cfg_setid(CFGFILE * cfg,char * ctag,char * tohost,char * tofile)3647836SJohn.Forte@Sun.COM get_cfg_setid(CFGFILE *cfg, char *ctag, char *tohost, char *tofile)
3657836SJohn.Forte@Sun.COM {
3667836SJohn.Forte@Sun.COM int setnum = 0;
3677836SJohn.Forte@Sun.COM int close_cfg = 0;
3687836SJohn.Forte@Sun.COM char key[CFG_MAX_KEY];
3697836SJohn.Forte@Sun.COM char setid[64];
3707836SJohn.Forte@Sun.COM
3717836SJohn.Forte@Sun.COM if (cfg == NULL) {
3727836SJohn.Forte@Sun.COM close_cfg = 1;
3737836SJohn.Forte@Sun.COM if ((cfg = cfg_open(NULL)) == NULL) {
3747836SJohn.Forte@Sun.COM return (-1); /* message printed by caller */
3757836SJohn.Forte@Sun.COM }
3767836SJohn.Forte@Sun.COM if (!cfg_lock(cfg, CFG_RDLOCK)) {
3777836SJohn.Forte@Sun.COM cfg_close(cfg);
3787836SJohn.Forte@Sun.COM return (-1);
3797836SJohn.Forte@Sun.COM }
3807836SJohn.Forte@Sun.COM }
3817836SJohn.Forte@Sun.COM setnum = find_setnumber_in_libcfg(cfg, ctag, tohost, tofile);
3827836SJohn.Forte@Sun.COM if (setnum < 0)
3837836SJohn.Forte@Sun.COM return (setnum);
3847836SJohn.Forte@Sun.COM
3857836SJohn.Forte@Sun.COM (void) snprintf(key, CFG_MAX_KEY, "sndr.set%d.options", setnum);
3867836SJohn.Forte@Sun.COM if (cfg_get_single_option(cfg, CFG_SEC_CONF, key, "setid",
3877836SJohn.Forte@Sun.COM setid, sizeof (setid)) < 0) {
3887836SJohn.Forte@Sun.COM if (close_cfg)
3897836SJohn.Forte@Sun.COM cfg_close(cfg);
3907836SJohn.Forte@Sun.COM
3917836SJohn.Forte@Sun.COM spcs_log("sndr", NULL,
3927836SJohn.Forte@Sun.COM gettext("%s unable to get unique setid "
3937836SJohn.Forte@Sun.COM "for %s:%s"), program, tohost, tofile);
3947836SJohn.Forte@Sun.COM return (-1);
3957836SJohn.Forte@Sun.COM
3967836SJohn.Forte@Sun.COM }
3977836SJohn.Forte@Sun.COM if (close_cfg)
3987836SJohn.Forte@Sun.COM cfg_close(cfg);
3997836SJohn.Forte@Sun.COM
4007836SJohn.Forte@Sun.COM return (atoi(setid));
4017836SJohn.Forte@Sun.COM
4027836SJohn.Forte@Sun.COM }
4037836SJohn.Forte@Sun.COM
4047836SJohn.Forte@Sun.COM int
get_new_cfg_setid(CFGFILE * cfg)4057836SJohn.Forte@Sun.COM get_new_cfg_setid(CFGFILE *cfg)
4067836SJohn.Forte@Sun.COM {
4077836SJohn.Forte@Sun.COM int setid;
4087836SJohn.Forte@Sun.COM char buf[CFG_MAX_BUF];
4097836SJohn.Forte@Sun.COM char *ctag;
4107836SJohn.Forte@Sun.COM
4117836SJohn.Forte@Sun.COM /* If in a Sun Cluster, SetIDs need to have a ctag */
4127836SJohn.Forte@Sun.COM if ((ctag = cfg_get_resource(cfg)) != NULL) {
4137836SJohn.Forte@Sun.COM ctag = strdup(ctag);
4147836SJohn.Forte@Sun.COM cfg_resource(cfg, "setid-ctag");
4157836SJohn.Forte@Sun.COM }
4167836SJohn.Forte@Sun.COM
4177836SJohn.Forte@Sun.COM if (cfg_get_cstring(cfg, "setid.set1.value", buf, CFG_MAX_BUF) < 0) {
4187836SJohn.Forte@Sun.COM setid = 1;
4197836SJohn.Forte@Sun.COM if (cfg_put_cstring(cfg, "setid", "1", CFG_MAX_BUF) < 0) {
4207836SJohn.Forte@Sun.COM rdc_err(NULL, "Unable to store new setid");
4217836SJohn.Forte@Sun.COM }
4227836SJohn.Forte@Sun.COM } else {
4237836SJohn.Forte@Sun.COM setid = atoi(buf);
4247836SJohn.Forte@Sun.COM setid++;
4257836SJohn.Forte@Sun.COM if (setid <= 0) {
4267836SJohn.Forte@Sun.COM setid = 1;
4277836SJohn.Forte@Sun.COM }
4287836SJohn.Forte@Sun.COM }
4297836SJohn.Forte@Sun.COM
4307836SJohn.Forte@Sun.COM bzero(&buf, CFG_MAX_BUF);
4317836SJohn.Forte@Sun.COM (void) snprintf(buf, sizeof (buf), "%d", setid);
4327836SJohn.Forte@Sun.COM if (cfg_put_cstring(cfg, "setid.set1.value", buf, CFG_MAX_BUF) < 0) {
4337836SJohn.Forte@Sun.COM rdc_err(NULL, "Unable to store new setid");
4347836SJohn.Forte@Sun.COM }
4357836SJohn.Forte@Sun.COM
4367836SJohn.Forte@Sun.COM /* Restore old ctag if in a Sun Cluster */
4377836SJohn.Forte@Sun.COM if (ctag) {
4387836SJohn.Forte@Sun.COM cfg_resource(cfg, ctag);
4397836SJohn.Forte@Sun.COM free(ctag);
4407836SJohn.Forte@Sun.COM }
4417836SJohn.Forte@Sun.COM
4427836SJohn.Forte@Sun.COM return (setid);
4437836SJohn.Forte@Sun.COM }
4447836SJohn.Forte@Sun.COM
4457836SJohn.Forte@Sun.COM sigset_t origmask;
4467836SJohn.Forte@Sun.COM
4477836SJohn.Forte@Sun.COM void
block_sigs(void)4487836SJohn.Forte@Sun.COM block_sigs(void)
4497836SJohn.Forte@Sun.COM {
4507836SJohn.Forte@Sun.COM sigset_t allsigs;
4517836SJohn.Forte@Sun.COM
452*11576SSurya.Prakki@Sun.COM (void) sigfillset(&allsigs);
4537836SJohn.Forte@Sun.COM if (sigprocmask(SIG_BLOCK, &allsigs, &origmask) < 0)
4547836SJohn.Forte@Sun.COM rdc_warn(NULL, gettext("Unable to block signals"));
4557836SJohn.Forte@Sun.COM }
4567836SJohn.Forte@Sun.COM
4577836SJohn.Forte@Sun.COM void
unblock_sigs(void)4587836SJohn.Forte@Sun.COM unblock_sigs(void)
4597836SJohn.Forte@Sun.COM {
4607836SJohn.Forte@Sun.COM if (sigprocmask(SIG_SETMASK, &origmask, NULL) < 0)
4617836SJohn.Forte@Sun.COM rdc_warn(NULL, gettext("Unable to unblock signals"));
4627836SJohn.Forte@Sun.COM
4637836SJohn.Forte@Sun.COM }
464