bool runner::init_process(char *cmd, const char *wd) { WaitForSingleObject(main_job_object_access_mutex, infinite); set_allow_breakaway(true); // LPVOID penv = createEnvironmentForProcess(); env_vars_list_t original = set_environment_for_process(); std::string run_program = program; if ( !CreateProcess(run_program.c_str(), cmd, NULL, NULL, TRUE, process_creation_flags, NULL, wd, &si, &process_info) ) { if (!options.use_cmd || !CreateProcess(NULL, cmd, NULL, NULL, TRUE, process_creation_flags, NULL, wd, &si, &process_info) ) { ReleaseMutex(main_job_object_access_mutex); PANIC("CreateProcess: \"" + run_program + "\", " + get_win_last_error_string()); restore_original_environment(original); return false; } } ReleaseMutex(main_job_object_access_mutex); restore_original_environment(original); get_times(&creation_time, NULL, NULL, NULL); return true; }
void ShiftTimesDialog::showEvent(QShowEvent *event) { ui.timeEdit->setTime(QTime(0, 0, 0, 0)); when = get_times(); //get time of first selected dive ui.currentTime->setText(get_dive_date_string(when)); ui.shiftedTime->setText(get_dive_date_string(when)); }
int get_times(int n) { // printf("%s\t%p\t%d\n",__func__,&n,n); if(n == 1) { return n; } else { // int(*pg)(int) = get_times; // printf("%p\n",pg); return get_times(n-1)*n; } }
int main() { int n; scanf("%d",&n); if(n >0) printf("get_times=%d\n",get_times(n)); else printf("please input int!\n"); return 0; }
static int set_renewal_times(glite_renewal_core_context ctx, char *proxy_file, proxy_record *record) { int ret; time_t end_time_x509 = 0, end_time_voms = 0; ret = get_times(ctx, proxy_file, &end_time_x509, &end_time_voms); if (ret) return ret; return schedule_renewal(ctx, end_time_x509, end_time_voms, record); }
bool split_clusters(const char *input_path,const char *cluster_path,const char *output_path,int num_features,int clip_size) { DiskReadMda C; C.setPath(cluster_path); Mda C2; C2.allocate(C.N1(),C.N2()); for (int i=0; i<C.N2(); i++) { C2.setValue(C.value(0,i),0,i); C2.setValue(C.value(1,i),1,i); } int K=get_K(C); int kk=1; #pragma omp parallel for for (int k=1; k<=K; k++) { DiskReadMda X; X.setPath(input_path); //needed here for thread safety? DiskReadMda C; C.setPath(cluster_path); printf("k=%d/%d... ",k,K); QList<int> times=get_times(C,k); Mda clips; printf("extract clips... "); extract_clips(clips,X,times,clip_size); Mda features; printf("compute features... "); compute_features(features,clips,num_features); printf("isosplit... "); QVector<int> labels0=isosplit(features); printf("setting...\n"); int K0=get_max_k(labels0); if (K0>1) printf("::: split into %d clusters\n",K0); else printf("\n"); int jjj=0; for (int bb=0; bb<C.N2(); bb++) { if (C.value(2,bb)==k) { C2.setValue(kk+labels0[jjj]-1,2,bb); jjj++; } } kk+=K0; } C2.write(output_path); return true; }
int tok_quantity (unsigned char byte, char *text, int *tex, int offset, char *tokens, int *tok) { int quantity, q, next; quantity = get_times (text, *tex + offset, MAXLINE - 1, &next); if (quantity) { for (q = *tok; q < *tok + quantity && q < MAXTOKENLINE - 1; q ++) tokens [q] = byte; *tok = q - 1; *tex = next - 1; return TRUE; } else return FALSE; }
void register_proxy(glite_renewal_core_context ctx, edg_wlpr_Request *request, edg_wlpr_Response *response) { proxy_record record; int ret; FILE *meta_fd = NULL; int last_suffix; char *basename = NULL; char filename[FILENAME_MAX]; time_t end_time_x509, end_time_voms; assert(request != NULL); assert(response != NULL); memset(&record, 0, sizeof(record)); memset(response, 0, sizeof(*response)); if (request->proxy_filename == NULL || request->jobid == NULL) { edg_wlpr_Log(ctx, LOG_ERR, "Registration request doesn't contain registration information"); return; /* EINVAL; */ } edg_wlpr_Log(ctx, LOG_DEBUG, "Registering proxy from %s belonging to job %s", request->proxy_filename, request->jobid); ret = get_base_filename(ctx, request->proxy_filename, &basename); if (ret) goto end; ret = open_metafile(ctx, basename, &meta_fd); if (ret) goto end; if (voms_enabled) { record.fqans = get_voms_fqans(ctx, request->proxy_filename); record.voms_exts = (record.fqans != NULL); } /* Find first free record */ record.suffix = -1; record.myproxy_server = strdup(request->myproxy_server); ret = get_record_ext(ctx, meta_fd, basename, &record, &last_suffix); fclose(meta_fd); meta_fd = NULL; if (ret && ret != EDG_WLPR_ERROR_PROTO_PARSE_NOT_FOUND) goto end; if (ret == EDG_WLPR_ERROR_PROTO_PARSE_NOT_FOUND || record.jobids.len == 0 || request->unique) { /* create a new proxy file in the repository */ int suffix; suffix = (record.jobids.len == 0 && record.suffix >= 0) ? record.suffix : last_suffix + 1; snprintf(filename, sizeof(filename), "%s.%d", basename, suffix); ret = copy_file(ctx, request->proxy_filename, filename); if (ret) goto end; ret = set_renewal_times(ctx, filename, &record); if (ret) goto end; record.suffix = suffix; ret = realloc_prd_list(ctx, &record.jobids); if (ret) goto end; record.jobids.val[record.jobids.len - 1] = strdup(request->jobid); record.unique = request->unique; edg_wlpr_Log(ctx, LOG_DEBUG, "Created a new proxy file in repository (%s)", filename); } else { ret = get_times(ctx, request->proxy_filename, &end_time_x509, &end_time_voms); if (ret) goto end; snprintf(filename, sizeof(filename), "%s.%d", basename, record.suffix); if (record.end_time < end_time_x509 && (end_time_voms == 0 || record.next_renewal < end_time_voms)) { ret = copy_file(ctx, request->proxy_filename, filename); if (ret) goto end; edg_wlpr_Log(ctx, LOG_DEBUG, "Proxy %s of job %s has replaced the registered one.", request->proxy_filename, request->jobid); schedule_renewal(ctx, end_time_x509, end_time_voms, &record); } ret = realloc_prd_list(ctx, &record.jobids); if (ret) goto end; record.jobids.val[record.jobids.len - 1] = strdup(request->jobid); edg_wlpr_Log(ctx, LOG_DEBUG, "Incremented counter on %s", filename); } ret = store_record(ctx, basename, &record); end: if (meta_fd) { fclose(meta_fd); } if (basename) free(basename); if (ret == 0) { ret = filename_to_response(ctx, filename, response); edg_wlpr_Log(ctx, LOG_NOTICE, "Proxy %s of job %s has been registered as %s", request->proxy_filename, request->jobid, filename); } else edg_wlpr_Log(ctx, LOG_ERR, "Failed to register proxy %s: %s", request->proxy_filename, glite_renewal_core_get_err(ctx)); record_to_response(ctx, ret, &record, response); free_record(ctx, &record); }
extern void FMgetval( void ) { char *buf; /* pointer to parameter to use */ char *ep; /* pointer to value of env var */ char *ename; /* pointer to environment var name */ char work[128]; char value[2048]; /* buffer to build .dv commands in */ char vname[128]; int m; /* parameters to get date/time in */ int d; int y; int h; int s; int i; struct col_blk *cp; *value = 0; *vname = 0; if( FMgetparm( &buf ) > 0 ) /* if there is a parameter on the line */ { iptr = 0; /* start the input pointer at beginning of buffer */ switch( *buf ) /* look at user parameter and set psuedo command */ { case 'D': /* get string formatted date */ get_mdy( &m, &d, &y ); /* get the values */ strcpy( vname, "_date" ); snprintf( value, sizeof( value ), "%d %s %d", d, mname[m], 1900 + y ); break; case 'd': /* set date value */ get_mdy( &m, &d, &y ); /* get the values */ strcpy( vname, "_date" ); snprintf( value, sizeof( value ), "%d/%d/%d", m, d, 1900 + y ); /* create value */ break; case 'E': // eurpoean date dd/mm/yyyy get_mdy( &m, &d, &y ); // values strcpy( vname, "_date" ); // variable name snprintf( value, sizeof( value ), "%d/%d/%d", d, m, 1900 + y ); // value break; case 'e': /* e env-name xfm-var-name */ if( FMgetparm( &buf ) > 0 ) /* if there is a parameter on the line */ { ename = strdup( buf ); if( FMgetparm( &buf ) > 0 ) { if( ep = getenv( ename ) ) { snprintf( vname, sizeof( vname ), "%s", buf ); snprintf( value, sizeof( value ), "%s", ep ); } } free( ename ); } break; case 'F': /* set figure number variable AND advance the counter */ if( *(buf+1) == 'i' ) { strcpy( vname, "_fig" ); if( flags & PARA_NUM ) { snprintf( value, sizeof( value ), "%d-%d", pnum[0], fig ); } else { snprintf( value, sizeof( value ), "%d", fig ); } fig++; } break; case 'f': /* set figure number or font variable */ if( *(buf+1) == 'i' ) { if( flags & PARA_NUM ) { strcpy( vname, "_fig" ); snprintf( value, sizeof( value ), "%d-%d", pnum[0], fig ); } else { strcpy( vname, "_fig" ); snprintf( value, sizeof( value ), "%d", fig ); } } else { strcpy( vname, "_font" ); snprintf( value, sizeof( value ), "%s", curfont ); } break; case 'h': /* get host name */ gethostname( work, 128 ); strcpy( vname, "_host" ); snprintf( value, sizeof( value ), "%s", work ); break; case 'i': // ISO 8601 extended date get_mdy( &m, &d, &y ); // values strcpy( vname, "_date" ); // variable name snprintf( value, sizeof( value ), "%d-%d-%d", 1900 + y, m, y ); // value break; case 'l': /* set margin variables (lmar) or lines remaining in col (lines) */ if( *(buf+1) == 'i' ) { strcpy( vname, "_lines" ); snprintf( value, sizeof( value ), "%d", (boty - cury)/(textsize + textspace) ); } else { strcpy( vname, "_lmar" ); snprintf( value, sizeof( value ), "%d", lmar ); } break; case 'm': /* set month day year */ get_mdy( &m, &d, &y ); /* get the values */ strcpy( vname, "_mon" ); snprintf( value, sizeof( value ), "%s", mname[m] ); FMset_var( vname, value ); strcpy( vname, "_day" ); snprintf( value, sizeof( value ), "%d", d ); FMset_var( vname, value ); strcpy( vname, "_year" ); snprintf( value, sizeof( value ), "%d", 1900 + y ); break; case 'p': /* set page variable */ strcpy( vname, "_page" ); snprintf( value, sizeof( value ), "%d", page+1 ); break; case 'r': /* remain | rmar */ if( *(buf+1) == 'e' ) /* assume remain - generate iremain (inches) lines */ { strcpy( vname, "_attop" ); snprintf( value, sizeof( value ), "%s", cury == topy ? "true" : "false" ); FMset_var( vname, value ); strcpy( vname, "_lremain" ); snprintf( value, sizeof( value ), "%d", (boty - cury)/(textsize + textspace) ); FMset_var( vname, value ); strcpy( vname, "_lines" ); snprintf( value, sizeof( value ), "%d", (boty - cury)/(textsize + textspace) ); FMset_var( vname, value ); strcpy( vname, "_iremain" ); snprintf( value, sizeof( value ), "%d", (boty - cury)/72 ); /* 72 points per inch */ FMset_var( vname, value ); strcpy( vname, "_premain" ); snprintf( value, sizeof( value ), "%d", (boty - cury)); /* points */ FMset_var( vname, value ); } else { strcpy( vname, "_rmar" ); snprintf( value, sizeof( value ), "%d", lmar + linelen ); } break; case 's': strcpy( vname, "_sect" ); ep = FMget_header_num(); // if numbering, get the number if( ! ep ) { ep = FMget_header_txt(); // else get the string } if( ep ) { snprintf( value, sizeof( value ), "%s", ep ); } else { return; } break; case 't': if( *(buf+1) == 'a' ) // table number { if( flags & PARA_NUM ) { strcpy( vname, "_table" ); snprintf( value, sizeof( value ), "%d-%d", pnum[0], table_number ); } else { strcpy( vname, "_table" ); snprintf( value, sizeof( value ), "%d", table_number ); } } else { strcpy( vname, "_tsize" ); snprintf( value, sizeof( value ), "%d", textsize ); } break; case 'T': if( *(buf+1) == 'a' ) // table number and advance it { if( flags & PARA_NUM ) { strcpy( vname, "_table" ); snprintf( value, sizeof( value ), "%d-%d", pnum[0], table_number ); } else { strcpy( vname, "_table" ); snprintf( value, sizeof( value ), "%d", table_number ); } table_number++; } else // set time variable { get_times( &h, &m, &s ); // current time strcpy( vname, "_time" ); snprintf( value, sizeof( value ), "%02d:%02d", h, m ); } break; case 'v': strcpy( vname, "_ver" ); snprintf( value, sizeof( value ), "%s", version ); break; case 'y': /* set current y info: current y, top y, col-number */ strcpy( vname, "_cury" ); snprintf( value, sizeof( value ), "%d", cury ); FMset_var( vname, value ); strcpy( vname, "_topy" ); snprintf( value, sizeof( value ), "%d", topy ); FMset_var( vname, value ); i = 0; for( cp = firstcol; cp && cp != cur_col; cp = cp->next ) i++; strcpy( vname, "_coln" ); snprintf( value, sizeof( value ), "%d", i ); break; default: FMmsg( E_PARMOOR, inbuf ); /* error message */ break; } /* end switch */ if( *value ) { TRACE( 2, "getval: setting: %s=%s\n", vname, value ); FMset_var( vname, value ); } else fprintf( stderr, "getval: value was emppty; nothing set for %s\n", vname ); } /* end if parameter entered */ } /* fmgetval */
int main (int argc, char *argv[]) { struct stats s, s0; int print = 0; FILE *fp = fopen(STATS_FILE, "rb"); if (fp != NULL) { fread(&s0, sizeof(struct stats), 1, fp); fclose(fp); print = 1; } get_times(&s); get_temp(&s); get_mail(&s); get_cputime(&s); get_power(&s); get_mem(&s); get_txrx(&s); if (print) { int i; double temp = 1e-3*s.temp; double charge = 100*s.charge_now/s.charge_full; double tx = (s.tx-s0.tx)/(s.t-s0.t); double rx = (s.rx-s0.rx)/(s.t-s0.t); double mem = s.mem*9.5367431640625e-07; double cpu_pct[MAX_CPUS]; for (i=0; i < s.n_cpus; i++) { double idle = s.cpu_idle[i] - s0.cpu_idle[i]; double total = s.cpu_total[i] - s0.cpu_total[i]; cpu_pct[i] = 1-idle/total; } fputs(" [", stdout); begin_color(color_bar); fputs(th_spc, stdout); for (i=0; i < s.n_cpus; i++) { print_bar(cpu_pct[i]); fputs(th_spc, stdout); } end_color(); fputc(']', stdout); begin_color (color_div); fputs(spc, stdout); fputs(divider, stdout); end_color(); begin_color_coded (temp, LO_TEMP, HI_TEMP); num_print (temp, 3, degc); end_color(); begin_color (color_div); fputs(spc, stdout); fputs(divider, stdout); fputs(spc, stdout); end_color(); begin_color_coded (mem, LO_MEM, HI_MEM); num_print (mem, 4, "MB"); end_color(); begin_color (color_div); fputs(spc, stdout); fputs(divider, stdout); fputs(spc, stdout); end_color(); begin_color (s.ac_connected ? "cyan" : "red"); fputs(s.ac_connected ? acon : acoff, stdout); fputc(' ', stdout); end_color(); begin_color_coded (100-charge, LO_CHARGE, HI_CHARGE); num_print (charge, 3, "%"); end_color(); begin_color (color_div); fputs(spc, stdout); fputs(divider, stdout); end_color(); begin_color_coded (tx, LO_RATE, HI_RATE); num_print (tx, 0, "B/s "); end_color(); begin_color (color_up); fputs(up, stdout); end_color(); begin_color_coded (rx, LO_RATE, HI_RATE); fputs(spc, stdout); num_print (rx, 0, "B/s "); end_color(); begin_color (color_down); fputs(down, stdout); end_color(); fputs(spc, stdout); begin_color (color_div); fputs(divider, stdout); fputs(spc, stdout); end_color(); if (s.gmail) { begin_color (color_mail); printf ("%2d/g", s.gmail); end_color(); } if (s.uiucmail) { begin_color (color_mail); printf ("%2d/u", s.uiucmail); end_color(); } if (s.uiucmail || s.gmail) { fputs(spc, stdout); begin_color (color_div); fputs(divider, stdout); fputs(spc, stdout); end_color(); } begin_color (color_date); fputs(s.date, stdout); end_color(); fputs(spc, stdout); begin_color (color_div); fputs(divider, stdout); end_color(); } fp = fopen(STATS_FILE, "wb"); fwrite(&s, sizeof(struct stats), 1, fp); fclose(fp); return 0; }
bool runner::init_process_with_logon(char *cmd, const char *wd) { WaitForSingleObject(main_job_object_access_mutex, infinite); set_allow_breakaway(false); STARTUPINFOW siw; //USES_CONVERSION; ZeroMemory(&siw, sizeof(siw)); siw.cb = sizeof(si); siw.dwFlags = si.dwFlags; siw.hStdInput = si.hStdInput; siw.hStdOutput = si.hStdOutput; siw.hStdError = si.hStdError; siw.wShowWindow = si.wShowWindow; siw.lpDesktop = NULL;//L""; std::string run_program = program + " " + options.get_arguments(); wchar_t *login = a2w(options.login.c_str()); wchar_t *password = a2w(options.password.c_str()); wchar_t *wprogram = a2w(run_program.c_str()); wchar_t *wcmd = a2w(cmd); wchar_t *wwd = a2w(wd); DWORD creation_flags = CREATE_SUSPENDED | CREATE_SEPARATE_WOW_VDM | CREATE_NO_WINDOW; HANDLE token = NULL; auto original = set_environment_for_process(); if ( !CreateProcessWithLogonW(login, NULL, password, 0, wprogram, wcmd, creation_flags, NULL, wwd, &siw, &process_info) ) { if (!options.use_cmd || !CreateProcessWithLogonW(login, NULL, password, 0, NULL, wcmd, creation_flags, NULL, wwd, &siw, &process_info) ) { ReleaseMutex(main_job_object_access_mutex); PANIC("CreateProcess: \"" + run_program + "\", " + get_win_last_error_string()); // TODO: cleanup below is useless now since we're in panic delete[] login; delete[] password; delete[] wprogram; delete[] wcmd; delete[] wwd; restore_original_environment(original); return false; } } set_allow_breakaway(true); ReleaseMutex(main_job_object_access_mutex); delete[] login; delete[] password; delete[] wprogram; delete[] wcmd; delete[] wwd; restore_original_environment(original); get_times(&creation_time, NULL, NULL, NULL); return true; }
int main(int argc, char **argv) { FILE *port; char *filename; int c, i, j, tmp; int debugmode = 0; int lanes; float times[MAX_LANES]; float prev_times[MAX_LANES][4]; int prev_head = 0;\ char *tmpbuf[10]; /* parse command line options */ if (argc == 1) { usage(); return 0; } opterr = 0; while ((c = getopt (argc, argv, "dp:")) != -1) { switch (c) { case 'd': printf("Debugging mode enabled\n"); debugmode = 1; break; case 'p': filename = optarg; break; case '?': default: usage(); return 1; } } /* open timer */ port = open_timer(filename, !debugmode); if (!port) { fprintf(stderr, "Eek! Unable to open timer port! Cannot continue.\n"); fprintf(stderr, "Possible problems:\n"); fprintf(stderr, "\tbad filename for port (if USB timer, check dmesg for port id\n"); fprintf(stderr, "\tno write access to device (check permissions or run as root)\n"); fprintf(stderr, "\tUSB timer not connected\n"); return 1; } /* reset timer */ lanes = init_timer(port); if (!lanes) { fprintf(stderr, "Eek! Cannot initialize timer! Cannot continue!\n"); fprintf(stderr, "Make sure your timer is supported by this program.\n"); close_timer(port); return 1; } memset(prev_times, 0, sizeof(float) * 3 * MAX_LANES); printf("Press enter to continue.\n"); fgets(tmpbuf, 10, stdin); /* main loop */ while (1) { printf("Begin racing when ready.\n"); tmp = get_times(port, lanes, times, debugmode); printf("Run is complete. Results:\n"); if (tmp > 0) { /* good race! */ display_winner(tmp); printf("\n"); // save current time, drop last time display_times(lanes, times); for (j = 0; j < lanes; j++) { prev_times[j][prev_head] = times[j]; } printf("\nPrevious results:\n"); i = prev_head - 1; if (i < 0) i = 3; while (i != prev_head) { for (j = 0; j < lanes; j++) printf("\t%1.4f", prev_times[j][i]); printf("\n"); i--; if (i < 0) i = 3; } prev_head++; if (prev_head == 4) prev_head = 0; } if (tmp == 0) { printf("Null race result! Please redo this run.\n"); } if (tmp < 0) { port = reinit_timer(port, filename, !debugmode, lanes); /* if this returns, we've succeeded */ } printf("Press enter to continue, X to exit.\n"); fgets(tmpbuf, 10, stdin); if (strchr(tmpbuf, 'x') || strchr(tmpbuf, 'X')) break; rearm_timer(port, debugmode); } /* all done */ printf("\nDone.\n"); close_timer(port); return 0; }