int talk2Acq(char *hostname, char *username, int cmd, char *msg_for_acq, char *msg_for_vnmr, int mfv_len ) { #ifdef NESSIE int mlen; char msg[256]; int ival; CommPort acq_addr = &comm_addr[ACQ_COMM_ID]; CommPort tmp_from = &comm_addr[LOCAL_COMM_ID]; (void) msg_for_vnmr; (void) mfv_len; tmp_from->path[0] = '\0'; tmp_from->pid = getpid(); strcpy(tmp_from->host,hostname); set_comm_port(tmp_from); /* this call creates a socket */ mlen = strlen( cmd_for_acq[cmd] ) + strlen( tmp_from->path ) + strlen( msg_for_acq ) + 2; if (mlen > 255) { acq_errno = MSG_LEN_ERROR; fprintf( stderr, "talk2Acq error - message len: %d greater than 255\n",mlen ); return( -1 ); } sprintf(msg,"%s%c%s%c%s%c%s%c%d%c%s", cmd_for_acq[cmd], DELIMITER_1, tmp_from->path,DELIMITER_2, username,DELIMITER_3,hostname,DELIMITER_3,tmp_from->pid,DELIMITER_2, msg_for_acq); if (SendAsyncInova( acq_addr, tmp_from, msg ) != RET_OK) { close( tmp_from->msgesocket ); return( -1 ); } /* Use `select' to wait for Acqproc to respond to us. */ ival = wait_for_select( tmp_from->msgesocket, 20 ); if (ival < 1) { if (ival < 0) acq_errno = SELECT_ERROR; else if (ival == 0) acq_errno = CONNECT_ERROR; close( tmp_from->msgesocket ); return( -1 ); } ival = accept( tmp_from->msgesocket, 0, 0 ); close( tmp_from->msgesocket ); /* We are finished with */ /* the original socket. */ if (ival < 0) { acq_errno = ACCEPT_ERROR; return( -1 ); } else return( ival ); /* file descriptor for the connected socket. */ #endif }
void init_comm_port(char *hostval) { CommPort ptr = &comm_addr[VNMR_COMM_ID]; TPRINT0("init vnmr port \n"); strcpy(ptr->host,hostval); ptr->pid = getpid(); ptr->msg_uid = getuid(); seteuid( ptr->msg_uid ); set_comm_port(ptr); TPRINT3("vnmr pid=%d host=%s port=%d\n",ptr->pid,ptr->host,ptr->port); TPRINT1("vnmr path=%s\n",ptr->path); }
void setupVnmrAsync(void (*func)()) { struct sigaction intserv; sigset_t qmask; GPRINT0("setupVnmrAsync: called....\n"); set_comm_port( &comm_addr[VNMR_COMM_ID] ); sigemptyset( &qmask ); sigaddset( &qmask, SIGIO ); sigaddset( &qmask, SIGALRM ); sigaddset( &qmask, SIGCHLD ); /* --- set up signal handler --- */ intserv.sa_handler = func; intserv.sa_mask = qmask; intserv.sa_flags = 0; sigaction(SIGIO,&intserv,0L); }
bool Config::init_with_args(int ac, char** av, const std::vector<std::string>& customized, WorkerInfo* worker_info) { namespace po = boost::program_options; po::options_description generic_options("Generic options"); generic_options.add_options()("help,H", "print help message"); std::string config_file_path; po::options_description config_file_options("Configuration File"); config_file_options.add_options()("conf,C", po::value<std::string>(&config_file_path), "Configure file Path"); std::string master_host; int master_port; int comm_port; std::string log_dir; po::options_description required_options("Required options"); required_options.add_options()("master_host", po::value<std::string>(&master_host), "Master hostname")( "master_port", po::value<int>(&master_port), "Master port")( "comm_port", po::value<int>(&comm_port), "Communication port")("log_dir", po::value<std::string>(&log_dir), "Log directory"); po::options_description worker_info_options("Worker Info options"); worker_info_options.add_options()("worker.info", po::value<std::vector<std::string>>()->multitoken(), "Worker information.\nFormat is '%worker_hostname:%thread_number'.\nUse " "colon ':' as separator."); po::options_description worker_info_config("Worker Info from config"); worker_info_config.add_options()("worker.info", po::value<std::vector<std::string>>()->multitoken(), "Worker information.\nFormat is '%worker_hostname:%thread_number'.\nUse " "colon ':' as separator."); po::options_description customized_options("Customized options"); if (!customized.empty()) for (auto& arg : customized) customized_options.add_options()(arg.c_str(), po::value<std::string>(), ""); po::options_description cmdline_options; cmdline_options.add(generic_options).add(config_file_options).add(required_options).add(worker_info_options); po::options_description config_options; config_options.add(required_options).add(worker_info_config); if (!customized_options.options().empty()) { cmdline_options.add(customized_options); config_options.add(customized_options); } po::variables_map vm; po::store(po::command_line_parser(ac, av).options(cmdline_options).run(), vm); po::notify(vm); if (ac == 1 || vm.count("help")) { std::cout << "Usage:" << std::endl; std::cout << cmdline_options << std::endl; return false; } if (vm.count("conf")) { std::ifstream config_file(config_file_path.c_str()); if (!config_file) { LOG_E << "Can not open config file: " << config_file_path; return false; } // The configure in config_file would be overwritten by cmdline as parsing order. // For details, the interface is: // parse_config_file(const char * filename, const options_description &, // bool allow_unregistered = false) auto parsed_config_options = po::parse_config_file(config_file, config_options, true); po::store(parsed_config_options, vm); po::notify(vm); // Store what is not registered in customized_options. for (const auto& o : parsed_config_options.options) if (vm.find(o.string_key) == vm.end()) set_param(o.string_key, o.value.front()); // Only accept `key=value`. } int setup_all = 0; if (vm.count("master_host")) { set_master_host(master_host); setup_all += 1; } else { LOG_E << "arg master_host is needed"; } if (vm.count("master_port")) { set_master_port(master_port); setup_all += 1; } else { LOG_E << "arg master_port is needed"; } if (vm.count("comm_port")) { set_comm_port(comm_port); setup_all += 1; } else { LOG_E << "arg comm_port is needed"; } if (vm.count("log_dir")) set_log_dir(log_dir); if (vm.count("worker.info")) { std::string hostname = get_hostname(); int proc_id = -1; int num_workers = 0; int num_local_threads = 0; int num_global_threads = 0; std::vector<std::string> workers_info = vm["worker.info"].as<std::vector<std::string>>(); for (auto& w : workers_info) { std::size_t colon_pos = w.find(':'); if (colon_pos == std::string::npos || colon_pos == w.size() - 1) { // Cannot find colon ':' or lack number of threads. LOG_E << "arg worker.info '" + w + "' not match the format"; return false; } std::string worker_hostname = w.substr(0, colon_pos); machines_.insert(worker_hostname); int num_threads = std::stoi(w.substr(colon_pos + 1, w.size() - colon_pos - 1)); if (is_local(worker_hostname)) { num_local_threads = num_threads; proc_id = num_workers; } if (worker_info != nullptr) worker_info->set_hostname(num_workers, worker_hostname); for (int i = 0; i < num_threads; i++) { if (worker_info != nullptr) worker_info->add_worker(num_workers, num_global_threads, i); ++num_global_threads; } num_workers += 1; } if (worker_info != nullptr) worker_info->set_process_id(proc_id); set_param("hostname", hostname); setup_all += 1; } else { LOG_E << "arg worker.info is needed"; } if (!customized.empty()) { for (auto& arg : customized) if (vm.count(arg.c_str())) { set_param(arg, vm[arg.c_str()].as<std::string>()); setup_all += 1; } else { LOG_E << "arg " << arg << " is needed"; } } if (setup_all != customized.size() + 4) { LOG_E << "Please provide all necessary args!"; return false; } return true; }