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