int debug_close(int fd) { int ret = 1; char buf[16]; if (!ps.opened || fd != ps.fd) return -1; eprintf("Do you want to kill the process? (Y/n/c)"); cons_set_raw(1); while( ret == 1 ) { //&& read(0,buf,1)>0 ) { ret = read (0, buf, 1); if (ret <=0) buf[0]='y'; buf[1] = '\n'; write(1, buf, 2); /* free mapped memory */ dealloc_all(); switch(buf[0]) { case 'c': case 'C': eprintf("Cancelled\n"); cons_set_raw(0); ret = -2; break; default: case 'y': case 'Y': case '\n': case '\r': /* TODO: w32 stuff here */ #if __UNIX__ ptrace(PTRACE_KILL, ps.pid, 0, 0); ptrace(PTRACE_DETACH, ps.pid, 0, 0); ptrace(PTRACE_KILL, ps.tid, 0, 0); ptrace(PTRACE_DETACH, ps.tid, 0, 0); /* TODO: Do it properly for all the childs! */ #endif #ifndef SIGKILL #define SIGKILL 9 #endif debug_os_kill(ps.pid, SIGKILL); debug_os_kill(ps.tid, SIGKILL); case 'n': case 'N': // radare_cmd("!detach", 0); /* TODO: w32 stuff here */ #if __UNIX__ ptrace(PTRACE_CONT, ps.pid, 0, 0); ptrace(PTRACE_DETACH, ps.pid, 0, 0); #endif free(ps.filename); ps.opened = 0; ret = 0; break; } } cons_set_raw(0); return ret; }
int main(int argc,char *argv[]){ ALLDATA *adt; FILE *f; //assign novalues number_novalue = -9999; number_absent = -9998; string_novalue = assign_string("none"); i_sim0 = 1; i_run0 = 1; cum_time = 0.; elapsed_time_start = 0.; MM1=0.; MM2=0.; MMR=0.; MMo=0.; /*dinamic allocations:*/ UV=(T_INIT *)malloc(sizeof(T_INIT)); if(!UV) t_error("UV was not allocated"); adt=(ALLDATA *)malloc(sizeof(ALLDATA)); if(!adt){ t_error("adt was not allocated"); }else { adt->I=(TIMES *)malloc(sizeof(TIMES)); if(!(adt->I)) t_error("times was not allocated"); adt->T=(TOPO *)malloc(sizeof(TOPO)); if(!(adt->T)) t_error("top was not allocated"); adt->S=(SOIL *)malloc(sizeof(SOIL)); if(!(adt->S)) t_error("sl was not allocated"); adt->L=(LAND *)malloc(sizeof(LAND)); if(!(adt->L)) t_error("land was not allocated"); adt->W=(WATER *)malloc(sizeof(WATER)); if(!(adt->W)) t_error("water was not allocated"); adt->P=(PAR *)malloc(sizeof(PAR)); if(!(adt->P)) t_error("par was not allocated"); adt->C=(CHANNEL *)malloc(sizeof(CHANNEL)); if(!(adt->C)) t_error("channel was not allocated"); adt->E=(ENERGY *)malloc(sizeof(ENERGY)); if(!(adt->E)) t_error("egy was not allocated"); adt->N=(SNOW *)malloc(sizeof(SNOW)); if(!(adt->N)) t_error("snow was not allocated"); adt->G=(GLACIER *)malloc(sizeof(GLACIER)); if(!(adt->G)) t_error("glac was not allocated"); adt->M=(METEO *)malloc(sizeof(METEO)); if(!(adt->M)) t_error("met was not allocated"); t_meteo=0.; t_energy=0.; t_water=0.; t_sub=0.; t_sup=0.; t_out=0.; t_blowingsnow=0.; /*------------------ 3. Acquisition of input data and initialisation --------------------*/ get_all_input(argc, argv, adt->T, adt->S, adt->L, adt->M, adt->W, adt->C, adt->P, adt->E, adt->N, adt->G, adt->I); /*----------------- 4. Time-loop for the balances of water-mass and egy -----------------*/ time_loop(adt); /*-------------------- 5.Completion of the output files and deallocaions --------------------*/ dealloc_all(adt->T, adt->S, adt->L, adt->W, adt->C, adt->P, adt->E, adt->N, adt->G, adt->M, adt->I); free(adt); } printf("End of simulation!\n"); f = fopen(SuccessfulRunFile, "w"); fclose(f); return 0; }