📄 smpd_connect.c
字号:
fprintf(stderr, "MPICH2 is unable to manage jobs using credentials with a blank password.\nPlease enter another account.\n"); } } while (strlen(password) == 0); smpd_exit_fn(FCNAME);}#undef FCNAME#define FCNAME "smpd_get_credentials_from_parent"int smpd_get_credentials_from_parent(MPIDU_Sock_set_t set, MPIDU_Sock_t sock){ smpd_enter_fn(FCNAME); SMPD_UNREFERENCED_ARG(set); SMPD_UNREFERENCED_ARG(sock); smpd_exit_fn(FCNAME); return SMPD_FAIL;}#undef FCNAME#define FCNAME "smpd_get_smpd_password_from_parent"int smpd_get_smpd_password_from_parent(MPIDU_Sock_set_t set, MPIDU_Sock_t sock){ smpd_enter_fn(FCNAME); SMPD_UNREFERENCED_ARG(set); SMPD_UNREFERENCED_ARG(sock); smpd_exit_fn(FCNAME); return SMPD_FAIL;}#undef FCNAME#define FCNAME "smpd_get_default_hosts"int smpd_get_default_hosts(){ char hosts[8192]; char *host; char *ncpu; smpd_host_node_t *cur_host, *iter;#ifdef HAVE_WINDOWS_H DWORD len;#else int dynamic = SMPD_FALSE; char myhostname[SMPD_MAX_HOST_LENGTH]; int found;#endif smpd_enter_fn(FCNAME); if (smpd_process.default_host_list != NULL && smpd_process.cur_default_host != NULL) { smpd_dbg_printf("default list already populated, returning success.\n"); smpd_exit_fn(FCNAME); return SMPD_SUCCESS; } if (smpd_get_smpd_data("hosts", hosts, 8192) != SMPD_SUCCESS) {#ifdef HAVE_WINDOWS_H len = 8192; /*if (GetComputerName(hosts, &len))*/ if (GetComputerNameEx(ComputerNameDnsFullyQualified, hosts, &len)) { smpd_process.default_host_list = (smpd_host_node_t*)malloc(sizeof(smpd_host_node_t)); if (smpd_process.default_host_list == NULL) { smpd_exit_fn(FCNAME); return SMPD_FAIL; } strcpy(smpd_process.default_host_list->host, hosts); smpd_process.default_host_list->alt_host[0] = '\0'; smpd_process.default_host_list->nproc = 1; smpd_process.default_host_list->connected = SMPD_FALSE; smpd_process.default_host_list->connect_cmd_tag = -1; smpd_process.default_host_list->next = smpd_process.default_host_list; smpd_process.default_host_list->left = NULL; smpd_process.default_host_list->right = NULL; smpd_process.cur_default_host = smpd_process.default_host_list; smpd_exit_fn(FCNAME); return SMPD_SUCCESS; } smpd_exit_fn(FCNAME); return SMPD_FAIL;#else if (smpd_option_on("no_dynamic_hosts")) { if (smpd_get_hostname(myhostname, SMPD_MAX_HOST_LENGTH) == SMPD_SUCCESS) { smpd_process.default_host_list = (smpd_host_node_t*)MPIU_Malloc(sizeof(smpd_host_node_t)); if (smpd_process.default_host_list == NULL) { smpd_exit_fn(FCNAME); return SMPD_FAIL; } strcpy(smpd_process.default_host_list->host, myhostname); smpd_process.default_host_list->alt_host[0] = '\0'; smpd_process.default_host_list->nproc = 1; smpd_process.default_host_list->connected = SMPD_FALSE; smpd_process.default_host_list->connect_cmd_tag = -1; smpd_process.default_host_list->next = smpd_process.default_host_list; smpd_process.default_host_list->left = NULL; smpd_process.default_host_list->right = NULL; smpd_process.cur_default_host = smpd_process.default_host_list; smpd_exit_fn(FCNAME); return SMPD_SUCCESS; } smpd_exit_fn(FCNAME); return SMPD_FAIL; } smpd_lock_smpd_data(); if (smpd_get_smpd_data(SMPD_DYNAMIC_HOSTS_KEY, hosts, 8192) != SMPD_SUCCESS) { smpd_unlock_smpd_data(); if (smpd_get_hostname(hosts, 8192) == 0) { smpd_process.default_host_list = (smpd_host_node_t*)MPIU_Malloc(sizeof(smpd_host_node_t)); if (smpd_process.default_host_list == NULL) { smpd_exit_fn(FCNAME); return SMPD_FAIL; } strcpy(smpd_process.default_host_list->host, hosts); smpd_process.default_host_list->alt_host[0] = '\0'; smpd_process.default_host_list->nproc = 1; smpd_process.default_host_list->connected = SMPD_FALSE; smpd_process.default_host_list->connect_cmd_tag = -1; smpd_process.default_host_list->next = smpd_process.default_host_list; smpd_process.default_host_list->left = NULL; smpd_process.default_host_list->right = NULL; smpd_process.cur_default_host = smpd_process.default_host_list; /* add this host to the dynamic_hosts key */ strcpy(myhostname, hosts); smpd_lock_smpd_data(); hosts[0] = '\0'; smpd_get_smpd_data(SMPD_DYNAMIC_HOSTS_KEY, hosts, 8192); if (strlen(hosts) > 0) { /* FIXME this could overflow */ strcat(hosts, " "); strcat(hosts, myhostname); } else { strcpy(hosts, myhostname); } smpd_set_smpd_data(SMPD_DYNAMIC_HOSTS_KEY, hosts); smpd_unlock_smpd_data(); smpd_exit_fn(FCNAME); return SMPD_SUCCESS; } smpd_exit_fn(FCNAME); return SMPD_FAIL; } smpd_unlock_smpd_data(); if (smpd_get_hostname(myhostname, SMPD_MAX_HOST_LENGTH) != 0) { dynamic = SMPD_FALSE; myhostname[0] = '\0'; } else { dynamic = SMPD_TRUE; }#endif } /* FIXME: Insert code here to parse a compressed host string */ /* For now, just use a space separated list of host names */ host = strtok(hosts, " \t\r\n"); while (host) { cur_host = (smpd_host_node_t*)MPIU_Malloc(sizeof(smpd_host_node_t)); if (cur_host != NULL) { /*printf("default host: %s\n", host);*/ strcpy(cur_host->host, host); cur_host->alt_host[0] = '\0'; cur_host->nproc = 1; ncpu = strstr(cur_host->host, ":"); if (ncpu) { *ncpu = '\0'; ncpu++; cur_host->nproc = atoi(ncpu); if (cur_host->nproc < 1) cur_host->nproc = 1; } cur_host->connected = SMPD_FALSE; cur_host->connect_cmd_tag = -1; cur_host->next = NULL; cur_host->left = NULL; cur_host->right = NULL; if (smpd_process.default_host_list == NULL) { smpd_process.default_host_list = cur_host; } else { iter = smpd_process.default_host_list; while (iter->next) iter = iter->next; iter->next = cur_host; } } host = strtok(NULL, " \t\r\n"); } if (smpd_process.default_host_list) {#ifndef HAVE_WINDOWS_H if (dynamic) { found = SMPD_FALSE; iter = smpd_process.default_host_list; while (iter) { if (strcmp(iter->host, myhostname) == 0) { found = SMPD_TRUE; break; } iter = iter->next; } if (!found) { /* add this host to the dynamic_hosts key */ smpd_lock_smpd_data(); hosts[0] = '\0'; smpd_get_smpd_data(SMPD_DYNAMIC_HOSTS_KEY, hosts, 8192); if (strlen(hosts) > 0) { /* FIXME this could overflow */ strcat(hosts, " "); strcat(hosts, myhostname); } else { strcpy(hosts, myhostname); } smpd_set_smpd_data(SMPD_DYNAMIC_HOSTS_KEY, hosts); smpd_unlock_smpd_data(); } }#endif /* make the default list into a ring */ iter = smpd_process.default_host_list; while (iter->next) iter = iter->next; iter->next = smpd_process.default_host_list; /* point the cur_default_host to the first node in the ring */ smpd_process.cur_default_host = smpd_process.default_host_list; } smpd_exit_fn(FCNAME); return SMPD_SUCCESS;}#undef FCNAME#define FCNAME "smpd_add_host_to_default_list"int smpd_add_host_to_default_list(const char *hostname){ int result; smpd_enter_fn(FCNAME); result = smpd_add_extended_host_to_default_list(hostname, NULL, 1); smpd_exit_fn(FCNAME); return result;}#undef FCNAME#define FCNAME "smpd_add_extended_host_to_default_list"int smpd_add_extended_host_to_default_list(const char *hostname, const char *alt_hostname, const int num_cpus){ smpd_host_node_t *iter; smpd_enter_fn(FCNAME); iter = smpd_process.default_host_list; if (iter == NULL) { smpd_process.default_host_list = (smpd_host_node_t*)MPIU_Malloc(sizeof(smpd_host_node_t)); if (smpd_process.default_host_list == NULL) { smpd_exit_fn(FCNAME); return SMPD_FAIL; } strcpy(smpd_process.default_host_list->host, hostname); smpd_process.default_host_list->alt_host[0] = '\0'; if (alt_hostname != NULL) { strcpy(smpd_process.default_host_list->alt_host, alt_hostname); } smpd_process.default_host_list->nproc = num_cpus; smpd_process.default_host_list->connected = SMPD_FALSE; smpd_process.default_host_list->connect_cmd_tag = -1; smpd_process.default_host_list->next = smpd_process.default_host_list; smpd_process.default_host_list->left = NULL; smpd_process.default_host_list->right = NULL; smpd_process.cur_default_host = smpd_process.default_host_list; smpd_exit_fn(FCNAME); return SMPD_SUCCESS; } if (strcmp(iter->host, hostname) == 0) { smpd_exit_fn(FCNAME); return SMPD_SUCCESS; } while (iter->next != NULL && iter->next != smpd_process.default_host_list) { iter = iter->next; if (strcmp(iter->host, hostname) == 0) { smpd_exit_fn(FCNAME); return SMPD_SUCCESS; } } iter->next = (smpd_host_node_t*)MPIU_Malloc(sizeof(smpd_host_node_t)); if (iter->next == NULL) { smpd_exit_fn(FCNAME); return SMPD_FAIL; } iter = iter->next; strcpy(iter->host, hostname); iter->alt_host[0] = '\0'; if (alt_hostname != NULL) { strcpy(iter->alt_host, alt_hostname); } iter->nproc = num_cpus; iter->connected = SMPD_FALSE; iter->connect_cmd_tag = -1; iter->next = smpd_process.default_host_list; iter->left = NULL; iter->right = NULL; smpd_exit_fn(FCNAME); return SMPD_SUCCESS;}#undef FCNAME#define FCNAME "smpd_insert_into_dynamic_hosts"int smpd_insert_into_dynamic_hosts(void){#ifndef HAVE_WINDOWS_H char myhostname[SMPD_MAX_HOST_LENGTH]; char hosts[8192]; char *host;#endif smpd_enter_fn(FCNAME);#ifndef HAVE_WINDOWS_H smpd_lock_smpd_data(); if (smpd_get_smpd_data(SMPD_DYNAMIC_HOSTS_KEY, hosts, 8192) != SMPD_SUCCESS) { if (smpd_get_hostname(hosts, 8192) == 0) { /* add this host to the dynamic_hosts key */ smpd_set_smpd_data(SMPD_DYNAMIC_HOSTS_KEY, hosts); smpd_unlock_smpd_data(); smpd_exit_fn(FCNAME); return SMPD_SUCCESS; } smpd_unlock_smpd_data(); smpd_exit_fn(FCNAME); return SMPD_FAIL; } smpd_unlock_smpd_data(); if (smpd_get_hostname(myhostname, SMPD_MAX_HOST_LENGTH) != 0) { smpd_exit_fn(FCNAME); return SMPD_FAIL; } /* check to see if the host is already in the key */ host = strtok(hosts, " \t\r\n"); while (host) { if (strcmp(host, myhostname) == 0) { smpd_exit_fn(FCNAME); return SMPD_SUCCESS; } host = strtok(NULL, " \t\r\n"); } /* add this host to the dynamic_hosts key */ smpd_lock_smpd_data(); hosts[0] = '\0'; if (smpd_get_smpd_data(SMPD_DYNAMIC_HOSTS_KEY, hosts, 8192) != SMPD_SUCCESS) { smpd_unlock_smpd_data(); smpd_exit_fn(FCNAME); return SMPD_FAIL; } if (strlen(hosts) > 0) { /* FIXME this could overflow */ strcat(hosts, " "); strcat(hosts, myhostname); } else { strcpy(hosts, myhostname); } smpd_set_smpd_data(SMPD_DYNAMIC_HOSTS_KEY, hosts); smpd_unlock_smpd_data();#endif smpd_exit_fn(FCNAME); return SMPD_SUCCESS;}#undef FCNAME#define FCNAME "smpd_remove_from_dynamic_hosts"int smpd_remove_from_dynamic_hosts(void){#ifndef HAVE_WINDOWS_H char myhostname[SMPD_MAX_HOST_LENGTH]; char hosts[8192]; char hosts_less_me[8192]; char *host;#endif smpd_enter_fn(FCNAME);#ifndef HAVE_WINDOWS_H if (smpd_get_hostname(myhostname, SMPD_MAX_HOST_LENGTH) != 0) { smpd_err_printf("smpd_get_hostname failed, errno = %d\n", errno); smpd_exit_fn(FCNAME); return SMPD_FAIL; } smpd_lock_smpd_data(); hosts[0] = '\0'; if (smpd_get_smpd_data(SMPD_DYNAMIC_HOSTS_KEY, hosts, 8192) != SMPD_SUCCESS) { smpd_unlock_smpd_data(); smpd_dbg_printf("not removing host because "SMPD_DYNAMIC_HOSTS_KEY" does not exist\n"); smpd_exit_fn(FCNAME); return SMPD_FAIL; } /* create a new hosts lists without this host name in it */ hosts_less_me[0] = '\0'; host = strtok(hosts, " \t\r\n"); while (host) { if (strcmp(host, myhostname)) { if (hosts_less_me[0] != '\0') strcat(hosts_less_me, " "); strcat(hosts_less_me, host); } host = strtok(NULL, " \t\r\n"); } if (hosts_less_me[0] == '\0') { smpd_dbg_printf("removing "SMPD_DYNAMIC_HOSTS_KEY"\n"); smpd_delete_smpd_data(SMPD_DYNAMIC_HOSTS_KEY); } else { smpd_dbg_printf("setting new "SMPD_DYNAMIC_HOSTS_KEY": %s\n", hosts_less_me); smpd_set_smpd_data(SMPD_DYNAMIC_HOSTS_KEY, hosts_less_me); } smpd_unlock_smpd_data();#endif smpd_exit_fn(FCNAME); return SMPD_SUCCESS;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -