void unblock_sigs(void) { if (sigprocmask(SIG_SETMASK, &origmask, NULL) < 0) rdc_warn(NULL, gettext("Unable to unblock signals")); }
void block_sigs(void) { sigset_t allsigs; (void) sigfillset(&allsigs); if (sigprocmask(SIG_BLOCK, &allsigs, &origmask) < 0) rdc_warn(NULL, gettext("Unable to block signals")); }
int mounted(char *device) { char target[NSC_MAXPATH]; struct mnttab mntref; struct mnttab mntent; FILE *mntfp; int rdsk; char *s; int i; rdsk = i = 0; for (s = target; i < NSC_MAXPATH && (*s = *device++); i++) { if (*s == 'r' && rdsk == 0 && strncmp(device, "dsk/", 4) == 0) rdsk = 1; else s++; } *s = '\0'; mntref.mnt_special = target; mntref.mnt_mountp = NULL; mntref.mnt_fstype = NULL; mntref.mnt_mntopts = NULL; mntref.mnt_time = NULL; mntfp = fopen(MNTTAB, "r"); if (mntfp == NULL) { rdc_warn(NULL, gettext("can not check volume %s against mount table"), mntref.mnt_special); /* Assume the worst, that it is mounted */ return (1); } if (getmntany(mntfp, &mntent, &mntref) != -1) { /* found something before EOF */ (void) fclose(mntfp); return (1); } (void) fclose(mntfp); return (0); }
void get_group_diskq(CFGFILE *cfg, char *group, char *diskq) { int i; char key[CFG_MAX_KEY]; char buf[CFG_MAX_BUF]; if (*group == '\0') return; for (i = 1; ; i++) { bzero(&key, sizeof (key)); bzero(&buf, sizeof (buf)); (void) sprintf(key, "sndr.set%d.group", i); if (cfg_get_cstring(cfg, key, &buf, sizeof (buf)) < 0) break; if (strncmp(group, buf, sizeof (buf)) == 0) { (void) sprintf(key, "sndr.set%d.diskq", i); if (cfg_get_cstring(cfg, key, diskq, CFG_MAX_BUF) < 0) { rdc_warn(NULL, gettext("unable to retrieve " "group %s's disk queue"), group); } } } }
/* * Look up a set in libcfg to find the setnumber. * * ASSUMPTIONS: * - a valid cfg handle * * INPUTS: * cfg - cfg handle * tohost - secondary hostname * tofile - secondary volume * * OUTPUTS: * set number if found, otherwise -1 for an error */ int find_setnumber_in_libcfg(CFGFILE *cfg, char *ctag, char *tohost, char *tofile) { int setnumber; int entries, rc; char *buf, *secondary, *shost; char **entry; char *cnode; int offset = 0; if (cfg == NULL) { #ifdef DEBUG rdc_warn(NULL, "cfg is NULL while looking up set number"); #endif return (-1); } entries = cfg_get_section(cfg, &entry, "sndr"); rc = -1; for (setnumber = 1; setnumber <= entries; setnumber++) { buf = entry[setnumber - 1]; (void) strtok(buf, " "); /* phost */ (void) strtok(NULL, " "); /* primary */ (void) strtok(NULL, " "); /* pbitmap */ shost = strtok(NULL, " "); secondary = strtok(NULL, " "); if (ctag && *ctag) { (void) strtok(NULL, " "); /* sbitmap */ (void) strtok(NULL, " "); /* type */ (void) strtok(NULL, " "); /* mode */ (void) strtok(NULL, " "); /* group */ cnode = strtok(NULL, " "); if (ctag && strcmp(cnode, ctag) != 0) { /* filter this out */ ++offset; continue; } } /* Check secondary volume name first, will get less hits */ if (strcmp(secondary, tofile) != 0) { free(buf); continue; } if (strcmp(shost, tohost) == 0) { free(buf); rc = setnumber - offset; break; } free(buf); } while (setnumber < entries) free(entry[setnumber++]); if (entries) free(entry); return (rc); }
int main(int argc, char *argv[]) #endif { char fromhost[MAX_RDC_HOST_SIZE]; char tohost[MAX_RDC_HOST_SIZE]; char fromfile[NSC_MAXPATH]; char tofile[NSC_MAXPATH]; char frombitmap[NSC_MAXPATH]; char tobitmap[NSC_MAXPATH]; char directfile[NSC_MAXPATH]; char diskqueue[NSC_MAXPATH]; char group[NSC_MAXPATH]; char lhost[MAX_RDC_HOST_SIZE]; int pairs; int pid; int flag = 0; int doasync; int rc; char *required; int setid; (void) setlocale(LC_ALL, ""); (void) textdomain("rdc"); program = basename(argv[0]); rc = rdc_check_release(&required); if (rc < 0) { rdc_err(NULL, gettext("unable to determine the current " "Solaris release: %s\n"), strerror(errno)); } else if (rc == FALSE) { rdc_err(NULL, gettext("incorrect Solaris release (requires %s)\n"), required); } rdc_maxsets = rdc_get_maxsets(); if (rdc_maxsets == -1) { spcs_log("sndr", NULL, gettext("%s unable to get maxsets value from kernel"), program); rdc_err(NULL, gettext("unable to get maxsets value from kernel")); } pair_list = calloc(rdc_maxsets, sizeof (*pair_list)); if (pair_list == NULL) { rdc_err(NULL, gettext( "unable to allocate pair_list" " array for %d sets"), rdc_maxsets); } if (parseopts(argc, argv, &flag)) return (1); pairs = read_libcfg(flag); if (flag == RDC_CMD_FIXSETIDS) { if (pairs) { spcs_log("sndr", NULL, gettext("Fixed %d Remote Mirror" " set IDs"), pairs); #ifdef DEBUG rdc_warn(NULL, gettext("Fixed %d Remote Mirror set " "IDs"), pairs); #endif } return (0); } if (pairs == 0) { #ifdef DEBUG rdc_err(NULL, gettext("Config contains no dual copy sets")); #else return (0); #endif } while (pairs--) { pid = fork(); if (pid == -1) { /* error forking */ perror("fork"); continue; } if (pid > 0) /* this is parent process */ continue; /* * At this point, this is the child process. Do the operation */ strncpy(fromfile, pair_list[pairs].ffile, NSC_MAXPATH); strncpy(tofile, pair_list[pairs].tfile, NSC_MAXPATH); strncpy(frombitmap, pair_list[pairs].fbitmap, NSC_MAXPATH); strncpy(fromhost, pair_list[pairs].fhost, MAX_RDC_HOST_SIZE); strncpy(tohost, pair_list[pairs].thost, MAX_RDC_HOST_SIZE); strncpy(tobitmap, pair_list[pairs].tbitmap, NSC_MAXPATH); strncpy(directfile, pair_list[pairs].directfile, NSC_MAXPATH); strncpy(diskqueue, pair_list[pairs].diskqueue, NSC_MAXPATH); strncpy(group, pair_list[pairs].group, NSC_MAXPATH); strncpy(lhost, pair_list[pairs].lhost, MAX_RDC_HOST_SIZE); doasync = pair_list[pairs].doasync; setid = pair_list[pairs].setid; if (rdc_operation(fromhost, fromfile, frombitmap, tohost, tofile, tobitmap, flag, directfile, group, diskqueue, doasync, lhost, setid) < 0) { exit(255); } exit(0); } while ((wait((int *)0) > 0)) ; return (0); }