void ci_log_buffer_till_exit(void) { if( real_log_fn ) return; ci_log_buffer_till_fail(); atexit(at_exit_fn); }
void ci_app_getopt(const char* usage, int* argc, char* argv[], const ci_cfg_desc* opts, int n_opts) { char* s; ci_assert(opts || n_opts == 0); ci_app_startup(argc ? *argc : 0, argv); cfg_opts = opts; n_cfg_opts = n_opts; usage_str = usage; /* look in the environment first */ if( (s = getenv("CI_OPTS")) ) parse_cfg_string(s); if( argc ) { --(*argc); ++argv; while( *argc > 0 ) { /* end of options? */ if( argv[0][0] != '-' ) break; if( !strcmp("--", argv[0]) ) break; chomp_arg(argc, argv, parse_cfg_opt(*argc, argv, "command line")); } ++(*argc); } if( ci_cfg_hang_on_fail ) ci_fail_stop_fn = ci_fail_hang; if( ci_cfg_segv_on_fail ) ci_fail_stop_fn = ci_fail_bomb; if( ci_cfg_exit_on_fail ) ci_fail_stop_fn = ci_fail_exit; if( ci_cfg_stop_on_fail ) ci_fail_stop_fn = ci_fail_stop; if( ci_cfg_abort_on_fail ) ci_fail_stop_fn = ci_fail_abort; if( ci_cfg_log_file ) { ci_log_file_fd = open(ci_cfg_log_file, O_WRONLY | O_CREAT | O_TRUNC, S_IREAD | S_IWRITE); if( ci_log_file_fd >= 0 ) ci_log_fn = ci_log_file; } if( ci_cfg_log_unique ) ci_log_uniquify(); if( ci_cfg_log_nth ) { ci_log_nth_n = ci_cfg_log_nth; ci_log_nth(); } if( ci_cfg_log_on_fail ) ci_log_buffer_till_fail(); if( ci_cfg_log_on_exit ) ci_log_buffer_till_exit(); if( ci_cfg_log_pid ) ci_log_options |= CI_LOG_PID; if( ci_cfg_log_tid ) ci_log_options |= CI_LOG_TID; if( ci_cfg_log_time ) ci_log_options |= CI_LOG_TIME; if( ci_cfg_log_delta ) ci_log_options |= CI_LOG_DELTA; if( ci_cfg_log_host ) { char hostname[80]; char logpf[100]; gethostname(hostname, 80); sprintf(logpf, "[%s] ", hostname); ci_set_log_prefix(strdup(logpf)); } if( ci_cfg_dump_format ) { if( !strcmp(ci_cfg_dump_format, "octets") ) ci_hex_dump_formatter = ci_hex_dump_format_octets; else if( !strcmp(ci_cfg_dump_format, "dwords") ) ci_hex_dump_formatter = ci_hex_dump_format_dwords; } }