int main (int argc, char **argv) { char address[1024] = "unix:"DEFAULT_SOCK; lcc_connection_t *c; int status; while (42) { int c; c = getopt (argc, argv, "s:h"); if (c == -1) break; switch (c) { case 's': snprintf (address, sizeof (address), "unix:%s", optarg); address[sizeof (address) - 1] = '\0'; break; case 'h': exit_usage (argv[0], 0); break; default: exit_usage (argv[0], 1); } } if (optind >= argc) { fprintf (stderr, "%s: missing command\n", argv[0]); exit_usage (argv[0], 1); } c = NULL; status = lcc_connect (address, &c); if (status != 0) { fprintf (stderr, "ERROR: Failed to connect to daemon at %s: %s.\n", address, strerror (errno)); return (1); } if (strcasecmp (argv[optind], "getval") == 0) status = getval (c, argc - optind, argv + optind); else if (strcasecmp (argv[optind], "flush") == 0) status = flush (c, argc - optind, argv + optind); else if (strcasecmp (argv[optind], "listval") == 0) status = listval (c, argc - optind, argv + optind); else if (strcasecmp (argv[optind], "putval") == 0) status = putval (c, argc - optind, argv + optind); else { fprintf (stderr, "%s: invalid command: %s\n", argv[0], argv[optind]); return (1); } LCC_DESTROY (c); if (status != 0) return (status); return (0); } /* main */
int main(int argc, char** argv) { const char* devname = "default"; int verbose = 0; KCFileFormat format = KC_FORMAT_ANY; int c, rc; while ((c = getopt(argc, argv, "a:d:f:r:t:v?")) != -1) switch (c) { case 'a': amplitude = kc_parse_arg_num(optarg, 0.0, 1.0, INT16_MAX); break; case 'd': devname = optarg; break; case 'f': basefreq = kc_parse_arg_num(optarg, 1.0, 1 << 20, 1.0); break; case 'r': samplerate = kc_parse_arg_num(optarg, 1.0, 1 << 24, 1.0); break; case 't': format = kc_parse_arg_format(optarg); break; case 'v': verbose = 1; break; case '?': exit_usage(); default: abort(); } if (optind >= argc) exit_usage(); setlocale(LC_ALL, ""); stdout_isterm = isatty(STDOUT_FILENO); init_audio(devname); if (verbose && (rc = snd_pcm_dump(audio, output)) < 0) exit_snd_error(rc, "dump setup"); if (8 * basefreq > samplerate) { fprintf(stderr, "Base frequency of %u Hz is out of range at %u samples per second\n", basefreq, samplerate); exit(1); } ratescale = 3373259426u / samplerate; // 2^30 * pi / samplerate periodbuf = malloc(periodsize * n_channels * sizeof(int16_t)); for (int i = optind; i < argc; ++i) play_kcfile(argv[i], format); free(periodbuf); if ((rc = snd_pcm_drain(audio)) < 0) exit_snd_error(rc, "drain"); if ((rc = snd_pcm_close(audio)) < 0) exit_snd_error(rc, "close"); return 0; }
exit_t main() { const char *ca_eq = "v:=v+(-4*(v>=4))" "+(a[-1,0]>=4)+(a[0,-1]>=4)+(a[1,0]>=4)+(a[0,1]>=4)", *input_eq = "v:=v+1"; switch(argc) { case 3: input_eq = argv[2]; case 2: ca_eq = argv[1]; case 1: break; default: exit_usage(); } std::cerr << "Waiting for a grid as input...\n" "If no GUI shows up, you might want to try:\n" " core/create 10 10 0 | gui_qt/gui\n" << std::endl; QApplication app(argc, argv); MainWindow mainwindow(ca_eq, input_eq); mainwindow.show(); return success(app.exec() == 0); }
exit_t main() { FILE* read_fp=stdin; char separator = ' '; switch(argc) { case 2: assert_usage(!strcmp(argv[1],"newlines")); separator = '\n'; case 1: break; default: exit_usage(); } std::vector<int> grid; dimension dim; read_grid(read_fp, &grid, &dim); for(unsigned int i=0; i<grid.size(); i++) { const int human = internal2human(i,dim.width()); while(grid[i] != INT_MIN && grid[i]--) fprintf(stdout, "%d%c", human, separator); } fputs("\n", stdout); return exit_t::success; }
int main(int argc, char** argv) { const char* portname = "/dev/ttyS0"; int c; while ((c = getopt(argc, argv, "p:?")) != -1) switch (c) { case 'p': portname = optarg; break; case '?': exit_usage(); default: abort(); } if (optind < argc) exit_usage(); setlocale(LC_ALL, ""); init_screen(); int portfd = open(portname, O_RDWR | O_NOCTTY | O_NONBLOCK); if (portfd < 0) exit_error(portname, errno); init_serial_port(portfd, portname); int flags = fcntl(portfd, F_GETFL, 0); if (flags < 0 || fcntl(portfd, F_SETFL, flags & ~O_NONBLOCK) < 0) exit_error(portname, errno); wprintw(win_header, "Using serial port %s.\nPress CTRL-D to quit.", portname); waddch(win_prompt, '>'); wnoutrefresh(win_header); wnoutrefresh(win_prompt); wnoutrefresh(win_input); doupdate(); input_loop(portfd); while (close(portfd) < 0) if (errno != EINTR) exit_error(portname, errno); destroy_screen(); return 0; }
static void read_cmdline(int argc, char **argv, struct cmdline_config *config) { /* read options */ while (1) { int c = getopt(argc, argv, "BhtTC:" #if COLLECT_DAEMON "fP:" #endif ); if (c == -1) break; switch (c) { case 'B': config->create_basedir = false; break; case 'C': config->configfile = optarg; break; case 't': config->test_config = true; break; case 'T': config->test_readall = true; global_option_set("ReadThreads", "-1", 1); #if COLLECT_DAEMON config->daemonize = false; #endif /* COLLECT_DAEMON */ break; #if COLLECT_DAEMON case 'P': global_option_set("PIDFile", optarg, 1); break; case 'f': config->daemonize = false; break; #endif /* COLLECT_DAEMON */ case 'h': exit_usage(0); default: exit_usage(1); } /* switch (c) */ } /* while (1) */ }
static int read_options (int argc, char **argv) /* {{{ */ { int opt; while ((opt = getopt (argc, argv, "n:H:p:i:d:D:h")) != -1) { switch (opt) { case 'n': get_integer_opt (optarg, &conf_num_values); break; case 'H': get_integer_opt (optarg, &conf_num_hosts); break; case 'p': get_integer_opt (optarg, &conf_num_plugins); break; case 'i': get_double_opt (optarg, &conf_interval); break; case 'd': conf_destination = optarg; break; case 'D': conf_service = optarg; break; case 'h': exit_usage (EXIT_SUCCESS); default: exit_usage (EXIT_FAILURE); } /* switch (opt) */ } /* while (getopt) */ return (0); } /* }}} int read_options */
struct cmdline_config init_config(int argc, char **argv) { struct cmdline_config config = { .daemonize = true, .create_basedir = true, .configfile = CONFIGFILE, }; read_cmdline(argc, argv, &config); if (config.test_config) exit(EXIT_SUCCESS); if (optind < argc) exit_usage(1); plugin_init_ctx(); if (configure_collectd(&config) != 0) exit(EXIT_FAILURE); return config; } int run_loop(bool test_readall) { int exit_status = 0; if (do_init() != 0) { ERROR("Error: one or more plugin init callbacks failed."); exit_status = 1; } if (test_readall) { if (plugin_read_all_once() != 0) { ERROR("Error: one or more plugin read callbacks failed."); exit_status = 1; } } else { INFO("Initialization complete, entering read-loop."); do_loop(); } /* close syslog */ INFO("Exiting normally."); if (do_shutdown() != 0) { ERROR("Error: one or more plugin shutdown callbacks failed."); exit_status = 1; } return exit_status; } /* int run_loop */
int main(int argc, char ** argv) { int local_socket; struct hostent *he; int result; struct sockaddr_in local_addr, remote_addr; void * dontcare; // check arguments if(argc != 3){ exit_usage(argv[0]); } // resolve hostname he = gethostbyname(argv[1]); if (!he) { fprintf(stderr,"Invalid host: %s\n", argv[1]); exit(1); } memcpy(&remote_addr.sin_addr, he->h_addr, he->h_length); // set up local tcp socket memset(&local_addr, 0, sizeof(local_addr)); remote_addr.sin_family = AF_INET; //remote_addr.sin_addr.s_addr = inet_addr(argv[1]); remote_addr.sin_port = htons(atoi(argv[2])); local_socket = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); if (local_socket == -1){ perror("socket"); exit(1); } // connect to peer result = connect(local_socket, (struct sockaddr*)&remote_addr, sizeof remote_addr); if(result == -1){ perror("connect"); } // create and run receiving and sending threads pthread_create(&recv_thread, NULL, recv_entry, (void*)local_socket); pthread_create(&send_thread, NULL, send_entry, (void*)local_socket); // wait for the threads to finish and exit pthread_join(recv_thread, &dontcare); pthread_join(send_thread, &dontcare); return 0; }
exit_t main() { const char* fname = nullptr; switch(argc) { case 2: fname = argv[1]; case 1: break; default: return exit_usage(); } std::cout << grid_t(fname, 0); return exit_t::success; }
/** * main */ int main(int argc, char *argv[]) { int opt; int token = 0; uint32_t arch; /* parse the command line */ while ((opt = getopt(argc, argv, "ht")) > 0) { switch (opt) { case 't': token = 1; break; case 'h': default: /* usage information */ exit_usage(argv[0]); } } arch = seccomp_arch_native(); if (token == 0) { switch (arch) { case SCMP_ARCH_X86: printf("x86\n"); break; case SCMP_ARCH_X86_64: printf("x86_64\n"); break; case SCMP_ARCH_X32: printf("x32\n"); break; case SCMP_ARCH_ARM: printf("arm\n"); break; case SCMP_ARCH_AARCH64: printf("aarch64\n"); break; case SCMP_ARCH_MIPS: printf("mips\n"); break; case SCMP_ARCH_MIPSEL: printf("mipsel\n"); break; case SCMP_ARCH_MIPS64: printf("mips64\n"); break; case SCMP_ARCH_MIPSEL64: printf("mipsel64\n"); break; case SCMP_ARCH_MIPS64N32: printf("mips64n32\n"); break; case SCMP_ARCH_MIPSEL64N32: printf("mipsel64n32\n"); break; case SCMP_ARCH_PARISC: printf("parisc\n"); break; case SCMP_ARCH_PARISC64: printf("parisc64\n"); break; case SCMP_ARCH_PPC: printf("ppc\n"); break; case SCMP_ARCH_PPC64: printf("ppc64\n"); break; case SCMP_ARCH_PPC64LE: printf("ppc64le\n"); break; case SCMP_ARCH_S390: printf("s390\n"); break; case SCMP_ARCH_S390X: printf("s390x\n"); break; default: printf("unknown\n"); } } else printf("%d\n", arch); return 0; }
static void get_options( int argc, char *argv[] ) { int i; char *p, *q; opt.server_addr = DFL_SERVER_ADDR; opt.server_port = DFL_SERVER_PORT; opt.listen_addr = DFL_LISTEN_ADDR; opt.listen_port = DFL_LISTEN_PORT; opt.pack = DFL_PACK; /* Other members default to 0 */ for( i = 1; i < argc; i++ ) { p = argv[i]; if( ( q = strchr( p, '=' ) ) == NULL ) exit_usage( p, NULL ); *q++ = '\0'; if( strcmp( p, "server_addr" ) == 0 ) opt.server_addr = q; else if( strcmp( p, "server_port" ) == 0 ) opt.server_port = q; else if( strcmp( p, "listen_addr" ) == 0 ) opt.listen_addr = q; else if( strcmp( p, "listen_port" ) == 0 ) opt.listen_port = q; else if( strcmp( p, "duplicate" ) == 0 ) { opt.duplicate = atoi( q ); if( opt.duplicate < 0 || opt.duplicate > 20 ) exit_usage( p, q ); } else if( strcmp( p, "delay" ) == 0 ) { opt.delay = atoi( q ); if( opt.delay < 0 || opt.delay > 20 || opt.delay == 1 ) exit_usage( p, q ); } else if( strcmp( p, "delay_ccs" ) == 0 ) { opt.delay_ccs = atoi( q ); if( opt.delay_ccs < 0 || opt.delay_ccs > 1 ) exit_usage( p, q ); } else if( strcmp( p, "drop" ) == 0 ) { opt.drop = atoi( q ); if( opt.drop < 0 || opt.drop > 20 || opt.drop == 1 ) exit_usage( p, q ); } else if( strcmp( p, "pack" ) == 0 ) { #if defined(MBEDTLS_TIMING_C) opt.pack = (unsigned) atoi( q ); #else mbedtls_printf( " option pack only defined if MBEDTLS_TIMING_C is enabled\n" ); exit( 1 ); #endif } else if( strcmp( p, "mtu" ) == 0 ) { opt.mtu = atoi( q ); if( opt.mtu < 0 || opt.mtu > MAX_MSG_SIZE ) exit_usage( p, q ); } else if( strcmp( p, "bad_ad" ) == 0 ) { opt.bad_ad = atoi( q ); if( opt.bad_ad < 0 || opt.bad_ad > 1 ) exit_usage( p, q ); } else if( strcmp( p, "protect_hvr" ) == 0 ) { opt.protect_hvr = atoi( q ); if( opt.protect_hvr < 0 || opt.protect_hvr > 1 ) exit_usage( p, q ); } else if( strcmp( p, "protect_len" ) == 0 ) { opt.protect_len = atoi( q ); if( opt.protect_len < 0 ) exit_usage( p, q ); } else if( strcmp( p, "seed" ) == 0 ) { opt.seed = atoi( q ); if( opt.seed == 0 ) exit_usage( p, q ); } else exit_usage( p, NULL ); } }
exit_t main() { bool ids = false; def_coord_traits::u_coord_t width; switch(argc) { case 3: assert_usage(!strcmp(argv[2],"ids")); ids = true; case 2: width = atoi(argv[1]) + 2; break; default: return exit_usage(); } FILE* const in_fp = stdin; FILE* const out_fp = stdout; struct hdr_info_t { uint8_t size_each, div_size; uint64_t offset; void print_info() { #ifdef AVALANCHES_DEBUG std::cerr << "Avalanche idx size is " << (int)size_each << std::endl; std::cerr << "Size each is " << (int)div_size << std::endl; std::cerr << "Index offset is " << offset << std::endl; #endif } bool parse(FILE* in_fp) { char hdr_buf[14]; auto safe_fread = [](void *ptr, size_t size, size_t nmemb, FILE *stream) { if(fread(ptr, size, nmemb, stream) != nmemb) throw "parse error."; }; safe_fread(hdr_buf, 1, sizeof(hdr_buf), in_fp); for(std::size_t i = 0; i < sizeof(hdr_buf); ++i) if(hdr_buf[i] != 0) { std::cerr << "Byte " << i << " is not a header byte" << std::endl; return false; } safe_fread(&size_each, 1, 1, in_fp); safe_fread(&div_size, 1, 1, in_fp); safe_fread(&offset, 8, 1, in_fp); return true; } } hdr_info; // parse header { if(!hdr_info.parse(in_fp)) exit("Error parsing header"); hdr_info.print_info(); } // TODO: better use a variadic list to check for 1,2,4,8 switch(hdr_info.size_each) { case 1: parse_avalanches<int8_t>(in_fp, out_fp, width, hdr_info.div_size, hdr_info.offset, ids); break; case 2: parse_avalanches<int16_t>(in_fp, out_fp, width, hdr_info.div_size, hdr_info.offset, ids); break; case 4: parse_avalanches<int32_t>(in_fp, out_fp, width, hdr_info.div_size, hdr_info.offset, ids); break; case 8: parse_avalanches<int64_t>(in_fp, out_fp, width, hdr_info.div_size, hdr_info.offset, ids); break; default: assert_always(false, "The avalanche index size" "must be out of {1,2,4,8}."); } return success(feof(in_fp)!=0); // feof==0 <=> stop, but no eof <=> error }
int main(int argc, char *argv[]) { int c, i; FILE *fin = stdin; FILE *fout = stdout; char encode = -1; int droptest = 0; char callsign[7]; uint8_t image_id = 0; ssdv_t ssdv; uint8_t pkt[SSDV_PKT_SIZE], b[128], *jpeg; size_t jpeg_length; callsign[0] = '\0'; opterr = 0; while((c = getopt(argc, argv, "edc:i:t:")) != -1) { switch(c) { case 'e': encode = 1; break; case 'd': encode = 0; break; case 'c': if(strlen(optarg) > 6) fprintf(stderr, "Warning: callsign is longer than 6 characters.\n"); strncpy(callsign, optarg, 7); break; case 'i': image_id = atoi(optarg); break; case 't': droptest = atoi(optarg); break; case '?': exit_usage(); } } c = argc - optind; if(c > 2) exit_usage(); for(i = 0; i < c; i++) { if(!strcmp(argv[optind + i], "-")) continue; switch(i) { case 0: fin = fopen(argv[optind + i], "rb"); if(!fin) { fprintf(stderr, "Error opening '%s' for input:\n", argv[optind + i]); perror("fopen"); return(-1); } break; case 1: fout = fopen(argv[optind + i], "wb"); if(!fout) { fprintf(stderr, "Error opening '%s' for output:\n", argv[optind + i]); perror("fopen"); return(-1); } break; } } switch(encode) { case 0: /* Decode */ if(droptest > 0) fprintf(stderr, "*** NOTE: Drop test enabled: %i ***\n", droptest); ssdv_dec_init(&ssdv); jpeg_length = 1024 * 1024 * 4; jpeg = malloc(jpeg_length); ssdv_dec_set_buffer(&ssdv, jpeg, jpeg_length); i = 0; while(fread(pkt, 1, SSDV_PKT_SIZE, fin) > 0) { /* Drop % of packets */ if(droptest && (rand() / (RAND_MAX / 100) < droptest)) continue; /* Test the packet is valid */ if(ssdv_dec_is_packet(pkt, NULL) != 0) continue; /* Feed it to the decoder */ ssdv_dec_feed(&ssdv, pkt); i++; } ssdv_dec_get_jpeg(&ssdv, &jpeg, &jpeg_length); fwrite(jpeg, 1, jpeg_length, fout); free(jpeg); fprintf(stderr, "Read %i packets\n", i); break; case 1: /* Encode */ ssdv_enc_init(&ssdv, callsign, image_id); ssdv_enc_set_buffer(&ssdv, pkt); i = 0; while(1) { while((c = ssdv_enc_get_packet(&ssdv)) == SSDV_FEED_ME) { size_t r = fread(b, 1, 128, fin); if(r <= 0) { fprintf(stderr, "Premature end of file\n"); break; } ssdv_enc_feed(&ssdv, b, r); } if(c == SSDV_EOI) { fprintf(stderr, "ssdv_enc_get_packet said EOI\n"); break; } else if(c != SSDV_OK) { fprintf(stderr, "ssdv_enc_get_packet failed: %i\n", c); return(-1); } fwrite(pkt, 1, SSDV_PKT_SIZE, fout); i++; } fprintf(stderr, "Wrote %i packets\n", i); break; default: fprintf(stderr, "No mode specified.\n"); break; } if(fin != stdin) fclose(fin); if(fout != stdout) fclose(fout); return(0); }
int main(int argc, char *argv[]) { struct termios serial; int c, i; FILE *fin = stdin; FILE *fout = stdout; int fd; int wcount; char encode = -1; int droptest = 0; char callsign[7]; uint8_t image_id = 0; ssdv_t ssdv; uint8_t pkt[SSDV_PKT_SIZE], b[128], *jpeg; size_t jpeg_length; callsign[0] = '\0'; opterr = 0; while((c = getopt(argc, argv, "edc:i:t:")) != -1) { switch(c) { case 'e': encode = 1; break; case 'd': encode = 0; break; case 'c': if(strlen(optarg) > 6) fprintf(stderr, "Warning: callsign is longer than 6 characters.\n"); strncpy(callsign, optarg, 7); break; case 'i': image_id = atoi(optarg); break; case 't': droptest = atoi(optarg); break; case '?': exit_usage(); } } c = argc - optind; if(c > 2) exit_usage(); for(i = 0; i < c; i++) { if(!strcmp(argv[optind + i], "-")) continue; switch(i) { case 0: fin = fopen(argv[optind + i], "rb"); if(!fin) { fprintf(stderr, "Error opening '%s' for input:\n", argv[optind + i]); perror("fopen"); return(-1); } break; } } switch(encode) { case 0: /* Decode */ if(droptest > 0) fprintf(stderr, "*** NOTE: Drop test enabled: %i ***\n", droptest); ssdv_dec_init(&ssdv); jpeg_length = 1024 * 1024 * 4; jpeg = malloc(jpeg_length); ssdv_dec_set_buffer(&ssdv, jpeg, jpeg_length); i = 0; while(fread(pkt, 1, SSDV_PKT_SIZE, fin) > 0) { /* Drop % of packets */ if(droptest && (rand() / (RAND_MAX / 100) < droptest)) continue; /* Test the packet is valid */ if(ssdv_dec_is_packet(pkt, NULL) != 0) continue; /* Feed it to the decoder */ ssdv_dec_feed(&ssdv, pkt); i++; } ssdv_dec_get_jpeg(&ssdv, &jpeg, &jpeg_length); fwrite(jpeg, 1, jpeg_length, fout); free(jpeg); fprintf(stderr, "Read %i packets\n", i); break; case 1: /* Encode */ ssdv_enc_init(&ssdv, callsign, image_id); ssdv_enc_set_buffer(&ssdv, pkt); i = 0; while(1) { fd = open(SERIAL_PORT, O_RDWR | O_NOCTTY | O_NDELAY); if (fd == -1) { perror("Failed to open Serial Port"); return -1; } if (tcgetattr(fd, &serial) < 0) { perror("Failed to read Serial Port Configuration"); return -1; } // Set up Serial Configuration serial.c_iflag = 0; serial.c_oflag = 0; serial.c_lflag = 0; serial.c_cflag = 0; serial.c_cc[VMIN] = 0; serial.c_cc[VTIME] = 0; serial.c_cflag = B600 | CS8 | CREAD; tcsetattr(fd, TCSANOW, &serial); // Apply Serial configuration while((c = ssdv_enc_get_packet(&ssdv)) == SSDV_FEED_ME) { size_t r = fread(b, 1, 128, fin); if(r <= 0) { fprintf(stderr, "Premature end of file\n"); break; } ssdv_enc_feed(&ssdv, b, r); } if(c == SSDV_EOI) { fprintf(stderr, "ssdv_enc_get_packet said EOI\n"); break; } else if(c != SSDV_OK) { fprintf(stderr, "ssdv_enc_get_packet failed: %i\n", c); return(-1); } wcount = write(fd, pkt, SSDV_PKT_SIZE); if (wcount < 0) { perror("Writing to Serial Port"); return -1; } close(fd); i++; } fprintf(stderr, "Wrote %i packets\n", i); break; default: fprintf(stderr, "No mode specified.\n"); break; } if(fin != stdin) fclose(fin); if(fout != stdout) fclose(fout); close(fd); return(0); }
exit_t main() { exit_t result = exit_t::success; const char* tbl_file = nullptr; const char* type = "split"; bool dump_on_exit = true; int dead_state = std::numeric_limits<int>::max(); bool pipe = false; catch_sigint(); /* * args */ assert_usage(argc >= 3); switch(argc) { case 6: assert_usage(!strcmp(argv[5], "pipe")); pipe = true; case 5: type = argv[4]; case 4: assert_usage(!strcmp(argv[3], "nodump") || !strcmp(argv[3], "dump")); dump_on_exit = (!strcmp(argv[3], "dump")); case 3: assert_usage((argv[2][1] == 0) && isdigit(argv[2][0])); dead_state = atoi(argv[2]); case 2: tbl_file = argv[1]; break; default: exit_usage(); } /* * parsing */ std::ifstream in(tbl_file, std::ios::in); std::ofstream outfile; if(!pipe) outfile.open("results.dat"); std::ostream& out = pipe ? std::cout : outfile; // TODO: error if in is not existing { std::unique_ptr<base> algo = nullptr; if(!strcmp(type, "greedy")) { algo.reset(new greedy::algo(in, dead_state, dump_on_exit)); } else throw "Unknown algorithm type specified"; algo->parse(); /* * algorithm */ try { algo->run(out); } catch(const char* s) { if(dump_on_exit) { std::cout << "Aborting algorithm, reason: " << s << std::endl; std::cout << "Writing debug_graph.dot ..." << std::endl; std::ofstream final_graph("debug_graph.dot"); final_graph << (base&)*algo; } else { std::cout << "Aborting algorithm, reason: " << s << std::endl; std::cout << "Dumping disabled by parameters" << std::endl; } result = exit_t::failure; } } //std::cout << "FINAL RESULTS: " << std::endl << *algo << std::endl; if(result == exit_t::success) std::cerr << std::endl << "Success. Now call: `./search/eval help < results.dat'." << std::endl << std::endl; else std::cerr << std::endl << "Failure." << std::endl << std::endl; return result; }
/** * main */ int main(int argc, char *argv[]) { int opt; int iter; char *opt_file = NULL; FILE *file; size_t file_read_len; struct seccomp_data sys_data; struct bpf_program bpf_prg; /* initialize the syscall record */ memset(&sys_data, 0, sizeof(sys_data)); /* parse the command line */ while ((opt = getopt(argc, argv, "a:f:hs:v0:1:2:3:4:5:")) > 0) { switch (opt) { case 'a': if (strcmp(optarg, "x86") == 0) arch = AUDIT_ARCH_I386; else if (strcmp(optarg, "x86_64") == 0) arch = AUDIT_ARCH_X86_64; else if (strcmp(optarg, "x32") == 0) arch = AUDIT_ARCH_X86_64; else if (strcmp(optarg, "arm") == 0) arch = AUDIT_ARCH_ARM; else if (strcmp(optarg, "aarch64") == 0) arch = AUDIT_ARCH_AARCH64; else if (strcmp(optarg, "mips") == 0) arch = AUDIT_ARCH_MIPS; else if (strcmp(optarg, "mipsel") == 0) arch = AUDIT_ARCH_MIPSEL; else if (strcmp(optarg, "mips64") == 0) arch = AUDIT_ARCH_MIPS64; else if (strcmp(optarg, "mipsel64") == 0) arch = AUDIT_ARCH_MIPSEL64; else if (strcmp(optarg, "mips64n32") == 0) arch = AUDIT_ARCH_MIPS64N32; else if (strcmp(optarg, "mipsel64n32") == 0) arch = AUDIT_ARCH_MIPSEL64N32; else if (strcmp(optarg, "parisc") == 0) arch = AUDIT_ARCH_PARISC; else if (strcmp(optarg, "parisc64") == 0) arch = AUDIT_ARCH_PARISC64; else if (strcmp(optarg, "ppc") == 0) arch = AUDIT_ARCH_PPC; else if (strcmp(optarg, "ppc64") == 0) arch = AUDIT_ARCH_PPC64; else if (strcmp(optarg, "ppc64le") == 0) arch = AUDIT_ARCH_PPC64LE; else if (strcmp(optarg, "s390") == 0) arch = AUDIT_ARCH_S390; else if (strcmp(optarg, "s390x") == 0) arch = AUDIT_ARCH_S390X; else exit_fault(EINVAL); break; case 'f': opt_file = strdup(optarg); if (opt_file == NULL) exit_fault(ENOMEM); break; case 's': sys_data.nr = strtol(optarg, NULL, 0); break; case 'v': opt_verbose = 1; break; case '0': sys_data.args[0] = strtoull(optarg, NULL, 0); break; case '1': sys_data.args[1] = strtoull(optarg, NULL, 0); break; case '2': sys_data.args[2] = strtoull(optarg, NULL, 0); break; case '3': sys_data.args[3] = strtoull(optarg, NULL, 0); break; case '4': sys_data.args[4] = strtoull(optarg, NULL, 0); break; case '5': sys_data.args[5] = strtoull(optarg, NULL, 0); break; case 'h': default: /* usage information */ exit_usage(argv[0]); } } /* adjust the endianess of sys_data to match the target */ sys_data.nr = htot32(arch, sys_data.nr); sys_data.arch = htot32(arch, arch); sys_data.instruction_pointer = htot64(arch, sys_data.instruction_pointer); for (iter = 0; iter < BPF_SYS_ARG_MAX; iter++) sys_data.args[iter] = htot64(arch, sys_data.args[iter]); /* allocate space for the bpf program */ /* XXX - we should make this dynamic */ bpf_prg.i_cnt = 0; bpf_prg.i = calloc(BPF_PRG_MAX_LEN, sizeof(*bpf_prg.i)); if (bpf_prg.i == NULL) exit_fault(ENOMEM); /* load the bpf program */ file = fopen(opt_file, "r"); if (file == NULL) exit_fault(errno); do { file_read_len = fread(&(bpf_prg.i[bpf_prg.i_cnt]), sizeof(*bpf_prg.i), 1, file); if (file_read_len == 1) bpf_prg.i_cnt++; /* check the size */ if (bpf_prg.i_cnt == BPF_PRG_MAX_LEN) exit_fault(E2BIG); } while (file_read_len > 0); fclose(file); /* execute the bpf program */ bpf_execute(&bpf_prg, &sys_data); /* we should never reach here */ exit_fault(EFAULT); return 0; }
int main(int argc, char *argv[]) { int fd, err; char *filename = NULL; char buf[BLOCKSZ]; struct stat ss; uint64_t nblocks; int64_t n = -1; int sequential = 0; if (argc < 2) exit_usage(); argv++; if (strcmp("-s", argv[0]) == 0) { sequential = 1; argv++; } if (argv[0] == NULL) exit_usage(); else filename = argv[0]; argv++; if (argv[0] != NULL) n = strtoull(argv[0], NULL, 0); fd = open(filename, O_RDWR|O_CREAT, 0666); err = fstat(fd, &ss); if (err != 0) { (void) fprintf(stderr, "error: fstat returned error code %d\n", err); exit(EXIT_FAILURE); } nblocks = ss.st_size / BLOCKSZ; if (nblocks == 0) { (void) fprintf(stderr, "error: " "file is too small (min allowed size is %d bytes)\n", BLOCKSZ); exit(EXIT_FAILURE); } srand48(getpid()); for (int i = 0; i < BLOCKSZ; i++) randbuf[i] = lrand48(); distribution_n = 0; for (uint64_t i = 0; i < sizeof (size_distribution) / sizeof (size_distribution[0]); i++) { distribution_n += size_distribution[i]; } if (sequential) sequential_writes(fd, buf, nblocks, n); else random_writes(fd, buf, nblocks, n); return (0); }
int main(int argc, char *argv[]) { int c; int n = 1; double m = 0.0; double s = 1.0; double a = -1.0; double b = 1.0; char *filename = NULL; FILE *file; long seed = 0; int i; gsl_rng *rng; opterr = 0; while ((c = getopt(argc, argv, "n:m:s:a:b:o:r:h")) != -1) { char *endptr = NULL; switch (c) { case 'n': n = strtol(optarg, &endptr, 10); break; case 'm': m = checked_strtod(argv, 'm', optarg); break; case 's': s = checked_strtod(argv, 's', optarg); break; case 'a': a = checked_strtod(argv, 'a', optarg); break; case 'b': b = checked_strtod(argv, 'b', optarg); break; case 'o': filename = optarg; break; case 'r': seed = strtol(optarg, &endptr, 0); break; case 'h': exit_usage(argv); break; case '?': exit_invalid_flag(argv, optopt); break; } } if (filename == NULL) { file = stdout; } else { file = fopen(filename, "wt"); if (file == NULL) { exit_eio(argv, filename); } } rng = gsl_rng_alloc(gsl_rng_taus); gsl_rng_set(rng, seed); for (i = 0; i < n; i++) { double y; y = ran_truncnormal(rng, a, b, m, s); fprintf(file, "%0.16f\n", y); } if (filename != NULL) { fclose(file); } gsl_rng_free(rng); return 0; }
/* execution for commands */ static void execute_command(char cmd[MAX_CMD][MAX_CMD_LEN], pid_t wpid[MAX_CMD], int cmd_num) { /* e.g. "ls", "-l" */ char buf[MAX_ARGC][MAX_ARG_LEN]; /* two pipes needed */ int fds[2][2]; int n; int fd; pid_t pid; /* 0: pipe1, 1: pipe2 */ int pipe_flag; COMMAND command; n = 0; pipe_flag = 0; while (n < cmd_num) { command_init(&command); argument_parser(cmd[n], buf, &command); if (!pipe_flag) { /* pipe1 */ /* last command doesn't need to create a pipe */ if(n != cmd_num - 1) { if (pipe(fds[0]) == -1) { fprintf(stderr, "%s: pipe() error: " "%s\n", command.arg[0], strerror(errno)); /* close read end of previous pipe */ if (n != 0) close(fds[1][0]); while (n < cmd_num) { wpid[n] = -1; n++; } break; } } if ((pid = fork()) == -1){ fprintf(stderr, "%s: fork() error: %s\n", command.arg[0], strerror(errno)); close(fds[0][0]); close(fds[0][1]); /* close read end of previous pipe */ if (n != 0) close(fds[1][0]); while (n < cmd_num) { wpid[n] = -1; n++; } break; } else if (pid == 0) { /* child */ /* * Close read end in child process. * Last command doesn't create a pipe. */ if(n != cmd_num - 1) close(fds[0][0]); /* stdin redirection */ if(strcmp(command.input, "") != 0) { if ((fd = open(command.input, O_RDONLY)) == -1) { fprintf(stderr, "%s: %s: open" "() error: %s\n", command.arg[0], command.input, strerror(errno)); exit(DEFAULT_STATUS); } if (dup2(fd, STDIN_FILENO) == -1) { fprintf(stderr, "%s: %s: dup2()" "error: %s\n", command.arg[0], command.input, strerror(errno)); close(fd); exit(DEFAULT_STATUS); } close(fd); } else if(n != 0){ if (dup2(fds[1][0], STDIN_FILENO) == -1) { fprintf(stderr, "%s: dup2()" "error: %s\n", command.arg[0], strerror(errno)); close(fds[1][0]); exit(DEFAULT_STATUS); } } /* close read end of previous pipe */ if(n != 0) close(fds[1][0]); /* stdout redirection */ if(strcmp(command.output,"")!=0) { if(command.append) fd = open(command.output, O_WRONLY | O_APPEND | O_CREAT, S_IWUSR | S_IRUSR); else fd = open(command.output, O_WRONLY | O_TRUNC | O_CREAT, S_IWUSR | S_IRUSR); if (fd == -1) { fprintf(stderr, "%s: %s: open" "() error: %s\n", command.arg[0], command.output, strerror(errno)); exit(DEFAULT_STATUS); } if (dup2(fd, STDOUT_FILENO) == -1) { fprintf(stderr, "%s: %s: dup2()" "error: %s\n", command.arg[0], command.output, strerror(errno)); close(fd); exit(DEFAULT_STATUS); } close(fd); } else if (n != cmd_num - 1){ if (dup2(fds[0][1], STDOUT_FILENO) == -1) { fprintf(stderr, "%s: dup2()" "error: %s\n", command.arg[0], strerror(errno)); close(fds[0][1]); exit(DEFAULT_STATUS); } } if(n != cmd_num - 1) close(fds[0][1]); /* builtin commands */ if (strcmp(command.arg[0], "exit") == 0) { if (exit_syntax_check(command.arg) == -1) { exit_usage(); exit(EXIT_FAILURE); } else exit(ret_val); } else if (strcmp(command.arg[0], "cd") == 0) { if (cd_syntax_check(command.arg) == -1) { cd_usage(); exit(EXIT_FAILURE); } else { exit(cd_exec(command.arg)); } } else if (strcmp(command.arg[0], "echo") == 0) { echo_exec(command.arg); exit(EXIT_SUCCESS); } execvp(command.arg[0], command.arg); fprintf(stderr, "%s: command not found\n", command.arg[0]); exit(DEFAULT_STATUS); } else { /* parent */ wpid[n] = pid; if(n != cmd_num - 1) close(fds[0][1]); if(n != 0) close(fds[1][0]); } pipe_flag = 1; } else { /* pipe2 */ /* last command doesn't need to create a pipe */ if(n != cmd_num - 1) { if (pipe(fds[1]) == -1) { fprintf(stderr, "%s: pipe() error: " "%s\n", command.arg[0], strerror(errno)); /* close read end of previous pipe */ if (n != 0) close(fds[0][0]); while (n < cmd_num) { wpid[n] = -1; n++; } break; } } if ((pid = fork()) == -1){ fprintf(stderr, "%s: fork() error: %s\n", command.arg[0], strerror(errno)); close(fds[1][0]); close(fds[1][1]); /* close read end of previous pipe */ if (n != 0) close(fds[0][0]); while (n < cmd_num) { wpid[n] = -1; n++; } break; } else if (pid == 0) { /* child */ /* * Close read end in child process. * Last command doesn't create a pipe. */ if(n != cmd_num - 1) close(fds[1][0]); /* stdin redirection */ if(strcmp(command.input, "") != 0) { if ((fd = open(command.input, O_RDONLY)) == -1) { fprintf(stderr, "%s: %s: open" "() error: %s\n", command.arg[0], command.input, strerror(errno)); exit(DEFAULT_STATUS); } if (dup2(fd, STDIN_FILENO) == -1) { fprintf(stderr, "%s: %s: dup2()" "error: %s\n", command.arg[0], command.input, strerror(errno)); close(fd); exit(DEFAULT_STATUS); } close(fd); } else if(n != 0){ if (dup2(fds[0][0], STDIN_FILENO) == -1) { fprintf(stderr, "%s: dup2()" "error: %s\n", command.arg[0], strerror(errno)); close(fds[0][0]); exit(DEFAULT_STATUS); } } /* close read end of previous pipe */ if(n != 0) close(fds[0][0]); /* stdout redirection */ if(strcmp(command.output,"")!=0) { if(command.append) fd = open(command.output, O_WRONLY | O_APPEND | O_CREAT, S_IWUSR | S_IRUSR); else fd = open(command.output, O_WRONLY | O_TRUNC | O_CREAT, S_IWUSR | S_IRUSR); if (fd == -1) { fprintf(stderr, "%s: %s: open" "() error: %s\n", command.arg[0], command.output, strerror(errno)); exit(DEFAULT_STATUS); } if (dup2(fd, STDOUT_FILENO) == -1) { fprintf(stderr, "%s: %s: dup2()" "error: %s\n", command.arg[0], command.output, strerror(errno)); close(fd); exit(DEFAULT_STATUS); } close(fd); } else if (n != cmd_num - 1){ if (dup2(fds[1][1], STDOUT_FILENO) == -1) { fprintf(stderr, "%s: dup2()" "error: %s\n", command.arg[0], strerror(errno)); close(fds[1][1]); exit(DEFAULT_STATUS); } } if(n != cmd_num - 1) close(fds[1][1]); /* builtin commands */ if (strcmp(command.arg[0], "exit") == 0) { if (exit_syntax_check(command.arg) == -1) { exit_usage(); exit(EXIT_FAILURE); } else exit(ret_val); } else if (strcmp(command.arg[0], "cd") == 0) { if (cd_syntax_check(command.arg) == -1) { cd_usage(); exit(EXIT_FAILURE); } else { exit(cd_exec(command.arg)); } } else if (strcmp(command.arg[0], "echo") == 0) { echo_exec(command.arg); exit(EXIT_SUCCESS); } execvp(command.arg[0], command.arg); fprintf(stderr, "%s: command not found\n", command.arg[0]); exit(DEFAULT_STATUS); } else { /* parent */ wpid[n] = pid; if(n != cmd_num - 1) close(fds[1][1]); if(n != 0) close(fds[0][0]); } pipe_flag = 0; } n++; } }
exit_t main() { const char *equation = "v"; std::string format = "ARGB"; int iterations = 1; MagickCore::MagickCoreGenesis(*argv, Magick::MagickFalse); switch(argc) { case 4: iterations = atoi(argv[3]); case 3: format = argv[2]; assert_always(format.length()==4, "Format must consist of 4 chars."); // TODO: only RGBACYMK allowed case 2: equation = argv[1]; break; case 1: default: exit_usage(); } // big endian -> reverse format for user std::reverse(format.begin(), format.end()); std::vector<char> content = get_file_contents(); try { // this is all much copying, // but it seems to be the only way... Magick::Blob blob(content.data(), content.size()); Magick::Image img(blob); const dimension dim(img.size().width(), img.size().height()); grid_t grid(dimension(dim.height(), dim.width()), 0); img.write(0, 0, dim.width(), dim.height(), format, Magick::CharPixel, grid.data().data()); using ca_sim_t = sca::ca::simulator_t< sca::ca::eqsolver_t, def_coord_traits, def_cell_traits>; ca_sim_t sim(equation); sim.grid() = grid; sim.finalize(); for(int i = 0; i < iterations; ++i) sim.run_once(ca_sim_t::synchronous()); Magick::Blob blob2; Magick::Image img2(dim.width(), dim.height(), format, Magick::CharPixel, sim.grid().data().data()); // needed, otherwise we write "format-less": img2.magick(img.magick()); img2.write(&blob2); std::cout.write(reinterpret_cast<const char*>(blob2.data()), blob2.length()); } catch ( Magick::Exception & error) { std::cerr << "Caught Magick++ exception: " << error.what() << std::endl; } return exit_t::success; }
int main (int argc, char **argv) { int collectd_argc = 0; char *collectd = NULL; char **collectd_argv = NULL; struct sigaction sa; int i = 0; /* parse command line options */ while (42) { int c = getopt (argc, argv, "hc:P:"); if (-1 == c) break; switch (c) { case 'c': collectd = optarg; break; case 'P': pidfile = optarg; break; case 'h': default: exit_usage (argv[0]); } } for (i = optind; i < argc; ++i) if (0 == strcmp (argv[i], "-f")) break; /* i < argc => -f already present */ collectd_argc = 1 + argc - optind + ((i < argc) ? 0 : 1); collectd_argv = (char **)calloc (collectd_argc + 1, sizeof (char *)); if (NULL == collectd_argv) { fprintf (stderr, "Out of memory."); return 3; } collectd_argv[0] = (NULL == collectd) ? "collectd" : collectd; if (i == argc) collectd_argv[collectd_argc - 1] = "-f"; for (i = optind; i < argc; ++i) collectd_argv[i - optind + 1] = argv[i]; collectd_argv[collectd_argc] = NULL; openlog ("collectdmon", LOG_CONS | LOG_PID, LOG_DAEMON); if (-1 == daemonize ()) return 1; sa.sa_handler = sig_int_term_handler; sa.sa_flags = 0; sigemptyset (&sa.sa_mask); if (0 != sigaction (SIGINT, &sa, NULL)) { syslog (LOG_ERR, "Error: sigaction() failed: %s", strerror (errno)); return 1; } if (0 != sigaction (SIGTERM, &sa, NULL)) { syslog (LOG_ERR, "Error: sigaction() failed: %s", strerror (errno)); return 1; } sa.sa_handler = sig_hup_handler; if (0 != sigaction (SIGHUP, &sa, NULL)) { syslog (LOG_ERR, "Error: sigaction() failed: %s", strerror (errno)); return 1; } while (0 == loop) { int status = 0; if (0 != collectd_start (collectd_argv)) { syslog (LOG_ERR, "Error: failed to start collectd."); break; } assert (0 < collectd_pid); while ((collectd_pid != waitpid (collectd_pid, &status, 0)) && (EINTR == errno)) if ((0 != loop) || (0 != restart)) collectd_stop (); collectd_pid = 0; log_status (status); check_respawn (); if (0 != restart) { syslog (LOG_INFO, "Info: restarting collectd"); restart = 0; } else if (0 == loop) syslog (LOG_WARNING, "Warning: restarting collectd"); } syslog (LOG_INFO, "Info: shutting down collectdmon"); pidfile_delete (); closelog (); free (collectd_argv); return 0; } /* main */
/* execution for the shell */ int execute() { /* e.g. "ls -l | cat -n" */ char line[MAX_LINE_LEN]; /* e.g. "ls -l", "cat -n" */ char cmd[MAX_CMD][MAX_CMD_LEN]; /* e.g. "ls", "-l" */ char buf[MAX_ARGC][MAX_ARG_LEN]; int status; /* background flag */ int is_bg; char str[2]; int i, n; /* processes to be waited */ pid_t wpid[MAX_CMD]; int cmd_num; COMMAND command; is_bg = 0; /* handle child processes exit signal and ctrl-c signal */ if (signal(SIGCHLD, chldHandler) == SIG_ERR || signal(SIGINT, intHandler) == SIG_ERR) { perror("Signal() error"); return DEFAULT_STATUS; } if (cflag) { if ((n = syntax_check(ccmd, &is_bg)) == -1) { fprintf(stderr, "sish: %s: Syntax error\n", ccmd); return DEFAULT_STATUS; } else if (n == 0) return EXIT_SUCCESS; cmd_num = command_parser(ccmd, cmd); if (xflag) { trace(cmd, cmd_num); } /* exit and cd */ if (cmd_num == 1) { command_init(&command); argument_parser(cmd[0], buf, &command); if (strcmp(command.arg[0], "exit") == 0) { if (exit_syntax_check(command.arg) == -1) { exit_usage(); ret_val = EXIT_FAILURE; return ret_val; } else { return ret_val; } } else if (strcmp(command.arg[0], "cd") == 0) { if (cd_syntax_check(command.arg) == -1) { cd_usage(); ret_val = EXIT_FAILURE; return ret_val; } ret_val = cd_exec(command.arg); return ret_val; } } execute_command(cmd, wpid, cmd_num); if (!is_bg) { for (i = 0; i < cmd_num; i++) { if (waitpid(wpid[i], &status, 0) == -1) { if (errno == ECHILD) { errno = 0; continue; } fprintf(stderr, "%d: waitpid() error" ": %s\n", wpid[i], strerror(errno)); return ret_val; } ret_val = check_status(status); } } return ret_val; } for (;;) { LBEGIN: print(); i = 0; while ((n = read(STDIN_FILENO, str, 1)) > 0) { str[1] = '\0'; if (strcmp(str, "\n") == 0) { line[i] = '\0'; break; } if (i >= MAX_LINE_LEN - 1) { fprintf(stderr, "sish: commands too long\n"); ret_val = EXIT_FAILURE; goto LBEGIN; } line[i] = str[0]; i++; } if (n < 0) { fprintf(stderr, "sish: read() error: %s\n", strerror(errno)); ret_val = EXIT_FAILURE; continue; } if ((n = syntax_check(line, &is_bg)) == -1) { fprintf(stderr, "sish: %s: Syntax error\n", line); ret_val = DEFAULT_STATUS; continue; } else if (n == 0) { continue; } cmd_num = command_parser(line, cmd); if (xflag) { trace(cmd, cmd_num); } /* exit and cd */ if (cmd_num == 1) { command_init(&command); argument_parser(cmd[0], buf, &command); if (strcmp(command.arg[0], "exit") == 0) { if (exit_syntax_check(command.arg) == -1) { exit_usage(); ret_val = EXIT_FAILURE; continue; } else { break; } } else if (strcmp(command.arg[0], "cd") == 0) { if (cd_syntax_check(command.arg) == -1) { cd_usage(); ret_val = EXIT_FAILURE; continue; } ret_val = cd_exec(command.arg); continue; } } execute_command(cmd, wpid, cmd_num); if (!is_bg) { for (i = 0; i < cmd_num; i++) { if (waitpid(wpid[i], &status, 0) == -1) { if (errno == ECHILD) { errno = 0; continue; } fprintf(stderr, "%d: waitpid() error" ": %s\n", wpid[i], strerror(errno)); return ret_val; } ret_val = check_status(status); } } } return ret_val; }
/*===========================================================================* * main * *===========================================================================*/ int main(int argc, char **argv) { endpoint_t ep_self, ep_child; size_t size = BUF_SIZE; int i, r, pid; int status; u64_t start, end, diff; double micros; char nr_pages_str[10], is_map_str[2], is_write_str[2]; int nr_pages, is_map, is_write; /* SEF local startup. */ env_setargs(argc, argv); sef_local_startup(); /* Parse the command line. */ r = env_get_param("pages", nr_pages_str, sizeof(nr_pages_str)); errno = 0; nr_pages = atoi(nr_pages_str); if (r != OK || errno || nr_pages <=0) { exit_usage(); } if(nr_pages > TEST_PAGE_NUM) { printf("REQUESTOR: too many pages. Max allowed: %d\n", TEST_PAGE_NUM); exit_usage(); } r = env_get_param("map", is_map_str, sizeof(is_map_str)); errno = 0; is_map = atoi(is_map_str); if (r != OK || errno || (is_map!=0 && is_map!=1)) { exit_usage(); } r = env_get_param("write", is_write_str, sizeof(is_write_str)); errno = 0; is_write = atoi(is_write_str); if (r != OK || errno || (is_write!=0 && is_write!=1)) { exit_usage(); } printf("REQUESTOR: Running tests with pages=%d map=%d write=%d...\n", nr_pages, is_map, is_write); /* Prepare work. */ buf = (char*) CLICK_CEIL(buf_buf); fid_get = open(FIFO_GRANTOR, O_RDONLY); fid_send = open(FIFO_REQUESTOR, O_WRONLY); if(fid_get < 0 || fid_send < 0) { printf("REQUESTOR: can't open fifo files.\n"); return 1; } /* Send the endpoint to the granter, in order to let him to * create the grant. */ ep_self = getprocnr(); write(fid_send, &ep_self, sizeof(ep_self)); dprint("REQUESTOR: sending my endpoint: %d\n", ep_self); /* Get the granter's endpoint and gid. */ read(fid_get, &ep_granter, sizeof(ep_granter)); read(fid_get, &gid, sizeof(gid)); dprint("REQUESTOR: getting granter's endpoint %d and gid %d\n", ep_granter, gid); FIFO_WAIT(fid_get); diff = make64(0, 0); if(is_map) { /* Test safemap. */ for(i=0;i<NR_TEST_ITERATIONS;i++) { read_tsc_64(&start); r = sys_safemap(ep_granter, gid, 0, (long)buf, nr_pages*CLICK_SIZE, D, 1); if(r != OK) { printf("REQUESTOR: safemap error: %d\n", r); return 1; } read_write_buff(buf, nr_pages*CLICK_SIZE, is_write); read_tsc_64(&end); diff = add64(diff, (sub64(end, start))); r = sys_safeunmap(D, (long)buf); if(r != OK) { printf("REQUESTOR: safeunmap error: %d\n", r); return 1; } } micros = ((double)tsc_64_to_micros(diff)) / (NR_TEST_ITERATIONS*nr_pages); REPORT_TEST("REQUESTOR", "SAFEMAP", micros); } else { /* Test safecopy. */ for(i=0;i<NR_TEST_ITERATIONS;i++) { read_tsc_64(&start); r = sys_safecopyfrom(ep_granter, gid, 0, (long)buf, nr_pages*CLICK_SIZE, D); if(r != OK) { printf("REQUESTOR: safecopy error: %d\n", r); return 1; } read_write_buff(buf, nr_pages*CLICK_SIZE, is_write); read_tsc_64(&end); diff = add64(diff, (sub64(end, start))); } micros = ((double)tsc_64_to_micros(diff)) / (NR_TEST_ITERATIONS*nr_pages); REPORT_TEST("REQUESTOR", "SAFECOPY", micros); } FIFO_NOTIFY(fid_send); return 0; }
/** * main */ int main(int argc, char *argv[]) { int opt; const struct arch_def *arch = arch_def_native; int offset = 0; int iter; int sys_num; const char *sys_name; /* parse the command line */ while ((opt = getopt(argc, argv, "a:o:h")) > 0) { switch (opt) { case 'a': arch = arch_def_lookup_name(optarg); if (arch == 0) exit_usage(argv[0]); break; case 'o': offset = atoi(optarg); break; case 'h': default: /* usage information */ exit_usage(argv[0]); } } iter = 0; do { switch (arch->token) { case SCMP_ARCH_X86: sys_name = x86_syscall_iterate_name(iter); break; case SCMP_ARCH_X86_64: sys_name = x86_64_syscall_iterate_name(iter); break; case SCMP_ARCH_X32: sys_name = x32_syscall_iterate_name(iter); break; case SCMP_ARCH_ARM: sys_name = arm_syscall_iterate_name(iter); break; case SCMP_ARCH_MIPS: case SCMP_ARCH_MIPSEL: sys_name = mips_syscall_iterate_name(iter); break; case SCMP_ARCH_MIPS64: case SCMP_ARCH_MIPSEL64: sys_name = mips64_syscall_iterate_name(iter); break; case SCMP_ARCH_MIPS64N32: case SCMP_ARCH_MIPSEL64N32: sys_name = mips64n32_syscall_iterate_name(iter); break; case SCMP_ARCH_AARCH64: sys_name = aarch64_syscall_iterate_name(iter); break; default: /* invalid arch */ exit_usage(argv[0]); } if (sys_name != NULL) { sys_num = arch_syscall_resolve_name(arch, sys_name); if (offset > 0 && sys_num > 0) sys_num -= offset; /* output the results */ printf("%s\t%d\n", sys_name, sys_num); /* next */ iter++; } } while (sys_name != NULL); return 0; }
int main(int argc, char **argv) { int error, i,j; int num_iterations; int seed = 12345; unsigned int lfsr[NUM_HWTS]; unsigned int index[NUM_HWTS]; unsigned int result[NUM_HWTS]; unsigned int *mem; if(argc < 2 || argc > 3) exit_usage(argv[0]); num_iterations = atoi(argv[1]); if(argc == 3) seed = atoi(argv[2]); fprintf(stderr,"Allocating %d pages. Accessing memory %d times.\n", NUM_PAGES, num_iterations); fprintf(stderr,"Using %d hardware threads\n",NUM_HWTS); mem = allocate_memory(NUM_PAGES); for(i = 0; i < NUM_HWTS; i++){ char name[32]; snprintf(name,32,"/mbox0%d",i); setup_mbox(&mbox0[i],&mbox0_attr[i],name); snprintf(name,32,"/mbox1%d",i); setup_mbox(&mbox1[i],&mbox1_attr[i],name); } //setup_mbox(&mbox00,&mbox00_attr,"/mbox00"); //setup_mbox(&mbox01,&mbox01_attr,"/mbox01"); //setup_mbox(&mbox10,&mbox10_attr,"/mbox10"); //setup_mbox(&mbox11,&mbox11_attr,"/mbox11"); //fprintf(stderr,"-- creating hw thread... "); fprintf(stderr,"Creating delegate threads...\n"); for(i = 0; i < NUM_HWTS; i++){ thread_resources[i][0].ptr = &mbox0[i]; thread_resources[i][0].type = PTHREAD_MQD_T; thread_resources[i][1].ptr = &mbox1[i]; thread_resources[i][1].type = PTHREAD_MQD_T; error = posix_hwt_create(i,(void*)pgd, thread_resources[i], 2); if(error){ perror("pthread_create"); exit(2); } } // ------------------------------------------------------------------------------------------ srand(seed); fprintf(stderr,"initializing memory...\n"); for(i = 0; i < NUM_PAGES; i++){ for(j = 0; j < NUM_HWTS; j++){ mem[i*1024 + j] = rand(); } } fprintf(stderr,"flushing cache...\n"); flush_dcache(); fprintf(stderr,"starting threads...\n"); for(i = 0; i < NUM_HWTS; i++){ put_msg(i,num_iterations); } //put_msg(0,0x00001000); for(i = 0; i < NUM_HWTS; i++){ put_msg(i,(unsigned int)(mem + i)); } fprintf(stderr,"running simulation...\n"); for(i = 0; i < NUM_HWTS; i++){ lfsr[i] = index[i] = result[i] = 0; } for(i = 0; i < num_iterations; i++){ for(j = 0; j < NUM_HWTS; j++){ lfsr[j] = lfsr_iterate(lfsr[j] ^ (0x0000FFFF & mem[index[j]*1024 + j])); index[j] = 0x3F & lfsr[j]; } } for(i = 0; i < NUM_HWTS; i++){ result[i] = get_msg(i) & 0x0000FFFF; } fprintf(stderr," "); for(i = 0; i < NUM_HWTS; i++){ fprintf(stderr,"| Thread %d ",i); } fprintf(stderr,"\ntarget "); for(i = 0; i < NUM_HWTS; i++){ fprintf(stderr,"| 0x%08X ",lfsr[i]); } fprintf(stderr,"\nactual "); for(i = 0; i < NUM_HWTS; i++){ fprintf(stderr,"| 0x%08X ",result[i]); } fprintf(stderr,"\n"); for(i = 0; i < NUM_HWTS; i++){ if(lfsr[i] != result[i]) fprintf(stderr,"Test FAILED for thread %d.\n",i); } return 0; }
static void get_options( int argc, char *argv[] ) { int i; char *p, *q; opt.server_addr = DFL_SERVER_ADDR; opt.server_port = DFL_SERVER_PORT; opt.listen_addr = DFL_LISTEN_ADDR; opt.listen_port = DFL_LISTEN_PORT; /* Other members default to 0 */ for( i = 1; i < argc; i++ ) { p = argv[i]; if( ( q = strchr( p, '=' ) ) == NULL ) exit_usage( p, NULL ); *q++ = '\0'; if( strcmp( p, "server_addr" ) == 0 ) opt.server_addr = q; else if( strcmp( p, "server_port" ) == 0 ) opt.server_port = q; else if( strcmp( p, "listen_addr" ) == 0 ) opt.listen_addr = q; else if( strcmp( p, "listen_port" ) == 0 ) opt.listen_port = q; else if( strcmp( p, "duplicate" ) == 0 ) { opt.duplicate = atoi( q ); if( opt.duplicate < 0 || opt.duplicate > 20 ) exit_usage( p, q ); } else if( strcmp( p, "delay" ) == 0 ) { opt.delay = atoi( q ); if( opt.delay < 0 || opt.delay > 20 || opt.delay == 1 ) exit_usage( p, q ); } else if( strcmp( p, "delay_ccs" ) == 0 ) { opt.delay_ccs = atoi( q ); if( opt.delay_ccs < 0 || opt.delay_ccs > 1 ) exit_usage( p, q ); } else if( strcmp( p, "drop" ) == 0 ) { opt.drop = atoi( q ); if( opt.drop < 0 || opt.drop > 20 || opt.drop == 1 ) exit_usage( p, q ); } else if( strcmp( p, "mtu" ) == 0 ) { opt.mtu = atoi( q ); if( opt.mtu < 0 || opt.mtu > MAX_MSG_SIZE ) exit_usage( p, q ); } else if( strcmp( p, "bad_ad" ) == 0 ) { opt.bad_ad = atoi( q ); if( opt.bad_ad < 0 || opt.bad_ad > 1 ) exit_usage( p, q ); } else if( strcmp( p, "protect_hvr" ) == 0 ) { opt.protect_hvr = atoi( q ); if( opt.protect_hvr < 0 || opt.protect_hvr > 1 ) exit_usage( p, q ); } else if( strcmp( p, "protect_len" ) == 0 ) { opt.protect_len = atoi( q ); if( opt.protect_len < 0 ) exit_usage( p, q ); } else if( strcmp( p, "seed" ) == 0 ) { opt.seed = atoi( q ); if( opt.seed == 0 ) exit_usage( p, q ); } else exit_usage( p, NULL ); } }
int main(int argc, char **argv) { const char *host = NULL; char *homedir; char hist_file[1024] = ""; sdb_input_t input = SDB_INPUT_INIT; sdb_llist_t *commands = NULL; while (42) { int opt = getopt(argc, argv, "H:U:c:C:K:A:hV"); if (-1 == opt) break; switch (opt) { case 'H': host = optarg; break; case 'U': input.user = optarg; break; case 'c': { sdb_object_t *obj; if (! commands) commands = sdb_llist_create(); if (! commands) { sdb_log(SDB_LOG_ERR, "Failed to create list object"); exit(1); } if (! (obj = sdb_object_create_T(optarg, sdb_object_t))) { sdb_log(SDB_LOG_ERR, "Failed to create object"); exit(1); } if (sdb_llist_append(commands, obj)) { sdb_log(SDB_LOG_ERR, "Failed to append command to list"); sdb_object_deref(obj); exit(1); } sdb_object_deref(obj); } break; case 'C': ssl_options.cert_file = optarg; break; case 'K': ssl_options.key_file = optarg; break; case 'A': ssl_options.ca_file = optarg; break; case 'h': exit_usage(argv[0], 0); break; case 'V': exit_version(); break; default: exit_usage(argv[0], 1); } } if (optind < argc) exit_usage(argv[0], 1); if (! host) host = DEFAULT_SOCKET; if (! input.user) input.user = sdb_get_current_user(); else input.user = strdup(input.user); if (! input.user) exit(1); if (sdb_ssl_init()) exit(1); input.client = sdb_client_create(host); if (! input.client) { sdb_log(SDB_LOG_ERR, "Failed to create client object"); sdb_input_reset(&input); exit(1); } canonicalize_ssl_options(); if (sdb_client_set_ssl_options(input.client, &ssl_options)) { sdb_log(SDB_LOG_ERR, "Failed to apply SSL options"); sdb_input_reset(&input); sdb_ssl_free_options(&ssl_options); exit(1); } sdb_ssl_free_options(&ssl_options); if (sdb_client_connect(input.client, input.user)) { sdb_log(SDB_LOG_ERR, "Failed to connect to SysDBd"); sdb_input_reset(&input); exit(1); } if (commands) { int status = execute_commands(input.client, commands); sdb_llist_destroy(commands); sdb_input_reset(&input); if ((status != SDB_CONNECTION_OK) && (status != SDB_CONNECTION_DATA)) exit(1); exit(0); } sdb_log(SDB_LOG_INFO, "SysDB client "SDB_CLIENT_VERSION_STRING SDB_CLIENT_VERSION_EXTRA" (libsysdbclient %s%s)", sdb_client_version_string(), sdb_client_version_extra()); sdb_command_print_server_version(&input); printf("\n"); using_history(); if ((homedir = sdb_get_homedir())) { snprintf(hist_file, sizeof(hist_file) - 1, "%s/.sysdb_history", homedir); hist_file[sizeof(hist_file) - 1] = '\0'; free(homedir); homedir = NULL; errno = 0; if (read_history(hist_file) && (errno != ENOENT)) { char errbuf[1024]; sdb_log(SDB_LOG_WARNING, "Failed to load history (%s): %s", hist_file, sdb_strerror(errno, errbuf, sizeof(errbuf))); } } input.input = sdb_strbuf_create(2048); sdb_input_init(&input); sdb_input_mainloop(); sdb_client_shutdown(input.client, SHUT_WR); while (! sdb_client_eof(input.client)) { /* wait for remaining data to arrive */ sdb_command_print_reply(input.client); } if (hist_file[0] != '\0') { errno = 0; if (write_history(hist_file)) { char errbuf[1024]; sdb_log(SDB_LOG_WARNING, "Failed to store history (%s): %s", hist_file, sdb_strerror(errno, errbuf, sizeof(errbuf))); } } sdb_input_reset(&input); sdb_ssl_shutdown(); return 0; } /* main */
int main(int argc, char* argv[]) { if( argc < 2 ) { exit_usage(argv[0]); } int bit_rate = 0, fps = 60, port = 8080, width = 0, height = 0; // Parse command line options for( int i = 1; i < argc-1; i+=2 ) { if( strlen(argv[i]) < 2 || i >= argc-2 || argv[i][0] != '-' ) { exit_usage(argv[0]); } switch( argv[i][1] ) { case 'b': bit_rate = atoi(argv[i+1]) * 1000; break; case 'p': port = atoi(argv[i+1]); break; case 's': sscanf(argv[i+1], "%dx%d", &width, &height); break; case 'f': fps = atoi(argv[i+1]); break; default: exit_usage(argv[0]); } } // Find target window char *window_title = argv[argc-1]; HWND window = NULL; if( strcmp(window_title, "desktop") == 0 ) { window = GetDesktopWindow(); } else if( strcmp(window_title, "cursor") == 0 ) { POINT cursor; GetCursorPos(&cursor); window = WindowFromPoint(cursor); } else { window = window_with_prefix(window_title); } if( !window ) { printf("No window with title starting with \"%s\"\n", window_title); return 0; } // Start the app app_t *app = app_create(window, port, bit_rate, width, height); char real_window_title[56]; GetWindowTextA(window, real_window_title, sizeof(real_window_title)); printf( "Window 0x%08x: \"%s\"\n" "Window size: %dx%d, output size: %dx%d, bit rate: %d kb/s\n\n" "Server started on: http://%s:%d/\n\n", window, real_window_title, app->grabber->width, app->grabber->height, app->encoder->out_width, app->encoder->out_height, app->encoder->context->bit_rate / 1000, server_get_host_address(app->server), app->server->port ); app_run(app, fps); app_destroy(app); return 0; }
int main(int argc,char *argv[]) { dasdfmt_info_t info; volume_label_t vlabel; char old_volser[7]; char dev_filename[PATH_MAX]; char str[ERR_LENGTH]; char buf[7]; char *blksize_param_str = NULL; char *reqsize_param_str = NULL; char *hashstep_str = NULL; int rc, index; /* Establish a handler for interrupt signals. */ signal (SIGTERM, program_interrupt_signal); signal (SIGINT, program_interrupt_signal); signal (SIGQUIT, program_interrupt_signal); /******************* initialization ********************/ prog_name = argv[0]; /* set default values */ init_info(&info); vtoc_volume_label_init(&vlabel); format_params.blksize = DEFAULT_BLOCKSIZE; format_params.intensity = DASD_FMT_INT_COMPAT; /*************** parse parameters **********************/ while (1) { rc=getopt_long(argc, argv, dasdfmt_getopt_string, dasdfmt_getopt_long_options, &index); switch (rc) { case 'F': info.force=1; break; case 'C': format_params.intensity |= DASD_FMT_INT_COMPAT; break; case 'd' : if (strncmp(optarg,"cdl",3)==0) { format_params.intensity |= DASD_FMT_INT_COMPAT; if (info.writenolabel) { printf("WARNING: using the cdl " \ "format without writing a " \ "label doesn't make much " \ "sense!\n"); exit(1); } } else if (strncmp(optarg,"ldl",3)==0) format_params.intensity &= ~DASD_FMT_INT_COMPAT; else { printf("%s is not a valid option!\n", optarg); exit(1); } break; case 'y': info.withoutprompt=1; break; case 'z': format_params.intensity |= DASD_FMT_INT_FMT_NOR0; break; case 't': info.testmode=1; break; case 'p': if (!(info.print_hashmarks || info.print_percentage)) info.print_progressbar = 1; break; case 'm': if (!(info.print_progressbar || info.print_percentage)) { hashstep_str=optarg; info.print_hashmarks=1; } break; case 'P': if (!(info.print_hashmarks || info.print_progressbar)) info.print_percentage = 1; break; case 'v': info.verbosity=1; break; case 'h': exit_usage(0); case 'V': print_version(); exit(0); case 'l': strncpy(buf, optarg, 6); if (check_volser(buf, 0) < 0) break; vtoc_volume_label_set_volser(&vlabel,buf); info.labelspec=1; break; case 'L': if (format_params.intensity & DASD_FMT_INT_COMPAT) { printf("WARNING: using the cdl format " \ "without writing a label doesn't " \ "make much sense!\n"); exit(1); } info.writenolabel=1; break; case 'b' : blksize_param_str=optarg; info.blksize_specified=1; break; case 'r': reqsize_param_str = optarg; info.reqsize_specified = 1; break; case 'f' : strncpy(dev_filename, optarg, PATH_MAX); info.node_specified=1; break; case 'k' : info.keep_volser=1; break; case -1: /* End of options string - start of devices list */ info.device_id = optind; break; default: ERRMSG_EXIT(EXIT_MISUSE, "Try '%s --help' for more" " information.\n",prog_name); } if (rc==-1) break; // exit loop if finished } CHECK_SPEC_MAX_ONCE(info.blksize_specified, "blocksize"); CHECK_SPEC_MAX_ONCE(info.labelspec, "label"); CHECK_SPEC_MAX_ONCE(info.writenolabel, "omit-label-writing flag"); if (info.blksize_specified) PARSE_PARAM_INTO(format_params.blksize,blksize_param_str,10, "blocksize"); if (info.reqsize_specified) { PARSE_PARAM_INTO(reqsize, reqsize_param_str, 10, "requestsize"); if (reqsize < 1 || reqsize > 255) ERRMSG_EXIT(EXIT_FAILURE, "invalid requestsize %d specified\n", reqsize); } else reqsize = DEFAULT_REQUESTSIZE; if (info.print_hashmarks) PARSE_PARAM_INTO(info.hashstep, hashstep_str,10,"hashstep"); get_device_name(&info, dev_filename, argc, argv); if (!info.blksize_specified) format_params = ask_user_for_blksize(format_params); if (info.keep_volser) { if(info.labelspec) { ERRMSG_EXIT(EXIT_MISUSE,"%s: The -k and -l options are mutually exclusive\n", prog_name); } if(!(format_params.intensity & DASD_FMT_INT_COMPAT)) { printf("WARNING: VOLSER cannot be kept " \ "when using the ldl format!\n"); exit(1); } if(dasdfmt_get_volser(info.devname, old_volser) == 0) vtoc_volume_label_set_volser(&vlabel, old_volser); else ERRMSG_EXIT(EXIT_FAILURE,"%s: VOLSER not found on device %s\n", prog_name, info.devname); } if ((filedes = open(info.devname, O_RDWR)) == -1) ERRMSG_EXIT(EXIT_FAILURE,"%s: Unable to open device %s: %s\n", prog_name, info.devname, strerror(errno)); check_disk(&info); if (check_param(str, ERR_LENGTH, &format_params) < 0) ERRMSG_EXIT(EXIT_MISUSE, "%s: %s\n", prog_name, str); do_format_dasd(&info, &format_params, &vlabel); if (close(filedes) != 0) ERRMSG("%s: error during close: %s\ncontinuing...\n", prog_name, strerror(errno)); return 0; }