bool VMGahpServer::command_async_mode_on(void) { static const char* command = "ASYNC_MODE_ON"; if( m_is_initialized == false ) { return false; } if( isSupportedCommand(command) == FALSE ) { return false; } if(write_line(command) == false) { return false; } // give some time to gahp server sleep(1); Gahp_Args result; if( read_argv(result) == false ) { return false; } if( result.argc == 0 || result.argv[0][0] != 'S' ) { dprintf(D_ALWAYS,"VMGAHP command '%s' failed\n",command); return false; } return true; }
bool VMGahpServer::command_quit(void) { static const char* command = "QUIT"; if( m_is_initialized == false ) { return false; } if(write_line(command) == false) { return false; } // give some time to gahp server sleep(1); Gahp_Args result; if( read_argv(result) == false ) { return false; } if( result.argc == 0 || result.argv[0][0] != 'S' ) { dprintf(D_ALWAYS,"VMGAHP command '%s' failed\n",command); return false; } return true; }
// ------------------------------------------------- int main(int argc, char *argv[]) { read_argv(argc, argv); getcwd(path_old, MAX_CHAR); //chdir("input"); /// Shrad made this change get_common_para(argv[2]); get_bas_info(argv[3]); if (((fcst_mn < 7) || (fcst_mn > 9)) && (fcst_type != 3)) op_calc_cum = 1; // calc seasonal cum flow during oct - jun. else {op_calc_cum = 0; op_calc_diff = 0;} //*chdir(".."); if (fcst_type == 1) { // need ENSO indexes and trace year information for ESP forecast read_enso_pdo_index(metyr0, metyr0 + MAX_METYR, mon0); read_hydro_trace_years(metyr0, metyr0 + MAX_METYR, mon0); } read_clim_stat(total_stn); if (op_read_data != 2) read_fcst_sflow(total_stn, total_mon, fcst_mn, fcst_dy, metyr0); else read_sav_data(total_stn, cur_fcst); //*chdir(path_work); update_bas_fcst_hist(cur_fcst); if (op_calc_diff) read_fcst_last(total_stn); srt_quart_fcst(total_stn, total_mon); if (fcst_type == 1) srt_quart_ESP_ENSO_PDO(total_stn, total_mon); // do ENSO statistics only for ESP forecast printf("\ncalculate cum flow and make stats...\n"); if (op_calc_cum) calc_cum_flow(total_stn, MN_IS_APR, total_mon_cum, 0, stn_cum_stat); else memset((void *)&stn_cum_stat[0][0], -1, sizeof(stn_cum_stat)); calc_cum_flow(total_stn, fcst_mn - mon0, 6, fcst_mn, stn_6mon_cum); write_stats(total_stn); //*chdir(path_old); printf("\njob finished!\n\n"); return(1); }
bool VMGahpServer::nowPending(const char *command, const char *args, VMGahpRequest *req) { if( m_is_initialized == false ) { return false; } if( !command || !req ) { return false; } int req_id; req_id = new_reqid(); if( req_id < 0 ) { return false; } //Set reqid req->setReqId(req_id); m_request_table.insert(req_id, req); req->setPendingStatus(REQ_SUBMITTED); // Write the command out to the gahp server. if(write_line(command,req_id,args) == false) { return false; } // give some time to gahp server sleep(1); Gahp_Args return_line; if( read_argv(return_line) == false ) { return false; } if( return_line.argc == 0 || return_line.argv[0][0] != 'S' ) { // Badness ! dprintf(D_ALWAYS,"Bad %s Request\n",command); return false; } return true; }
/** \brief Loads from opened Config file * \param fd Open config file, positioned at file start. * */ void elf_fromconf(int fd){ //Called for reading config struct admin_s params; ZERO_ADMINP(¶ms); params.core_start = 0; params.core_size = 1; /** Default verbosity, nice and LOUD */ params.verbose = VERB_TRACE+1; params.settings = 0; read_settings(fd, ¶ms); read_argv(fd, ¶ms); if (!params.fname) { #if ENABLE_DEBUG //Params have been read, it might have requested silence if (params.verbose > VERB_ERR){ locked_print_string("No filename in config to run\n", PRINTERR); } #endif /* ENABLE_DEBUG */ return; } if (read_env(fd, ¶ms)){ #if ENABLE_DEBUG if (params.verbose > VERB_ERR){ locked_print_string("Problems reading env from config\n", PRINTERR); } #endif /* ENABLE_DEBUG */ return; } int i = 0; elf_loadfile_p(¶ms, params.settings); for (i=0;i < params.argc;i++) { free(params.argv[i]); } free(params.argv); free(params.envp); }
bool VMGahpServer::command_support_vms(void) { static const char* command = "SUPPORT_VMS"; if( m_is_initialized == false ) { return false; } // Before sending command, print the remaining stderr messages from vmgahp printSystemErrorMsg(); if( write_line(command) == false) { return false; } // give some time to gahp server sleep(1); Gahp_Args result; if( read_argv(result) == false ) { return false; } if( result.argc == 0 || result.argv[0][0] != 'S' ) { dprintf(D_ALWAYS,"VMGAHP command '%s' failed\n",command); return false; } m_vms_supported.clearAll(); int i; for (i = 1; i < result.argc; i++) { m_vms_supported.append(result.argv[i]); } return true; }
bool VMGahpServer::publishVMClassAd(const char *workingdir) { static const char* command = "CLASSAD"; if( !m_job_ad || !workingdir ) { return false; } if( m_is_initialized == false ) { return false; } if( isSupportedCommand(command) == FALSE ) { return false; } // Before sending command, print the remaining stderr messages from vmgahp printSystemErrorMsg(); if(write_line(command) == false) { return false; } // give some time to gahp server sleep(1); Gahp_Args start_result; if( read_argv(start_result) == false ) { return false; } if( start_result.argc == 0 || start_result.argv[0][0] != 'S' ) { dprintf(D_ALWAYS,"VMGAHP command '%s' failed\n",command); return false; } // Send Working directory MyString vmAttr; vmAttr.sprintf("VM_WORKING_DIR = \"%s\"", workingdir); if ( write_line( vmAttr.Value() ) == false ) { return false; } // publish job ClassAd to vmgahp server via pipe bool can_send_it = false; int total_len = 0; const char *name; ExprTree *expr = NULL; m_job_ad->ResetExpr(); while( m_job_ad->NextExpr(name, expr) ) { can_send_it = false; if( !m_send_all_classad ) { // Instead of sending entire job ClassAd to vmgahp, // we will send some part of job ClassAd necessary to vmgahp. if( !strncasecmp( name, "JobVM", strlen("JobVM") ) || !strncasecmp( name, "VMPARAM", strlen("VMPARAM") ) || !strncasecmp( name, ATTR_CLUSTER_ID, strlen(ATTR_CLUSTER_ID)) || !strncasecmp( name, ATTR_PROC_ID, strlen(ATTR_PROC_ID)) || !strncasecmp( name, ATTR_USER, strlen(ATTR_USER)) || !strncasecmp( name, ATTR_ORIG_JOB_IWD, strlen(ATTR_ORIG_JOB_IWD)) || !strncasecmp( name, ATTR_JOB_ARGUMENTS1, strlen(ATTR_JOB_ARGUMENTS1)) || !strncasecmp( name, ATTR_JOB_ARGUMENTS2, strlen(ATTR_JOB_ARGUMENTS2)) || !strncasecmp( name, ATTR_TRANSFER_INTERMEDIATE_FILES, strlen(ATTR_TRANSFER_INTERMEDIATE_FILES)) || !strncasecmp( name, ATTR_TRANSFER_INPUT_FILES, strlen(ATTR_TRANSFER_INPUT_FILES)) ) { can_send_it = true; } } else { // We will send the entire job ClassAd to vmgahp can_send_it = true; } if( !can_send_it ) { continue; } vmAttr.sprintf( "%s = %s", name, ExprTreeToString( expr ) ); if ( write_line( vmAttr.Value() ) == false ) { return false; } total_len += vmAttr.Length(); if( total_len > 2048 ) { // Give some time for vmgahp to read this pipe sleep(1); printSystemErrorMsg(); total_len = 0; } } static const char *endcommand = "CLASSAD_END"; if(write_line(endcommand) == false) { return false; } // give some time to vmgahp sleep(1); Gahp_Args end_result; if( read_argv(end_result) == false ) { return false; } if( end_result.argc == 0 || end_result.argv[0][0] != 'S' ) { dprintf(D_ALWAYS,"VMGAHP command '%s' failed\n",endcommand); return false; } m_workingdir = workingdir; return true; }
int VMGahpServer::poll() { Gahp_Args* result = NULL; int num_results = 0; int i, result_reqid; VMGahpRequest* entry; ExtArray<Gahp_Args*> result_lines; if( m_is_initialized == false ) { return 0; } // First, send the RESULTS comand to the vmgahp server if( write_line("RESULTS") == false) { return -1; } // give some time to gahp server sleep(1); // First line of RESULTS command contains how many subsequent // result lines should be read. result = new Gahp_Args; ASSERT(result); if( read_argv(result) == false ) { delete result; return -1; } if( result->argc < 2 || result->argv[0][0] != 'S' ) { // Badness ! dprintf(D_ALWAYS,"VMGAHP command 'RESULTS' failed\n"); delete result; return -1; } num_results = strtol(result->argv[1], (char **)NULL, 10); if( num_results < 0 ) { dprintf(D_ALWAYS,"Invalid number of results('%s') from vmgahp Server\n", result->argv[1]); delete result; return -1; } // Now store each result line in an array. for (i=0; i < num_results; i++) { // Allocate a result buffer if we don't already have one if( !result ) { result = new Gahp_Args; ASSERT(result); } if( read_argv(result) == false ) { delete result; return -1; } result_lines[i] = result; result = NULL; } // At this point, the Results command has compelted. We needed // to store all the results in an array before operating on them, // because we need the Results command to complete before we // operate on the results. Why? Because some of the results // require us to make a callback, and the callback may want to // initiate a new Gahp request... // Now for each stored request line, // lookup the request id in our hash table and stash the result. for (i=0; i < num_results; i++) { if( result ) { delete result; result = NULL; } result = result_lines[i]; result_reqid = 0; if( result->argc > 0 ) { result_reqid = (int)strtol(result->argv[0], (char **)NULL, 10); } if( result_reqid <= 0 ) { // something is very weird; log it and move on... dprintf(D_ALWAYS,"VMGAHP - Bad RESULTS line\n"); continue; } // Now lookup in our hashtable.... entry = NULL; m_request_table.lookup(result_reqid,entry); if( entry ) { // found the entry! stash the result entry->setResult(result); // set result to NULL so we do not deallocate above result = NULL; // and set pending status entry->setPendingStatus(REQ_DONE); // mark pending request completed by setting reqid to 0 entry->setReqId(0); // and reset the user's timer if requested entry->resetUserTimer(); } // clear entry from our hashtable so we can reuse the reqid m_request_table.remove(result_reqid); } // end of looping through each result line if( result ) { delete result; result = NULL; } return num_results; }
int main(int argc, char *argv[]) { char error[256]; int capture = 1; time_t last_refresh_t; scap_t *h ; //apro la cattura live degli eventi read_argv(argc, argv); if(global_data.export_elk) init_connection_socket(); if(global_data.show_help_enabled){ print_help(); return(1); } printf("\n\t\t INIZIO INIZIALIZZAZIONE \n"); if( ( h = scap_open_live(error)) == NULL){ printf("Unable to connect to open sysdig: %s\n", error); return(false); } //setto i filtri per gli eventi da catturare solo se la cattura è live scap_clear_eventmask(h); if(scap_set_eventmask(h, PPME_CLONE_16_X) != SCAP_SUCCESS) printf("[ERROR] scap call failed: old driver ?\n"); if(scap_set_eventmask(h, PPME_PROCEXIT_E) != SCAP_SUCCESS) printf("[ERROR] scap call failed: old driver ?\n"); if(scap_set_eventmask(h, PPM_SC_EXIT_GROUP) != SCAP_SUCCESS) printf("[ERROR] scap call failed: old driver ?\n"); if(scap_set_eventmask(h, PPM_SC_EXIT) != SCAP_SUCCESS) printf("[ERROR] scap call failed: old driver ?\n"); if(global_data.get_all_proc) init_add_active_proc(h); printf("\n\t\t FINE INIZIALIZZAZIONE \n"); //ciclo di cattura last_refresh_t = time(NULL); while(capture) { struct ppm_evt_hdr* ev; u_int16_t cpuid; int32_t res = scap_next(h, &ev, &cpuid); if(res > 0 ) { printf("[ERROR] %s\n", scap_getlasterr(h)); scap_close(h); break; } else if( res == SCAP_SUCCESS ) { handle_event(ev,cpuid,h); } else if( res != -1 ) //timeout fprintf(stderr, "scap_next() returned %d\n", res); /*si aggiornano i dati ogni refresh_t secondi (5 default) (XXX numero da regolare) */ if( (time(NULL) - last_refresh_t) > global_data.refresh_t){ manage_data(h); last_refresh_t = time(NULL); } } //chiudo la cattura live degli eventi close(global_data.socket_desc); scap_close(h); }