static int init_etherfabric_char(void) { int rc = 0; int major = 0; /* specify default major number here */ ci_set_log_prefix("[sfc_char_debug] "); ci_mm_tbl_init(); if ((rc = register_chrdev(major, EFAB_CHAR_NAME, &ci_char_fops)) < 0) { ci_log("%s: can't register char device %d", EFAB_CHAR_NAME, rc); return rc; } if (major == 0) major = rc; ci_char_major = major; #ifdef NEED_IOCTL32 /* In 2.6.11 onwards, this uses the .compat_ioctl file op instead */ /* register 64 bit handler for 32 bit ioctls */ { int ioc; for(ioc = CI_IOC_CHAR_BASE; ioc <= CI_IOC_CHAR_MAX; ioc ++){ register_ioctl32_conversion(ioc, NULL); } } #endif return 0; }
static int citp_setup_logging_early(void) { /* If stderr is a tty, use it. Else, use ioctl. */ if( isatty(STDERR_FILENO) ) ci_log_fn = citp_log_fn_ul; else { ci_log_fn = citp_log_fn_drv; } ci_set_log_prefix("onload: "); return 0; }
void ci_app_startup(int argc, char* argv[]) { int rc; if( ci_appname ) return; if( getenv("EFAB_NIC") ) ci_cfg_nic_name = getenv("EFAB_NIC"); ci_cfg_nic_index = atoi(ci_cfg_nic_name); if( ci_app_cpu_khz == 0 ) { do_platform_init(); rc = ci_get_cpu_khz(&ci_app_cpu_khz); if( rc < 0 ) ci_log("ci_get_cpu_khz: %d", rc); } if( argc > 0 ) { int i, n = 0; char* p; for( i = 0; i < argc; ++i ) n += strlen(argv[i]) + 1; ci_cmdline = malloc(n); if( ci_cmdline ) { p = ci_cmdline; for( i = 0; i < argc; ++i ) p += sprintf(p, "%s%s", i == 0 ? "":" ", argv[i]); CI_TEST(p == ci_cmdline + n - 1); } if( argc >= 1 && argv && argv[0] ) { ci_appname = argv[0] + strlen(argv[0]); while( ci_appname > argv[0] && ci_appname[-1] != '/' && ci_appname[-1] != '\\' ) --ci_appname; } else ci_appname = ""; if( strlen(ci_appname) < (LOG_PREFIX_BUF_SIZE - 5) ) { strcpy(log_prefix_buf, ci_appname); strcat(log_prefix_buf, ": "); ci_set_log_prefix(log_prefix_buf); } } }
void citp_setup_logging_prefix(void) { static char s0[64]; sprintf(s0, "oo:%.16s[%d]: ", citp.process_name, (int) getpid()); ci_set_log_prefix(s0); }
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; } }