termination_baset::termination_baset( const cmdlinet &_cmd, const goto_functionst &_gf, const contextt &_ctxt, class contextt &_sctxt, class value_set_analysist &_vsa, class invariant_propagationt &_ip, message_handlert &_mh, ui_message_handlert::uit _ui): messaget(_mh), context(_ctxt), shadow_context(_sctxt), cmdline(_cmd), ns(_ctxt, _sctxt), ui(_ui), goto_functions(_gf), value_set_analysis(_vsa), invariant_propagation(_ip), start_time(current_time()), ranking_time(0), modelchecker_time(0), counter_example_extraction_time(0), final_check_time(0), ranksynth_calls(0), total_loops(0), nonterminating_loops(0), nondet_counter(0) { set_verbosity(6); if(cmdline.isset("v")) set_verbosity(atoi(cmdline.getval("v"))); set_options(); }
int cbmc_parseoptionst::doit() { if(cmdline.isset("version")) { std::cout << CBMC_VERSION << std::endl; return 0; } // // unwinding of transition systems // if(cmdline.isset("module") || cmdline.isset("gen-interface")) { error("This version of CBMC has no support for " " hardware modules. Please use hw-cbmc."); return 1; } register_languages(); // // command line options // optionst options; get_command_line_options(options); bmct bmc(options, context, ui_message_handler); set_verbosity(bmc); set_verbosity(*this); if(cmdline.isset("preprocess")) { preprocessing(); return 0; } goto_functionst goto_functions; if(get_goto_program(options, bmc, goto_functions)) return 6; if(cmdline.isset("show-claims")) { const namespacet ns(context); show_claims(ns, get_ui(), goto_functions); return 0; } if(set_claims(goto_functions)) return 7; // do actual BMC return do_bmc(bmc, goto_functions); }
static WORD LEX_readln(LEX_class *LEX) { WORD i, j, done; done = 0; do { if (!read_text_line(LEX->handle, MAX_IN_LEN, LEX->buf)) return (-1); if (LEX->buf[0] == '') switch (LEX->buf[1]) { case '<': set_verbosity(verbose() + 1); break; case '>': set_verbosity(verbose() - 1); break; } else done = 1; } while (!done); if (!(LEX->flags & LEX_LININFO)) return (0); j = strlen(LEX->buf); if (LEX->file_list != NULL) for (i = 0; i < j; i++) if (LEX->buf[i] == ' ') { LEX->buf[i] = 0; if (DICT_lookup(LEX->file_list, LEX->buf) == NULL) DICT_enter(LEX->file_list, LEX->buf, 0); LEX->buf[i] = ' '; break; } for (i = 2; i < j; i++) if ((LEX->buf[i - 2] == ':') && (LEX->buf[i - 1] == ' ')) break; if (i == j) return (-1); LEX->buf[i - 2] = 0; LEX->state[0].new_line = 1; LEX->state[1].new_line = 1; report(E_NEWLINE, NULL, NULL); return (i); }
HydroDriver::HydroDriver(GridNode* a) { ChildIndex i; root = a; step_cnt = 0; ostep_cnt = 0; set_output_off(); set_rk(RK_ORDER); #ifndef NDEBUG set_verbosity(DEBUG_V); #else set_verbosity(DEBUG_V); #endif }
bool tan_parseoptionst::check_and_set_options() { if (config.set(cmdline)) { usage_error(); return true; } if(cmdline.isset("version")) { std::cout << TAN_VERSION << std::endl; return true; } int verbosity=6; if(cmdline.isset("v")) verbosity=atoi(cmdline.getval("v")); set_verbosity(verbosity); if(cmdline.args.size()==0) { error("Please provide an input file."); return 1; } else if (cmdline.args.size()>1) { error("Multiple input files not supported."); return 1; } std::string engine="cta"; if(cmdline.isset("engine")) engine=cmdline.getval("engine"); if(cmdline.isset("no-loop-slicing") && engine!="direct" && engine!="bre") warning("Warning: --no-loop-slicing is only available " "with the following engines: bre, direct."); if(cmdline.isset("unranked-method")) { std::string u_mode=cmdline.getval("unranked-method"); if(u_mode!="none" && u_mode!="precondition" && u_mode!="bmc-precondition" && u_mode!="cegar" && u_mode!="bmc") warning("Warning: unknown unranked-method."); } return false; }
void symex_parseoptionst::eval_verbosity() { // this is our default verbosity int v=messaget::M_STATISTICS; if(cmdline.isset("verbosity")) { v=unsafe_string2int(cmdline.getval("verbosity")); if(v<0) v=0; else if(v>10) v=10; } set_verbosity(v); }
void CommandLineHandlerBase::parse( const int argc, const char* argv[], SuperLogger& logger) { ParseResults results; impl->m_parser.parse(argc, argv, results); if (impl->m_message_coloring.is_set()) logger.enable_message_coloring(); if (impl->m_message_verbosity.is_set()) set_verbosity(logger, impl->m_message_verbosity.value()); if (impl->m_version.is_set()) print_version_information(logger); if (impl->m_system.is_set()) print_system_information(logger); if (impl->m_help.is_set()) { const string program_name = filesystem::path(argv[0]).filename().string(); print_program_usage(program_name.c_str(), logger); exit(0); } if (impl->m_display_options.is_set()) { LOG_INFO(logger, "recognized options:"); impl->m_parser.print_recognized_options(logger); } results.m_messages.print(logger); if (results.m_errors > 0 || results.m_warnings > 0) { LOG( logger, results.m_errors > 0 ? LogMessage::Fatal : LogMessage::Warning, FMT_SIZE_T " error%s, " FMT_SIZE_T " warning%s encountered while parsing the command line.", results.m_errors, results.m_errors > 1 ? "s" : "", results.m_warnings, results.m_warnings > 1 ? "s" : ""); } }
int main(int argc, char **argv) { char mac_addr[ETH_ALEN]; char elan_name[32 + 1]; char preferred_les[ATM_ESA_LEN]; /* LANE2 */ char foreId[255]; /* Max size for a TLV */ char atm2textbuff[100]; char esibuff[20]; int esi_set = 0; int listen_addr_set = 0; int atm_set=0; int proxy_flag = 0; int lane_version = 0; /* LANE2 */ int max_frame_size = MTU_UNSPEC; int lecs_method = LECS_WELLKNOWN; int poll_ret = 0, itf = 0, phys_itf = 0, selector = 0; int daemon_flag = 0; pid_t pid; struct sockaddr_atmsvc manual_atm_addr; struct sockaddr_atmsvc listen_addr; char pidbuf[PATH_MAX + 1]; int fd; int retval; memset(elan_name, '\0', sizeof(elan_name)); memset(foreId, '\0', sizeof(foreId)); memset(preferred_les, 0, ATM_ESA_LEN); memset(&manual_atm_addr, 0, sizeof(struct sockaddr_atmsvc)); memset(&listen_addr, 0, sizeof(struct sockaddr_atmsvc)); listen_addr.sas_family = AF_ATMSVC; set_application("zeppelin"); /* for debug msgs */ while(poll_ret != -1) { poll_ret = getopt(argc, argv, "bc:e:n:s:m:l:i:I:q:12pf:t:F:"); switch(poll_ret) { case 'b': daemon_flag = 1; break; case 'c': if (atm_set) { usage(argv[0]); exit(-1); } if (text2atm(optarg, (struct sockaddr *)&manual_atm_addr, sizeof(struct sockaddr_atmsvc), T2A_NAME) < 0) { diag(COMPONENT, DIAG_ERROR, "Invalid LECS address"); usage(argv[0]); exit(-1); } atm2text(atm2textbuff, sizeof(atm2textbuff), (struct sockaddr *)&manual_atm_addr, 0); diag(COMPONENT, DIAG_INFO, "LECS address: %s", atm2textbuff); lecs_method = LECS_MANUAL; atm_set=1; break; case 'e': if(esi_convert(optarg, mac_addr)<0) { diag(COMPONENT, DIAG_ERROR, "Invalid ESI format"); usage(argv[0]); exit(-1); } mac2text(esibuff, mac_addr); diag(COMPONENT, DIAG_DEBUG, "LEC ESI:%s", esibuff); esi_set=1; break; case 'n': if (strlen(optarg) > 32) { diag(COMPONENT, DIAG_ERROR, "ELAN name too long"); exit(-1); } strcpy(elan_name, optarg); diag(COMPONENT, DIAG_INFO, "Vlan name :'%s'", elan_name); break; case 's': if (atm_set) { usage(argv[0]); exit(-1); } if (text2atm(optarg, (struct sockaddr *)&manual_atm_addr, sizeof(struct sockaddr_atmsvc), T2A_NAME) < 0) { diag(COMPONENT, DIAG_ERROR, "Invalid LES address"); usage(argv[0]); exit(-1); } atm2text(atm2textbuff, sizeof(atm2textbuff), (struct sockaddr *)&manual_atm_addr, 0); diag(COMPONENT, DIAG_INFO, "LES address: %s", atm2textbuff); lecs_method = LECS_NONE; atm_set=1; break; case 'm': set_verbosity(NULL, DIAG_DEBUG); break; case 'l': if (isdigit(optarg[0]) && strlen(optarg) < 4 && sscanf(optarg, "%d", &selector) && selector >=0 && selector <= 0xff) { listen_addr.sas_addr.prv[ATM_ESA_LEN - 1] = (char) selector; diag(COMPONENT, DIAG_INFO, "Selector byte set " "to %d", selector); } else { if (text2atm(optarg, (struct sockaddr *)&listen_addr, sizeof(struct sockaddr_atmsvc), T2A_NAME) < 0) { diag(COMPONENT, DIAG_ERROR, "Invalid ATM listen address"); usage(argv[0]); exit(-1); } listen_addr_set = 1; } break; case 'i': if (sscanf(optarg, "%d", &itf) <= 0 || itf >= MAX_LEC_ITF) { diag(COMPONENT, DIAG_ERROR, "Invalid interface number"); usage(argv[0]); exit(-1); } diag(COMPONENT, DIAG_INFO, "Interface number set to %d", itf); break; case 'I': if (sscanf(optarg, "%d", &phys_itf) <= 0 || phys_itf < 0) { diag(COMPONENT, DIAG_ERROR, "Invalid physical interface number"); usage(argv[0]); exit(-1); } diag(COMPONENT, DIAG_INFO, "Physical interface number set to %d", phys_itf); break; case 'q': #if 0 if (text2qos(optarg,NULL,0) < 0) { diag(COMPONENT, DIAG_ERROR, "Invalid QOS specification"); usage(argv[0]); exit(-1); } qos_spec = optarg; #endif diag(COMPONENT, DIAG_INFO, "-q is deprecated, ignoring it"); break; case '1': lane_version = 1; break; case '2': lane_version = 2; break; case 'p': proxy_flag = 1; break; case 'f': if (strlen(optarg) > 255) { diag(COMPONENT, DIAG_ERROR, "foreId too long"); exit(-1); } memcpy (foreId, optarg, strlen(optarg)); foreId[strlen(optarg)] = '\0'; diag(COMPONENT, DIAG_INFO, "foreId :'%s'", foreId); break; case 't': /* ERIC */ if( !strncmp( optarg, "1516", 4 )) max_frame_size = MTU_1516; else if( !strncmp( optarg, "1580", 4 )) max_frame_size = MTU_1580; else if( !strncmp( optarg, "4544", 4 )) max_frame_size = MTU_4544; else if( !strncmp( optarg, "9234", 4 )) max_frame_size = MTU_9234; else if( !strncmp( optarg, "18190", 5 )) max_frame_size = MTU_18190; break; case 'F': set_logfile(optarg); diag(COMPONENT, DIAG_DEBUG, "logfile set to %s", optarg); break; case -1: break; default: usage(argv[0]); exit(-1); } } if (argc != optind) { usage(argv[0]); exit(1); } if (lane_version == 1 && max_frame_size == MTU_1580) { diag(COMPONENT, DIAG_ERROR, "MTU 1580 not defined with LANEv1"); exit(-1); } /* Reserve signals */ signal(SIGHUP, sig_reset); signal(SIGPIPE, SIG_IGN); if (!esi_set) { if(addr_getesi(mac_addr, phys_itf) < 0) { diag(COMPONENT, DIAG_ERROR, "Can't get ESI from kernel!"); return -1; } mac2text(esibuff, mac_addr); diag(COMPONENT, DIAG_DEBUG, "LEC ESI:%s", esibuff); if (itf != 0) mac_addr[0] = 0x2 | ((itf - 1) << 2); } if ((itf = kernel_init(mac_addr, itf)) < 0 ) { diag(COMPONENT, DIAG_FATAL, "Kernel interface creation failed, exiting..."); return -1; } if (daemon_flag == 1) { daemon_flag = 0; pid = fork(); if (pid < 0) { diag(COMPONENT, DIAG_FATAL, "fork failed, exiting..."); return -1; } if (pid) { /* parent */ return 0; } else { /* child */ if (setsid() < 0) { diag(COMPONENT, DIAG_FATAL, "setsid failed, exiting..."); return -1; } } } sprintf(pidbuf, "/var/run/lec%d.pid", itf); fd = open(pidbuf, O_CREAT | O_WRONLY, 0600); if (fd < 0) { diag(COMPONENT, DIAG_FATAL, "open(%s, ..) failed, %s", pidbuf, strerror(errno)); return -1; } sprintf(pidbuf, "%d\n", getpid()); write(fd, pidbuf, strlen(pidbuf)); close(fd); /* Loop here until the Sun gets cold */ while (1) { if (!listen_addr_set) { char sel = listen_addr.sas_addr.prv[ATM_ESA_LEN - 1]; if (get_listenaddr(listen_addr.sas_addr.prv, phys_itf) < 0) { diag(COMPONENT, DIAG_FATAL, "Could not figure out my ATM address"); exit(-1); } listen_addr.sas_addr.prv[ATM_ESA_LEN - 1] = sel; } atm2text(atm2textbuff, sizeof(atm2textbuff), (struct sockaddr *)&listen_addr, A2T_NAME | A2T_PRETTY | A2T_LOCAL); diag(COMPONENT, DIAG_INFO, "Our ATM address: %s", atm2textbuff); diag(COMPONENT, DIAG_DEBUG, "initializing lec parameters"); init_lec_params(mac_addr, elan_name, listen_addr.sas_addr.prv, itf, foreId, max_frame_size, proxy_flag, lane_version); if (lecs_method != LECS_MANUAL && lecs_method != LECS_NONE) { diag(COMPONENT, DIAG_DEBUG, "trying to get LECS address from ILMI"); /* Not sure why this memset is necessary */ memset(&manual_atm_addr, 0, sizeof(struct sockaddr_atmsvc)); retval = get_lecsaddr(phys_itf, &manual_atm_addr); if (retval <= 0) { diag(COMPONENT, DIAG_DEBUG, "get_lecsaddr failed; not enough " "memory allocated for all addresses " "or no LECS address registered"); } else { diag(COMPONENT, DIAG_DEBUG, "obtained LECS address from ILMI"); lecs_method = LECS_FROM_ILMI; } } diag(COMPONENT, DIAG_DEBUG, "About to connect LECS"); if (lec_configure(lecs_method, &manual_atm_addr, &listen_addr) < 0) { close_connections(); random_delay(); continue; } diag(COMPONENT, DIAG_DEBUG, "About to connect LES"); if (les_connect(lecs_method, &manual_atm_addr, &listen_addr) < 0) { close_connections(); random_delay(); continue; } diag(COMPONENT, DIAG_DEBUG, "About to connect BUS"); if (bus_connect() < 0) { close_connections(); random_delay(); continue; } diag(COMPONENT, DIAG_DEBUG, "About to create data direct listen socket"); if (create_data_listen() < 0) { close_connections(); random_delay(); continue; } diag(COMPONENT, DIAG_DEBUG, "About to tell kernel our LEC_ID %d", lec_params.c14_lec_id); if (set_lec_id(lec_params.c14_lec_id) < 0) { close_connections(); continue; } diag(COMPONENT, DIAG_DEBUG, "About to tell kernel LEC parameters"); if (config_kernel() < 0) { close_connections(); continue; } diag(COMPONENT, DIAG_DEBUG, "Joined ELAN '%s' successfully", lec_params.c5_elan_name); main_loop(); diag(COMPONENT, DIAG_INFO, "Resetting..."); close_connections(); random_delay(); reset = 0; } return 0; /* not reached */ }
bool armcc_modet::doit() { int verbosity=1; compilet compiler(cmdline); #if 0 bool act_as_ld= has_prefix(base_name, "ld") || has_prefix(base_name, "goto-ld") || has_prefix(base_name, "link") || has_prefix(base_name, "goto-link"); #endif if(cmdline.isset("verbosity")) verbosity=atoi(cmdline.getval("verbosity")); compiler.set_verbosity(verbosity); set_verbosity(verbosity); debug("ARM mode"); // get configuration config.set(cmdline); config.ansi_c.mode=configt::ansi_ct::MODE_ARM; config.ansi_c.arch=configt::ansi_ct::ARCH_ARM; // determine actions to be taken if(cmdline.isset('E')) compiler.mode=compilet::PREPROCESS_ONLY; else if(cmdline.isset('c') || cmdline.isset('S')) compiler.mode=compilet::COMPILE_ONLY; else compiler.mode=compilet::COMPILE_LINK_EXECUTABLE; if(cmdline.isset('U')) config.ansi_c.undefines=cmdline.get_values('U'); if(cmdline.isset('L')) compiler.library_paths=cmdline.get_values('L'); // Don't add the system paths! // these take precedence over -I if(cmdline.isset('J')) { const std::list<std::string> &values= cmdline.get_values('J'); for(std::list<std::string>::const_iterator it=values.begin(); it!=values.end(); it++) config.ansi_c.preprocessor_options.push_back("-J"+*it); } if(cmdline.isset("preinclude=")) { const std::list<std::string> &values= cmdline.get_values("preinclude="); for(std::list<std::string>::const_iterator it=values.begin(); it!=values.end(); it++) config.ansi_c.preprocessor_options.push_back("--preinclude="+*it); } // armcc's default is .o if(cmdline.isset("default_extension=")) compiler.object_file_extension= cmdline.getval("default_extension="); else compiler.object_file_extension="o"; // note that ARM's default is "unsigned_chars", // in contrast to gcc's default! if(cmdline.isset("signed_chars")) config.ansi_c.char_is_unsigned=false; else config.ansi_c.char_is_unsigned=true; // ARM's default is 16 bits for wchar_t if(cmdline.isset("wchar32")) config.ansi_c.wchar_t_width=32; else config.ansi_c.wchar_t_width=16; if(cmdline.isset('o')) { // given goto-armcc -o file1 -o file2, we output to file2, not file1 compiler.output_file_object=cmdline.get_values('o').back(); compiler.output_file_executable=cmdline.get_values('o').back(); } else { compiler.output_file_object=""; compiler.output_file_executable="a.out"; } if(verbosity>8) { std::list<std::string>::iterator it; std::cout << "Defines:\n"; for(it=config.ansi_c.defines.begin(); it!=config.ansi_c.defines.end(); it++) { std::cout << " " << (*it) << std::endl; } std::cout << "Undefines:\n"; for(it=config.ansi_c.undefines.begin(); it!=config.ansi_c.undefines.end(); it++) { std::cout << " " << (*it) << std::endl; } std::cout << "Preprocessor Options:\n"; for(it=config.ansi_c.preprocessor_options.begin(); it!=config.ansi_c.preprocessor_options.end(); it++) { std::cout << " " << (*it) << std::endl; } std::cout << "Include Paths:\n"; for(it=config.ansi_c.include_paths.begin(); it!=config.ansi_c.include_paths.end(); it++) { std::cout << " " << (*it) << std::endl; } std::cout << "Library Paths:\n"; for(it=compiler.library_paths.begin(); it!=compiler.library_paths.end(); it++) { std::cout << " " << (*it) << std::endl; } std::cout << "Output file (object): " << compiler.output_file_object << std::endl; std::cout << "Output file (executable): " << compiler.output_file_executable << std::endl; } // Parse input program, convert to goto program, write output return compiler.doit(); }
static dvdcss_t dvdcss_open_common ( const char *psz_target, void *p_stream, dvdcss_stream_cb *p_stream_cb ) { int i_ret; /* Allocate the library structure. */ dvdcss_t dvdcss = malloc( sizeof( *dvdcss ) ); if( dvdcss == NULL ) { return NULL; } if( psz_target == NULL && ( p_stream == NULL || p_stream_cb == NULL ) ) { goto error; } /* Initialize structure with default values. */ dvdcss->i_fd = -1; dvdcss->i_pos = 0; dvdcss->p_titles = NULL; dvdcss->psz_device = psz_target ? strdup( psz_target ) : NULL; dvdcss->psz_error = "no error"; dvdcss->i_method = DVDCSS_METHOD_KEY; dvdcss->psz_cachefile[0] = '\0'; dvdcss->p_stream = p_stream; dvdcss->p_stream_cb = p_stream_cb; /* Set library verbosity from DVDCSS_VERBOSE environment variable. */ set_verbosity( dvdcss ); /* Set DVD access method from DVDCSS_METHOD environment variable. */ if( set_access_method( dvdcss ) < 0 ) { goto error; } /* Open device. */ dvdcss_check_device( dvdcss ); i_ret = dvdcss_open_device( dvdcss ); if( i_ret < 0 ) { goto error; } dvdcss->b_scrambled = 1; /* Assume the worst */ dvdcss->b_ioctls = dvdcss_use_ioctls( dvdcss ); if( dvdcss->b_ioctls ) { i_ret = dvdcss_test( dvdcss ); if( i_ret == -3 ) { print_debug( dvdcss, "scrambled disc on a region-free RPC-II " "drive: possible failure, but continuing " "anyway" ); } else if( i_ret < 0 ) { /* Disable the CSS ioctls and hope that it works? */ print_debug( dvdcss, "could not check whether the disc was scrambled" ); dvdcss->b_ioctls = 0; } else { print_debug( dvdcss, i_ret ? "disc is scrambled" : "disc is unscrambled" ); dvdcss->b_scrambled = i_ret; } } memset( dvdcss->css.p_disc_key, 0, DVD_KEY_SIZE ); /* If disc is CSS protected and the ioctls work, authenticate the drive */ if( dvdcss->b_scrambled && dvdcss->b_ioctls ) { i_ret = dvdcss_disckey( dvdcss ); if( i_ret < 0 ) { print_debug( dvdcss, "could not get disc key" ); } } init_cache( dvdcss ); /* Seek to the beginning, just for safety. */ dvdcss->pf_seek( dvdcss, 0 ); return dvdcss; error: free( dvdcss->psz_device ); free( dvdcss ); return NULL; }
int run_receiver(UDR_Options * udr_options) { int orig_ppid = getppid(); UDT::startup(); addrinfo hints; addrinfo* res; set_verbosity(udr_options->verbose); memset(&hints, 0, sizeof(struct addrinfo)); hints.ai_flags = AI_PASSIVE; hints.ai_family = AF_INET; hints.ai_socktype = SOCK_STREAM; char receiver_port[NI_MAXSERV]; UDTSOCKET serv; bool bad_port = false; for(int port_num = udr_options->start_port; port_num < udr_options->end_port; port_num++) { bad_port = false; snprintf(receiver_port, sizeof(receiver_port), "%d", port_num); if (0 != getaddrinfo(NULL, receiver_port, &hints, &res)) { bad_port = true; } else { serv = UDT::socket(res->ai_family, res->ai_socktype, res->ai_protocol); if (UDT::ERROR == UDT::bind(serv, res->ai_addr, res->ai_addrlen)) { bad_port = true; } } freeaddrinfo(res); if(!bad_port) break; } if(bad_port){ fprintf(stderr, "[udr receiver] ERROR: could not bind to any port in range %d - %d\n", udr_options->start_port, udr_options->end_port); return 0; } unsigned char rand_pp[PASSPHRASE_SIZE]; if (!RAND_bytes((unsigned char *) rand_pp, PASSPHRASE_SIZE)) { fprintf(stderr, "Couldn't generate random key: %ld\n", ERR_get_error()); exit(EXIT_FAILURE); } //stdout port number and password -- to send back to the client printf("%s ", receiver_port); for(int i = 0; i < PASSPHRASE_SIZE; i++) { printf("%02x", rand_pp[i]); } printf(" \n"); fflush(stdout); verbose_print("[udr receiver] server is ready at port %s\n", receiver_port); if (UDT::ERROR == UDT::listen(serv, 10)) { cerr << "[udr receiver] listen: " << UDT::getlasterror().getErrorMessage() << endl; return 0; } sockaddr_storage clientaddr; int addrlen = sizeof(clientaddr); UDTSOCKET recver; if (UDT::INVALID_SOCK == (recver = UDT::accept(serv, (sockaddr*)&clientaddr, &addrlen))) { fprintf(stderr, "[udr receiver] accept: %s\n", UDT::getlasterror().getErrorMessage()); return 0; } char clienthost[NI_MAXHOST]; char clientservice[NI_MAXSERV]; getnameinfo((sockaddr *)&clientaddr, addrlen, clienthost, sizeof(clienthost), clientservice, sizeof(clientservice), NI_NUMERICHOST|NI_NUMERICSERV); string cmd_str = udt_recv_string(recver); const char * cmd = cmd_str.c_str(); //perhaps want to at least check that starts with rsync? if(strncmp(cmd, "rsync ", 5) != 0){ exit(1); } char * rsync_cmd; if(udr_options->server_connect){ verbose_print("[udr receiver] server connect mode\n"); rsync_cmd = (char *)malloc(100); if(strlen(udr_options->server_config) > 0){ sprintf(rsync_cmd, "%s%s %s", "rsync --config=", udr_options->server_config, " --server --daemon ."); } else{ strcpy(rsync_cmd, "rsync --server --daemon ."); } } else{ rsync_cmd = (char *)malloc(strlen(cmd) + 1); strcpy(rsync_cmd, cmd); } verbose_print("[udr receiver] rsync cmd: %s\n", rsync_cmd); char ** sh_cmd = (char **)malloc(sizeof(char *) * 4); sh_cmd[0] = udr_options->shell_program; sh_cmd[1] = "-c"; sh_cmd[2] = rsync_cmd; sh_cmd[3] = NULL; //now fork and exec the rsync on the remote side using sh (so that wildcards will be expanded properly) int child_to_parent, parent_to_child; int rsync_pid = fork_execvp(udr_options->shell_program, sh_cmd, &parent_to_child, &child_to_parent); //now if we're in server mode need to drop privileges if specified if(udr_options->rsync_gid > 0){ setgid(udr_options->rsync_gid); } if(udr_options->rsync_uid > 0){ setuid(udr_options->rsync_uid); } verbose_print("[udr receiver] rsync pid: %d\n", rsync_pid); struct thread_data recv_to_udt; recv_to_udt.udt_socket = &recver; recv_to_udt.fd = child_to_parent; //stdout of rsync server process recv_to_udt.id = 2; recv_to_udt.is_complete = false; struct thread_data udt_to_recv; udt_to_recv.udt_socket = &recver; udt_to_recv.fd = parent_to_child; //stdin of rsync server process udt_to_recv.id = 3; udt_to_recv.is_complete = false; if(udr_options->encryption){ crypto encrypt(EVP_ENCRYPT, PASSPHRASE_SIZE, rand_pp, udr_options->encryption_type); crypto decrypt(EVP_DECRYPT, PASSPHRASE_SIZE, rand_pp, udr_options->encryption_type); recv_to_udt.crypt = &encrypt; udt_to_recv.crypt = &decrypt; } else{ recv_to_udt.crypt = NULL; udt_to_recv.crypt = NULL; } pthread_t recv_to_udt_thread; pthread_create(&recv_to_udt_thread, NULL, handle_to_udt, (void *)&recv_to_udt); pthread_t udt_to_recv_thread; pthread_create(&udt_to_recv_thread, NULL, udt_to_handle, (void*)&udt_to_recv); verbose_print("[udr receiver] waiting to join on recv_to_udt_thread\n"); verbose_print("[udr receiver] ppid %d pid %d\n", getppid(), getpid()); //going to poll if the ppid changes then we know it's exited and then we exit all of our threads and exit as well //also going to check if either thread is complete, if one is then the other should also be killed //bit of a hack to deal with the pthreads while(true){ if(getppid() != orig_ppid){ pthread_kill(recv_to_udt_thread, SIGUSR1); pthread_kill(udt_to_recv_thread, SIGUSR1); break; } if(recv_to_udt.is_complete && udt_to_recv.is_complete){ verbose_print("[udr receiver] both threads are complete: recv_to_udt.is_complete %d udt_to_recv.is_complete %d\n", recv_to_udt.is_complete, udt_to_recv.is_complete); break; } else if(recv_to_udt.is_complete){ verbose_print("[udr receiver] recv_to_udt is complete: recv_to_udt.is_complete %d udt_to_recv.is_complete %d\n", recv_to_udt.is_complete, udt_to_recv.is_complete); break; } else if(udt_to_recv.is_complete){ verbose_print("[udr receiver] udt_to_recv is complete: recv_to_udt.is_complete %d udt_to_recv.is_complete %d\n", recv_to_udt.is_complete, udt_to_recv.is_complete); break; } sleep(ppid_poll); } verbose_print("[udr receiver] Trying to close recver\n"); UDT::close(recver); verbose_print("[udr receiver] Closed recver\n"); UDT::close(serv); verbose_print("[udr receiver] Closed serv\n"); UDT::cleanup(); verbose_print("[udr receiver] UDT cleaned up\n"); return 0; }
int run_sender(UDR_Options * udr_options, unsigned char * passphrase, const char* cmd, int argc, char ** argv) { UDT::startup(); struct addrinfo hints, *local, *peer; set_verbosity(udr_options->verbose); memset(&hints, 0, sizeof(struct addrinfo)); hints.ai_flags = AI_PASSIVE; hints.ai_family = AF_INET; hints.ai_socktype = SOCK_STREAM; if (0 != getaddrinfo(NULL, udr_options->port_num, &hints, &local)) { cerr << "[udr sender] incorrect network address.\n" << endl; return 1; } UDTSOCKET client = UDT::socket(local->ai_family, local->ai_socktype, local->ai_protocol); freeaddrinfo(local); if (0 != getaddrinfo(udr_options->host, udr_options->port_num, &hints, &peer)) { cerr << "[udr sender] incorrect server/peer address. " << udr_options->host << ":" << udr_options->port_num << endl; return 1; } if (UDT::ERROR == UDT::connect(client, peer->ai_addr, peer->ai_addrlen)) { cerr << "[udr sender] connect: " << UDT::getlasterror().getErrorMessage() << endl; return 1; } freeaddrinfo(peer); // not using CC method yet //CUDPBlast* cchandle = NULL; // int value; // int temp; char* data = new char[max_block_size]; ssize_t n; //very first thing we send is the rsync argument so that the rsync server can be started and piped to from the UDT connection n = strlen(cmd) + 1; int ssize = 0; int ss; while(ssize < n) { if (UDT::ERROR == (ss = UDT::send(client, cmd + ssize, n - ssize, 0))) { cerr << "[udr sender] Send:" << UDT::getlasterror().getErrorMessage() << endl; break; } ssize += ss; } struct thread_data sender_to_udt; sender_to_udt.udt_socket = &client; sender_to_udt.fd = STDIN_FILENO; //stdin of this process, from stdout of rsync sender_to_udt.id = 0; sender_to_udt.is_complete = false; struct thread_data udt_to_sender; udt_to_sender.udt_socket = &client; udt_to_sender.fd = STDOUT_FILENO; //stdout of this process, going to stdin of rsync, rsync defaults to set this is non-blocking udt_to_sender.id = 1; udt_to_sender.is_complete = false; if(udr_options->encryption){ crypto encrypt(EVP_ENCRYPT, PASSPHRASE_SIZE, (unsigned char *)passphrase, udr_options->encryption_type); crypto decrypt(EVP_DECRYPT, PASSPHRASE_SIZE, (unsigned char *)passphrase, udr_options->encryption_type); // free_key(passphrase); sender_to_udt.crypt = &encrypt; udt_to_sender.crypt = &decrypt; } else{ sender_to_udt.crypt = NULL; udt_to_sender.crypt = NULL; } pthread_t sender_to_udt_thread; pthread_create(&sender_to_udt_thread, NULL, handle_to_udt, (void *)&sender_to_udt); pthread_t udt_to_sender_thread; pthread_create(&udt_to_sender_thread, NULL, udt_to_handle, (void*)&udt_to_sender); int rc1 = pthread_join(udt_to_sender_thread, NULL); verbose_print("[udr sender] joined on udt_to_sender_thread %d\n", rc1); UDT::close(client); pthread_kill(sender_to_udt_thread, SIGUSR1); int rc2 = pthread_join(sender_to_udt_thread, NULL); verbose_print("[udr sender] joined on sender_to_udt_thread %d\n", rc2); UDT::close(client); UDT::cleanup(); delete [] data; return 0; }
void saldl(saldl_params *params_ptr) { /* Definitions */ info_s info = DEF_INFO_S; info.params = params_ptr; /* Handle signals */ info_global = &info; saldl_handle_signals(); /* Need to be set as early as possible */ set_color(¶ms_ptr->no_color); set_verbosity(¶ms_ptr->verbosity, ¶ms_ptr->libcurl_verbosity); /* Check if loaded libcurl is recent enough */ info.curl_info = curl_version_info(CURLVERSION_NOW); check_libcurl(info.curl_info); /* Library initializations, should run only once */ SALDL_ASSERT(!curl_global_init(CURL_GLOBAL_ALL)); SALDL_ASSERT(!evthread_use_pthreads()); /* get/set initial info */ main_msg("URL", "%s", params_ptr->start_url); check_url(params_ptr->start_url); get_info(&info); set_info(&info); check_remote_file_size(&info); /* initialize chunks early for extra_resume() */ chunks_init(&info); if (params_ptr->resume) { check_resume(&info); } print_chunk_info(&info); global_progress_init(&info); /* exit here if dry_run was set */ if ( params_ptr->dry_run ) { saldl_free_all(&info); finish_msg_and_exit("Dry-run done."); } check_files_and_dirs(&info); /* Check if download was interrupted after all data was merged */ if (info.already_finished) { goto saldl_all_data_merged; } /* threads, needed by set_modes() */ info.threads = saldl_calloc(params_ptr->num_connections, sizeof(thread_s)); set_modes(&info); /* 1st iteration */ for (size_t counter = 0; counter < params_ptr->num_connections; counter++) { queue_next_chunk(&info, counter, 1); } /* Create event pthreads */ saldl_pthread_create(&info.trigger_events_pth, NULL, events_trigger_thread, &info); if (!params_ptr->read_only && !params_ptr->to_stdout) { saldl_pthread_create(&info.sync_ctrl_pth, NULL, sync_ctrl, &info); } if (info.chunk_count != 1) { saldl_pthread_create(&info.status_display_pth, NULL, status_display, &info); saldl_pthread_create(&info.queue_next_pth, NULL, queue_next_thread, &info); saldl_pthread_create(&info.merger_pth, NULL, merger_thread, &info); } /* Now that everything is initialized */ info.session_status = SESSION_IN_PROGRESS; /* Avoid race in joining event threads if the session was interrupted, or finishing without downloading if single_mode */ do { usleep(100000); } while (params_ptr->single_mode ? info.chunks[0].progress != PRG_FINISHED : info.global_progress.complete_size != info.file_size); /* Join event pthreads */ if (!params_ptr->read_only && !params_ptr->to_stdout) { join_event_pth(&info.ev_ctrl ,&info.sync_ctrl_pth); } if (info.chunk_count !=1) { join_event_pth(&info.ev_status, &info.status_display_pth); join_event_pth(&info.ev_queue, &info.queue_next_pth); join_event_pth(&info.ev_merge, &info.merger_pth); } info.events_queue_done = true; event_queue(&info.ev_trigger, NULL); join_event_pth(&info.ev_trigger ,&info.trigger_events_pth); saldl_all_data_merged: /* Remove tmp_dirname */ if (!params_ptr->read_only && !params_ptr->mem_bufs && !params_ptr->single_mode) { if ( rmdir(info.tmp_dirname) ) { err_msg(FN, "Failed to delete %s: %s", info.tmp_dirname, strerror(errno) ); } } /*** Final Steps ***/ /* One last check */ if (info.file_size && !params_ptr->no_remote_info && !params_ptr->read_only && !params_ptr->to_stdout && (!info.remote_info.content_encoded || params_ptr->no_decompress)) { off_t saved_file_size = saldl_fsizeo(info.part_filename, info.file); if (saved_file_size != info.file_size) { pre_fatal(FN, "Unexpected saved file size (%"SAL_JU"!=%"SAL_JU").", saved_file_size, info.file_size); pre_fatal(FN, "This could happen if you're downloading from a dynamic site."); pre_fatal(FN, "If that's the case and the download is small, retry with --no-remote-info"); fatal(FN, "If you think that's a bug in saldl, report it: https://github.com/saldl/saldl/issues"); } } else { debug_msg(FN, "Strict check for finished file size skipped."); } if (!params_ptr->read_only && !params_ptr->to_stdout) { saldl_fclose(info.part_filename, info.file); if (rename(info.part_filename, params_ptr->filename) ) { err_msg(FN, "Failed to rename now-complete %s to %s: %s", info.part_filename, params_ptr->filename, strerror(errno)); } saldl_fclose(info.ctrl_filename, info.ctrl_file); if ( remove(info.ctrl_filename) ) { err_msg(FN, "Failed to remove %s: %s", info.ctrl_filename, strerror(errno)); } } /* cleanups */ curl_cleanup(&info); saldl_free_all(&info); finish_msg_and_exit("Download Finished."); }
int goto_fence_inserter_parse_optionst::doit() { if(cmdline.isset("version")) { std::cout << MUSKETEER_VERSION << std::endl; return 0; } if(cmdline.args.size()!=1 && cmdline.args.size()!=2) { help(); return 0; } set_verbosity(); try { register_languages(); goto_functionst goto_functions; get_goto_program(goto_functions); instrument_goto_program(goto_functions); // write new binary? if(cmdline.args.size()==2) { status() << "Writing GOTO program to " << cmdline.args[1] << eom; if(write_goto_binary( cmdline.args[1], symbol_table, goto_functions, get_message_handler())) return 1; else return 0; } // help(); return 0; } catch(const char *e) { error() << e << eom; return 11; } catch(const std::string e) { error() << e << eom; return 11; } catch(int) { return 11; } catch(std::bad_alloc) { error() << "Out of memory" << eom; return 11; } }