int main(int argc, char const *argv[]) { struct version v = {.major = 3, .minor = 5, .flags = 0}; printf("empreinte mémoire de la structure version = %d\n", (int)sizeof(struct version)); display_version(&v, &isUnstableBis); printf("\n"); v.minor++; display_version(&v, &isUnstableBis); printf("\n"); v.major++; v.minor = 0; display_version(&v, &isUnstableBis); printf("\n"); v.minor++; display_version(&v, &isUnstableBis); printf("\n"); return 0; }
static void check_options(int argc, char *argv[]) { char opt; int index; static struct option options[]={ {"help", 0, NULL, 'h'}, {"version", 0, NULL, 'V'} }; opterr = 0; while((opt = getopt_long(argc, argv, "hV", options, &index)) != -1) { switch(opt) { case 'V': display_version(); exit(1); break; case 'h': display_usage(); exit(1); break; default: die("Unknown option: %s\nUse --help to show valid options.\n", argv[optind - 1]); break; } } }
int main(int argc, char *argv[]) { struct option longopts[] = { { "version", no_argument, NULL, 'v' }, { "help", no_argument, NULL, 'h' }, { 0, 0, 0, 0 } }; int c = 0; /* Parse command-line options */ while ((c = getopt_long(argc, argv, "vh", longopts, NULL)) > -1) { switch (c) { case 'h': display_usage(stdout); return EXIT_SUCCESS; case 'v': display_version(); return EXIT_SUCCESS; default: /* Unknown option */ display_usage(stderr); return EXIT_FAILURE; } } /* Start the wm */ if (leaf_init() != ERR_NONE) return leaf_exit(EXIT_FAILURE); if (leaf_run() != ERR_NONE) return leaf_exit(EXIT_FAILURE); return leaf_exit(EXIT_SUCCESS); }
/*-------------------------------------------------------------------*/ int syntax (char *pgm) { char usage[8192]; char buflfs[64]; #ifdef CCKD_COMPRESS_ZLIB char *bufz = " -z compress using zlib [default]\n"; #else char *bufz = ""; #endif #ifdef CCKD_COMPRESS_BZIP2 char *bufbz = " -bz2 compress using bzip2\n"; #else char *bufbz = ""; #endif strncpy( buflfs, (sizeof(off_t) > 4) ? " -lfs create single large output file\n" : "", sizeof( buflfs)); MSGBUF( usage, MSG_C( HHC02499, "I", pgm, "DASD copy/convert" ) ); display_version (stderr, usage+10, FALSE); if (strcasecmp(pgm, "ckd2cckd") == 0) MSGBUF( usage ,MSG( HHC02435, "I", bufz, bufbz ) ); else if (strcasecmp(pgm, "cckd2ckd") == 0) MSGBUF( usage ,MSG( HHC02436, "I", buflfs ) ); else if (strcasecmp(pgm, "fba2cfba") == 0) MSGBUF( usage ,MSG( HHC02437, "I", bufz, bufbz ) ); else if (strcasecmp(pgm, "cfba2fba") == 0) MSGBUF( usage ,MSG( HHC02438, "I", buflfs ) ); else MSGBUF( usage ,MSG( HHC02439, "I", pgm, bufz, bufbz, buflfs ) ); printf ("%s", usage); return -1; } /* end function syntax */
int main(int argc, char **argv) { int rc = 0; char *fn, *sfn; INITIALIZE_UTILITY("dasdls"); /* Display program info message */ display_version (stderr, "Hercules DASD list program ", FALSE); if (argc < 2) { fprintf(stderr, "Usage: dasdls dasd_image [sf=shadow-file-name]...\n"); exit(2); } /* * If your version of Hercules doesn't have support in its * dasdutil.c for turning off verbose messages, then remove * the following line but you'll have to live with chatty * progress output on stdout. */ set_verbose_util(0); while (*++argv) { fn = *argv; if (*(argv+1) && strlen (*(argv+1)) > 3 && !memcmp(*(argv+1), "sf=", 3)) sfn = *++argv; else sfn = NULL; if (do_ls(fn, sfn)) rc = 1; } return rc; }
int main(int argc, char **argv) { struct state state; memset(&state, 0, sizeof(struct state)); if (rc_read_options(&state, argc, argv) < 0) return EXIT_FAILURE; switch (state.rc.action) { case ACTION_NONE: /* this should never happen... */ assert(0); break; case ACTION_USAGE: display_usage(); break; case ACTION_VERSION: display_version(); break; case ACTION_ANALYZE: case ACTION_RANK: case ACTION_PREDICT: db_load(&state); break; } return EXIT_SUCCESS; }
int main(int argc, char *argv[]) { char *exec_name = argv[0]; int option, option_index; static struct option long_options[] = { {"help",0,0,'h'}, {"version",0,0,'v'}, {0,0,0,0} }; while ((option = getopt_long(argc, argv, "hv", long_options, &option_index)) != -1) { switch(option) { case 'h': display_usage(exec_name); exit(EXIT_SUCCESS); case 'v': display_version(); exit(EXIT_SUCCESS); default: display_usage(exec_name); exit(EXIT_FAILURE); } } begin(); return EXIT_SUCCESS; }
static void process_command_line_args (int argc, char *const *argv) { int ch = -1; while (-1 != (ch = getopt (argc, argv, "rf:vVh"))) { switch (ch) { case 'r': /* FIXME: implement read-only option */ break; case 'f': set_contacts_file (); break; case 'v': display_version (); exit (0); break; case 'V': display_license (); exit (0); break; case 'h': case '?': default: display_usage (argv[0]); exit (0); } } }
void process_options (int argc, char *argv[]) { int error = 0; exe_name = argv[0]; for (;;) { int option_index = 0; static const char *short_options = "jq"; static const struct option long_options[] = { {"help", no_argument, 0, 0}, {"version", no_argument, 0, 0}, {"jffs2", no_argument, 0, 'j'}, {"quiet", no_argument, 0, 'q'}, {"silent", no_argument, 0, 'q'}, {0, 0, 0, 0}, }; int c = getopt_long(argc, argv, short_options, long_options, &option_index); if (c == EOF) { break; } switch (c) { case 0: switch (option_index) { case 0: display_help(); break; case 1: display_version(); break; } break; case 'q': quiet = 1; break; case 'j': jffs2 = 1; break; case '?': error = 1; break; } } if (optind == argc) { fprintf(stderr, "%s: no MTD device specified\n", exe_name); error = 1; } if (error) { fprintf(stderr, "Try `%s --help' for more information.\n", exe_name); exit(1); } mtd_device = argv[optind]; }
int main(int argc, char *argv[]) { int log_errno=0; time_t my_time; FILE *log_handle; int i; for(i=1; i<argc; i++) { if(strcmp(argv[i],"/help")==0 || strcmp(argv[i],"-help")==0 || strcmp(argv[i],"--help")==0 || strcmp(argv[i],"/h")==0 || strcmp(argv[i],"-h")==0 || strcmp(argv[i],"/?")==0 || strcmp(argv[i],"-?")==0) { display_help(); return 0; } else if((strcmp(argv[i],"/version")==0) || (strcmp(argv[i],"-version")==0) || (strcmp(argv[i],"--version")==0) || (strcmp(argv[i],"/v")==0) || (strcmp(argv[i],"-v")==0)) { display_version(); return 0; } } #ifdef Q_WS_X11 if(getenv("DISPLAY")==NULL) { printf("DISPLAY variable not set. Switching to PhotoRec in text mode.\n"); if(execv("photorec", argv)<0) { printf("photorec failed: %s\n", strerror(errno)); } } #endif QApplication a(argc, argv); log_handle=log_open("qphotorec.log", TD_LOG_CREATE, &log_errno); #ifdef HAVE_DUP2 if(log_handle) { dup2(fileno(log_handle),2); } #endif my_time=time(NULL); log_info("\n\n%s",ctime(&my_time)); log_info("PhotoRec %s, Data Recovery Utility, %s\nChristophe GRENIER <*****@*****.**>\nhttp://www.cgsecurity.org\n", VERSION, TESTDISKDATE); log_info("OS: %s\n" , get_os()); log_info("Compiler: %s\n", get_compiler()); #ifdef RECORD_COMPILATION_DATE log_info("Compilation date: %s\n", get_compilation_date()); #endif log_info("ext2fs lib: %s, ntfs lib: %s, ewf lib: %s, libjpeg: %s\n", td_ext2fs_version(), td_ntfs_version(), td_ewf_version(), td_jpeg_version()); QPhotorec *p = new QPhotorec(); p->showMaximized(); p->show(); int ret=a.exec(); delete p; log_close(); return ret; }
static void display_help( void ) { display_version(); eprintf( "\n" "Usage: boxdumper [option] input\n" " options:\n" " --help Display help\n" " --version Display version information\n" " --box Dump box structure\n" " --chapter Extract chapter list\n" " --timestamp Dump media timestamps\n" ); }
int configure(int argc, char **argv){ parse_cmdline(argc, argv); if(conf.help){ display_help(); return 1; } if(conf.version) display_version(); if(strcmp(conf.confile, "")!=0 && load_conf(conf.confile)) return 1; if(conf.config) show_config(); }
void process_options(int argc, char *argv[]) { int error = 0; input_file = NULL; output_file = NULL; for (;;) { int option_index = 0; static const char *short_options = "i:o:"; static const struct option long_options[] = { {"help", no_argument, 0, 0}, {"version", no_argument, 0, 0}, {"input", required_argument, 0, 'i'}, {"output", required_argument, 0, 'o'}, {0, 0, 0, 0}, }; int c = getopt_long(argc, argv, short_options, long_options, &option_index); if (c == EOF) break; switch (c) { case 0: switch (option_index) { case 0: display_help(); break; case 1: display_version(); break; } break; case 'i': input_file = optarg; break; case 'o': output_file = optarg; break; case '?': error = 1; break; } } if (input_file == NULL || output_file == NULL || error) display_help(); }
void process_options(int argc, char *argv[], struct rfd *rfd) { int error = 0; rfd->block_size = 0; rfd->verbose = 0; for (;;) { int option_index = 0; static const char *short_options = "hvVb:"; static const struct option long_options[] = { { "help", no_argument, 0, 'h' }, { "version", no_argument, 0, 'V', }, { "blocksize", required_argument, 0, 'b' }, { "verbose", no_argument, 0, 'v' }, { NULL, 0, 0, 0 } }; int c = getopt_long(argc, argv, short_options, long_options, &option_index); if (c == EOF) break; switch (c) { case 'h': display_help(); break; case 'V': display_version(); break; case 'v': rfd->verbose = 1; break; case 'b': rfd->block_size = atoi(optarg); break; case '?': error = 1; break; } } if ((argc - optind) != 2 || error) display_help(); rfd->mtd_filename = argv[optind]; rfd->out_filename = argv[optind + 1]; }
/** * parses command line arguments and assigns values to run time * variables. relies on GNU getopts included with this distribution. */ void parse_cmdline(CONF C, int argc, char *argv[]) { int c = 0; BOOLEAN display = FALSE; while ((c = getopt_long(argc, argv, "Vhvf:CDd:l:p:", long_options, (int *)0)) != EOF) { switch (c) { case 'V': display_version(TRUE); break; case 'h': display_help(EXIT_SUCCESS); case 'v': set_verbose(C, TRUE); break; case 'C': display = TRUE; break; //case 'f': //XXX: parsed separately // set_cfgfile(C, optarg); // break; case 'D': set_debug(C, TRUE); break; case 'd': if (!optarg) { puts("NO OPTARG"); } if (optarg != NULL && !strncasecmp(optarg, "false", 5)) { set_daemon(C, FALSE); } else { set_daemon(C, TRUE); } break; case 'l': set_logfile(C, optarg); break; case 'p': set_pidfile(C, optarg); break; } /* end of switch */ } /* end of while */ if (display) { show(C, TRUE); } return; } /* end of parse_cmdline */
int main(int argc, char **argv) { SDL_Thread *server_thread; printf("Welcome to the Zod Engine\n"); if(argc<=1) starting_conditions.setdefaults(); //read in the arguments starting_conditions.getoptions(argc, argv); //make sure there is nothing conflicting, //like we are trying to make a dedicated server that is supposed to connect to another server starting_conditions.checkoptions(); //init this for the bots ZCore::CreateRandomBotBypassData(bot_bypass_data, bot_bypass_size); //now see what we have if(starting_conditions.read_display_version) display_version(); if(starting_conditions.read_display_help) display_help(argv[0]); //now what do we really run? else if(starting_conditions.read_run_tray) { run_tray_app(); } else if(starting_conditions.read_is_dedicated) { //run only a server //server_thread = SDL_CreateThread(run_server_thread, NULL); run_server_thread(NULL); } else if(starting_conditions.read_connect_address) { //connect to a server run_player_thread(); } else { //run a server, then connect to it server_thread = SDL_CreateThread(run_server_thread, NULL); run_player_thread(); } return 1; }
/** * parses command line arguments and assigns * values to run time variables. relies on GNU * getopts included with this distribution. */ void parse_cmdline( int argc, char *argv[] ) { int c = 0; int nhosts; while(( c = getopt_long( argc, argv, "VhvCDH:i", long_options, (int *)0)) != EOF ){ switch( c ){ case 'V': display_version( TRUE ); break; case 'h': display_help(); exit( EXIT_SUCCESS ); case 'v': my.verbose = TRUE; break; case 'C': my.config = TRUE; break; case 'D': my.debug = TRUE; break; case 'i': my.images = TRUE; break; case 'H': { int ll; if(!strchr(optarg,':')) joe_fatal("no ':' in http-header"); if((strlen(optarg) + strlen(my.extra) + 3) > 512) joe_fatal("too many headers"); strcat(my.extra,optarg); strcat(my.extra,"\015\012"); } break; } /** end of switch( c ) **/ } /** end of while c = getopt_long **/ nhosts = argc - optind; if( my.config ){ show_config( TRUE ); } if( !nhosts ) { display_help( TRUE ); } else{ my.url = strdup( argv[argc-1] ); } } /* end of parse_cmdline */
/** * display_help * displays the help section to STDOUT and exits */ void display_help() { /** * call display_version, but do not exit */ display_version(FALSE); printf("Usage: %s [options]\n", program_name); printf(" %s [options] URL\n", program_name); printf(" %s -g URL\n", program_name); printf("Options:\n" ); puts(" -V, --version VERSION, prints the version number."); puts(" -h, --help HELP, prints this section."); puts(" -C, --config CONFIGURATION, show the current config."); puts(" -v, --verbose VERBOSE, prints notification to screen."); puts(" -q, --quiet QUIET turns verbose off and suppresses output."); puts(" -g, --get GET, pull down HTTP headers and display the"); puts(" transaction. Great for application debugging."); puts(" -c, --concurrent=NUM CONCURRENT users, default is 10"); puts(" -i, --internet INTERNET user simulation, hits URLs randomly." ); puts(" -b, --benchmark BENCHMARK: no delays between requests." ); puts(" -t, --time=NUMm TIMED testing where \"m\" is modifier S, M, or H" ); puts(" ex: --time=1H, one hour test." ); puts(" -r, --reps=NUM REPS, number of times to run the test." ); puts(" -f, --file=FILE FILE, select a specific URLS FILE." ); printf(" -R, --rc=FILE RC, specify an %src file\n",program_name); puts(" -l, --log[=FILE] LOG to FILE. If FILE is not specified, the"); printf(" default is used: PREFIX/var/%s.log\n", program_name); puts(" -m, --mark=\"text\" MARK, mark the log file with a string." ); puts(" -d, --delay=NUM Time DELAY, random delay before each requst"); puts(" between 1 and NUM. (NOT COUNTED IN STATS)"); puts(" -H, --header=\"text\" Add a header to request (can be many)" ); puts(" -A, --user-agent=\"text\" Sets User-Agent in request" ); puts(" -T, --content-type=\"text\" Sets Content-Type in request" ); puts(""); puts(copyright); /** * our work is done, exit nicely */ exit( EXIT_SUCCESS ); }
/** * \brief Parse command-line arguments * \details Parses the CLI arguments passed to the program and sets the * pertinent values. * * \param argv A pointer to the first argument */ static void parse_args(char **argv) { argument_t argument = ARGUMENT_NONE; while (*++argv) { if (argument == ARGUMENT_NONE) { /* Parse argument names */ if (!strcmp(*argv, "-c") || !strcmp(*argv, "--count")) { // UUID count (-c, --count) argument = ARGUMENT_COUNT; } else if (!strcmp(*argv, "-b") || !strcmp(*argv, "--brackets")) { // Enclose the UUID between curly brackets (-b, --brackets) g_brackets = 1; } else if (!strcmp(*argv, "-u") || !strcmp(*argv, "--uppercase")) { // UUID should be uppercase (-u, --uppercase) g_uppercase = 1; } else if (!strcmp(*argv, "-h") || !strcmp(*argv, "--help")) { // Show help and exit display_help(); exit(0); } else if (!strcmp(*argv, "-v") || !strcmp(*argv, "--version")) { // Show versioning information display_version(); exit(0); } else { fprintf(stderr, "%s: error: unrecognized command line argument: `%s'\n", PROGRAM_NAME, *argv); exit(1); } } else if (argument == ARGUMENT_COUNT) { unsigned long count = strtoul(*argv, NULL, 10); // Check for any possible overflow if (count > 0 && count <= UINT_MAX) { g_uuid_count = (unsigned)count; argument = ARGUMENT_NONE; } else { fprintf(stderr, "%s: error: invalid count supplied. It must be greater than 0 and less than %u\n", PROGRAM_NAME, UINT_MAX + 1); exit(1); } } } }
/** * display help section to STDOUT and exit */ void display_help(int status) { display_version(FALSE); printf("Usage: %s [options]\n", program_name); printf("Options:\n" ); puts(" -V, --version VERSION, prints version number to screen."); puts(" -h, --help HELP, prints this section."); puts(" -v, --verbose VERBOSE, prints notification to screen."); printf( " -f, --file=/path/file FILE, an alternative config file (default: /etc/%s/%s.conf)\n", program_name, program_name ); puts(" -C, --config CONFIG, displays the default settings and exits"); puts(" -d, --daemon=[true|false] DAEMON, run in the background as a daemon (-d <no arg> means true)"); puts(" -l, --log=arg LOG, set the default log which can be overridden at the file level."); puts(" You can include a path to a file or 'syslog' to use system logging"); puts(" -p, --pid=/path/file PID, set an alternative path to a process ID file."); printf(" The default pid is: /var/run/%s.pid\n", program_name); exit(status); }
/** * display_help * displays the help section to STDOUT and exits */ void display_help() { /** * call display_version, but do not exit */ display_version( FALSE ); printf("Usage: scout [options] host.domain.com\n"); printf("Options:\n" ); puts(" -V, --version VERSION, prints version number to screen."); puts(" -h, --help HELP, prints this section."); puts(" -C, --config CONFIGURATION, show the current configuration."); puts(" -v, --verbose VERBOSE, prints notification to screen."); puts(" -f, --file=FILE FILE, change the configuration file to file." ); puts(" -H, --header=\"text\" Add a header to request (can be many)" ); puts(" -i, --images IMAGES, parse server for images."); /** * our work is done, exit nicely */ exit( EXIT_SUCCESS ); }
/** * display_help * displays the help section to STDOUT and exits */ void display_help() { /** * call display_version, but do not exit */ display_version(FALSE); printf("Usage: %s [options]\n", program_name); printf(" %s [options] URL\n", program_name); printf(" %s -g URL\n", program_name); printf("Options:\n" ); puts(" -V, --version VERSION, prints version number to screen."); puts(" -h, --help HELP, prints this section."); puts(" -C, --config CONFIGURATION, show the current configuration."); puts(" -v, --verbose VERBOSE, prints notification to screen."); puts(" -g, --get GET, pull down headers from the server and display HTTP"); puts(" transaction. Great for web application debugging."); puts(" -c, --concurrent=NUM CONCURRENT users, default is 10"); puts(" -u, --url=\"URL\" Deprecated. Set URL as the last argument." ); puts(" -i, --internet INTERNET user simulation, hits the URLs randomly." ); puts(" -b, --benchmark BENCHMARK, signifies no delay for time testing." ); puts(" -t, --time=NUMm TIME based testing where \"m\" is the modifier S, M, or H" ); puts(" no space between NUM and \"m\", ex: --time=1H, one hour test." ); puts(" -r, --reps=NUM REPS, number of times to run the test, default is 25" ); puts(" -f, --file=FILE FILE, change the configuration file to file." ); printf(" -R, --rc=FILE RC, change the %src file to file. Overrides\n",program_name); puts(" the SIEGERC environmental variable."); printf(" -l, --log LOG, logs the transaction to PREFIX/var/%s.log\n", program_name); puts(" -m, --mark=\"text\" MARK, mark the log file with a string separator." ); puts(" -d, --delay=NUM Time DELAY, random delay between 1 and num designed" ); puts(" to simulate human activity. Default value is 3" ); puts(" -H, --header=\"text\" Add a header to request (can be many)" ); puts(" -A, --user-agent=\"text\" Sets User-Agent in request" ); puts(" -E, --extra=FILE EXTRA, writes notification to the specified file"); /** * our work is done, exit nicely */ exit( EXIT_SUCCESS ); }
/* parse command line options and save settings in struct */ static void parse_cmdline(int argc, char *argv[]) { int optc; while ((optc = getopt_long(argc, argv, NSLCD_OPTIONSTRING, nslcd_options, NULL)) != -1) { switch (optc) { case 'c': /* -c, --check check if the daemon already is running */ nslcd_checkonly = 1; break; case 'd': /* -d, --debug don't fork and print debugging to stderr */ nslcd_debugging++; log_setdefaultloglevel(LOG_DEBUG); break; case 'n': /* -n, --nofork don't fork */ nslcd_nofork++; break; case 'h': /* --help display this help and exit */ display_usage(stdout, argv[0]); exit(EXIT_SUCCESS); case 'V': /* --version output version information and exit */ display_version(stdout); exit(EXIT_SUCCESS); case ':': /* missing required parameter */ case '?': /* unknown option character or extraneous parameter */ default: fprintf(stderr, "Try '%s --help' for more information.\n", argv[0]); exit(EXIT_FAILURE); } } /* check for remaining arguments */ if (optind < argc) { fprintf(stderr, "%s: unrecognized option '%s'\n", argv[0], argv[optind]); fprintf(stderr, "Try '%s --help' for more information.\n", argv[0]); exit(EXIT_FAILURE); } }
void display_help(){ printf("OVERVIEW: a website stress/load test tool\n"); display_version(); printf("USAGE: %s [options]\n", PROGRAMNAME); printf("OPTIONS:\n"); printf(" -V, --version print the version.\n"); printf(" -v, --verbose print notification on screen\n"); printf(" -C, --config print the current config\n"); printf(" -a, --agent=anum concurrent users, default 10\n"); printf(" -t, --time=tnum test tnum seconds, default 10\n"); printf(" -i, --interval=inum interval between requests in [0, inum] seconds, default 0\n"); printf(" -o, --timeout=onum connection timeout, default -1(system timeout)\n"); printf(" -u, --url=url url to be tested, default www.example.com\n"); printf(" -p, --port=port server port, default 80\n"); printf(" -m, --method=method request method, default 0(GET)\n"); printf(" -s, --sysinfo=snum interval for system inforamtion, default 100ms\n"); printf(" -I, --inputfile=input get configuration from input\n"); printf(" -D, --datadir=dir store data in the dirctor dir\n"); printf(" -O, --outputfile=out write data to output\n"); printf(" -H, --html save the received html\n"); printf(" -l, --log[=filename] log to file, default location is in dir result\n"); printf(" -h, --help print help instruction.\n"); }
void process_calling_arguments (int argc, char *argv[]) { progname = argv[0]; parse_options (argc, argv); /* first parse all. Crashing on errors */ /* After we have parsed the optional arguments, we set the right flags accordingly. This is the place where we do sanity checks *before* launching the actual computations. */ if (display_version_opt) display_version (stdout); if (display_help_opt) display_help (stdout); if (display_help_opt || display_version_opt) { exit (EXIT_SUCCESS); /* exits on -h and -l */ } if (graphical_opt) { if (underground_opt) { cantcontinue("Graphical -g and underground -u modes incompatible.\n"); } else { cursing_mode = true; terminal_mode = false; } } if (underground_opt) { if (with_data_file) { underground_mode = true; terminal_mode = false; } else { cantcontinue("Underground -u mode requires data_file mode.\n"); } if (strcmp(machine_uname(), SERVER_UNAME) == 0) { if (strncmp(cwd(), REQUIRED_DIR_ON_SERVER, sizeof(REQUIRED_DIR_ON_SERVER) - 1) != 0) { cantcontinue("Underground -u mode on machine %s required being in dir %s.\n", SERVER_UNAME, REQUIRED_DIR_ON_SERVER); } } } }
void process_options(int argc, char *argv[], const char **mtd_filename) { int error = 0; for (;;) { int option_index = 0; static const char *short_options = "hV"; static const struct option long_options[] = { { "help", no_argument, 0, 'h' }, { "version", no_argument, 0, 'V', }, { NULL, 0, 0, 0 } }; int c = getopt_long(argc, argv, short_options, long_options, &option_index); if (c == EOF) break; switch (c) { case 'h': display_help(); break; case 'V': display_version(); break; case '?': error = 1; break; } } if ((argc - optind) != 1 || error) display_help(); *mtd_filename = argv[optind]; }
int main(int argc, char *argv[]) { int x; int result; DATA D = new_data(); ARRAY urls = new_array(); CREW crew; LINES *lines; CLIENT *client; pthread_t cease; pthread_t timer; pthread_attr_t scope_attr; void *statusp; sigset_t sigs; sigemptyset(&sigs); sigaddset(&sigs, SIGHUP); sigaddset(&sigs, SIGINT); sigaddset(&sigs, SIGALRM); sigaddset(&sigs, SIGTERM); sigprocmask(SIG_BLOCK, &sigs, NULL); lines = xcalloc(1, sizeof *lines); lines->index = 0; lines->line = NULL; memset(&my, 0, sizeof(struct CONFIG)); parse_rc_cmdline(argc, argv); if (init_config() < 0) { /* defined in init.h */ exit( EXIT_FAILURE ); /* polly was a girl... */ } parse_cmdline(argc, argv); /* defined above */ ds_module_check(); /* check config integ */ /** * XXX: we should consider moving the following * if-checks into the ds_module_check */ if (my.config) { show_config(TRUE); } if (my.url != NULL) { my.length = 1; } else { my.length = read_cfg_file(lines, my.file); } if (my.reps < 0) { my.reps = my.length; } if (my.length == 0) { display_help(); } /* cookie is an EXTERN, defined in setup */ cookie = xcalloc(sizeof(COOKIE), 1); cookie->first = NULL; if ((result = pthread_mutex_init( &(cookie->mutex), NULL)) !=0) { NOTIFY(FATAL, "pthread_mutex_init" ); } /* memory allocation for threads and clients */ client = xcalloc(my.cusers, sizeof(CLIENT)); if ((crew = new_crew(my.cusers, my.cusers, FALSE)) == NULL) { NOTIFY(FATAL, "unable to allocate memory for %d simulated browser", my.cusers); } /** * determine the source of the url(s), * command line or file, and add them * to the urls struct. */ if (my.url != NULL) { URL tmp = new_url(my.url); url_set_ID(tmp, 0); if (my.get && url_get_method(tmp) != POST && url_get_method(tmp) != PUT) { url_set_method(tmp, my.method); } array_npush(urls, tmp, URLSIZE); // from cmd line } else { for (x = 0; x < my.length; x++) { URL tmp = new_url(lines->line[x]); url_set_ID(tmp, x); array_npush(urls, tmp, URLSIZE); } } /** * display information about the siege * to the user and prepare for verbose * output if necessary. */ if (!my.get && !my.quiet) { fprintf(stderr, "** "); display_version(FALSE); fprintf(stderr, "** Preparing %d concurrent users for battle.\n", my.cusers); fprintf(stderr, "The server is now under siege..."); if (my.verbose) { fprintf(stderr, "\n"); } } /** * record start time before spawning threads * as the threads begin hitting the server as * soon as they are created. */ data_set_start(D); /** * for each concurrent user, spawn a thread and * loop until condition or pthread_cancel from the * handler thread. */ pthread_attr_init(&scope_attr); pthread_attr_setscope(&scope_attr, PTHREAD_SCOPE_SYSTEM); #if defined(_AIX) /* AIX, for whatever reason, defies the pthreads standard and * * creates threads detached by default. (see pthread.h on AIX) */ pthread_attr_setdetachstate(&scope_attr, PTHREAD_CREATE_JOINABLE); #endif /** * invoke OpenSSL's thread safety */ #ifdef HAVE_SSL SSL_thread_setup(); #endif /** * create the signal handler and timer; the * signal handler thread (cease) responds to * ctrl-C (sigterm) and the timer thread sends * sigterm to cease on time out. */ if ((result = pthread_create(&cease, NULL, (void*)sig_handler, (void*)crew)) < 0) { NOTIFY(FATAL, "failed to create handler: %d\n", result); } if (my.secs > 0) { if ((result = pthread_create(&timer, NULL, (void*)siege_timer, (void*)cease)) < 0) { NOTIFY(FATAL, "failed to create handler: %d\n", result); } } /** * loop until my.cusers and create a corresponding thread... */ for (x = 0; x < my.cusers && crew_get_shutdown(crew) != TRUE; x++) { client[x].id = x; client[x].bytes = 0; client[x].time = 0.0; client[x].hits = 0; client[x].code = 0; client[x].ok200 = 0; client[x].fail = 0; client[x].urls = urls; client[x].auth.www = 0; client[x].auth.proxy = 0; client[x].auth.type.www = BASIC; client[x].auth.type.proxy = BASIC; client[x].rand_r_SEED = urandom(); result = crew_add(crew, (void*)start_routine, &(client[x])); if (result == FALSE) { my.verbose = FALSE; fprintf(stderr, "Unable to spawn additional threads; you may need to\n"); fprintf(stderr, "upgrade your libraries or tune your system in order\n"); fprintf(stderr, "to exceed %d users.\n", my.cusers); NOTIFY(FATAL, "system resources exhausted"); } } /* end of for pthread_create */ crew_join(crew, TRUE, &statusp); #ifdef HAVE_SSL SSL_thread_cleanup(); #endif /** * collect all the data from all the threads that * were spawned by the run. */ for (x = 0; x < ((crew_get_total(crew) > my.cusers || crew_get_total(crew)==0 ) ? my.cusers : crew_get_total(crew)); x++) { data_increment_count(D, client[x].hits); data_increment_bytes(D, client[x].bytes); data_increment_total(D, client[x].time); data_increment_code (D, client[x].code); data_increment_ok200(D, client[x].ok200); data_increment_fail (D, client[x].fail); data_set_highest (D, client[x].himark); data_set_lowest (D, client[x].lomark); client[x].rand_r_SEED = urandom(); } /* end of stats accumulation */ /** * record stop time */ data_set_stop(D); /** * cleanup crew */ crew_destroy(crew); for (x = 0; x < my.cusers; x++) { // XXX: TODO //digest_challenge_destroy(client[x].auth.wwwchlg); //digest_credential_destroy(client[x].auth.wwwcred); //digest_challenge_destroy(client[x].auth.proxychlg); //digest_credential_destroy(client[x].auth.proxycred); } array_destroy(my.lurl); xfree(client); if (my.get) { if (data_get_ok200(D) > 0) { exit(EXIT_SUCCESS); } else { if (!my.quiet) echo("[done]\n"); exit(EXIT_FAILURE); } } /** * take a short nap for cosmetic effect * this does NOT affect performance stats. */ pthread_usleep_np(10000); if (my.verbose) fprintf(stderr, "done.\n"); else fprintf(stderr, "\b done.\n"); /** * prepare and print statistics. */ if (my.failures > 0 && my.failed >= my.failures) { fprintf(stderr, "%s aborted due to excessive socket failure; you\n", program_name); fprintf(stderr, "can change the failure threshold in $HOME/.%src\n", program_name); } fprintf(stderr, "\nTransactions:\t\t%12u hits\n", data_get_count(D)); fprintf(stderr, "Availability:\t\t%12.2f %%\n", data_get_count(D)==0 ? 0 : (double)data_get_count(D) / (data_get_count(D)+my.failed) *100 ); fprintf(stderr, "Elapsed time:\t\t%12.2f secs\n", data_get_elapsed(D)); fprintf(stderr, "Data transferred:\t%12.2f MB\n", data_get_megabytes(D)); /*%12llu*/ fprintf(stderr, "Response time:\t\t%12.3f secs\n", data_get_response_time(D)); fprintf(stderr, "Transaction rate:\t%12.2f trans/sec\n", data_get_transaction_rate(D)); fprintf(stderr, "Throughput:\t\t%12.2f MB/sec\n", data_get_throughput(D)); fprintf(stderr, "Concurrency:\t\t%12.2f\n", data_get_concurrency(D)); fprintf(stderr, "Successful transactions:%12u\n", data_get_code(D)); if (my.debug) { fprintf(stderr, "HTTP OK received:\t%12u\n", data_get_ok200(D)); } fprintf(stderr, "Failed transactions:\t%12u\n", my.failed); fprintf(stderr, "Longest transaction:\t%12.3f\n", data_get_highest(D)); fprintf(stderr, "Shortest transaction:\t%12.3f\n", data_get_lowest(D)); fprintf(stderr, " \n"); if(my.mark) mark_log_file(my.markstr); if(my.logging) log_transaction(D); data_destroy(D); if (my.url == NULL) { for (x = 0; x < my.length; x++) xfree(lines->line[x]); xfree(lines->line); xfree(lines); } else { xfree(lines->line); xfree(lines); } pthread_mutex_destroy( &(cookie->mutex)); /** * I should probably take a deeper look * at cookie content to free it but at * this point we're two lines from exit */ xfree (cookie); xfree (my.url); exit(EXIT_SUCCESS); } /* end of int main **/
/** * parses command line arguments and assigns * values to run time variables. relies on GNU * getopts included with this distribution. */ void parse_cmdline(int argc, char *argv[]) { int c = 0; int nargs; while ((c = getopt_long(argc, argv, "VhvqCDgl::ibr:t:f:d:c:m:H:R:A:T:", long_options, (int *)0)) != EOF) { switch (c) { case 'V': display_version(TRUE); break; case 'h': display_help(); exit(EXIT_SUCCESS); case 'D': my.debug = TRUE; break; case 'C': my.config = TRUE; my.get = FALSE; break; case 'c': my.cusers = atoi(optarg); break; case 'i': my.internet = TRUE; break; case 'b': my.bench = TRUE; break; case 'd': /* XXX range checking? use strtol? */ my.delay = atoi(optarg); if(my.delay < 0){ my.delay = 0; } break; case 'g': my.get = TRUE; break; case 'l': my.logging = TRUE; if (optarg) { my.logfile[strlen(optarg)] = '\0'; strncpy(my.logfile, optarg, strlen(optarg)); } break; case 'm': my.mark = TRUE; my.markstr = optarg; my.logging = TRUE; break; case 'q': my.quiet = TRUE; break; case 'v': my.verbose = TRUE; break; case 'r': if(strmatch(optarg, "once")){ my.reps = -1; } else { my.reps = atoi(optarg); } break; case 't': parse_time(optarg); break; case 'f': memset(my.file, 0, sizeof(my.file)); if(optarg == NULL) break; /*paranoia*/ strncpy(my.file, optarg, strlen(optarg)); break; case 'A': strncpy(my.uagent, optarg, 255); break; case 'T': strncpy(my.conttype, optarg, 255); break; case 'R': /** * processed above */ break; case 'H': { if(!strchr(optarg,':')) NOTIFY(FATAL, "no ':' in http-header"); if((strlen(optarg) + strlen(my.extra) + 3) > 2048) NOTIFY(FATAL, "header is too large"); strcat(my.extra,optarg); strcat(my.extra,"\015\012"); } break; } /* end of switch( c ) */ } /* end of while c = getopt_long */ nargs = argc - optind; if (nargs) my.url = xstrdup(argv[argc-1]); if (my.get && my.url==NULL) { puts("ERROR: -g/--get requires a commandline URL"); exit(1); } return; } /* end of parse_cmdline */
int main(int argc, char *argv[], char *envp[]) { //FIXME:user could choose only a website no all website.which means --host is available. static const struct option options[] = { {"debug", 0, NULL, 'd'}, {"verbose", 0, NULL, 'V'}, {"action", 1, NULL, 'A'}, {"logfile", 1, NULL, 'L'}, {"shrink-urls", 0, NULL, 's'}, {"help", 0, NULL, 'h'}, {"bash", 0, NULL, 'b'}, {"background", 0, NULL, 'B'}, {"dry-run", 0, NULL, 'n'}, {"page", 1, NULL, 'g'}, {"version", 0, NULL, 'v'}, {"config", 1, NULL, 'c'}, {"replyto", 1, NULL, 'r'}, {"retweet", 1, NULL, 'w'}, {} }; struct session *session; pid_t child; int retval = 0; int option; char *home; const char *config_file; time_t t; int page_nr; char *tweet; debug = 0; session = session_alloc(); if (!session) { fprintf(stderr, "no more memory...\n"); return -1; } /* get the current time so that we can log it later */ time(&t); session->time = strdup(ctime(&t)); session->time[strlen(session->time) - 1] = 0x00; /* * Get the home directory so we can try to find a config file. * If we have no home dir set up, look in /etc/bti */ home = getenv("HOME"); if (home) { /* We have a home dir, so this might be a user */ session->homedir = strdup(home); config_file = config_user_default; } else { session->homedir = strdup(""); config_file = config_default; } /* set up a default config file location (traditionally ~/.bti) */ session->configfile = zalloc(strlen(session->homedir) + strlen(config_file) + 7); sprintf(session->configfile, "%s/%s", session->homedir, config_file); session_readline_init(session); struct account *account = parse_configfile(session); if (account == NULL) { fprintf(stderr, "parse err, goto exit\n"); exit(-1); } while (1) { option = getopt_long_only(argc, argv, "dp:P:H:a:A:u:c:hg:G:sr:nVvw:", options, NULL); if (option == -1) break; switch (option) { case 'd': debug = 1; break; case 'V': session->verbose = 1; break; case 'g': page_nr = atoi(optarg); dbg("page = %d\n", page_nr); session->page = page_nr; break; case 'r': session->replyto = strdup(optarg); dbg("in_reply_to_status_id = %s\n", session->replyto); break; case 'A': if (strcasecmp(optarg, "update") == 0) session->action = ACTION_UPDATE; else if (strcasecmp(optarg, "friends") == 0) session->action = ACTION_FRIENDS; else if (strcasecmp(optarg, "user") == 0) session->action = ACTION_USER; else if (strcasecmp(optarg, "replies") == 0) session->action = ACTION_REPLIES; else if (strcasecmp(optarg, "public") == 0) session->action = ACTION_PUBLIC; else if (strcasecmp(optarg, "group") == 0) session->action = ACTION_GROUP; else if (strcasecmp(optarg, "retweet") == 0) session->action = ACTION_RETWEET; else session->action = ACTION_UNKNOWN; dbg("action = %d\n", session->action); break; case 'u': if (session->user) free(session->user); session->user = strdup(optarg); dbg("user = %s\n", session->user); break; case 'G': if (session->group) free(session->group); session->group = strdup(optarg); dbg("group = %s\n", session->group); break; case 'L': if (session->logfile) free(session->logfile); session->logfile = strdup(optarg); dbg("logfile = %s\n", session->logfile); break; case 's': session->shrink_urls = 1; break; case 'b': session->bash = 1; /* fall-through intended */ case 'B': session->background = 1; break; case 'c': if (session->configfile) free(session->configfile); session->configfile = strdup(optarg); dbg("configfile = %s\n", session->configfile); /* * read the config file now. Yes, this could override * previously set options from the command line, but * the user asked for it... */ //bti_parse_configfile(session); break; case 'h': display_help(); goto exit; case 'n': session->dry_run = 1; break; case 'v': display_version(); goto exit; default: display_help(); goto exit; } } /* * Show the version to make it easier to determine what * is going on here */ if (debug) display_version(); if (session->action == ACTION_UNKNOWN) { fprintf(stderr, "Unknown action, valid actions are:\n" "'update', 'friends', 'public', 'replies', 'group' or 'user'.\n"); goto exit; } dbg("config file = %s\n", session->configfile); dbg("action = %d\n", session->action); /* fork ourself so that the main shell can get on * with it's life as we try to connect and handle everything */ if (session->background) { child = fork(); if (child) { dbg("child is %d\n", child); exit(0); } } switch (session->action) { case ACTION_PUBLIC: PUBLIC(account, session, retval); break; case ACTION_UPDATE: if (session->background || !session->interactive) tweet = get_string_from_stdin(); else tweet = session->readline("tweet: "); if (!tweet || strlen(tweet) == 0) { dbg("no tweet?\n"); return -1; } if (session->shrink_urls) tweet = shrink_urls(tweet); session->tweet = zalloc(strlen(tweet) + 10); if (session->bash) sprintf(session->tweet, "%c %s", getuid()? '$' : '#', tweet); else sprintf(session->tweet, "%s", tweet); if (tweet) free(tweet); dbg("tweet = %s\n", session->tweet); UPDATE(account, session, retval); break; case ACTION_FRIENDS: FRIENDS(account, session, retval); break; case ACTION_REPLIES: REPLIES(account, session, retval); break; default: retval = -1; break; } // retval = send_request(session); if (retval && !session->background) fprintf(stderr, "operation failed\n"); /* log_session(session, retval); */ DESTORY(account); exit: session_readline_cleanup(session); session_free(session); return retval;; }
void process_options (int argc, char *argv[]) { int error = 0; for (;;) { int option_index = 0; static const char *short_options = "bs:f:il:op"; static const struct option long_options[] = { {"help", no_argument, 0, 0}, {"version", no_argument, 0, 0}, {"ignoreerrors", no_argument, 0, 'i'}, {"prettyprint", no_argument, 0, 'p'}, {"omitoob", no_argument, 0, 'o'}, {"omitbad", no_argument, 0, 'b'}, {"startaddress", required_argument, 0, 's'}, {"length", required_argument, 0, 'l'}, {0, 0, 0, 0}, }; int c = getopt_long(argc, argv, short_options, long_options, &option_index); if (c == EOF) { break; } switch (c) { case 0: switch (option_index) { case 0: display_help(); break; case 1: display_version(); break; } break; case 'b': omitbad = 1; break; case 's': start_addr = atol(optarg); break; case 'f': if (!(dumpfile = strdup(optarg))) { perror("stddup"); exit(1); } break; case 'i': ignoreerrors = 1; break; case 'l': length = atol(optarg); break; case 'o': omitoob = 1; break; case 'p': pretty_print = 1; break; case '?': error = 1; break; } } if ((argc - optind) != 1 || error) display_help (); mtddev = argv[optind]; }