xref: /titanic_54/usr/src/cmd/avs/rdc/sndrsubr.c (revision fcf3ce441efd61da9bb2884968af01cb7c1452cc)
1*fcf3ce44SJohn Forte /*
2*fcf3ce44SJohn Forte  * CDDL HEADER START
3*fcf3ce44SJohn Forte  *
4*fcf3ce44SJohn Forte  * The contents of this file are subject to the terms of the
5*fcf3ce44SJohn Forte  * Common Development and Distribution License (the "License").
6*fcf3ce44SJohn Forte  * You may not use this file except in compliance with the License.
7*fcf3ce44SJohn Forte  *
8*fcf3ce44SJohn Forte  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*fcf3ce44SJohn Forte  * or http://www.opensolaris.org/os/licensing.
10*fcf3ce44SJohn Forte  * See the License for the specific language governing permissions
11*fcf3ce44SJohn Forte  * and limitations under the License.
12*fcf3ce44SJohn Forte  *
13*fcf3ce44SJohn Forte  * When distributing Covered Code, include this CDDL HEADER in each
14*fcf3ce44SJohn Forte  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*fcf3ce44SJohn Forte  * If applicable, add the following below this CDDL HEADER, with the
16*fcf3ce44SJohn Forte  * fields enclosed by brackets "[]" replaced with your own identifying
17*fcf3ce44SJohn Forte  * information: Portions Copyright [yyyy] [name of copyright owner]
18*fcf3ce44SJohn Forte  *
19*fcf3ce44SJohn Forte  * CDDL HEADER END
20*fcf3ce44SJohn Forte  */
21*fcf3ce44SJohn Forte /*
22*fcf3ce44SJohn Forte  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
23*fcf3ce44SJohn Forte  * Use is subject to license terms.
24*fcf3ce44SJohn Forte  */
25*fcf3ce44SJohn Forte 
26*fcf3ce44SJohn Forte #include <sys/types.h>
27*fcf3ce44SJohn Forte #include <stdio.h>
28*fcf3ce44SJohn Forte #include <sys/mnttab.h>
29*fcf3ce44SJohn Forte #include <errno.h>
30*fcf3ce44SJohn Forte #include <limits.h>
31*fcf3ce44SJohn Forte #include <fcntl.h>
32*fcf3ce44SJohn Forte #include <strings.h>
33*fcf3ce44SJohn Forte #include <stdlib.h>
34*fcf3ce44SJohn Forte #include <unistd.h>
35*fcf3ce44SJohn Forte #include <sys/stat.h>
36*fcf3ce44SJohn Forte #include <signal.h>
37*fcf3ce44SJohn Forte 
38*fcf3ce44SJohn Forte #include <locale.h>
39*fcf3ce44SJohn Forte #include <langinfo.h>
40*fcf3ce44SJohn Forte #include <libintl.h>
41*fcf3ce44SJohn Forte #include <stdarg.h>
42*fcf3ce44SJohn Forte #include <sys/nsctl/rdc_io.h>
43*fcf3ce44SJohn Forte #include <sys/nsctl/rdc_ioctl.h>
44*fcf3ce44SJohn Forte #include <sys/nsctl/rdc_prot.h>
45*fcf3ce44SJohn Forte 
46*fcf3ce44SJohn Forte #include <sys/nsctl/cfg.h>
47*fcf3ce44SJohn Forte 
48*fcf3ce44SJohn Forte #include <sys/unistat/spcs_s.h>
49*fcf3ce44SJohn Forte #include <sys/unistat/spcs_s_u.h>
50*fcf3ce44SJohn Forte #include <sys/unistat/spcs_errors.h>
51*fcf3ce44SJohn Forte 
52*fcf3ce44SJohn Forte #include "rdcadm.h"
53*fcf3ce44SJohn Forte 
54*fcf3ce44SJohn Forte 
55*fcf3ce44SJohn Forte int maxqfbas = MAXQFBAS;
56*fcf3ce44SJohn Forte int maxqitems = MAXQITEMS;
57*fcf3ce44SJohn Forte int autosync = AUTOSYNC;
58*fcf3ce44SJohn Forte int asyncthr = ASYNCTHR;
59*fcf3ce44SJohn Forte int qblock = QBLOCK;
60*fcf3ce44SJohn Forte 
61*fcf3ce44SJohn Forte int
62*fcf3ce44SJohn Forte mounted(char *device)
63*fcf3ce44SJohn Forte {
64*fcf3ce44SJohn Forte 	char target[NSC_MAXPATH];
65*fcf3ce44SJohn Forte 	struct mnttab mntref;
66*fcf3ce44SJohn Forte 	struct mnttab mntent;
67*fcf3ce44SJohn Forte 	FILE *mntfp;
68*fcf3ce44SJohn Forte 	int rdsk;
69*fcf3ce44SJohn Forte 	char *s;
70*fcf3ce44SJohn Forte 	int i;
71*fcf3ce44SJohn Forte 
72*fcf3ce44SJohn Forte 	rdsk = i = 0;
73*fcf3ce44SJohn Forte 	for (s = target; i < NSC_MAXPATH && (*s = *device++); i++) {
74*fcf3ce44SJohn Forte 		if (*s == 'r' && rdsk == 0 && strncmp(device, "dsk/", 4) == 0)
75*fcf3ce44SJohn Forte 			rdsk = 1;
76*fcf3ce44SJohn Forte 		else
77*fcf3ce44SJohn Forte 			s++;
78*fcf3ce44SJohn Forte 	}
79*fcf3ce44SJohn Forte 	*s = '\0';
80*fcf3ce44SJohn Forte 
81*fcf3ce44SJohn Forte 	mntref.mnt_special = target;
82*fcf3ce44SJohn Forte 	mntref.mnt_mountp = NULL;
83*fcf3ce44SJohn Forte 	mntref.mnt_fstype = NULL;
84*fcf3ce44SJohn Forte 	mntref.mnt_mntopts = NULL;
85*fcf3ce44SJohn Forte 	mntref.mnt_time = NULL;
86*fcf3ce44SJohn Forte 
87*fcf3ce44SJohn Forte 	mntfp = fopen(MNTTAB, "r");
88*fcf3ce44SJohn Forte 
89*fcf3ce44SJohn Forte 	if (mntfp == NULL) {
90*fcf3ce44SJohn Forte 		rdc_warn(NULL,
91*fcf3ce44SJohn Forte 			gettext("can not check volume %s against mount table"),
92*fcf3ce44SJohn Forte 			mntref.mnt_special);
93*fcf3ce44SJohn Forte 		/* Assume the worst, that it is mounted */
94*fcf3ce44SJohn Forte 		return (1);
95*fcf3ce44SJohn Forte 	}
96*fcf3ce44SJohn Forte 
97*fcf3ce44SJohn Forte 	if (getmntany(mntfp, &mntent, &mntref) != -1) {
98*fcf3ce44SJohn Forte 		/* found something before EOF */
99*fcf3ce44SJohn Forte 		(void) fclose(mntfp);
100*fcf3ce44SJohn Forte 		return (1);
101*fcf3ce44SJohn Forte 	}
102*fcf3ce44SJohn Forte 
103*fcf3ce44SJohn Forte 	(void) fclose(mntfp);
104*fcf3ce44SJohn Forte 	return (0);
105*fcf3ce44SJohn Forte }
106*fcf3ce44SJohn Forte 
107*fcf3ce44SJohn Forte 
108*fcf3ce44SJohn Forte /* Needs to match parsing code in rdcboot.c and rdcadm.c */
109*fcf3ce44SJohn Forte char *
110*fcf3ce44SJohn Forte rdc_decode_flag(int flag, int options)
111*fcf3ce44SJohn Forte {
112*fcf3ce44SJohn Forte 	static char str[32];
113*fcf3ce44SJohn Forte 
114*fcf3ce44SJohn Forte 	switch (flag) {
115*fcf3ce44SJohn Forte 	case (RDC_CMD_COPY):
116*fcf3ce44SJohn Forte 		if (options & RDC_OPT_FULL)
117*fcf3ce44SJohn Forte 			strcpy(str, "-m");
118*fcf3ce44SJohn Forte 		else
119*fcf3ce44SJohn Forte 			strcpy(str, "-u");
120*fcf3ce44SJohn Forte 		if (options & RDC_OPT_REVERSE)
121*fcf3ce44SJohn Forte 			strcat(str, " -r");
122*fcf3ce44SJohn Forte 		break;
123*fcf3ce44SJohn Forte 
124*fcf3ce44SJohn Forte 	case (RDC_CMD_DISABLE):
125*fcf3ce44SJohn Forte 		strcpy(str, "-d");
126*fcf3ce44SJohn Forte 		break;
127*fcf3ce44SJohn Forte 
128*fcf3ce44SJohn Forte 	case (RDC_CMD_ENABLE):
129*fcf3ce44SJohn Forte 		if (options & RDC_OPT_SETBMP)
130*fcf3ce44SJohn Forte 			strcpy(str, "-e");
131*fcf3ce44SJohn Forte 		else
132*fcf3ce44SJohn Forte 			strcpy(str, "-E");
133*fcf3ce44SJohn Forte 		break;
134*fcf3ce44SJohn Forte 
135*fcf3ce44SJohn Forte 	case (RDC_CMD_LOG):
136*fcf3ce44SJohn Forte 		strcpy(str, "-l");
137*fcf3ce44SJohn Forte 		break;
138*fcf3ce44SJohn Forte 
139*fcf3ce44SJohn Forte 	case (RDC_CMD_HEALTH):
140*fcf3ce44SJohn Forte 		strcpy(str, "-H");
141*fcf3ce44SJohn Forte 		break;
142*fcf3ce44SJohn Forte 
143*fcf3ce44SJohn Forte 	case (RDC_CMD_WAIT):
144*fcf3ce44SJohn Forte 		strcpy(str, "-w");
145*fcf3ce44SJohn Forte 		break;
146*fcf3ce44SJohn Forte 
147*fcf3ce44SJohn Forte 	case (RDC_CMD_RECONFIG):
148*fcf3ce44SJohn Forte 		strcpy(str, "-R ...");
149*fcf3ce44SJohn Forte 		break;
150*fcf3ce44SJohn Forte 
151*fcf3ce44SJohn Forte 	case (RDC_CMD_TUNABLE):
152*fcf3ce44SJohn Forte 		strcpy(str, "");
153*fcf3ce44SJohn Forte 		if (maxqfbas != MAXQFBAS)
154*fcf3ce44SJohn Forte 			strcat(str, " -F");
155*fcf3ce44SJohn Forte 		if (maxqitems != MAXQITEMS)
156*fcf3ce44SJohn Forte 			strcat(str, " -W");
157*fcf3ce44SJohn Forte 		if (autosync != AUTOSYNC)
158*fcf3ce44SJohn Forte 			strcat(str, " -a");
159*fcf3ce44SJohn Forte 		if (asyncthr != ASYNCTHR)
160*fcf3ce44SJohn Forte 			strcat(str, " -A");
161*fcf3ce44SJohn Forte 		if (qblock != QBLOCK)
162*fcf3ce44SJohn Forte 			strcat(str, " -D");
163*fcf3ce44SJohn Forte 		break;
164*fcf3ce44SJohn Forte 
165*fcf3ce44SJohn Forte 	case (RDC_CMD_SUSPEND):
166*fcf3ce44SJohn Forte 		strcpy(str, "-s");
167*fcf3ce44SJohn Forte 		break;
168*fcf3ce44SJohn Forte 
169*fcf3ce44SJohn Forte 	case (RDC_CMD_RESUME):
170*fcf3ce44SJohn Forte 		strcpy(str, "-r");
171*fcf3ce44SJohn Forte 		break;
172*fcf3ce44SJohn Forte 
173*fcf3ce44SJohn Forte 	case (RDC_CMD_RESET):
174*fcf3ce44SJohn Forte 		strcpy(str, "-R");
175*fcf3ce44SJohn Forte 		break;
176*fcf3ce44SJohn Forte 
177*fcf3ce44SJohn Forte 	case (RDC_CMD_ADDQ):
178*fcf3ce44SJohn Forte 		strcpy(str, "-q a");
179*fcf3ce44SJohn Forte 		break;
180*fcf3ce44SJohn Forte 
181*fcf3ce44SJohn Forte 	case (RDC_CMD_REMQ):
182*fcf3ce44SJohn Forte 		strcpy(str, "-q d");
183*fcf3ce44SJohn Forte 		break;
184*fcf3ce44SJohn Forte 
185*fcf3ce44SJohn Forte 	case (RDC_CMD_REPQ):
186*fcf3ce44SJohn Forte 		strcpy(str, "-q r");
187*fcf3ce44SJohn Forte 		break;
188*fcf3ce44SJohn Forte 
189*fcf3ce44SJohn Forte 	default:
190*fcf3ce44SJohn Forte 		strcpy(str, gettext("unknown"));
191*fcf3ce44SJohn Forte 		break;
192*fcf3ce44SJohn Forte 	}
193*fcf3ce44SJohn Forte 
194*fcf3ce44SJohn Forte 	return (str);
195*fcf3ce44SJohn Forte }
196*fcf3ce44SJohn Forte 
197*fcf3ce44SJohn Forte 
198*fcf3ce44SJohn Forte static void
199*fcf3ce44SJohn Forte rdc_msg(char *prefix, spcs_s_info_t *status, char *string, va_list ap)
200*fcf3ce44SJohn Forte {
201*fcf3ce44SJohn Forte 	if (status) {
202*fcf3ce44SJohn Forte 		(void) fprintf(stderr, "Remote Mirror: %s\n", prefix);
203*fcf3ce44SJohn Forte 		spcs_s_report(*status, stderr);
204*fcf3ce44SJohn Forte 	} else {
205*fcf3ce44SJohn Forte 		(void) fprintf(stderr, "%s: %s: ", program, prefix);
206*fcf3ce44SJohn Forte 	}
207*fcf3ce44SJohn Forte 
208*fcf3ce44SJohn Forte 	if (string && *string != '\0') {
209*fcf3ce44SJohn Forte 		(void) vfprintf(stderr, string, ap);
210*fcf3ce44SJohn Forte 	}
211*fcf3ce44SJohn Forte 
212*fcf3ce44SJohn Forte 	(void) fprintf(stderr, "\n");
213*fcf3ce44SJohn Forte }
214*fcf3ce44SJohn Forte 
215*fcf3ce44SJohn Forte void
216*fcf3ce44SJohn Forte rdc_err(spcs_s_info_t *status, char *string, ...)
217*fcf3ce44SJohn Forte {
218*fcf3ce44SJohn Forte 	va_list ap;
219*fcf3ce44SJohn Forte 	va_start(ap, string);
220*fcf3ce44SJohn Forte 
221*fcf3ce44SJohn Forte 	rdc_msg(gettext("Error"), status, string, ap);
222*fcf3ce44SJohn Forte 
223*fcf3ce44SJohn Forte 	va_end(ap);
224*fcf3ce44SJohn Forte 	exit(1);
225*fcf3ce44SJohn Forte }
226*fcf3ce44SJohn Forte 
227*fcf3ce44SJohn Forte void
228*fcf3ce44SJohn Forte rdc_warn(spcs_s_info_t *status, char *string, ...)
229*fcf3ce44SJohn Forte {
230*fcf3ce44SJohn Forte 	va_list ap;
231*fcf3ce44SJohn Forte 	va_start(ap, string);
232*fcf3ce44SJohn Forte 
233*fcf3ce44SJohn Forte 	rdc_msg(gettext("warning"), status, string, ap);
234*fcf3ce44SJohn Forte 
235*fcf3ce44SJohn Forte 	va_end(ap);
236*fcf3ce44SJohn Forte }
237*fcf3ce44SJohn Forte 
238*fcf3ce44SJohn Forte int
239*fcf3ce44SJohn Forte rdc_get_maxsets(void)
240*fcf3ce44SJohn Forte {
241*fcf3ce44SJohn Forte 	rdc_status_t rdc_status;
242*fcf3ce44SJohn Forte 	spcs_s_info_t ustatus;
243*fcf3ce44SJohn Forte 	int rc;
244*fcf3ce44SJohn Forte 
245*fcf3ce44SJohn Forte 	rdc_status.nset = 0;
246*fcf3ce44SJohn Forte 	ustatus = spcs_s_ucreate();
247*fcf3ce44SJohn Forte 
248*fcf3ce44SJohn Forte 	rc = RDC_IOCTL(RDC_STATUS, &rdc_status, 0, 0, 0, 0, ustatus);
249*fcf3ce44SJohn Forte 	if (rc == SPCS_S_ERROR) {
250*fcf3ce44SJohn Forte 		rdc_err(&ustatus, gettext("statistics error"));
251*fcf3ce44SJohn Forte 	}
252*fcf3ce44SJohn Forte 
253*fcf3ce44SJohn Forte 	spcs_s_ufree(&ustatus);
254*fcf3ce44SJohn Forte 	return (rdc_status.maxsets);
255*fcf3ce44SJohn Forte }
256*fcf3ce44SJohn Forte 
257*fcf3ce44SJohn Forte /*
258*fcf3ce44SJohn Forte  * Look up a set in libcfg to find the setnumber.
259*fcf3ce44SJohn Forte  *
260*fcf3ce44SJohn Forte  * ASSUMPTIONS:
261*fcf3ce44SJohn Forte  *      - a valid cfg handle
262*fcf3ce44SJohn Forte  *
263*fcf3ce44SJohn Forte  * INPUTS:
264*fcf3ce44SJohn Forte  *      cfg - cfg handle
265*fcf3ce44SJohn Forte  *      tohost - secondary hostname
266*fcf3ce44SJohn Forte  *      tofile - secondary volume
267*fcf3ce44SJohn Forte  *
268*fcf3ce44SJohn Forte  * OUTPUTS:
269*fcf3ce44SJohn Forte  *      set number if found, otherwise -1 for an error
270*fcf3ce44SJohn Forte  */
271*fcf3ce44SJohn Forte int
272*fcf3ce44SJohn Forte find_setnumber_in_libcfg(CFGFILE *cfg, char *ctag, char *tohost, char *tofile)
273*fcf3ce44SJohn Forte {
274*fcf3ce44SJohn Forte 	int setnumber;
275*fcf3ce44SJohn Forte 	int entries, rc;
276*fcf3ce44SJohn Forte 	char *buf, *secondary, *shost;
277*fcf3ce44SJohn Forte 	char **entry;
278*fcf3ce44SJohn Forte 	char *cnode;
279*fcf3ce44SJohn Forte 	int offset = 0;
280*fcf3ce44SJohn Forte 
281*fcf3ce44SJohn Forte 	if (cfg == NULL) {
282*fcf3ce44SJohn Forte #ifdef DEBUG
283*fcf3ce44SJohn Forte 		rdc_warn(NULL, "cfg is NULL while looking up set number");
284*fcf3ce44SJohn Forte #endif
285*fcf3ce44SJohn Forte 		return (-1);
286*fcf3ce44SJohn Forte 	}
287*fcf3ce44SJohn Forte 
288*fcf3ce44SJohn Forte 	entries = cfg_get_section(cfg, &entry, "sndr");
289*fcf3ce44SJohn Forte 
290*fcf3ce44SJohn Forte 	rc = -1;
291*fcf3ce44SJohn Forte 	for (setnumber = 1; setnumber <= entries; setnumber++) {
292*fcf3ce44SJohn Forte 		buf = entry[setnumber - 1];
293*fcf3ce44SJohn Forte 
294*fcf3ce44SJohn Forte 		(void) strtok(buf, " ");	/* phost */
295*fcf3ce44SJohn Forte 		(void) strtok(NULL, " ");	/* primary */
296*fcf3ce44SJohn Forte 		(void) strtok(NULL, " ");	/* pbitmap */
297*fcf3ce44SJohn Forte 		shost = strtok(NULL, " ");
298*fcf3ce44SJohn Forte 		secondary = strtok(NULL, " ");
299*fcf3ce44SJohn Forte 
300*fcf3ce44SJohn Forte 		if (ctag && *ctag) {
301*fcf3ce44SJohn Forte 			(void) strtok(NULL, " ");	/* sbitmap */
302*fcf3ce44SJohn Forte 			(void) strtok(NULL, " ");	/* type */
303*fcf3ce44SJohn Forte 			(void) strtok(NULL, " ");	/* mode */
304*fcf3ce44SJohn Forte 			(void) strtok(NULL, " ");	/* group */
305*fcf3ce44SJohn Forte 			cnode = strtok(NULL, " ");
306*fcf3ce44SJohn Forte 
307*fcf3ce44SJohn Forte 			if (ctag && strcmp(cnode, ctag) != 0) {
308*fcf3ce44SJohn Forte 				/* filter this out */
309*fcf3ce44SJohn Forte 				++offset;
310*fcf3ce44SJohn Forte 				continue;
311*fcf3ce44SJohn Forte 			}
312*fcf3ce44SJohn Forte 		}
313*fcf3ce44SJohn Forte 
314*fcf3ce44SJohn Forte 		/* Check secondary volume name first, will get less hits */
315*fcf3ce44SJohn Forte 		if (strcmp(secondary, tofile) != 0) {
316*fcf3ce44SJohn Forte 			free(buf);
317*fcf3ce44SJohn Forte 			continue;
318*fcf3ce44SJohn Forte 		}
319*fcf3ce44SJohn Forte 
320*fcf3ce44SJohn Forte 		if (strcmp(shost, tohost) == 0) {
321*fcf3ce44SJohn Forte 			free(buf);
322*fcf3ce44SJohn Forte 			rc = setnumber - offset;
323*fcf3ce44SJohn Forte 			break;
324*fcf3ce44SJohn Forte 		}
325*fcf3ce44SJohn Forte 
326*fcf3ce44SJohn Forte 		free(buf);
327*fcf3ce44SJohn Forte 	}
328*fcf3ce44SJohn Forte 
329*fcf3ce44SJohn Forte 	while (setnumber < entries)
330*fcf3ce44SJohn Forte 		free(entry[setnumber++]);
331*fcf3ce44SJohn Forte 	if (entries)
332*fcf3ce44SJohn Forte 		free(entry);
333*fcf3ce44SJohn Forte 
334*fcf3ce44SJohn Forte 	return (rc);
335*fcf3ce44SJohn Forte }
336*fcf3ce44SJohn Forte 
337*fcf3ce44SJohn Forte void
338*fcf3ce44SJohn Forte get_group_diskq(CFGFILE *cfg, char *group, char *diskq)
339*fcf3ce44SJohn Forte {
340*fcf3ce44SJohn Forte 	int i;
341*fcf3ce44SJohn Forte 	char key[CFG_MAX_KEY];
342*fcf3ce44SJohn Forte 	char buf[CFG_MAX_BUF];
343*fcf3ce44SJohn Forte 
344*fcf3ce44SJohn Forte 	if (*group == '\0')
345*fcf3ce44SJohn Forte 		return;
346*fcf3ce44SJohn Forte 	for (i = 1; ; i++) {
347*fcf3ce44SJohn Forte 		bzero(&key, sizeof (key));
348*fcf3ce44SJohn Forte 		bzero(&buf, sizeof (buf));
349*fcf3ce44SJohn Forte 		(void) sprintf(key, "sndr.set%d.group", i);
350*fcf3ce44SJohn Forte 		if (cfg_get_cstring(cfg, key, &buf, sizeof (buf)) < 0)
351*fcf3ce44SJohn Forte 			break;
352*fcf3ce44SJohn Forte 		if (strncmp(group, buf, sizeof (buf)) == 0) {
353*fcf3ce44SJohn Forte 			(void) sprintf(key, "sndr.set%d.diskq", i);
354*fcf3ce44SJohn Forte 			if (cfg_get_cstring(cfg, key, diskq, CFG_MAX_BUF) < 0) {
355*fcf3ce44SJohn Forte 				rdc_warn(NULL, gettext("unable to retrieve "
356*fcf3ce44SJohn Forte 				    "group %s's disk queue"), group);
357*fcf3ce44SJohn Forte 			}
358*fcf3ce44SJohn Forte 		}
359*fcf3ce44SJohn Forte 	}
360*fcf3ce44SJohn Forte }
361*fcf3ce44SJohn Forte 
362*fcf3ce44SJohn Forte int
363*fcf3ce44SJohn Forte get_cfg_setid(CFGFILE *cfg, char *ctag, char *tohost, char *tofile)
364*fcf3ce44SJohn Forte {
365*fcf3ce44SJohn Forte 	int setnum = 0;
366*fcf3ce44SJohn Forte 	int close_cfg = 0;
367*fcf3ce44SJohn Forte 	char key[CFG_MAX_KEY];
368*fcf3ce44SJohn Forte 	char setid[64];
369*fcf3ce44SJohn Forte 
370*fcf3ce44SJohn Forte 	if (cfg == NULL) {
371*fcf3ce44SJohn Forte 		close_cfg = 1;
372*fcf3ce44SJohn Forte 		if ((cfg = cfg_open(NULL)) == NULL) {
373*fcf3ce44SJohn Forte 			return (-1); /* message printed by caller */
374*fcf3ce44SJohn Forte 		}
375*fcf3ce44SJohn Forte 		if (!cfg_lock(cfg, CFG_RDLOCK)) {
376*fcf3ce44SJohn Forte 			cfg_close(cfg);
377*fcf3ce44SJohn Forte 			return (-1);
378*fcf3ce44SJohn Forte 		}
379*fcf3ce44SJohn Forte 	}
380*fcf3ce44SJohn Forte 	setnum = find_setnumber_in_libcfg(cfg, ctag, tohost, tofile);
381*fcf3ce44SJohn Forte 	if (setnum < 0)
382*fcf3ce44SJohn Forte 		return (setnum);
383*fcf3ce44SJohn Forte 
384*fcf3ce44SJohn Forte 	(void) snprintf(key, CFG_MAX_KEY, "sndr.set%d.options", setnum);
385*fcf3ce44SJohn Forte 	if (cfg_get_single_option(cfg, CFG_SEC_CONF, key, "setid",
386*fcf3ce44SJohn Forte 		    setid, sizeof (setid)) < 0) {
387*fcf3ce44SJohn Forte 		if (close_cfg)
388*fcf3ce44SJohn Forte 			cfg_close(cfg);
389*fcf3ce44SJohn Forte 
390*fcf3ce44SJohn Forte 		spcs_log("sndr", NULL,
391*fcf3ce44SJohn Forte 		    gettext("%s unable to get unique setid "
392*fcf3ce44SJohn Forte 		    "for %s:%s"), program, tohost, tofile);
393*fcf3ce44SJohn Forte 		return (-1);
394*fcf3ce44SJohn Forte 
395*fcf3ce44SJohn Forte 	}
396*fcf3ce44SJohn Forte 	if (close_cfg)
397*fcf3ce44SJohn Forte 		cfg_close(cfg);
398*fcf3ce44SJohn Forte 
399*fcf3ce44SJohn Forte 	return (atoi(setid));
400*fcf3ce44SJohn Forte 
401*fcf3ce44SJohn Forte }
402*fcf3ce44SJohn Forte 
403*fcf3ce44SJohn Forte int
404*fcf3ce44SJohn Forte get_new_cfg_setid(CFGFILE *cfg)
405*fcf3ce44SJohn Forte {
406*fcf3ce44SJohn Forte 	int setid;
407*fcf3ce44SJohn Forte 	char buf[CFG_MAX_BUF];
408*fcf3ce44SJohn Forte 	char *ctag;
409*fcf3ce44SJohn Forte 
410*fcf3ce44SJohn Forte 	/* If in a Sun Cluster, SetIDs need to have a ctag */
411*fcf3ce44SJohn Forte 	if ((ctag = cfg_get_resource(cfg)) != NULL) {
412*fcf3ce44SJohn Forte 		ctag = strdup(ctag);
413*fcf3ce44SJohn Forte 		cfg_resource(cfg, "setid-ctag");
414*fcf3ce44SJohn Forte 	}
415*fcf3ce44SJohn Forte 
416*fcf3ce44SJohn Forte 	if (cfg_get_cstring(cfg, "setid.set1.value", buf, CFG_MAX_BUF) < 0) {
417*fcf3ce44SJohn Forte 		setid = 1;
418*fcf3ce44SJohn Forte 		if (cfg_put_cstring(cfg, "setid", "1", CFG_MAX_BUF) < 0) {
419*fcf3ce44SJohn Forte 			rdc_err(NULL, "Unable to store new setid");
420*fcf3ce44SJohn Forte 		}
421*fcf3ce44SJohn Forte 	} else {
422*fcf3ce44SJohn Forte 		setid = atoi(buf);
423*fcf3ce44SJohn Forte 		setid++;
424*fcf3ce44SJohn Forte 		if (setid <= 0) {
425*fcf3ce44SJohn Forte 			setid = 1;
426*fcf3ce44SJohn Forte 		}
427*fcf3ce44SJohn Forte 	}
428*fcf3ce44SJohn Forte 
429*fcf3ce44SJohn Forte 	bzero(&buf, CFG_MAX_BUF);
430*fcf3ce44SJohn Forte 	(void) snprintf(buf, sizeof (buf), "%d", setid);
431*fcf3ce44SJohn Forte 	if (cfg_put_cstring(cfg, "setid.set1.value", buf, CFG_MAX_BUF) < 0) {
432*fcf3ce44SJohn Forte 		rdc_err(NULL, "Unable to store new setid");
433*fcf3ce44SJohn Forte 	}
434*fcf3ce44SJohn Forte 
435*fcf3ce44SJohn Forte 	/* Restore old ctag if in a Sun Cluster */
436*fcf3ce44SJohn Forte 	if (ctag) {
437*fcf3ce44SJohn Forte 		cfg_resource(cfg, ctag);
438*fcf3ce44SJohn Forte 		free(ctag);
439*fcf3ce44SJohn Forte 	}
440*fcf3ce44SJohn Forte 
441*fcf3ce44SJohn Forte 	return (setid);
442*fcf3ce44SJohn Forte }
443*fcf3ce44SJohn Forte 
444*fcf3ce44SJohn Forte sigset_t origmask;
445*fcf3ce44SJohn Forte 
446*fcf3ce44SJohn Forte void
447*fcf3ce44SJohn Forte block_sigs(void)
448*fcf3ce44SJohn Forte {
449*fcf3ce44SJohn Forte 	sigset_t allsigs;
450*fcf3ce44SJohn Forte 
451*fcf3ce44SJohn Forte 	sigfillset(&allsigs);
452*fcf3ce44SJohn Forte 	if (sigprocmask(SIG_BLOCK, &allsigs, &origmask) < 0)
453*fcf3ce44SJohn Forte 		rdc_warn(NULL, gettext("Unable to block signals"));
454*fcf3ce44SJohn Forte }
455*fcf3ce44SJohn Forte 
456*fcf3ce44SJohn Forte void
457*fcf3ce44SJohn Forte unblock_sigs(void)
458*fcf3ce44SJohn Forte {
459*fcf3ce44SJohn Forte 	if (sigprocmask(SIG_SETMASK, &origmask, NULL) < 0)
460*fcf3ce44SJohn Forte 		rdc_warn(NULL, gettext("Unable to unblock signals"));
461*fcf3ce44SJohn Forte 
462*fcf3ce44SJohn Forte }
463