int is_reserved_lvname(const char *name) { int rc, old_suppress; old_suppress = log_suppress(2); rc = !apply_lvname_restrictions(name); log_suppress(old_suppress); return rc; }
DECLARE_TEST( library, lookup ) { object_t lib = 0; object_t otherlib = 0; void* symbol = 0; #if FOUNDATION_PLATFORM_WINDOWS const char* libraryname = "kernel32"; const char* symbolname = "ExitProcess"; #elif FOUNDATION_PLATFORM_APPLE const char* libraryname = "dl"; const char* symbolname = "dlsym"; #elif FOUNDATION_PLATFORM_POSIX const char* libraryname = "dl"; const char* symbolname = "dlsym"; #else const char* libraryname = "somelib"; const char* symbolname = "somesym"; #endif lib = library_load( libraryname ); EXPECT_NE( lib, 0 ); otherlib = library_load( libraryname ); EXPECT_EQ( lib, otherlib ); library_unload( otherlib ); library_unload( 0 ); otherlib = 0; log_suppress( ERRORLEVEL_WARNING ); EXPECT_EQ( library_load( "this_library_should_not_exist" ), 0 ); log_suppress( ERRORLEVEL_DEBUG ); EXPECT_TRUE( library_valid( lib ) ); EXPECT_FALSE( library_valid( 0 ) ); symbol = library_symbol( lib, symbolname ); EXPECT_NE( symbol, 0 ); EXPECT_EQ( library_symbol( 0, symbolname ), 0 ); library_unload( lib ); EXPECT_EQ( library_symbol( lib, symbolname ), 0 ); EXPECT_FALSE( library_valid( lib ) ); return 0; }
void log_infof( uint64_t context, const char* format, ... ) { va_list list; va_start( list, format ); if( log_suppress( context ) < ERRORLEVEL_INFO ) _log_outputf( context, ERRORLEVEL_INFO, "", format, list, stdout ); va_end( list ); }
static lvm_t _lvm_init(const char *system_dir) { struct cmd_context *cmd; /* FIXME: logging bound to handle */ if (!udev_init_library_context()) stack; /* * It's not necessary to use name mangling for LVM: * - the character set used for VG-LV names is subset of udev character set * - when we check other devices (e.g. device_is_usable fn), we use major:minor, not dm names */ dm_set_name_mangling_mode(DM_STRING_MANGLING_NONE); /* create context */ /* FIXME: split create_toolcontext */ /* FIXME: make all globals configurable */ cmd = create_toolcontext(0, system_dir, 0, 0, 1, 1); if (!cmd) return NULL; if (stored_errno()) return (lvm_t) cmd; /* * FIXME: if an non memory error occured, return the cmd (maybe some * cleanup needed). */ /* initialization from lvm_run_command */ init_error_message_produced(0); /* FIXME: locking_type config option needed? */ /* initialize locking */ if (!init_locking(-1, cmd, 0)) { /* FIXME: use EAGAIN as error code here */ lvm_quit((lvm_t) cmd); return NULL; } /* * FIXME: Use cmd->cmd_line as audit trail for liblvm calls. Used in * archive() call. Possible example: * cmd_line = "lvm_vg_create: vg1\nlvm_vg_extend vg1 /dev/sda1\n" */ cmd->cmd_line = "liblvm"; /* * Turn off writing to stdout/stderr. * FIXME Fix lib/ to support a non-interactive mode instead. */ log_suppress(1); return (lvm_t) cmd; }
void log_error_context( uint64_t context, error_level_t error_level ) { int i; error_context_t* err_context = error_context(); if( err_context && ( log_suppress( context ) < error_level ) ) { error_frame_t* frame = err_context->frame; for( i = 0; i < err_context->depth; ++i, ++frame ) _log_error_contextf( context, error_level, error_level > ERRORLEVEL_WARNING ? stderr : stdout, "When %s: %s", frame->name ? frame->name : "<something>", frame->data ? frame->data : "" ); } }
lvm_t lvm_init(const char *system_dir) { struct cmd_context *cmd; /* FIXME: logging bound to handle */ if (!udev_init_library_context()) stack; /* create context */ /* FIXME: split create_toolcontext */ /* FIXME: make all globals configurable */ cmd = create_toolcontext(0, system_dir, 0, 0); if (!cmd) return NULL; if (stored_errno()) return (lvm_t) cmd; /* * FIXME: if an non memory error occured, return the cmd (maybe some * cleanup needed). */ /* initialization from lvm_run_command */ init_error_message_produced(0); /* FIXME: locking_type config option needed? */ /* initialize locking */ if (!init_locking(-1, cmd, 0)) { /* FIXME: use EAGAIN as error code here */ lvm_quit((lvm_t) cmd); return NULL; } /* * FIXME: Use cmd->cmd_line as audit trail for liblvm calls. Used in * archive() call. Possible example: * cmd_line = "lvm_vg_create: vg1\nlvm_vg_extend vg1 /dev/sda1\n" */ cmd->cmd_line = "liblvm"; /* * Turn off writing to stdout/stderr. * FIXME Fix lib/ to support a non-interactive mode instead. */ log_suppress(1); return (lvm_t) cmd; }
static void hashify_print_usage(void) { const error_level_t saved_level = log_suppress(0); log_set_suppress(0, ERRORLEVEL_DEBUG); log_info(0, STRING_CONST( "hashify usage:\n" " hashify [--validate] [--generate-string <string>] [<filename> <filename> ...] [--debug] [--help] [--]\n" " Generated files have the same file name as the input file, with the extension replaced by .h\n" " Optional arguments:\n" " --validate Suppress output and only validate existing hashes\n" " --generate-string <string> Generate hash of the given string\n" " <filename> <filename> ... Any number of input files\n" " --debug Enable debug output\n" " --help Display this help message\n" " -- Stop processing command line arguments" )); log_set_suppress(0, saved_level); }
static void rendercompile_print_usage(void) { const error_level_t saved_level = log_suppress(0); log_set_suppress(0, ERRORLEVEL_DEBUG); log_info(0, STRING_CONST( "rendercompile usage:\n" " rendercompile [--source <path>] [--ascii] [--binary] [--debug] [--help] <file> <uuid> ... [--]\n" " Arguments:\n" " <file> <uuid> ... Any number of input files or UUIDs\n" " Optional arguments:\n" " --source <path> Operate on resource file source structure given by <path>\n" " --binary Write binary files\n" " --ascii Write ASCII files (default)\n" " --debug Enable debug output\n" " --help Display this help message\n" " -- Stop processing command line arguments" )); log_set_suppress(0, saved_level); }
void log_warnf( uint64_t context, warning_t warn, const char* format, ... ) { char prefix[32]; va_list list; if( log_suppress( context ) >= ERRORLEVEL_WARNING ) return; log_error_context( context, ERRORLEVEL_WARNING ); if( warn < WARNING_LAST_BUILTIN ) string_format_buffer( prefix, 32, "WARNING [%s]: ", _log_warning_name[warn] ); else string_format_buffer( prefix, 32, "WARNING [%d]: ", warn ); va_start( list, format ); _log_outputf( context, ERRORLEVEL_WARNING, prefix, format, list, stdout ); va_end( list ); }
void log_errorf( uint64_t context, error_t err, const char* format, ... ) { char prefix[32]; va_list list; if( log_suppress( context ) >= ERRORLEVEL_ERROR ) return; log_error_context( context, ERRORLEVEL_ERROR ); if( err < ERROR_LAST_BUILTIN ) string_format_buffer( prefix, 32, "ERROR [%s]: ", _log_error_name[err] ); else string_format_buffer( prefix, 32, "ERROR [%d]: ", err ); va_start( list, format ); _log_outputf( context, ERRORLEVEL_ERROR, prefix, format, list, stderr ); va_end( list ); error_report( ERRORLEVEL_ERROR, err ); }