本文整理汇总了C++中SB_LOG函数的典型用法代码示例。如果您正苦于以下问题:C++ SB_LOG函数的具体用法?C++ SB_LOG怎么用?C++ SB_LOG使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了SB_LOG函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: sb2_stat64_file
int sb2_stat64_file(const char *path, struct stat64 *buf, int *result_errno_ptr,
int (*stat64fn_with_ver_ptr)(int ver, const char *filename, struct stat64 *buf),
int ver,
int (*stat64fn_ptr)(const char *filename, struct stat64 *buf))
{
int res;
SB_LOG(SB_LOGLEVEL_NOISE, "sb2_stat64(%s)", path);
if (stat64fn_with_ver_ptr) {
/* glibc; it doesn't have a real stat64() function */
res = (*stat64fn_with_ver_ptr)(ver, path, buf);
} else if (stat64fn_ptr) {
/* probably something else than glibc.
* hope this works (not tested...) */
res = (*stat64fn_ptr)(path, buf);
} else {
*result_errno_ptr = EINVAL;
return(-1);
}
if (res == 0) {
i_virtualize_struct_stat(__func__, NULL, buf);
} else {
*result_errno_ptr = errno;
SB_LOG(SB_LOGLEVEL_NOISE, "sb2_stat64(%s) : failed, errno=%d",
path, errno);
}
SB_LOG(SB_LOGLEVEL_NOISE, "sb2_stat64(%s) returns %d", path, res);
return(res);
}
示例2: if_exists_in
static int if_exists_in(ruletree_fsrule_t *action,
const char *abs_clean_virtual_path)
{
const char *map_to_target;
char *test_path = NULL;
map_to_target = offset_to_ruletree_string_ptr(action->rtree_fsr_action_offs, NULL);
if (!strcmp(map_to_target, "/")) {
test_path = strdup(abs_clean_virtual_path);
} else {
if (asprintf(&test_path, "%s%s", map_to_target, abs_clean_virtual_path) < 0) {
SB_LOG(SB_LOGLEVEL_ERROR, "asprintf failed");
return(0);
}
}
if (sb_path_exists(test_path)) {
SB_LOG(SB_LOGLEVEL_DEBUG,
"if_exists_in: True '%s' -> proceed to then_actions", test_path);
free(test_path);
return (1);
}
SB_LOG(SB_LOGLEVEL_DEBUG,
"if_exists_in: False '%s'", test_path);
free(test_path);
return(0);
}
示例3: compare_and_log_strvec_changes
/* compare vectors of strings and log if there are any changes.
* TO BE IMPROVED: a more clever algorithm would be nice, something
* that would log only the modified parts... now this displays
* everything if something was changed, which easily creates
* a *lot* of noise if SB_LOGLEVEL_NOISE is enabled.
*/
static void compare_and_log_strvec_changes(const char *vecname,
char *const *orig_strv, char *const *new_strv)
{
char *const *ptr2old = orig_strv;
char *const *ptr2new = new_strv;
int strv_modified = 0;
while (*ptr2old && *ptr2new) {
if (strcmp(*ptr2old, *ptr2new)) {
strv_modified = 1;
break;
}
ptr2old++, ptr2new++;
}
if (!strv_modified && (*ptr2old || *ptr2new)) {
strv_modified = 1;
}
if (strv_modified) {
SB_LOG(SB_LOGLEVEL_DEBUG, "%s[] was modified", vecname);
if (SB_LOG_IS_ACTIVE(SB_LOGLEVEL_NOISE)) {
int i;
for (i = 0, ptr2new = new_strv;
*ptr2new;
i++, ptr2new++) {
SB_LOG(SB_LOGLEVEL_NOISE,
"[%d]='%s'", i,
*ptr2new);
}
}
} else {
SB_LOG(SB_LOGLEVEL_NOISE,
"%s[] was not modified", vecname);
}
}
示例4: change_environment_variable
/* "patch" environment = change environment variables.
* the variable must already exist in the environment;
* this doesn't do anything if the variable has been
* removed from environment.
*
* - "var_perfix" should contain the variable name + '='
*/
static void change_environment_variable(
char **my_envp, const char *var_prefix, const char *new_value)
{
size_t idx;
if (strvec_contains_prefix(my_envp, var_prefix, &idx)) {
char *new_value_buf, *orig_value;
/* release the placeholder */
orig_value = my_envp[idx];
free(orig_value);
if (asprintf(&new_value_buf, "%s%s",
var_prefix, new_value) < 0) {
SB_LOG(SB_LOGLEVEL_ERROR,
"asprintf failed to create new value %s%s",
var_prefix, new_value);
} else {
my_envp[idx] = new_value_buf;
}
SB_LOG(SB_LOGLEVEL_DEBUG, "Changed: %s", new_value_buf);
} else {
SB_LOG(SB_LOGLEVEL_DEBUG, "Failed to change %s%s",
var_prefix, new_value);
}
}
示例5: if_exists_then_replace_by
static int if_exists_then_replace_by(
ruletree_fsrule_t *action, ruletree_fsrule_t *rule_selector,
const char *abs_clean_virtual_path, char **resultp)
{
char *test_path;
const char *replacement = NULL;
*resultp = NULL;
replacement = offset_to_ruletree_string_ptr(action->rtree_fsr_action_offs, NULL);
test_path = ruletree_execute_replace_rule(abs_clean_virtual_path,
replacement, rule_selector);
if (!test_path) return(0);
if (sb_path_exists(test_path)) {
SB_LOG(SB_LOGLEVEL_DEBUG,
"if_exists_then_replace_by: True '%s'", test_path);
*resultp = test_path;
return(1);
}
SB_LOG(SB_LOGLEVEL_DEBUG,
"if_exists_then_replace_by: False '%s'", test_path);
free(test_path);
return(0);
}
示例6: SB_LOG
void *sbox_find_next_symbol(int log_enabled, const char *fn_name)
{
char *msg;
void *fn_ptr;
if(log_enabled)
SB_LOG(SB_LOGLEVEL_DEBUG, "%s: %s", __func__, fn_name);
fn_ptr = dlsym(RTLD_NEXT, fn_name);
if ((msg = dlerror()) != NULL) {
fprintf(stderr, "%s: dlsym(%s): %s\n",
PACKAGE_NAME, fn_name, msg);
if(log_enabled)
SB_LOG(SB_LOGLEVEL_ERROR, "ERROR: %s: dlsym(%s): %s",
PACKAGE_NAME, fn_name, msg);
assert(0);
}
if (log_enabled && SB_LOG_IS_ACTIVE(SB_LOGLEVEL_NOISE)) {
Dl_info dli;
if (dladdr(fn_ptr, &dli)) {
SB_LOG(SB_LOGLEVEL_NOISE, "%s: %s at 0x%p, in file '%s'",
__func__, fn_name, fn_ptr, dli.dli_fname);
} else {
SB_LOG(SB_LOGLEVEL_NOISE, "%s: %s at 0x%p",
__func__, fn_name, fn_ptr);
}
}
return(fn_ptr);
}
示例7: test_if_str_in_colon_separated_list_from_env
int test_if_str_in_colon_separated_list_from_env(
const char *str, const char *env_var_name)
{
int result = 0; /* boolean; default result is "not found" */
char *list;
char *tok = NULL;
char *tok_state = NULL;
list = getenv(env_var_name);
if (!list) {
SB_LOG(SB_LOGLEVEL_DEBUG, "no %s", env_var_name);
return(0);
}
list = strdup(list); /* will be modified by strtok_r */
SB_LOG(SB_LOGLEVEL_DEBUG, "%s is '%s'", env_var_name, list);
tok = strtok_r(list, ":", &tok_state);
while (tok) {
result = !strcmp(str, tok);
if (result) break; /* return if matched */
tok = strtok_r(NULL, ":", &tok_state);
}
free(list);
return(result);
}
示例8: lua_sb_path_exists
/* "sb.path_exists", to be called from lua code
* returns true if file or directory exists at the specified real path,
* false if not.
*/
static int lua_sb_path_exists(lua_State *l)
{
int n;
n = lua_gettop(l);
if (n != 1) {
lua_pushboolean(l, 0);
} else {
char *path = strdup(lua_tostring(l, 1));
int result = 0;
SB_LOG(SB_LOGLEVEL_DEBUG, "lua_sb_path_exists testing '%s'",
path);
if (access_nomap_nolog(path, F_OK) == 0) {
/* target exists */
lua_pushboolean(l, 1);
result=1;
} else {
lua_pushboolean(l, 0);
result=0;
}
SB_LOG(SB_LOGLEVEL_DEBUG, "lua_sb_path_exists got %d",
result);
free(path);
}
return 1;
}
示例9: scratchbox_reverse_path
static char *getcwd_common(char *buf, size_t size,
const char *realfnname, char *cwd)
{
char *sbox_path = NULL;
if (*cwd != '\0') {
sbox_path = scratchbox_reverse_path(realfnname, cwd,
SB2_INTERFACE_CLASS_GETCWD);
}
if (sbox_path) {
SB_LOG(SB_LOGLEVEL_DEBUG, "GETCWD: '%s'", sbox_path);
if(buf) {
if (strlen(sbox_path) >= size) {
/* path does not fit to the buffer */
free(sbox_path);
errno = ERANGE;
return(NULL);
}
strncpy(buf, sbox_path, size);
free(sbox_path);
} else {
/* buf==NULL: real getcwd() used malloc() to
* allocate cwd (some implementations) [or the
* behavior may be unspecified (posix definition)]
* Assume memory was allocated, because the real
* getcwd() already returned a pointer to us...
*/
free(cwd);
cwd = sbox_path;
}
}
SB_LOG(SB_LOGLEVEL_DEBUG, "GETCWD: returns '%s'", cwd);
return cwd;
}
示例10: dump_lua_stack
/* This stack dump routine is based on an example from the
* book "Programming in Lua"
*
* - This uses logging level DEBUG, but the calls are usually
* enabled only at NOISE3.
*/
void dump_lua_stack(const char *msg, lua_State *L)
{
int i;
int top = lua_gettop(L);
SB_LOG(SB_LOGLEVEL_DEBUG, "Stack dump/%s (gettop=%d):", msg, top);
for (i = 1; i <= top; i++) {
int t = lua_type(L, i);
switch (t) {
case LUA_TSTRING: /* strings */
SB_LOG(SB_LOGLEVEL_DEBUG,
"%d: '%s'", i, lua_tostring(L, i));
break;
case LUA_TBOOLEAN: /* booleans */
SB_LOG(SB_LOGLEVEL_DEBUG,
"%d: %s", i,
(lua_toboolean(L, i) ? "true" : "false"));
break;
case LUA_TNUMBER: /* numbers */
SB_LOG(SB_LOGLEVEL_DEBUG,
"%d: %g", i, lua_tonumber(L, i));
break;
default:
SB_LOG(SB_LOGLEVEL_DEBUG,
"%d: %s", i, lua_typename(L, t));
break;
}
}
}
示例11: sbox_map_path_for_sb2show
void sbox_map_path_for_sb2show(
const char *binary_name,
const char *func_name,
const char *virtual_path,
mapping_results_t *res)
{
interface_function_and_classes_t *ifp = interface_functions_and_classes__public;
uint32_t fn_class = 0;
while (ifp && ifp->fn_name) {
if (!strcmp(func_name, ifp->fn_name)) {
fn_class = ifp->fn_classmask;
SB_LOG(SB_LOGLEVEL_DEBUG,
"%s: Found func_class 0x%X (%s)",
__func__, fn_class, func_name);
break;
}
ifp++;
}
if (!fn_class) {
SB_LOG(SB_LOGLEVEL_DEBUG,
"%s: No func_class for %s",
__func__, func_name);
}
fwd_map_path(binary_name, func_name, virtual_path,
0/*dont_resolve_final_symlink*/, 0/*exec_mode*/, fn_class, res);
}
示例12: compare_results_from_c_and_lua_engines
static void compare_results_from_c_and_lua_engines(
const char *name,
const char *fn_name,
const char *c_res,
const char *lua_res)
{
if (c_res && lua_res) {
if (!strcmp(c_res, lua_res)) {
SB_LOG(SB_LOGLEVEL_DEBUG,
"%s: ResultCheck: %s same, OK",
fn_name, name);
} else {
SB_LOG(SB_LOGLEVEL_ERROR,
"%s: ResultCheck: DIFFERENT %s: C='%s', Lua='%s'",
fn_name, name, c_res, lua_res);
}
} else if (!c_res && !lua_res) {
SB_LOG(SB_LOGLEVEL_DEBUG,
"%s: ResultCheck: no %s result from C nor Lua",
fn_name, name);
} else {
if (!c_res) {
SB_LOG(SB_LOGLEVEL_ERROR,
"%s: ResultCheck: no %s result from C (Lua='%s')",
fn_name, name, lua_res);
}
if (!lua_res) {
SB_LOG(SB_LOGLEVEL_ERROR,
"%s: ResultCheck: no %s result from Lua (C='%s')",
fn_name, name, c_res);
}
}
}
示例13: call_lua_function_sbox_get_mapping_requirements
/* - returns 1 if ok (then *min_path_lenp is valid)
* - returns 0 if failed to find the rule
* Note: this leaves the rule to the stack!
*/
int call_lua_function_sbox_get_mapping_requirements(
const path_mapping_context_t *ctx,
const struct path_entry_list *abs_virtual_source_path_list,
int *min_path_lenp,
int *call_translate_for_all_p)
{
struct sb2context *sb2ctx = ctx->pmc_sb2ctx;
int rule_found;
int min_path_len;
int flags;
char *abs_virtual_source_path_string;
abs_virtual_source_path_string = path_list_to_string(abs_virtual_source_path_list);
SB_LOG(SB_LOGLEVEL_NOISE,
"calling sbox_get_mapping_requirements for %s(%s)",
ctx->pmc_func_name, abs_virtual_source_path_string);
if (!sb2ctx->lua) sb2context_initialize_lua(sb2ctx);
SB_LOG(SB_LOGLEVEL_NOISE,
"call_lua_function_sbox_get_mapping_requirements: gettop=%d",
lua_gettop(sb2ctx->lua));
lua_getfield(sb2ctx->lua, LUA_GLOBALSINDEX,
"sbox_get_mapping_requirements");
lua_pushstring(sb2ctx->lua, ctx->pmc_binary_name);
lua_pushstring(sb2ctx->lua, ctx->pmc_func_name);
lua_pushstring(sb2ctx->lua, abs_virtual_source_path_string);
lua_pushnumber(sb2ctx->lua, ctx->pmc_fn_class);
/* 4 arguments, returns 4: (rule, rule_found_flag,
* min_path_len, flags) */
lua_call(sb2ctx->lua, 4, 4);
rule_found = lua_toboolean(sb2ctx->lua, -3);
min_path_len = lua_tointeger(sb2ctx->lua, -2);
flags = lua_tointeger(sb2ctx->lua, -1);
check_mapping_flags(flags, "sbox_get_mapping_requirements");
if (min_path_lenp) *min_path_lenp = min_path_len;
if (call_translate_for_all_p)
*call_translate_for_all_p =
(flags & SB2_MAPPING_RULE_FLAGS_CALL_TRANSLATE_FOR_ALL);
/* remove last 3 values; leave "rule" to the stack */
lua_pop(sb2ctx->lua, 3);
SB_LOG(SB_LOGLEVEL_DEBUG, "sbox_get_mapping_requirements -> %d,%d,0%o",
rule_found, min_path_len, flags);
SB_LOG(SB_LOGLEVEL_NOISE,
"call_lua_function_sbox_get_mapping_requirements:"
" at exit, gettop=%d",
lua_gettop(sb2ctx->lua));
free(abs_virtual_source_path_string);
return(rule_found);
}
示例14: check_pthread_library
static void check_pthread_library()
{
if (pthread_detection_done == 0) {
/* these are available only in libpthread: */
pthread_key_create_fnptr = dlsym(RTLD_DEFAULT,
"pthread_key_create");
pthread_getspecific_fnptr = dlsym(RTLD_DEFAULT,
"pthread_getspecific");
pthread_setspecific_fnptr = dlsym(RTLD_DEFAULT,
"pthread_setspecific");
pthread_once_fnptr = dlsym(RTLD_DEFAULT,
"pthread_once");
pthread_mutex_lock_fnptr = dlsym(RTLD_DEFAULT,
"pthread_mutex_lock");
pthread_mutex_unlock_fnptr = dlsym(RTLD_DEFAULT,
"pthread_mutex_unlock");
/* Linux/glibc: pthread_self seems to exist in both
* glibc and libpthread. */
pthread_self_fnptr = dlsym(RTLD_DEFAULT,
"pthread_self");
if (pthread_key_create_fnptr &&
pthread_getspecific_fnptr &&
pthread_setspecific_fnptr &&
pthread_once_fnptr) {
SB_LOG(SB_LOGLEVEL_DEBUG,
"pthread library FOUND");
pthread_detection_done = 1;
pthread_library_is_available = 1;
} else if (!pthread_key_create_fnptr &&
!pthread_getspecific_fnptr &&
!pthread_setspecific_fnptr &&
!pthread_once_fnptr) {
SB_LOG(SB_LOGLEVEL_DEBUG,
"pthread library not found");
pthread_detection_done = -1;
pthread_library_is_available = 0;
} else {
SB_LOG(SB_LOGLEVEL_ERROR,
"pthread library is only partially available"
" - operation may become unstable");
pthread_detection_done = -2;
pthread_library_is_available = 0;
}
} else {
SB_LOG(SB_LOGLEVEL_NOISE,
"pthread detection already done (%d)",
pthread_detection_done);
}
}
示例15: sb_execve_preprocess
/* Exec preprocessor:
* (previously known as "sb_execve_mod")
*/
int sb_execve_preprocess(char **file, char ***argv, char ***envp)
{
struct lua_instance *luaif = get_lua();
int res, new_argc, new_envc;
if (!luaif) return(0);
if (!argv || !envp) {
SB_LOG(SB_LOGLEVEL_ERROR,
"ERROR: sb_argvenvp: (argv || envp) == NULL");
release_lua(luaif);
return -1;
}
if (getenv("SBOX_DISABLE_ARGVENVP")) {
SB_LOG(SB_LOGLEVEL_DEBUG, "sb_argvenvp disabled(E):");
release_lua(luaif);
return 0;
}
SB_LOG(SB_LOGLEVEL_NOISE,
"sb_execve_preprocess: gettop=%d", lua_gettop(luaif->lua));
lua_getfield(luaif->lua, LUA_GLOBALSINDEX, "sbox_execve_preprocess");
lua_pushstring(luaif->lua, *file);
free(*file);
strvec_to_lua_table(luaif, *argv);
strvec_free(*argv);
strvec_to_lua_table(luaif, *envp);
strvec_free(*envp);
/* args: binaryname, argv, envp
* returns: err, file, argc, argv, envc, envp */
lua_call(luaif->lua, 3, 6);
res = lua_tointeger(luaif->lua, -6);
*file = strdup(lua_tostring(luaif->lua, -5));
new_argc = lua_tointeger(luaif->lua, -4);
new_envc = lua_tointeger(luaif->lua, -2);
lua_string_table_to_strvec(luaif, -3, argv, new_argc);
lua_string_table_to_strvec(luaif, -1, envp, new_envc);
/* remove sbox_execve_preprocess' return values from the stack. */
lua_pop(luaif->lua, 6);
SB_LOG(SB_LOGLEVEL_NOISE,
"sb_execve_preprocess: at exit, gettop=%d", lua_gettop(luaif->lua));
release_lua(luaif);
return res;
}