static void print_content(t_btree *list, int flags, t_padding paddings) { void (*trav)(t_btree*, void(*)(void*)); void (*print_way)(void*); trav = flags & REV ? &btree_apply_infix_rev : &btree_apply_infix; print_way = flags & LONG ? &print_long : &print_name_only; adjust_padding(list, paddings); if (list) { trav(list, print_way); clean_all(&list); } }
//Пусть эта штука будет рекурсивно себя вызывать и возвращать число итераций int layer(double eps,int n,double tau,double h,double *v,double *hat_v){ double err,gamma,*a,*c,*d,*b,*w,*pts[5]; int i; new_double(5,n,pts); a = pts[0]; c = pts[1]; d = pts[2]; b = pts[3]; w = pts[4]; _G(n,b,tau,h,v,hat_v); err = norm_max(n,b); if (err<eps) printf("Ошибка %e\neps %e\n",norm_max(n,b),eps); if (norm_max(n,b) < eps) { clean_all(5,pts); return 0; } for(i=n-6,a[n-5] = 1/tau;i>=0;i--) { a[i] = 1/tau; c[i] = hat_v[i+3]/(2*h); d[i] = -hat_v[i+2]/(2*h); } thomas(n-4,w+2,a,c,d,b); for (gamma=1.;gamma>AESH_MIN;gamma/=2.){ if (gamma<10*AESH_MIN) exit(-1); for (i=2;i<n-2;i++) hat_v[i] += gamma * w[i]; _G(n,b,tau,h,v,hat_v); printf("Ошибка %e\n",norm_max(n,b)); if (norm_max(n,b)<err) break; for (i=2;i<n-2;i++) hat_v[i] -= gamma * w[i]; } clean_all(5,pts); return 1 + layer(eps,n,tau,h,v,hat_v); }
int thomas(int n,double *dest,double*a,double*c,double*d,double *b){ double *l,*v,*u,*pts[3]; int i; if (n<2) return n-2; // for (i=0;i<n-5;i++) printf("%e %e %e %e\n",a[i],c[i],d[i],b[i]); new_double(3,n,pts); l = pts[0]; v = pts[1], u = pts[2]; // Богачёв первый этап прогонки // printf("d0 = %e\n",d[0]); v[0]=d[0]; if (fabs(v[0])<AESH_MIN) {printf("d[0] zero delimeter\n"); clean_all(3,pts); exit(-1);} l[0] = a[0]/v[0];if (fabs(l[0])<AESH_MIN) {printf("l[0] zero delimeter %e/%e = %e\n",a[0],v[0],l[0]); clean_all(3,pts);exit(-1);} u[0] = c[0]/l[0]; for (i=1;i<n-1;i++) { v[i] = d[i]; if (fabs(v[i])<AESH_MIN) {printf("v[%d] zero delimeter\n",i); exit(-1);} l[i] = (a[i] - u[i-1])/v[i];if (fabs(l[i])<AESH_MIN) {printf("l[%d] zero delimeter\n",i); clean_all(3,pts); exit(-1);} u[i] = c[i]/l[i]; } l[n-1]=a[n-1]-u[n-2]; v[n-1]=1; // Богачёв замечание 4 for(i=1,dest[0]=b[0]/l[0]; i<n; i++) dest[i] = (b[i]-dest[i-1])/l[i]; for(i=n-2;i>=0; i--) dest[i] = (dest[i] - u[i]*dest[i+1])/v[i]; clean_all(3,pts); return 0; }
void VOMS_server_list::reload(bool force) { if ( client_config->contacts_changes_since(last_list_modify) ) { last_list_modify = time(NULL) + timezone; } else if ( force ) { last_list_modify = time(NULL) + timezone; current_vo = client_engine->get_VO(); } else { return; } if ( contacts_map.size()>0 ) { clean_all(); } std::cout << "Reloading server list" << std::endl; contact_data_vector vomses_buffer = contact_data_vector(); /* * TODO missing error handling */ client_config->get_contacts(vomses_buffer); std::cout << "Recreating menu" << std::endl; for ( contact_data_vector::iterator buff_item = vomses_buffer.begin(); buff_item != vomses_buffer.end(); buff_item++ ) { if ( contacts_map.find(buff_item->vo) == contacts_map.end() ) { VOMS_menu_item* tmp_menu = new VOMS_menu_item(buff_item->vo, this); contacts_map[buff_item->vo] = tmp_menu; if ( !current_vo.empty() && current_vo == buff_item->vo ) { if ( icon_file.update(client_engine->get_proxy_status()) ) { tmp_menu->set_icon(icon_file.path()); } } this->items().push_back(*tmp_menu); } contacts_map[buff_item->vo]->push_back(*buff_item); } std::cout << "Menu ok" << std::endl; }
static void err_exit(char* str) { int err = errno; if (err) { SWI_LOG("APPMON", ERROR, "err_exit: strerror(errno)=[%s], ctx=[%s]\n", strerror(errno), str); } else { err = APPMON_ERR_EXIT_CODE; SWI_LOG("APPMON", ERROR, "err_exit: ctx=[%s]\n", str); } SWI_LOG("APPMON", ERROR, "cleaning and exiting\n"); clean_all(); exit(err); }
static int __init seq_init(void) { struct proc_dir_entry *entry; mutex_init(&lock); INIT_LIST_HEAD(&head); add_one("aaaa"); add_one("bbbb"); entry = create_proc_entry("my_data", S_IWUGO | S_IRUGO, NULL); if (entry == NULL) { clean_all(&head); return -ENOMEM; } entry->proc_fops = &list_seq_fops; return 0; }
//function used to clear resources void term_signal(int sig) { int status; Log(LOG_DEBUG, "SIGTERM trapped.Clean all things\n"); status = clean_all(&connections); status = remove(pid_file); if (status) { status = errno; Log(LOG_ERR, "Error removing PID file %s, Err(%s)", pid_file, strerror(status)); } status = remove(socket_file); if (status) { status = errno; Log(LOG_ERR, "Error removing Socket file %s, Err(%s)", socket_file, strerror(status)); } exit(status); }
static int after_while(t_env **ev, t_data *en, t_edit **lst, t_hist **hst) { if (ft_sigleton(0) == 3) { ft_sigleton(-1); ft_putchar('\n'); ft_read(ev, en); } else { if (*lst) ft_jumprint(lst); ft_putchar('\n'); if ((ft_write_on_file(lst, en->env)) == 0) ft_lexer(ft_creat_string(*lst), en); clean_all(lst, hst); ft_read(ev, en); return (1); } return (0); }
int main(int argc,char**argv){ int N,M,i,j; double tau,h,eps,*v,*hat_v,*delta_v,*pts[3]; if (argc<4) {printf("%s 1/tau 1/h eps\n",argv[0]); return 0;} N = atoi(argv[1]); M = atoi(argv[2]); eps = atof(argv[3]); h = 1./M; tau = 1./N; new_double(3,N,pts); v = pts[0]; hat_v = pts[1]; delta_v = pts[2]; v0(N,v); // pl(N,v); for(j=0;j<M;j++){ v_bounds(N,j/M,hat_v); for (i=2;i<N-2;i++) hat_v[i] = v[i]; layer(eps,N,tau,h,v,hat_v); for (i=0;i<N;i++) delta_v[i] = fabs(analitic( ((double)j)/M ,((double)i)/N) - hat_v[i] ); printf("layer %d с ошибкой %e\n",j,norm_max(N,delta_v)); for (i=2;i<N-2;i++) v[i] = hat_v[i]; } clean_all(3,pts); return 0; }
static void daemonize(void) { pid_t pid; /* already a daemon */ if (getppid() == 1) return; /* Fork off the parent process */ pid = fork(); if (pid < 0) //last sync error, afterwards errors will be reported using socket API. err_exit("daemonize:fork() failed"); /* If we got a good PID, then we can exit the parent process. */ if (pid > 0) { clean_all(); exit(EXIT_SUCCESS); } //the child is the daemon, keep running }
int main(int ac, char **av, char **env) { t_token *root; t_parse_tree *tree; t_shell *sh; (void)av; (void)ac; if (!(sh = init_sh(env))) return (FAILURE); parse_config_file(sh); while (!sh->exe->exit && get_line_caps(sh->line) != FAILURE) { pre_parsing(sh); if (!(root = get_tokens(sh->line->line))) return (FAILURE); if ((tree = start_parsing(root, sh)) && (sh->exe->return_value = 2)) exec_cmd(tree, sh->exe); free_tokens(root); XFREE(sh->line->line); } add_in_history_file(sh->line); return (clean_all(sh)); }
int main(int argc, char *argv[]) { int ret = 0; int dma = TRUE; int status; int failed = FALSE; unsigned long j, k; unsigned long rep; // Initializing the card. status = card_initialize(); if (status == -1) { printf("Failed to initialize the FPGA. Exiting\n"); return -1; } // Loading the values onto rambuf which is to be written to ZBTRAM for (j = 0; j < bankSize; j++) { rambuf[j] = j; rambuf[j+2*bankSize] = 262143 - j; rambuf[j+4*bankSize] = 0x12348765; } // Writing the rambuf data to ZBTRAM at specified location status = writeSSRAM(rambuf, 0 , 6*bankSize, dma); if (status != ADMXRC2_SUCCESS) { printf("Error: failed to write SSRAM\n"); failed = TRUE; } //Signals the FPGA to start its processing start_fpga_execution(); //Wait to complete the processing by FPGA wait_for_completion(); //initializing chkbuf with all 0 values for (j = 0; j < numBank; j++) { for (k = 0; k < bankSize; k++) { unsigned long idx = j * bankSize + k; chkbuf[idx] = 0; } } //Reading the ZBTRAM values to chkbuf status = readSSRAM(chkbuf, 0,6*bankSize, dma); if (status != ADMXRC2_SUCCESS) { printf("Error: failed to read SSRAM\n"); failed = TRUE; } //Print the results to output_file1 in the required format printf("\nData written onto the banks\n"); for (j = 0;j < 20;j++){ printf("\n%02d %08X %08X %08X %08X %08X %08X ", j,rambuf[j],rambuf[1*bankSize+j],rambuf[2*bankSize+j],rambuf[3*bankSize+j],rambuf[4*bankSize+j],rambuf[5*bankSize+j]); } printf("\n\nData read from all the banks\n"); for (j = 0;j < 20;j++){ printf("\n%02d %08X %08X %08X %08X %08X %08X ", j,chkbuf[j],chkbuf[1*bankSize+j],chkbuf[2*bankSize+j],chkbuf[3*bankSize+j],chkbuf[4*bankSize+j],chkbuf[5*bankSize+j]); } if (failed){ printf("\n*** FAILED***\n"); } //Closing all the handles and frreing allocated space clean_all(); return ret; }
int main(int argc, char *argv[]) { int dma = TRUE; int status; int failed = FALSE; unsigned long j, k; unsigned long rep; FILE *fptr; unsigned long read_value; // Initializing the card. status = card_initialize(); if (status == -1) { printf("Failed to initialize the FPGA. Exiting\n"); return -1; } // Loading the values onto rambuf from the input_file user loaded, which is to be written to ZBTRAM if(!(fptr = fopen("../temp/input_file1","r"))) { printf("input_file1 does not exist specify some other existing file \n"); return -1; } fscanf(fptr,"%ld",&read_value); for (j = 0; (j < bankSize) && (!feof(fptr)); j++) { rambuf[j+5*bankSize] = read_value; fscanf(fptr,"%ld",&read_value); } fclose (fptr); // Writing the rambuf data to ZBTRAM at specified location status = writeSSRAM(rambuf, 5*bankSize , 1*bankSize, dma); if (status != ADMXRC2_SUCCESS) { printf("Error: failed to write SSRAM\n"); failed = TRUE; } //Signals the FPGA to start its processing start_fpga_execution(); //Wait to complete the processing by FPGA wait_for_completion(); //initializing chkbuf with all 0 values for (j = 0; j < numBank; j++) { for (k = 0; k < bankSize; k++) { unsigned long idx = j * bankSize + k; chkbuf[idx] = 0; } } //Reading the ZBTRAM values to chkbuf status = readSSRAM(chkbuf, 5*bankSize , 1*bankSize, dma); if (status != ADMXRC2_SUCCESS) { printf("Error: failed to read SSRAM\n"); failed = TRUE; } //*******************PRINTING THE VALUES************************** //Print the written values to output_file1 in the required format if(!(fptr = fopen("../temp/output_file1","w"))) { printf("output_file1 cannot be opened.\n"); return -1; } fprintf(fptr,"Data written onto the bank-5\n"); for (j = 0;j < 20;j++) { fprintf(fptr, "%d\t\t\t %08X \n", j,rambuf[j+5*bankSize]); } fclose(fptr); //Print the results to output_file2 in the required format if(!(fptr = fopen("../temp/output_file2","w"))) { printf("output_file2 cannot be opened.\n"); return -1; } fprintf(fptr,"Data written onto the bank-5\n"); for (j = 0;j < 20;j++) { fprintf(fptr, "%d\t\t\t %08X \n", j,chkbuf[j+5*bankSize]); } fclose(fptr); //********************************************************************* if (failed){ printf("\n*** FAILED***\n"); } //Closing all the handles and frreing allocated space clean_all(); return 0; }
static void __exit seq_exit(void) { remove_proc_entry("my_data", NULL); clean_all(&head); }
int main(int argc, char** argv) { char *buffer = NULL; int portno = 0, stop, optval; socklen_t clilen; struct sockaddr_in serv_addr, cli_addr; struct sigaction action_CHLD; struct sigaction action_ALRM; /* Preliminary signal configuration: * SIGCHLD and SIGALRM are used with different handler * configure each handler to mask the other signal during it's process * Note: within a handler called upon a signal SIGX, the SIGX signal is * automatically de-activated. */ sigemptyset(&block_sigs); sigaddset(&block_sigs, SIGCHLD); sigaddset(&block_sigs, SIGALRM); action_CHLD.sa_flags = SA_RESTART; action_CHLD.sa_handler = SIGCHLD_handler; sigemptyset(&(action_CHLD.sa_mask)); sigaddset(&(action_CHLD.sa_mask), SIGALRM); action_ALRM.sa_flags = SA_RESTART; action_ALRM.sa_handler = SIGALRM_handler; sigemptyset(&(action_ALRM.sa_mask)); sigaddset(&(action_ALRM.sa_mask), SIGCHLD); PointerList_Create(&apps, 0); if (NULL == apps) err_exit("PointerList_Create"); /* Command line arguments Parsing * Options * a : privileged app path * w : privileged app working directory * v : user id to use to start privileged app * h : group id to use to start privileged app * p : TCP port to receive commands * u : user id to use to start regular apps * g : group id to use to start regular apps * n : nice value (process priority) for regular apps */ char* init_app = NULL; char* init_app_wd = NULL; app_t* privileged_app = NULL; int opt; char useropt_given = 0; char grpopt_given = 0; //optarg is set by getopt while ((opt = getopt(argc, argv, "a:w:v:h:p:u:g:n:")) != -1) { switch (opt) { case 'a': init_app = optarg; SWI_LOG("APPMON", DEBUG, "Command line arguments parsing: init_app %s\n", init_app); break; case 'w': init_app_wd = optarg; SWI_LOG("APPMON", DEBUG, "Command line arguments parsing: init_app_wd %s\n", init_app_wd); break; case 'p': parse_arg_integer(optarg, &portno, "Command line arguments parsing: bad format for port argument"); SWI_LOG("APPMON", DEBUG, "Command line arguments parsing: port =%d\n", portno); if (portno > UINT16_MAX) { err_exit("Command line arguments parsing: bad value for port, range=[0, 65535]"); } break; case 'u': useropt_given = 1; //used to set default value after cmd line option parsing get_uid_option(&uid); break; case 'v': get_uid_option(&puid); break; case 'g': grpopt_given = 1; //used to set default value after cmd line option parsing get_gid_option(&gid); break; case 'h': get_gid_option(&pgid); break; case 'n': parse_arg_integer(optarg, &app_priority, "Command line arguments parsing: app process priority must be an integer"); if (19 < app_priority || -20 > app_priority) { err_exit("Command line arguments parsing: app process priority must be between -20 and 19"); } SWI_LOG("APPMON", DEBUG, "Command line arguments parsing: nice increment =%d\n", app_priority); break; default: /* '?' */ SWI_LOG("APPMON", ERROR, "Command line arguments parsing: unknown argument\n"); break; } } if (NULL != init_app) { if (NULL == init_app_wd) { //using current working directory as privileged app wd. cwd = malloc(PATH_MAX); if (NULL == cwd) { err_exit("Cannot malloc init_app_wd"); } cwd = getcwd(cwd, PATH_MAX); if (NULL == cwd) { err_exit("getcwd failed to guess privileged app default wd"); } init_app_wd = cwd; } char * res = check_params(init_app_wd, init_app); if (NULL != res) { SWI_LOG("APPMON", ERROR, "check_params on privileged app failed: %s\n", res); err_exit("check_params on privileged app failed"); } privileged_app = add_app(init_app_wd, init_app, 1); if (NULL == privileged_app) { err_exit("add_app on privileged app failed"); } } if (!uid && !useropt_given) { //get default "nobody" user. uid = 65534; } if (!gid && !grpopt_given) { //get default "nogroup" group. gid = 65534; } SWI_LOG("APPMON", DEBUG, "Command line arguments parsing: will use uid=%d and gid=%d to run unprivileged apps\n", uid, gid); /* configuring signals handling */ if (sigaction(SIGCHLD, &action_CHLD, NULL)) err_exit("configuring signals handling: sigaction SIGCHLD call error"); if (sigaction(SIGALRM, &action_ALRM, NULL)) err_exit("configuring signals handling: sigaction SIGCHLD call error"); srv_skt = socket(AF_INET, SOCK_STREAM, 0); if (srv_skt < 0) err_exit("socket configuration: opening socket error"); // set SO_REUSEADDR on socket: optval = 1; if (setsockopt(srv_skt, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof optval)) err_exit("socket configuration: setting SO_REUSEADDR on socket failed"); bzero((char *) &serv_addr, sizeof(serv_addr)); portno = portno ? portno : DEFAULT_LISTENING_PORT; serv_addr.sin_family = AF_INET; serv_addr.sin_addr.s_addr = INADDR_ANY; serv_addr.sin_port = htons(portno); if (bind(srv_skt, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0) err_exit("socket configuration: error on binding"); if (listen(srv_skt, 5)) err_exit("socket configuration: error on listen"); clilen = sizeof(cli_addr); stop = 0; SWI_LOG("APPMON", DEBUG, "Init successful, now running as daemon.\n"); /* daemonize the later possible to enhance sync error reporting*/ daemonize(); /* Now we are a simple daemon */ SWI_LOG("APPMON", DEBUG, "Daemon pid=%d, Listening port = %d\n", getpid(), portno); if (privileged_app) { SWI_LOG("APPMON", DEBUG, "Autostarting privileged app\n"); start_app(privileged_app); } while (!stop) { fflush(stdout); client_skt = accept(srv_skt, (struct sockaddr *) &cli_addr, &clilen); if (client_skt < 0) { SWI_LOG("APPMON", ERROR, "socket configuration: error on accept: %s\n", strerror(errno)); SWI_LOG("APPMON", ERROR, "Now going to crippled mode: cannot use socket API anymore!\n"); if (client_skt) close(client_skt); if (srv_skt) close(srv_skt); // Sleep for 1.5 sec // sleep() function not used here, as it may disrupt the use of SIGALRM made in this program. struct timeval tv; while (1) { tv.tv_sec = 1; tv.tv_usec = 0; int res = select(0, NULL, NULL, NULL, &tv); SWI_LOG("APPMON", DEBUG, "crippled mode: select, res = %d\n", res); } //never returning from here, need to kill the daemon // but apps should still be managed. } SWI_LOG("APPMON", DEBUG, "new client ...\n"); buffer = readline(client_skt); //deal with all the requests coming from the new client while (NULL != buffer && !stop) { SWI_LOG("APPMON", DEBUG, "NEW cmd=[%s]\n", buffer); do { if (!strncmp(buffer, STOP_DAEMON, strlen(STOP_DAEMON))) { stop = 1; send_result("ok, destroy is in progress, stopping aps, closing sockets."); break; } if (!strncmp(buffer, PCONFIG, strlen(PCONFIG))) { send_result( fill_output_buf( "appmon_daemon: version[%s], uid=[%d], gid=[%d], puid=[%d], pgid=[%d], app_priority=[%d]", GIT_REV, uid, gid, puid, pgid, app_priority)); break; } if (!strncmp(buffer, SETUP_APP, strlen(SETUP_APP))) { char* buf = buffer; strsep(&buf, " "); char* wd = strsep(&buf, " "); char* prog = strsep(&buf, " "); SWI_LOG("APPMON", DEBUG, "SETUP wd =%s, prog = %s\n", wd, prog); if (NULL == wd || NULL == prog) { send_result("Bad command format, must have wd and prog params"); break; } char *res = check_params(wd, prog); if (res) { send_result(res); break; } sigprocmask(SIG_BLOCK, &block_sigs, NULL); app_t* app = add_app(wd, prog, 0); if (NULL == app) send_result("Cannot add app"); else send_result(fill_output_buf("%d", app->id)); sigprocmask(SIG_UNBLOCK, &block_sigs, NULL); break; } if (!strncmp(buffer, START_APP, strlen(START_APP))) { char* str_id = buffer + strlen(START_APP); int id = atoi(str_id); SWI_LOG("APPMON", DEBUG, "START_APP, id =%d\n", id); if (id == 0) { send_result("Bad command format, start called with invalid app id"); break; } sigprocmask(SIG_BLOCK, &block_sigs, NULL); app_t* app = find_by_id(id); if (app == NULL) { send_result("Unknown app"); sigprocmask(SIG_UNBLOCK, &block_sigs, NULL); break; } if (app->privileged) { send_result("Privileged App, cannot act on it through socket."); sigprocmask(SIG_UNBLOCK, &block_sigs, NULL); break; } if (app->status != KILLED) { send_result("App already running (or set to be restarted), start command discarded"); sigprocmask(SIG_UNBLOCK, &block_sigs, NULL); break; } send_result(start_app(app)); sigprocmask(SIG_UNBLOCK, &block_sigs, NULL); break; } if (!strncmp(buffer, STOP_APP, strlen(STOP_APP))) { char* str_id = buffer + strlen(STOP_APP); int id = atoi(str_id); if (id == 0) { send_result("Bad command format, stop called with invalid app id"); break; } sigprocmask(SIG_BLOCK, &block_sigs, NULL); app_t* app = find_by_id(id); if (NULL == app) send_result("Unknown app"); else { if (app->privileged) { send_result("Privileged App, cannot act on it through socket."); sigprocmask(SIG_UNBLOCK, &block_sigs, NULL); break; } //stop command has effect only if application is running. if (app->status == STARTED || app->status == TO_BE_KILLED) { send_result(stop_app(app)); } else { //application is already stopped (app->status could be KILLED or TO_BE_RESTARTED) app->status = KILLED; //force app->status = KILLED, prevent app to be restarted if restart was scheduled. (see SIG ALRM handler) send_result("ok, already stopped, won't be automatically restarted anymore"); } } sigprocmask(SIG_UNBLOCK, &block_sigs, NULL); break; } if (!strncmp(buffer, REMOVE_APP, strlen(REMOVE_APP))) { char* str_id = buffer + strlen(REMOVE_APP); int id = atoi(str_id); if (id == 0) { send_result("Bad command format, remove called with invalid app id"); break; } sigprocmask(SIG_BLOCK, &block_sigs, NULL); app_t* app = find_by_id(id); if (NULL == app) send_result("Unknown app"); else { if (app->privileged) { send_result("Privileged App, cannot act on it through socket."); sigprocmask(SIG_UNBLOCK, &block_sigs, NULL); break; } //stop command has effect only if application is running. if (app->status == STARTED || app->status == TO_BE_KILLED) { stop_app(app); //trying to stop, no big deal with it fails } app_t* app = NULL; unsigned int size, i = 0; PointerList_GetSize(apps, &size, NULL); for (i = 0; i < size; i++) { PointerList_Peek(apps, i, (void**) &app); if (app->id == id) { rc_ReturnCode_t res = 0; if (RC_OK != (res = PointerList_Remove(apps, i, (void**) &app))) { send_result(fill_output_buf("Remove: PointerList_Remove failed, AwtStatus =%d", res)); } else { free(app); send_result("ok"); } break; } } } sigprocmask(SIG_UNBLOCK, &block_sigs, NULL); break; } if (!strncmp(buffer, STATUS_APP, strlen(STATUS_APP))) { char* str_id = buffer + strlen(STATUS_APP); int id = atoi(str_id); if (id == 0) { send_result("Bad command format, status called with invalid app id"); break; } sigprocmask(SIG_BLOCK, &block_sigs, NULL); app_t* app = find_by_id(id); if (NULL == app) send_result("Unknown app"); else { SWI_LOG("APPMON", DEBUG, "sending app status...\n"); send_result(create_app_status(app)); } sigprocmask(SIG_UNBLOCK, &block_sigs, NULL); break; } if (!strncmp(buffer, LIST_APPS, strlen(LIST_APPS))) { SWI_LOG("APPMON", DEBUG, "sending app list ...\n"); sigprocmask(SIG_BLOCK, &block_sigs, NULL); app_t* app = NULL; unsigned int size, i = 0; PointerList_GetSize(apps, &size, NULL); for (i = 0; i < size; i++) { PointerList_Peek(apps, i, (void**) &app); char* app_status_tmp = create_app_status(app); if (strlen(app_status_tmp) != write(client_skt, app_status_tmp, strlen(app_status_tmp))) { SWI_LOG("APPMON", ERROR, "list: cannot write res to socket\n"); } SWI_LOG("APPMON", DEBUG, "list: send status, app_status_tmp=%s\n", app_status_tmp); char* statussep = "\t"; if (strlen(statussep) != write(client_skt, statussep, strlen(statussep))) { SWI_LOG("APPMON", ERROR, "list: cannot write statussep: %s\n", statussep); } } send_result(""); sigprocmask(SIG_UNBLOCK, &block_sigs, NULL); break; } if (!strncmp(buffer, SETENV, strlen(SETENV))) { char *arg, *varname, *tmp; arg = buffer + strlen(SETENV); varname = arg; tmp = strchr(arg, '='); *tmp++ = '\0'; SWI_LOG("APPMON", DEBUG, "Setting Application framework environment variable %s = %s...\n", varname, tmp); setenv(varname, tmp, 1); send_result(""); break; } //command not found send_result("command not found"); SWI_LOG("APPMON", DEBUG, "Command not found\n"); } while (0); if (stop) break; //read some data again to allow to send several commands with the same socket buffer = readline(client_skt); } //end while buffer not NULL: current client has no more data to send //current client exited, let's close client skt, wait for another connexion close(client_skt); } sigprocmask(SIG_BLOCK, &block_sigs, NULL); int exit_status_daemon = clean_all(); SWI_LOG("APPMON", DEBUG, "appmon daemon end, exit_status_daemon: %d\n", exit_status_daemon); return exit_status_daemon; }
int main ( int argc, char *argv[] ) { pwr_tStatus sts; int event; plc_sProcess *pp; uid_t ruid; struct passwd *pwd; /* struct rlimit rlim; int i; */ /* Set core dump file size limit to infinite */ /* rlim.rlim_cur = RLIM_INFINITY; rlim.rlim_max = RLIM_INFINITY; sts = setrlimit(RLIMIT_CORE, &rlim); printf("%d\n", sts); i = 1/0; printf("%d\n", i); */ pp = init_process(); qcom_WaitAnd(&sts, &pp->eventQ, &qcom_cQini, ini_mEvent_newPlcInit, qcom_cTmoEternal); init_plc(pp); create_threads(pp); init_threads(pp); /* Once threads has set their priority don't run as root */ #if 0 ruid = getuid(); if (ruid == 0) { pwd = getpwnam("pwrp"); if (pwd != NULL) { setreuid(pwd->pw_uid, pwd->pw_uid); } } else setreuid(ruid, ruid); #endif qcom_SignalOr(&sts, &qcom_cQini, ini_mEvent_newPlcInitDone); qcom_WaitAnd(&sts, &pp->eventQ, &qcom_cQini, ini_mEvent_newPlcStart, qcom_cTmoEternal); // proc_SetPriority(pp->PlcProcess->Prio); set_values(pp); start_threads(pp); run_threads(pp); time_Uptime(&sts, &pp->PlcProcess->StartTime, NULL); qcom_SignalOr(&sts, &qcom_cQini, ini_mEvent_newPlcStartDone); #if 0 /* Force the backup to take care initialized backup objects. */ bck_ForceBackup(NULL); #endif errh_SetStatus( PWR__SRUN); qcom_WaitOr(&sts, &pp->eventQ, &qcom_cQini, ini_mEvent_terminate | ini_mEvent_oldPlcStop, qcom_cTmoEternal, &event); switch ( event) { case ini_mEvent_terminate: errh_SetStatus( PWR__SRVTERM); stop_threads(pp); clean_all(pp); nmps_delete_lock( &sts); break; case ini_mEvent_oldPlcStop: errh_SetStatus( PWR__SRVTERM); time_Uptime(&sts, &pp->PlcProcess->StopTime, NULL); stop_threads(pp); save_values(pp); qcom_SignalOr(&sts, &qcom_cQini, ini_mEvent_oldPlcStopDone); #if defined OS_ELN sts = proc_SetPriority(31); #endif clean_all(pp); break; default: ; } exit(0); }
/*! A function version of the program mc by Thomas Lewiner see main.c in ./MarchingCubes */ SUMA_SurfaceObject *SUMA_MarchingCubesSurface( SUMA_GENERIC_PROG_OPTIONS_STRUCT * Opt) { static char FuncName[]={"SUMA_MarchingCubesSurface"}; SUMA_SurfaceObject *SO=NULL; int nxx, nyy, nzz, cnt, i, j, k, *FaceSetList=NULL; float *NodeList=NULL; SUMA_NEW_SO_OPT *nsoopt = NULL; THD_fvec3 fv, iv; MCB *mcp ; SUMA_ENTRY; if (Opt->obj_type < 0) { nxx = DSET_NX(Opt->in_vol); nyy = DSET_NY(Opt->in_vol); nzz = DSET_NZ(Opt->in_vol); if (Opt->debug) { fprintf(SUMA_STDERR, "%s:\nNxx=%d\tNyy=%d\tNzz=%d\n", FuncName, nxx, nyy, nzz); } mcp = MarchingCubes(-1, -1, -1); set_resolution( mcp, nxx, nyy, nzz ) ; init_all(mcp) ; if (Opt->debug) fprintf(SUMA_STDERR,"%s:\nSetting data...\n", FuncName); cnt = 0; for( k = 0 ; k < mcp->size_z ; k++ ) { for( j = 0 ; j < mcp->size_y ; j++ ) { for( i = 0 ; i < mcp->size_x ; i++ ) { SUMA_SET_MC_DATA ( mcp, Opt->mcdatav[cnt], i, j, k); ++cnt; } } } } else { /* built in */ nxx = nyy = nzz = Opt->obj_type_res; mcp = MarchingCubes(-1, -1, -1); set_resolution( mcp, nxx, nyy, nzz) ; init_all(mcp) ; compute_data( *mcp , Opt->obj_type) ; } if (Opt->debug) fprintf(SUMA_STDERR,"%s:\nrunning MarchingCubes...\n", FuncName); run(mcp) ; clean_temps(mcp) ; if (Opt->debug > 1) { fprintf(SUMA_STDERR,"%s:\nwriting out NodeList and FaceSetList...\n", FuncName); write1Dmcb(mcp); } if (Opt->debug) { fprintf(SUMA_STDERR,"%s:\nNow creating SO...\n", FuncName); } NodeList = (float *)SUMA_malloc(sizeof(float)*3*mcp->nverts); FaceSetList = (int *)SUMA_malloc(sizeof(int)*3*mcp->ntrigs); if (!NodeList || !FaceSetList) { SUMA_SL_Crit("Failed to allocate!"); SUMA_RETURN(SO); } nsoopt = SUMA_NewNewSOOpt(); if (Opt->obj_type < 0) { nsoopt->LargestBoxSize = -1; if (Opt->debug) { fprintf(SUMA_STDERR, "%s:\nCopying vertices, changing to DICOM \n" "Orig:(%f %f %f) \nD:(%f %f %f)...\n", FuncName, DSET_XORG(Opt->in_vol), DSET_YORG(Opt->in_vol), DSET_ZORG(Opt->in_vol), DSET_DX(Opt->in_vol), DSET_DY(Opt->in_vol), DSET_DZ(Opt->in_vol)); } for ( i = 0; i < mcp->nverts; i++ ) { j = 3*i; /* change from index coordinates to mm DICOM, next three lines are equivalent of SUMA_THD_3dfind_to_3dmm*/ fv.xyz[0] = DSET_XORG(Opt->in_vol) + mcp->vertices[i].x * DSET_DX(Opt->in_vol); fv.xyz[1] = DSET_YORG(Opt->in_vol) + mcp->vertices[i].y * DSET_DY(Opt->in_vol); fv.xyz[2] = DSET_ZORG(Opt->in_vol) + mcp->vertices[i].z * DSET_DZ(Opt->in_vol); /* change mm to RAI coords */ iv = SUMA_THD_3dmm_to_dicomm( Opt->in_vol->daxes->xxorient, Opt->in_vol->daxes->yyorient, Opt->in_vol->daxes->zzorient, fv ); NodeList[j ] = iv.xyz[0]; NodeList[j+1] = iv.xyz[1]; NodeList[j+2] = iv.xyz[2]; } for ( i = 0; i < mcp->ntrigs; i++ ) { j = 3*i; FaceSetList[j ] = mcp->triangles[i].v3; FaceSetList[j+1] = mcp->triangles[i].v2; FaceSetList[j+2] = mcp->triangles[i].v1; } } else { nsoopt->LargestBoxSize = 100; /* built in */ for ( i = 0; i < mcp->nverts; i++ ) { j = 3*i; NodeList[j ] = mcp->vertices[i].x; NodeList[j+1] = mcp->vertices[i].y; NodeList[j+2] = mcp->vertices[i].z; } for ( i = 0; i < mcp->ntrigs; i++ ) { j = 3*i; FaceSetList[j ] = mcp->triangles[i].v3; FaceSetList[j+1] = mcp->triangles[i].v2; FaceSetList[j+2] = mcp->triangles[i].v1; } } SO = SUMA_NewSO(&NodeList, mcp->nverts, &FaceSetList, mcp->ntrigs, nsoopt); if (Opt->obj_type < 0) { /* not sure if anything needs to be done here ...*/ } else { if (Opt->obj_type == 0) SO->normdir = 1; else SO->normdir = -1; } if (Opt->debug) { fprintf(SUMA_STDERR,"%s:\nCleaning mcp...\n", FuncName); } clean_all(mcp) ; free(mcp); nsoopt=SUMA_FreeNewSOOpt(nsoopt); SUMA_RETURN(SO); }
fireworks::~fireworks() { clean_all(); }