int main(int argc, char **argv) { int rc = 0; memset(ctx, 0, sizeof(context_t)); /* parse command line parameters (and set ctx vars) */ dbg_err_if(parse_opt(argc, argv)); if(getenv("GATEWAY_INTERFACE")) ctx->cgi = 1; /* load config and initialize */ warn_err_ifm(app_init(), "kloned init error (more info in the log file)"); #ifdef HAVE_FORK /* daemonize if not -F */ if(ctx->daemon && !ctx->cgi) con_err_ifm(daemon(ctx->nochdir, 0), "daemon error"); #endif /* HAVE_FORK */ /* save the PID in a file */ if(ctx->pid_file) dbg_err_if(u_savepid(ctx->pid_file)); /* jump to the main loop */ rc = app_run(); dbg_err_if(app_term()); /* if debugging then call exit(3) because it's needed to gprof to dump its stats file (gmon.out) */ if(ctx->debug) return rc; /* don't use return because exit(3) will be called and we don't want FILE* buffers to be automatically flushed (klog_file_t will write same lines more times, once by the parent process and N times by any child created when FILE buffer was not empty) */ _exit(rc); err: app_term(); if(ctx->debug) return ~0; _exit(EXIT_FAILURE); }
int main(int argc, char **argv) { parse_opt(argc, argv); init(); if (my_rank == RANK_SERVER) { // server run_pp_server(); } else if (my_rank == RANK_CLIENT) { do_pp_client(); } else { printf("Unkown rank:%d\n", my_rank); exit(1); } return 0; }
int ping_main (struct Ping_Options *Ping_Opt) { int one = 1; int ret = 0; if (getuid () == 0) is_root = true; /* Parse command line */ parse_opt(Ping_Opt); ping = ping_init (ICMP_ECHO, getpid ()); if (ping == NULL) /* ping_init() prints our error message. */ exit (1); ping_set_sockopt (ping, SO_BROADCAST, (char *) &one, sizeof (one)); /* Reset root privileges */ setuid (getuid ()); if (count != 0) ping_set_count (ping, count); if (socket_type != 0) ping_set_sockopt (ping, socket_type, &one, sizeof (one)); if (options & OPT_INTERVAL) ping_set_interval (ping, interval); init_data_buffer (patptr, pattern_len); ret = ping_echo (Ping_Opt->Host); Ping_Opt->SuccessCount = ping->ping_num_recv; Ping_Opt->FailureCount = ping->ping_num_xmit - ping->ping_num_recv; Ping_Opt->AverageResponseTime = ping->avg_time; Ping_Opt->MaximumResponseTime = ping->max_time; Ping_Opt->MinimumResponseTime = ping->min_time; free (ping); free (data_buffer); return ret; }
int main(int argc, char **argv) { int fd; struct stat st; unsigned char *buf = NULL; struct conf_c conf = {0}; struct s_comp comp = {0}; parse_opt(argc, argv, &conf); check_opt(&conf, argv[0]); fd = open(conf.in, O_RDONLY); if (fd == -1) { perror("open()"); exit(EXIT_FAILURE); } if (fstat(fd, &st) == -1) { perror("fstat()"); exit(EXIT_FAILURE); } if ((buf = malloc(sizeof (char) * st.st_size)) == NULL) { perror("malloc()"); exit(EXIT_FAILURE); } if (read(fd, buf, st.st_size) != st.st_size) { perror("read()"); goto clean; } huff(buf, st.st_size, &comp); if (comp.tree) { if (conf.dot) dotty(comp.tree, conf.dot); uncomp(&comp, buf + st.st_size); if (comp.buf_out) dump_to_file(conf.out, comp.buf_out, comp.size); } clean: free(buf); close(fd); return 0; }
int main(int argc, char **args) { int rc = ~0; gs_error_t *err = NULL; gs_grid_storage_t *gs = NULL; g_set_prgname(args[0]); log4c_init(); if (!parse_opt(argc, args)) { PRINT_ERROR("cannot parse the options\n"); return 1; } if (flag_help || argc == 1) { help(); return 0; } if (!meta0_url || !container_name) { meta0_url = strtok(args[1], "/"); container_name = strtok(NULL, "/"); event_message = args[2]; if (!meta0_url || !container_name) { PRINT_ERROR("Missing argument, please check help (-h) for more informations\n"); return 1; } } if (!event_message) { PRINT_ERROR("Missing argument, please check help (-h) for more informations\n"); return 1; } gs = gs_grid_storage_init(meta0_url, &err); if (!gs) PRINT_ERROR("cannot init the GridStorage client\n"); else rc = add_event(gs, container_name, event_message) ? 0 : 1; return rc; }
int main(int argc, char *argv[]) { int cmd; if(init_winsock()){ err("can't init winsock"); return 0; } cmd = parse_opt(argc, argv); switch(cmd) { case CMD_ATTACH: if (optind == argc - 2) attach_device(argv[optind], argv[optind+1]); else show_help(argv[0]); break; case CMD_DETACH: while (optind < argc) detach_port(argv[optind++]); break; case CMD_PORT: show_port_status(); break; case CMD_LIST: while (optind < argc) show_exported_devices(argv[optind++]); break; case CMD_ATTACHALL: while(optind < argc) attach_devices_all(argv[optind++]); break; case CMD_VERSION: printf("%s\n", version); break; case CMD_HELP: show_help(argv[0]); break; default: show_help(argv[0]); } return 0; }
ERL_NIF_TERM parse_opts( ErlNifEnv* env, ERL_NIF_TERM list, hi_opts_t* acc, ERL_NIF_TERM(*parse_opt)(ErlNifEnv*, ERL_NIF_TERM, void* acc) ) { ERL_NIF_TERM hd, tl = list; while(enif_get_list_cell(env, tl, &hd, &tl)) { ERL_NIF_TERM rc = parse_opt(env, hd, acc); if (rc != ATOM_OK) { return rc; } } return ATOM_OK; }
int main(int argc, char **argv) { parse_opt(argc, argv); psib_debug = arg_verbose; if ((!arg_server && !arg_client) || (arg_server && arg_client)) { printf("run as server or client? (-s or -c)\n"); exit(1); } if (psib_init()) { printf("Initialisation of IB failed : %s\n", psib_err_str); exit(1); } do_pp(); return 0; }
/* ENTRY POINT */ int main(int argc, char **argv) { struct execute_context exec_ctx; pid_t c_pid; debug_printf(stderr,"start!\n"); parse_opt(argc, argv, &exec_ctx); fprintf(stderr, "[Tracer] Target program is %s\n", exec_ctx.passing_args[0]); c_pid = fork(); exec_ctx.target_pid = c_pid; if (c_pid == -1) { return -1; } else if(c_pid == 0) { target_proc(&exec_ctx); } else { debugger_proc(c_pid, &exec_ctx); } chk_free(exec_ctx.passing_args); return 0; }
int main(int argc, char **argv) { int num_cpus; int i ; num_cpus = get_num_cpus(); assert(num_cpus >= 1); num_devices = ps_list_devices(devices); if (num_devices == -1) { perror("ps_list_devices"); exit(1); } parse_opt(argc, argv); for (i = 0; i < num_cpus; i++) { int ret = fork(); assert(ret >= 0); my_cpu = i; if (ret == 0) { bind_cpu(i); signal(SIGINT, handle_signal); echo(); return 0; } } signal(SIGINT, SIG_IGN); while (1) { int ret = wait(NULL); if (ret == -1 && errno == ECHILD) break; } return 0; }
static void parse_opts(char *src, int len) { char *opt, *val; int n; config.to_ack = 0; while(len>0 && (n = parse_opt(src, &opt, &val))>2) { if(strcmp(opt, "blksize")==0) { config.blksize = min(atoi(val), TFTP_MAX_BLKSIZE); config.to_ack |= OACK_BLKSIZE; } else if(strcmp(opt, "timeout")==0) { config.timeout = atoi(val); config.to_ack |= OACK_TIMEOUT; } else if(strcmp(opt, "exec")==0 && val[0]=='1') { config.exec = 1; config.to_ack |= OACK_EXEC; } len -= n; src += n; } PRINTF("blksize: %d\ntimeout: %d\n", config.blksize, config.timeout); }
int main(int argc, char** argv) { int i, j, k = 1; parse_opt( argc, argv ); for( i = 0; i < NDIM; i++ ) { for( j = 0; j < NDIM; j++ ) { a[i][j] = k; b[i][j] = k; k++; } } timer_start(1); mat_mul( c, a, b ); timer_stop(1); printf("Time elapsed : %lf sec\n", timer_read(1)); if( validation ) check_mat_mul( c, a, b ); if( print_matrix ) { printf("MATRIX A: \n"); print_mat(a); printf("MATRIX B: \n"); print_mat(b); printf("MATRIX C: \n"); print_mat(c); } return 0; }
PUBLIC int main(int argc, char** argv) { status* state; char path[MAX_PATH]; int len = 0; search_pattern* pattern; if (alloc_status(&state) == FAILURE) return EXIT_FAILURE; if (parse_opt(argc, argv, state, &pattern) == FAILURE) return EXIT_FAILURE; /* if no path provided take the current one */ if (argc == 1) { strncpy(path, ".\0", 2); len = 1; } /* check that the last arg is not an option */ else { strncpy(path, argv[argc - 1], strlen(argv[argc - 1])); len = strlen(argv[argc - 1]); path[len ] = '\0'; if (path[0] == '-') strncpy(path, ".\0", 2); } if (start_browse(path, 0, state, pattern) == FAILURE) return EXIT_FAILURE; if (state->opt->d_total == ON) print_total(state); free(state); return EXIT_SUCCESS; }
int main(int argc, char** args) { int rc = -1; log4c_init(); if (argc <= 1) { help(argc, args); return 1; } if (!parse_opt(argc, args)) { help(argc, args); return 1; } if (flag_help) { help(argc, args); return 0; } if (optind < argc) { GError *local_error = NULL; int i; for (i = optind; i < argc; i++) { /* Sanity check */ PRINT_DEBUG("Going to work with chunk file [%s]\n", args[i]); /* Run decompression */ if(uncompress_chunk2(args[i], preserve, keep_pending, &local_error) != 1) { if(local_error) PRINT_ERROR("Failed to uncompress chunk [%s] :\n %s", args[i], local_error->message); else PRINT_ERROR("Failed to uncompress chunk [%s] : no error\n",args[i]); if (keep_pending) PRINT_DEBUG("%s.pending file kept\n", args[i]); } else { PRINT_DEBUG("Chunk [%s] uncompressed\n",args[i]); } } } return rc; }
/* Take -o options list and compute 4th and 5th args to mount(2). flags gets the standard options (indicated by bits) and extra_opts all the rest */ void parse_opts(const char *options, int *flags, char **extra_opts) { *flags = 0; *extra_opts = NULL; clear_string_opts(); if (options != NULL) { char *opts = xstrdup(options); int open_quote = 0; char *opt, *p; for (p = opts, opt = NULL; p && *p; p++) { if (!opt) opt = p; /* begin of the option item */ if (*p == '"') open_quote ^= 1;/* reverse the status */ if (open_quote) continue; /* still in quoted block */ if (*p == ',') *p = '\0'; /* terminate the option item */ /* end of option item or last item */ if (*p == '\0' || *(p + 1) == '\0') { if (!parse_string_opt(opt)) parse_opt(opt, flags, extra_opts); opt = NULL; } } free(opts); } if (readonly) *flags |= MS_RDONLY; if (readwrite) *flags &= ~MS_RDONLY; #if 0 *flags |= mounttype; #endif }
int main(int argc, char** args) { int rc = -1; if (argc <= 1) { help(argc, args); return 1; } if (!parse_opt(argc, args)) { help(argc, args); return 1; } if (flag_help) { help(argc, args); return 0; } if (optind < argc) { GError *local_error = NULL; int i; for (i = optind; i < argc; i++) { PRINT_DEBUG("Going to work with chunk file [%s]\n", args[i]); /* Run compression */ if(compress_chunk(args[i], algo, blocksize, preserve, &local_error) != 1) { if(local_error) PRINT_ERROR("Failed to compress chunk [%s] :\n%s", args[i], local_error->message); else PRINT_ERROR("Failed to compress chunk [%s] : no error",args[i]); } else { PRINT_DEBUG("Chunk [%s] compressed\n",args[i]); } } PRINT_DEBUG("Process done\n"); } return rc; }
int main(int argc, char * const argv[]) { int err = 0; uint32_t crc = UBI_CRC32_INIT; char buf[BUFSIZE]; FILE *fp; if (argc > 1) { fp = fopen(argv[1], "r"); if (!fp) return sys_errmsg("cannot open \"%s\"", argv[1]); } else fp = stdin; err = parse_opt(argc, argv); if (err) return err; while (!feof(fp)) { size_t read; read = fread(buf, 1, BUFSIZE, fp); if (ferror(fp)) { sys_errmsg("cannot read input file"); err = -1; goto out_close; } crc = crc32(crc, buf, read); } printf("0x%08x\n", crc); out_close: if (fp != stdin) fclose(fp); return err; }
int main(int argc, char **argv) { num_devices = ps_list_devices(devices); if (num_devices == -1) { perror("ps_list_devices"); exit(1); } parse_opt(argc, argv); num_cpus = get_num_cpus(); assert(num_cpus >= 1); for (my_cpu = 0; my_cpu < num_cpus; my_cpu++) { int ret = fork(); assert(ret >= 0); if (ret == 0) { bind_cpu(my_cpu); signal(SIGINT, stat_signal); attach(); dump(); return 0; } } signal(SIGINT, SIG_IGN); while(1) { int ret = wait(NULL); if(-1 == ret && ECHILD == errno) break; } return 0; }
int main(int argc, char *argv[]) { parse_opt(argc, argv); return 0; }
static int do_test(int argc, char *argv[]) { char **ap; int left, adv, expr, last_expr, neg, last_cmp, opt, zero; ulong a, b; struct stat statbuf; if (*argv[0] == '[') { if (*argv[argc - 1] != ']') { printf("[: missing `]'\n"); return 1; } argc--; } /* args? */ if (argc < 2) return 1; last_expr = 0; left = argc - 1; ap = argv + 1; if (strcmp(ap[0], "!") == 0) { neg = 1; ap++; left--; } else neg = 0; expr = -1; last_cmp = -1; last_expr = -1; adv = 0; while (left - adv > 0) { ap += adv; left -= adv; adv = 1; opt = parse_opt(ap[0]); switch (opt) { /* one argument options */ case OPT_OR: last_expr = expr; last_cmp = 0; continue; case OPT_AND: last_expr = expr; last_cmp = 1; continue; /* two argument options */ case OPT_ZERO: case OPT_NONZERO: adv = 2; zero = 1; if (ap[1] && *ap[1] != ']' && strlen(ap[1])) zero = 0; expr = (opt == OPT_ZERO) ? zero : !zero; break; case OPT_FILE: case OPT_DIRECTORY: case OPT_EXISTS: case OPT_SYMBOLIC_LINK: adv = 2; if (ap[1] && *ap[1] != ']' && strlen(ap[1])) { expr = (opt == OPT_SYMBOLIC_LINK ? lstat : stat)(ap[1], &statbuf); if (expr < 0) { expr = 0; break; } expr = 0; if (opt == OPT_EXISTS) { expr = 1; break; } if (opt == OPT_FILE && S_ISREG(statbuf.st_mode)) { expr = 1; break; } if (opt == OPT_DIRECTORY && S_ISDIR(statbuf.st_mode)) { expr = 1; break; } if (opt == OPT_SYMBOLIC_LINK && S_ISLNK(statbuf.st_mode)) { expr = 1; break; } } break; /* three argument options */ default: adv = 3; if (left < 3) { expr = 1; break; } a = simple_strtol(ap[0], NULL, 0); b = simple_strtol(ap[2], NULL, 0); switch (parse_opt(ap[1])) { case OPT_EQUAL: expr = strcmp(ap[0], ap[2]) == 0; break; case OPT_NOT_EQUAL: expr = strcmp(ap[0], ap[2]) != 0; break; case OPT_ARITH_EQUAL: expr = a == b; break; case OPT_ARITH_NOT_EQUAL: expr = a != b; break; case OPT_ARITH_LESS_THAN: expr = a < b; break; case OPT_ARITH_LESS_EQUAL: expr = a <= b; break; case OPT_ARITH_GREATER_THAN: expr = a > b; break; case OPT_ARITH_GREATER_EQUAL: expr = a >= b; break; default: expr = 1; goto out; } } if (last_cmp == 0) expr = last_expr || expr; else if (last_cmp == 1) expr = last_expr && expr; last_cmp = -1; } out: if (neg) expr = !expr; expr = !expr; return expr; }
s32 get_tracert_list (char *argv, char* option, u32 *count, tracert_cfg_item_t *item_buf,char *info1,char *info2) { trace_t trace; struct tracert_info tracert_info; int i = 0; int ret; int fd; struct sockaddr_in loc_addr; stop = 0; /* Parse command line */ parse_opt(argv); if (geteuid () != 0) return -1; ret = tracert_opt_parse(option, &tracert_info, info1); if(0 != ret) { return 0; } dest.sin_addr = *(struct in_addr *) tracehost->h_addr; dest.sin_family = AF_INET; dest.sin_port = htons (tracert_info.port); //给trace结构体的源地址赋初值 if(NULL != tracert_info.host_addr) { //测试源地址是否存在 loc_addr.sin_family=AF_INET; loc_addr.sin_addr.s_addr=inet_addr(tracert_info.host_addr); loc_addr.sin_port=htons(SRCPORT); fd = socket(AF_INET, SOCK_RAW, IPPROTO_ICMP); if(bind(fd,(struct sockaddr*)&loc_addr,sizeof(loc_addr))) { close(fd); sprintf(info1,"Please select a local address!"); return 1; } close(fd); trace.from.sin_addr.s_addr = inet_addr(tracert_info.host_addr); sprintf(info1, "traceroute from %s to %s (%s), %d hops max", tracert_info.host_addr, tracehost->h_name, inet_ntoa (dest.sin_addr), tracert_info.max_hops); } else { sprintf(info1, "traceroute to %s (%s), %d hops max", tracehost->h_name, inet_ntoa (dest.sin_addr), tracert_info.max_hops); } trace_init (&trace, dest, opt_type, tracert_info.hop, tracert_info.host_addr); while (!stop) { item_buf[i].rowid = tracert_info.hop; if (tracert_info.hop > tracert_info.max_hops) break; ret = do_try (&trace, tracert_info.hop, tracert_info.max_hops, tracert_info.max_tries, tracert_info.wait_time, &(item_buf[i])); if(ret == 1) { sprintf(info2, "sendto: Network is unreachable!"); return 1; } if(ret < 0) return -1; trace_inc_ttl (&trace); trace_inc_port (&trace); tracert_info.hop++; i++; (*count)++; } return 0; }
int main( int argc, char * argv[] ) { int ret; int bindFd; char * php_ini_path = NULL; char * php_bind = NULL; int n; int climode = 0; struct timeval tv_req_begin; struct timeval tv_req_end; int slow_script_msec = 0; char time_buf[40]; #ifdef HAVE_SIGNAL_H #if defined(SIGPIPE) && defined(SIG_IGN) signal(SIGPIPE, SIG_IGN); #endif #endif #ifdef ZTS tsrm_startup(1, 1, 0, NULL); #endif zend_signal_startup(); if (argc > 1 ) { if ( parse_opt( argc, argv, &climode, &php_ini_path, &php_bind ) == -1 ) { return 1; } } if ( climode ) { lsapi_sapi_module.phpinfo_as_text = 1; } else { setArgv0(argc, argv ); } sapi_startup(&lsapi_sapi_module); #ifdef ZTS compiler_globals = ts_resource(compiler_globals_id); executor_globals = ts_resource(executor_globals_id); core_globals = ts_resource(core_globals_id); sapi_globals = ts_resource(sapi_globals_id); tsrm_ls = ts_resource(0); SG(request_info).path_translated = NULL; #endif lsapi_sapi_module.executable_location = argv[0]; /* Initialize from environment variables before processing command-line * options: the latter override the former. */ init_sapi_from_env(&lsapi_sapi_module); if ( ignore_php_ini ) lsapi_sapi_module.php_ini_ignore = 1; if ( php_ini_path ) { lsapi_sapi_module.php_ini_path_override = php_ini_path; } lsapi_sapi_module.ini_defaults = sapi_lsapi_ini_defaults; if (php_module_startup(&lsapi_sapi_module, &litespeed_module_entry, 1) == FAILURE) { #ifdef ZTS tsrm_shutdown(); #endif return FAILURE; } if ( climode ) { return cli_main(argc, argv); } if ( php_bind ) { bindFd = LSAPI_CreateListenSock( php_bind, 10 ); if ( bindFd == -1 ) { fprintf( stderr, "Failed to bind socket [%s]: %s\n", php_bind, strerror( errno ) ); exit( 2 ); } if ( bindFd != 0 ) { dup2( bindFd, 0 ); close( bindFd ); } } LSAPI_Init(); LSAPI_Init_Env_Parameters( NULL ); lsapi_mode = 1; slow_script_msec = LSAPI_Get_Slow_Req_Msecs(); if ( php_bind ) { LSAPI_No_Check_ppid(); free( php_bind ); php_bind = NULL; } while( LSAPI_Prefork_Accept_r( &g_req ) >= 0 ) { if ( slow_script_msec ) { gettimeofday( &tv_req_begin, NULL ); } ret = processReq(); if ( slow_script_msec ) { gettimeofday( &tv_req_end, NULL ); n = ((long) tv_req_end.tv_sec - tv_req_begin.tv_sec ) * 1000 + (tv_req_end.tv_usec - tv_req_begin.tv_usec) / 1000; if ( n > slow_script_msec ) { strftime( time_buf, 30, "%d/%b/%Y:%H:%M:%S", localtime( &tv_req_end.tv_sec ) ); fprintf( stderr, "[%s] Slow PHP script: %d ms\n URL: %s %s\n Query String: %s\n Script: %s\n", time_buf, n, LSAPI_GetRequestMethod(), LSAPI_GetScriptName(), LSAPI_GetQueryString(), LSAPI_GetScriptFileName() ); } } LSAPI_Finish(); if ( ret ) { break; } } php_module_shutdown(); #ifdef ZTS tsrm_shutdown(); #endif return ret; }
int do_ubiformat(int argc, char *argv[]) { int err, verbose; struct mtd_dev_info mtd; struct ubigen_info ui; struct ubi_scan_info *si; err = parse_opt(argc, argv); if (err) return err; err = mtd_get_dev_info(args.node, &mtd); if (err) { sys_errmsg("cannot get information about \"%s\"", args.node); goto out_close_mtd; } if (!is_power_of_2(mtd.min_io_size)) { errmsg("min. I/O size is %d, but should be power of 2", mtd.min_io_size); goto out_close_mtd; } if (args.subpage_size && args.subpage_size != mtd.subpage_size) { mtd.subpage_size = args.subpage_size; args.manual_subpage = 1; } if (args.manual_subpage) { /* Do some sanity check */ if (args.subpage_size > mtd.min_io_size) { errmsg("sub-page cannot be larger than min. I/O unit"); goto out_close_mtd; } if (mtd.min_io_size % args.subpage_size) { errmsg("min. I/O unit size should be multiple of " "sub-page size"); goto out_close_mtd; } } args.node_fd = open(args.node, O_RDWR); if (args.node_fd < 0) { sys_errmsg("cannot open \"%s\"", args.node); goto out_close_mtd; } /* Validate VID header offset if it was specified */ if (args.vid_hdr_offs != 0) { if (args.vid_hdr_offs % 8) { errmsg("VID header offset has to be multiple of min. I/O unit size"); goto out_close; } if (args.vid_hdr_offs + (int)UBI_VID_HDR_SIZE > mtd.eb_size) { errmsg("bad VID header offset"); goto out_close; } } if (!mtd.writable) { errmsg("%s (%s) is a read-only device", mtd.node, args.node); goto out_close; } /* Make sure this MTD device is not attached to UBI */ /* FIXME! Find a proper way to do this in barebox! */ if (!args.quiet) { normsg_cont("%s (%s), size %lld bytes (%s)", mtd.node, mtd.type_str, mtd.size, size_human_readable(mtd.size)); printf(", %d eraseblocks of %d bytes (%s)", mtd.eb_cnt, mtd.eb_size, size_human_readable(mtd.eb_size)); printf(", min. I/O size %d bytes\n", mtd.min_io_size); } if (args.quiet) verbose = 0; else if (args.verbose) verbose = 2; else verbose = 1; err = libscan_ubi_scan(&mtd, args.node_fd, &si, verbose); if (err) { errmsg("failed to scan %s (%s)", mtd.node, args.node); goto out_close; } if (si->good_cnt == 0) { errmsg("all %d eraseblocks are bad", si->bad_cnt); goto out_free; } if (si->good_cnt < 2 && (!args.novtbl || args.image)) { errmsg("too few non-bad eraseblocks (%d) on %s", si->good_cnt, mtd.node); goto out_free; } if (!args.quiet) { if (si->ok_cnt) normsg("%d eraseblocks have valid erase counter, mean value is %lld", si->ok_cnt, si->mean_ec); if (si->empty_cnt) normsg("%d eraseblocks are supposedly empty", si->empty_cnt); if (si->corrupted_cnt) normsg("%d corrupted erase counters", si->corrupted_cnt); print_bad_eraseblocks(&mtd, si); } if (si->alien_cnt) { if (!args.quiet) warnmsg("%d of %d eraseblocks contain non-ubifs data", si->alien_cnt, si->good_cnt); if (!args.yes && !args.quiet) warnmsg("use '-y' to force erasing"); if (!args.yes) goto out_free; } if (!args.override_ec && si->empty_cnt < si->good_cnt) { int percent = (si->ok_cnt * 100) / si->good_cnt; /* * Make sure the majority of eraseblocks have valid * erase counters. */ if (percent < 50) { if (!args.quiet) { warnmsg("only %d of %d eraseblocks have valid erase counter", si->ok_cnt, si->good_cnt); if (args.yes) { normsg("erase counter 0 will be used for all eraseblocks"); normsg("note, arbitrary erase counter value may be specified using -e option"); } else { warnmsg("use '-y' to force erase counters"); } } if (!args.yes) goto out_free; args.ec = 0; args.override_ec = 1; } else if (percent < 95) { if (!args.quiet) { warnmsg("only %d of %d eraseblocks have valid erase counter", si->ok_cnt, si->good_cnt); if (args.yes) normsg("mean erase counter %lld will be used for the rest of eraseblock", si->mean_ec); else warnmsg("use '-y' to force erase counters"); } if (!args.yes) goto out_free; args.ec = si->mean_ec; args.override_ec = 1; } } if (!args.quiet && args.override_ec) normsg("use erase counter %lld for all eraseblocks", args.ec); ubigen_info_init(&ui, mtd.eb_size, mtd.min_io_size, mtd.subpage_size, args.vid_hdr_offs, args.ubi_ver, args.image_seq); if (si->vid_hdr_offs != -1 && ui.vid_hdr_offs != si->vid_hdr_offs) { /* * Hmm, what we read from flash and what we calculated using * min. I/O unit size and sub-page size differs. */ if (!args.quiet) { warnmsg("VID header and data offsets on flash are %d and %d, " "which is different to requested offsets %d and %d", si->vid_hdr_offs, si->data_offs, ui.vid_hdr_offs, ui.data_offs); normsg("using offsets %d and %d", ui.vid_hdr_offs, ui.data_offs); } } if (args.image) { err = flash_image(&mtd, &ui, si); if (err < 0) goto out_free; err = format(&mtd, &ui, si, err, 1); if (err) goto out_free; } else { err = format(&mtd, &ui, si, 0, args.novtbl); if (err) goto out_free; } libscan_ubi_scan_free(si); close(args.node_fd); return 0; out_free: libscan_ubi_scan_free(si); out_close: close(args.node_fd); out_close_mtd: return 1; }
int application_start(int argc, char *argv[]) { #if AOS_ATCMD uart_dev_t at_uart; at_uart_configure(&at_uart); at.init(&at_uart, AT_RECV_DELIMITER, AT_SEND_DELIMITER, 1000); at.set_mode(ASYN); #endif #ifdef WITH_SAL sal_init(); #endif parse_opt(argc, argv); aos_set_log_level(AOS_LL_DEBUG); #ifndef AOS_AT_ADAPTER if (mesh_mode == MESH_MASTER) { #ifdef CONFIG_AOS_DDM ddm_run(argc, argv); #endif return 0; } #ifdef CONFIG_AOS_DDA dda_enable(atoi(mesh_num)); dda_service_init(); #endif #endif // #ifndef AOS_AT_ADAPTER aos_cli_register_command(&uuidcmd); alink_cloud_init(); if (mesh_mode == MESH_GATEWAY) { aos_cli_register_command(&ncmd); aos_cli_register_command(&modelcmd); aos_cli_register_command(&resetcmd); if (env == SANDBOX) alink_enable_sandbox_mode(); else if (env == DAILY) alink_enable_daily_mode(NULL, 0); #ifndef AOS_AT_ADAPTER aos_register_event_filter(EV_WIFI, alink_service_event, NULL); #else aos_register_event_filter(EV_AT, alink_service_event, NULL); #endif aos_register_event_filter(EV_SYS, alink_connect_event, NULL); aos_register_event_filter(EV_KEY, alink_key_process, NULL); #ifndef AOS_AT_ADAPTER aos_register_event_filter(EV_YUNIO, auto_active_handler, NULL); auto_netmgr = get_auto_netmgr_config(); awss_register_callback(AWSS_HOTSPOT_CONNECTED, &awss_hotspot_connected_handler); awss_register_callback(AWSS_HOTSPOT_SWITCH_AP_DONE, &awss_hotspot_switch_ap_done_handler); if (auto_netmgr) start_auto_netmgr_timer(); #else auto_netmgr = false; at_adapter_init(); #endif netmgr_init(); netmgr_start(auto_netmgr); } #if defined(CONFIG_AOS_DDA) && !defined(AOS_AT_ADAPTER) dda_service_start(); #else aos_loop_run(); LOG("alink end."); alink_end(); #endif return 0; }
int main(int argc, char **argv) { pscom_err_t rc; int ret; progname = strdup(argc && argv[0] ? argv[0] : "< ??? >"); parse_opt(argc, argv); pscom_set_debug(arg_verbose); pscom_init(PSCOM_VERSION); sock = pscom_open_socket(0, 0); if (!sock) abort_on_error("pscom_open_socket() failed", PSCOM_ERR_STDERROR); sock->ops = socket_ops_server; pscom_socket_set_name(sock, arg_listenname); rc = pscom_listen(sock, arg_listenport); if (rc) abort_on_error("pscom_listen() failed", rc); pscom_connection_t *con = pscom_open_connection(sock); rc = pscom_connect_socket_str(con, arg_peer_str); if (rc) abort_on_error("pscom_connect_socket_str()", rc); if (0) { // dummy connection pscom_connection_t *cond = pscom_open_connection(sock); rc = pscom_connect_socket_str(cond, "localhost:8912@dummy"); if (rc) abort_on_error("pscom_connect_socket_str()", rc); } // printf("Lokal connection: %p\n", con); { int peer_port; char peer_name[8]; ret = pscom_parse_socket_ondemand_str(arg_peer_str, NULL, &peer_port, &peer_name); if (ret) error(1, errno, "parse peer address failed"); printf("Call:\n"); printf("%s -l %d -n %1.8s %s%s\n" , progname, peer_port, peer_name, pscom_listen_socket_ondemand_str(sock), arg_send ? "" : " -s"); } pscom_stop_listen(sock); if (arg_send) { printf("Send in 2 sec\n"); sleep(2); char buf[1] = "x"; pscom_send(con, NULL, 0, buf, 1); printf("Send: %1.1s\n", buf); rc = pscom_recv(con, NULL, NULL, 0, buf, 1); if (rc) abort_on_error("pscom_recv()", rc); printf("Receive: %1.1s\n", buf); } else { char buf[1] = "o"; rc = pscom_recv(con, NULL, NULL, 0, buf, 1); if (rc) abort_on_error("pscom_recv()", rc); printf("Receive: %1.1s\n", buf); buf[0] = 'y'; pscom_send(con, NULL, 0, buf, 1); printf("Send: %1.1s\n", buf); } // sleep(10); puts(CYAN); pscom_dump_info(stdout); puts(NORM); pscom_flush(con); pscom_close_connection(con); pscom_close_socket(sock); return 0; }
int main(int argc, char **args) { int rc; gs_error_t *err = NULL; gs_grid_storage_t *gs = NULL; gs_container_t *container = NULL; signal(SIGPIPE, sig_pipe); if (argc <= 1) { help(); return 1; } if (!parse_opt(argc, args)) { PRINT_ERROR("Cannot parse the arguments\n"); help(); return 1; } if (!conf_check()) { PRINT_ERROR("Missing parameters\n"); help(); return 1; } /*open the connection to the META0 */ gs = gs_grid_storage_init(meta0_url, &err); if (!gs) { PRINT_ERROR("grid storage error : cannot init the namespace configuration from %s\n", meta0_url); return -1; } PRINT_DEBUG("Connected to the GridStorage namespace %s\n", meta0_url); /*find the container */ container = gs_get_container(gs, container_name, 0, &err); if (!container) { PRINT_ERROR("grid storage error : cannot find the container %s : %s\n", container_name, err->msg); gs_grid_storage_free(gs); return -1; } PRINT_DEBUG("container %s found\n", container_name); switch (action) { case A_CONTAINER_GET: rc = get_service_for_container(container,&err); if (rc != 0) PRINT_ERROR("Failed to list the index services used in container [%s] : %s\n", container_name, gs_error_get_message(err)); break; case A_CONTAINER_LIST: rc = list_services_used_by_container(container,&err); if (rc != 0) PRINT_ERROR("Failed to list the index services used in container [%s] : %s\n", container_name, gs_error_get_message(err)); break; case A_LISTSRV: rc = list_services_used(container,&err); if (rc != 0) PRINT_ERROR("Failed to list the index services used in container [%s] : %s\n", container_name, gs_error_get_message(err)); break; case A_LISTCONTENT: rc = list_services_for_path(container,&err, remote_path); if (rc != 0) PRINT_ERROR("Failed to list the index services used in container [%s] for path [%s] : %s\n", container_name, remote_path, gs_error_get_message(err)); break; default: PRINT_ERROR("Action not set, please provide at least '-l' or '-c'\n"); rc = -1; break; } gs_container_free(container); gs_grid_storage_free(gs); return 0; }
s32 get_tracert_info(char *argv, char* option, char *info1,char *info2) { trace_t trace; struct tracert_info tracert_info; int ret; int fd; struct sockaddr_in loc_addr; /* Parse command line */ parse_opt(argv); if (geteuid () != 0) return -1; ret = tracert_opt_parse(option, &tracert_info, info1); if(0 != ret) { return 0; } dest.sin_addr = *(struct in_addr *) tracehost->h_addr; dest.sin_family = AF_INET; dest.sin_port = htons (tracert_info.port); //给trace结构体的源地址赋初值 if(NULL != tracert_info.host_addr) { //测试源地址是否存在 memset(&loc_addr, '0', sizeof(loc_addr)); loc_addr.sin_family=AF_INET; loc_addr.sin_addr.s_addr=inet_addr(tracert_info.host_addr); loc_addr.sin_port=htons(SRCPORT); fd = socket(AF_INET, SOCK_RAW, IPPROTO_ICMP); if(bind(fd,(struct sockaddr*)&loc_addr,sizeof(loc_addr))) { close(fd); sprintf(info1,"Please select a local address!"); return 1; } close(fd); trace.from.sin_addr.s_addr = inet_addr(tracert_info.host_addr); sprintf(info1, "traceroute from %s to %s (%s), %d hops max", tracert_info.host_addr, tracehost->h_name, inet_ntoa (dest.sin_addr), tracert_info.max_hops); } else { sprintf(info1, "traceroute to %s (%s), %d hops max", tracehost->h_name, inet_ntoa (dest.sin_addr), tracert_info.max_hops); } trace_init (&trace, dest, opt_type, tracert_info.hop, tracert_info.host_addr); ret = do_try_info(&trace); if(ret == 1) { sprintf(info2, "sendto: Network is unreachable!"); return 1; } if(ret < 0) { return -1; } return 0; }
int main(int argc, char * const argv[]) { int err, verbose; libmtd_t libmtd; struct mtd_info mtd_info; struct mtd_dev_info mtd; libubi_t libubi; struct ubigen_info ui; struct ubi_scan_info *si; libmtd = libmtd_open(); if (!libmtd) return errmsg("MTD subsystem is not present"); err = parse_opt(argc, argv); if (err) goto out_close_mtd; err = mtd_get_info(libmtd, &mtd_info); if (err) { if (errno == ENODEV) errmsg("MTD is not present"); sys_errmsg("cannot get MTD information"); goto out_close_mtd; } err = mtd_get_dev_info(libmtd, args.node, &mtd); if (err) { sys_errmsg("cannot get information about \"%s\"", args.node); goto out_close_mtd; } if (!is_power_of_2(mtd.min_io_size)) { errmsg("min. I/O size is %d, but should be power of 2", mtd.min_io_size); goto out_close; } if (!mtd_info.sysfs_supported) { /* * Linux kernels older than 2.6.30 did not support sysfs * interface, and it is impossible to find out sub-page * size in these kernels. This is why users should * provide -s option. */ if (args.subpage_size == 0) { warnmsg("your MTD system is old and it is impossible " "to detect sub-page size. Use -s to get rid " "of this warning"); normsg("assume sub-page to be %d", mtd.subpage_size); } else { mtd.subpage_size = args.subpage_size; args.manual_subpage = 1; } } else if (args.subpage_size && args.subpage_size != mtd.subpage_size) { mtd.subpage_size = args.subpage_size; args.manual_subpage = 1; } if (args.manual_subpage) { /* Do some sanity check */ if (args.subpage_size > mtd.min_io_size) { errmsg("sub-page cannot be larger than min. I/O unit"); goto out_close; } if (mtd.min_io_size % args.subpage_size) { errmsg("min. I/O unit size should be multiple of " "sub-page size"); goto out_close; } } args.node_fd = open(args.node, O_RDWR); if (args.node_fd == -1) { sys_errmsg("cannot open \"%s\"", args.node); goto out_close_mtd; } /* Validate VID header offset if it was specified */ if (args.vid_hdr_offs != 0) { if (args.vid_hdr_offs % 8) { errmsg("VID header offset has to be multiple of min. I/O unit size"); goto out_close; } if (args.vid_hdr_offs + (int)UBI_VID_HDR_SIZE > mtd.eb_size) { errmsg("bad VID header offset"); goto out_close; } } if (!mtd.writable) { errmsg("mtd%d (%s) is a read-only device", mtd.mtd_num, args.node); goto out_close; } /* Make sure this MTD device is not attached to UBI */ libubi = libubi_open(); if (libubi) { int ubi_dev_num; err = mtd_num2ubi_dev(libubi, mtd.mtd_num, &ubi_dev_num); libubi_close(libubi); if (!err) { errmsg("please, first detach mtd%d (%s) from ubi%d", mtd.mtd_num, args.node, ubi_dev_num); goto out_close; } } if (!args.quiet) { normsg_cont("mtd%d (%s), size ", mtd.mtd_num, mtd.type_str); ubiutils_print_bytes(mtd.size, 1); printf(", %d eraseblocks of ", mtd.eb_cnt); ubiutils_print_bytes(mtd.eb_size, 1); printf(", min. I/O size %d bytes\n", mtd.min_io_size); } if (args.quiet) verbose = 0; else if (args.verbose) verbose = 2; else verbose = 1; err = ubi_scan(&mtd, args.node_fd, &si, verbose); if (err) { errmsg("failed to scan mtd%d (%s)", mtd.mtd_num, args.node); goto out_close; } if (si->good_cnt == 0) { errmsg("all %d eraseblocks are bad", si->bad_cnt); goto out_free; } if (si->good_cnt < 2 && (!args.novtbl || args.image)) { errmsg("too few non-bad eraseblocks (%d) on mtd%d", si->good_cnt, mtd.mtd_num); goto out_free; } if (!args.quiet) { if (si->ok_cnt) normsg("%d eraseblocks have valid erase counter, mean value is %lld", si->ok_cnt, si->mean_ec); if (si->empty_cnt) normsg("%d eraseblocks are supposedly empty", si->empty_cnt); if (si->corrupted_cnt) normsg("%d corrupted erase counters", si->corrupted_cnt); print_bad_eraseblocks(&mtd, si); } if (si->alien_cnt) { if (!args.yes || !args.quiet) warnmsg("%d of %d eraseblocks contain non-ubifs data", si->alien_cnt, si->good_cnt); if (!args.yes && want_exit()) { if (args.yes && !args.quiet) printf("yes\n"); goto out_free; } } if (!args.override_ec && si->empty_cnt < si->good_cnt) { int percent = ((double)si->ok_cnt)/si->good_cnt * 100; /* * Make sure the majority of eraseblocks have valid * erase counters. */ if (percent < 50) { if (!args.yes || !args.quiet) warnmsg("only %d of %d eraseblocks have valid erase counter", si->ok_cnt, si->good_cnt); normsg("erase counter 0 will be used for all eraseblocks"); normsg("note, arbitrary erase counter value may be specified using -e option"); if (!args.yes && want_exit()) { if (args.yes && !args.quiet) printf("yes\n"); goto out_free; } args.ec = 0; args.override_ec = 1; } else if (percent < 95) { if (!args.yes || !args.quiet) warnmsg("only %d of %d eraseblocks have valid erase counter", si->ok_cnt, si->good_cnt); normsg("mean erase counter %lld will be used for the rest of eraseblock", si->mean_ec); if (!args.yes && want_exit()) { if (args.yes && !args.quiet) printf("yes\n"); goto out_free; } args.ec = si->mean_ec; args.override_ec = 1; } } if (!args.quiet && args.override_ec) normsg("use erase counter %lld for all eraseblocks", args.ec); ubigen_info_init(&ui, mtd.eb_size, mtd.min_io_size, mtd.subpage_size, args.vid_hdr_offs, args.ubi_ver, args.image_seq); if (si->vid_hdr_offs != -1 && ui.vid_hdr_offs != si->vid_hdr_offs) { /* * Hmm, what we read from flash and what we calculated using * min. I/O unit size and sub-page size differs. */ if (!args.yes || !args.quiet) { warnmsg("VID header and data offsets on flash are %d and %d, " "which is different to requested offsets %d and %d", si->vid_hdr_offs, si->data_offs, ui.vid_hdr_offs, ui.data_offs); normsg_cont("use new offsets %d and %d? (yes/no) ", ui.vid_hdr_offs, ui.data_offs); } if (args.yes || answer_is_yes()) { if (args.yes && !args.quiet) printf("yes\n"); } else ubigen_info_init(&ui, mtd.eb_size, mtd.min_io_size, 0, si->vid_hdr_offs, args.ubi_ver, args.image_seq); normsg("use offsets %d and %d", ui.vid_hdr_offs, ui.data_offs); } if (args.image) { err = flash_image(libmtd, &mtd, &ui, si); if (err < 0) goto out_free; err = format(libmtd, &mtd, &ui, si, err, 1); if (err) goto out_free; } else { err = format(libmtd, &mtd, &ui, si, 0, args.novtbl); if (err) goto out_free; } ubi_scan_free(si); close(args.node_fd); libmtd_close(libmtd); return 0; out_free: ubi_scan_free(si); out_close: close(args.node_fd); out_close_mtd: libmtd_close(libmtd); return -1; }
int STD_CALL main(int argc, char ** argv) { try{ unsigned return_value = 0; memory::initialize(0); memory::exit_when_out_of_memory(true, "ERROR: out of memory"); parse_cmd_line_args(argc, argv); env_params::updt_params(); if (g_input_file && g_standard_input) { error("using standard input to read formula."); } if (!g_input_file && !g_standard_input) { error("input file was not specified."); } if (g_input_kind == IN_UNSPECIFIED) { g_input_kind = IN_SMTLIB_2; char const * ext = get_extension(g_input_file); if (ext) { if (strcmp(ext, "datalog") == 0 || strcmp(ext, "dl") == 0) { g_input_kind = IN_DATALOG; } else if (strcmp(ext, "dimacs") == 0 || strcmp(ext, "cnf") == 0) { g_input_kind = IN_DIMACS; } else if (strcmp(ext, "wcnf") == 0) { g_input_kind = IN_WCNF; } else if (strcmp(ext, "opb") == 0) { g_input_kind = IN_OPB; } else if (strcmp(ext, "log") == 0) { g_input_kind = IN_Z3_LOG; } else if (strcmp(ext, "smt2") == 0) { g_input_kind = IN_SMTLIB_2; } else if (strcmp(ext, "mps") == 0 || strcmp(ext, "sif") == 0 || strcmp(ext, "MPS") == 0 || strcmp(ext, "SIF") == 0) { g_input_kind = IN_MPS; } } } switch (g_input_kind) { case IN_SMTLIB_2: memory::exit_when_out_of_memory(true, "(error \"out of memory\")"); return_value = read_smtlib2_commands(g_input_file); break; case IN_DIMACS: return_value = read_dimacs(g_input_file); break; case IN_WCNF: return_value = parse_opt(g_input_file, true); break; case IN_OPB: return_value = parse_opt(g_input_file, false); break; case IN_DATALOG: read_datalog(g_input_file); break; case IN_Z3_LOG: replay_z3_log(g_input_file); break; case IN_MPS: return_value = read_mps_file(g_input_file); break; default: UNREACHABLE(); } memory::finalize(); #ifdef _WINDOWS _CrtDumpMemoryLeaks(); #endif return return_value; } catch (z3_exception & ex) { // unhandled exception std::cerr << "ERROR: " << ex.msg() << "\n"; if (ex.has_error_code()) return ex.error_code(); else return ERR_INTERNAL_FATAL; } }
int main(int argc, char *argv[]) { char dir[DIRSIZE]; int sd; struct sockaddr_in sin; struct sockaddr_in pin; struct hostent *hp; options_data opts; parse_opt(argc, argv, &opts); signal(SIGALRM, end_program); /* go find out about the desired host machine */ if ((hp = gethostbyname(opts.hostname)) == 0) { perror("gethostbyname"); exit(EXIT_FAILURE); } /* fill in the socket structure with host information */ memset(&pin, 0, sizeof(pin)); pin.sin_family = AF_INET; pin.sin_addr.s_addr = ((struct in_addr *)(hp->h_addr))->s_addr; pin.sin_port = htons(opts.port); /* grab an Internet domain socket */ if ((sd = socket(AF_INET, SOCK_STREAM, 0)) == -1) { perror("socket"); exit(EXIT_FAILURE); } /*set the congestion control algorithm to ledbat*/ if ( setsockopt(sd, SOL_TCP, TCP_CONGESTION, "ledbat", 6) == -1 ) { perror("setsockopt"); exit(EXIT_FAILURE); } /* connect to the host */ if (connect(sd,(struct sockaddr *) &pin, sizeof(pin)) == -1) { perror("connect"); exit(EXIT_FAILURE); } if (opts.duration > 0) { alarm(opts.duration); } int n = DIRSIZE, count = 0; memset (dir, 1, DIRSIZE); while (1) { if ( send(sd, dir, n, 0) == -1 ) { perror("send"); exit(EXIT_FAILURE); } count += n; if ( opts.count > 0 && count > opts.count ) { exit(EXIT_SUCCESS); } } close(sd); }