static void dmq_rpc_list_nodes(rpc_t *rpc, void *c) { void *h; dmq_node_t* cur = node_list->nodes; char ip[IP6_MAX_STR_SIZE + 1]; while(cur) { memset(ip, 0, IP6_MAX_STR_SIZE + 1); ip_addr2sbuf(&cur->ip_address, ip, IP6_MAX_STR_SIZE); if (rpc->add(c, "{", &h) < 0) goto error; if (rpc->struct_add(h, "SSsSdd", "host", &cur->uri.host, "port", &cur->uri.port, "resolved_ip", ip, "status", get_status_str(cur->status), "last_notification", cur->last_notification, "local", cur->local) < 0) goto error; cur = cur->next; } return; error: LM_ERR("Failed to add item to RPC response\n"); rpc->fault(c, 500, "Server failure"); return; }
void ExtFrameBuffer::check_status() const { GLuint status; status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT); if (status != GL_FRAMEBUFFER_COMPLETE_EXT) { EL_THROW_EXCEPTION(OpenGlException() << errinfo_message(get_status_str(status)) << errinfo_opengl_error(status)); } }
/** * @brief build dmq node string */ int build_node_str(dmq_node_t* node, char* buf, int buflen) { /* sip:host:port;status=[status] */ int len = 0; if(buflen < node->orig_uri.len + 32) { LM_ERR("no more space left for node string\n"); return -1; } memcpy(buf + len, "sip:", 4); len += 4; memcpy(buf + len, node->uri.host.s, node->uri.host.len); len += node->uri.host.len; memcpy(buf + len, ":", 1); len += 1; memcpy(buf + len, node->uri.port.s, node->uri.port.len); len += node->uri.port.len; memcpy(buf + len, ";", 1); len += 1; memcpy(buf + len, "status=", 7); len += 7; memcpy(buf + len, get_status_str(node->status)->s, get_status_str(node->status)->len); len += get_status_str(node->status)->len; return len; }
int pres_update_status(subs_t subs, str reason, db_key_t* query_cols, db_val_t* query_vals, int n_query_cols, subs_t** subs_array) { db_key_t update_cols[5]; db_val_t update_vals[5]; int n_update_cols= 0; int u_status_col, u_reason_col, q_wuser_col, q_wdomain_col; int status; query_cols[q_wuser_col=n_query_cols]= &str_watcher_username_col; query_vals[n_query_cols].nul= 0; query_vals[n_query_cols].type= DB1_STR; n_query_cols++; query_cols[q_wdomain_col=n_query_cols]= &str_watcher_domain_col; query_vals[n_query_cols].nul= 0; query_vals[n_query_cols].type= DB1_STR; n_query_cols++; update_cols[u_status_col= n_update_cols]= &str_status_col; update_vals[u_status_col].nul= 0; update_vals[u_status_col].type= DB1_INT; n_update_cols++; update_cols[u_reason_col= n_update_cols]= &str_reason_col; update_vals[u_reason_col].nul= 0; update_vals[u_reason_col].type= DB1_STR; n_update_cols++; status= subs.status; if(subs.event->get_auth_status(&subs)< 0) { LM_ERR( "getting status from rules document\n"); return -1; } LM_DBG("subs.status= %d\n", subs.status); if(get_status_str(subs.status)== NULL) { LM_ERR("wrong status: %d\n", subs.status); return -1; } if(subs.status!= status || reason.len!= subs.reason.len || (reason.s && subs.reason.s && strncmp(reason.s, subs.reason.s, reason.len))) { /* update in watchers_table */ query_vals[q_wuser_col].val.str_val= subs.watcher_user; query_vals[q_wdomain_col].val.str_val= subs.watcher_domain; update_vals[u_status_col].val.int_val= subs.status; update_vals[u_reason_col].val.str_val= subs.reason; if (pa_dbf.use_table(pa_db, &watchers_table) < 0) { LM_ERR( "in use_table\n"); return -1; } if(pa_dbf.update(pa_db, query_cols, 0, query_vals, update_cols, update_vals, n_query_cols, n_update_cols)< 0) { LM_ERR( "in sql update\n"); return -1; } /* save in the list all affected dialogs */ /* if status switches to terminated -> delete dialog */ if(update_pw_dialogs(&subs, subs.db_flag, subs_array)< 0) { LM_ERR( "extracting dialogs from [watcher]=%.*s@%.*s to" " [presentity]=%.*s\n", subs.watcher_user.len, subs.watcher_user.s, subs.watcher_domain.len, subs.watcher_domain.s, subs.pres_uri.len, subs.pres_uri.s); return -1; } } return 0; }
int execute(int cmd_type, int cmd_block, char * filename, char *argv[]) { int ret,count,status; char buffer[MAX_INPUT_LENGTH]; switch(cmd_type) { case -1: print_out("Invalid Command"); break; case 0: ret = fork(); if(ret == 0) { sprintf(buffer,"Executing child %d",getpid()); print_out(buffer); execvp(argv[0],argv); perror("Error occured in exec() call"); exit(1); } else if(ret == -1) { perror("Error occured in fork() call"); } else { if(cmd_block){ waitpid(ret,&status,0); get_status_str(status,ret,buffer); print_out(buffer); } } break; case 1: chdir(argv[1]); break; case 2: getcwd(buffer,MAX_INPUT_LENGTH * sizeof(char)); print_out(buffer); break; case 3: sprintf(buffer,"Process ID: %d", getpid()); print_out(buffer); break; case 4: sprintf(buffer,"Parent Process ID: %d", getppid()); print_out(buffer); break; case 5: if(argv[1] == NULL || strcmp(argv[1],"") == 0) { count = history_count; } else { sscanf(argv[1],"-%d",&count); if(count > history_count) { count = history_count; } } int j; sprintf(buffer,"Printing out the last %d commands",count); print_out(buffer); for(j = count -1; j >= 0; j--) { printf("%s\n",history[j]); } break; case 6: return 1;//exit break; } return 0; }
int main(int argc, char ** argv) { //get command line arguments int c; char * pvalue = NULL; while ((c = getopt (argc, argv, "p:")) != -1) { switch (c) { case 'p': pvalue = optarg; break; default: break; } } int cmd_type; //enumerated value to determine how command is executed int cmd_block; //whether to wait for child to exit or not int cmd_argc; //number of args counted while parsing char cmd_args[MAX_ARG_COUNT][MAX_INPUT_LENGTH]; //store command line args char * exec_args[MAX_ARG_COUNT]; //cmd_args incompatible type with execvp //ready prompt char prompt[MAX_INPUT_LENGTH]; init_prompt(prompt); if(pvalue != NULL) { change_prompt(prompt,pvalue); } char buffer[MAX_INPUT_LENGTH]; //general purpose string buffer int done = 0; do { //clear command buffer int i; for(i = 0; i < MAX_ARG_COUNT; i++) { cmd_args[i][0] = '\0'; } //get input print_prompt(prompt); scanf("\n"); scanf("%[^\n]",buffer); //store history strcpy(history[history_count],buffer); history_count++; //tokenize char * ptr = strtok(buffer," "); i = 0; while(ptr != NULL) { strcpy(cmd_args[i],ptr); ptr = strtok(NULL," "); i++; } argc = i; //set state based on input cmd_type = get_type(cmd_args[0]); cmd_block = get_block(cmd_args[argc-1]); int j; for(j = 0; j < argc; j++) { exec_args[j] = cmd_args[j]; } if(!cmd_block) //want to eliminate & { exec_args[argc-1] = NULL; } else //keep all args parsed { exec_args[argc] = NULL; } //check if any children exited int status, child_pid; child_pid = waitpid(-1,&status,WNOHANG); if(child_pid > 0) { get_status_str(status,child_pid,buffer); print_out(buffer); } //execute done = execute(cmd_type,cmd_block,cmd_args[0],exec_args); }while(!done); return 0; }