void init_host_list(void) { host_list = calloc(1, sizeof (host_list_t)); if (host_list == NULL) { spcs_log("sndr", NULL, gettext("host list not initialized, cannot run")); rdc_err(NULL, gettext("host list not initialized, cannot run")); } (void) mutex_init(&host_list->hosts_mutex, USYNC_THREAD, NULL); }
int get_new_cfg_setid(CFGFILE *cfg) { int setid; char buf[CFG_MAX_BUF]; char *ctag; /* If in a Sun Cluster, SetIDs need to have a ctag */ if ((ctag = cfg_get_resource(cfg)) != NULL) { ctag = strdup(ctag); cfg_resource(cfg, "setid-ctag"); } if (cfg_get_cstring(cfg, "setid.set1.value", buf, CFG_MAX_BUF) < 0) { setid = 1; if (cfg_put_cstring(cfg, "setid", "1", CFG_MAX_BUF) < 0) { rdc_err(NULL, "Unable to store new setid"); } } else { setid = atoi(buf); setid++; if (setid <= 0) { setid = 1; } } bzero(&buf, CFG_MAX_BUF); (void) snprintf(buf, sizeof (buf), "%d", setid); if (cfg_put_cstring(cfg, "setid.set1.value", buf, CFG_MAX_BUF) < 0) { rdc_err(NULL, "Unable to store new setid"); } /* Restore old ctag if in a Sun Cluster */ if (ctag) { cfg_resource(cfg, ctag); free(ctag); } return (setid); }
int rdc_get_maxsets(void) { rdc_status_t rdc_status; spcs_s_info_t ustatus; int rc; rdc_status.nset = 0; ustatus = spcs_s_ucreate(); rc = RDC_IOCTL(RDC_STATUS, &rdc_status, 0, 0, 0, 0, ustatus); if (rc == SPCS_S_ERROR) { rdc_err(&ustatus, gettext("statistics error")); } spcs_s_ufree(&ustatus); return (rdc_status.maxsets); }
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); }