diff options
author | Lauri Aarnio <Lauri.Aarnio@iki.fi> | 2008-09-16 18:38:46 +0300 |
---|---|---|
committer | Lauri Leukkunen <lle@rahina.org> | 2008-09-27 00:02:42 +0300 |
commit | 759aec56c7e0edbe3ee9aaf625e1352ae3ce6dbd (patch) | |
tree | 88cb5e9eb66d3ed5e5a6f2bc9eac9eb3c5d177c3 | |
parent | bfa948dd17f22f444ddec99225120fc6d0e4911d (diff) |
sb2-show can be used to query string variables from the Lua engine - Also introduces a new C function, sb2__read_string_variable_from_lua__(), which can be used to replace getenv() for variables that have been moved or will be moved away from environment
-rw-r--r-- | luaif/luaif.c | 24 | ||||
-rw-r--r-- | preload/interface.master | 1 | ||||
-rw-r--r-- | utils/sb2-show.c | 27 |
3 files changed, 50 insertions, 2 deletions
diff --git a/luaif/luaif.c b/luaif/luaif.c index af9ef05..af1bab2 100644 --- a/luaif/luaif.c +++ b/luaif/luaif.c @@ -246,6 +246,30 @@ void sb2_lua_init(void) lua_engine_state = LES_READY; } +/* Read string variables from lua. + * Note that this function is exported from libsb2.so (for sb2-show etc): */ +char *sb2__read_string_variable_from_lua__(const char *name) +{ + struct lua_instance *luaif; + char *result = NULL; + + luaif = get_lua(); + + if (luaif && name && *name) { + lua_getglobal(luaif->lua, name); + result = (char *)lua_tostring(luaif->lua, -1); + if (result) { + result = strdup(result); + } + SB_LOG(SB_LOGLEVEL_DEBUG, + "Lua variable %s = '%s', gettop=%d", + name, (result ? result : "<NULL>"), + lua_gettop(luaif->lua)); + } + return(result); +} + + /* "sb.decolonize_path", to be called from lua code */ static int lua_sb_decolonize_path(lua_State *l) { diff --git a/preload/interface.master b/preload/interface.master index efe2119..9b43318 100644 --- a/preload/interface.master +++ b/preload/interface.master @@ -31,6 +31,7 @@ EXPORT: int sb2show__execve_mods__( \ char *file, \ char *const *orig_argv, char *const *orig_envp, \ char **new_file, char ***new_argv, char ***new_envp) +EXPORT: char *sb2__read_string_variable_from_lua__(const char *name) -- FIXME: The following two functions do not have anything to do with path -- remapping. Instead the implementations in libsb2.c prevent locking of diff --git a/utils/sb2-show.c b/utils/sb2-show.c index 5fb361c..93641d8 100644 --- a/utils/sb2-show.c +++ b/utils/sb2-show.c @@ -40,8 +40,10 @@ static void usage_exit(const char *progname, const char *errmsg, int exitstatus) "\tlog-warning 'message'" "\tAdd a warning message to the log\n" "\tverify-pathlist-mappings required-prefix [ignorelist]" - "\tread list of paths from stdin and/n" - "\t\tcheck that all paths will be mapped to required prefix/n" + "\tread list of paths from stdin and\n" + "\t\tcheck that all paths will be mapped to required prefix\n" + "\tvar variablename" + "\tShow value of a string variable\n" "\n'%s' must be executed inside sb2 sandbox" " (see the 'sb2' command)\n", progname, progname, progname); @@ -49,6 +51,25 @@ static void usage_exit(const char *progname, const char *errmsg, int exitstatus) exit(exitstatus); } +static int command_show_variable( + int verbose, + const char *progname, + const char *varname) +{ + char *value = sb2__read_string_variable_from_lua__(varname); + + if (value) { + if (verbose) printf("%s = \"%s\"\n", varname, value); + else printf("%s\n", value); + free(value); + return(0); + } + /* failed */ + if (verbose) printf("%s: %s does not exist\n", + progname, varname); + return(1); +} + static void command_show_exec( const char *binary_name, const char *fn_name, @@ -244,6 +265,8 @@ int main(int argc, char *argv[]) return command_verify_pathlist_mappings(binary_name, function_name, ignore_directories, verbose, progname, argv + optind + 1); + } else if (!strcmp(argv[optind], "var")) { + return(command_show_variable(verbose, progname, argv[optind+1])); } else { usage_exit(progname, "Unknown command", 1); } |