summaryrefslogtreecommitdiff
path: root/luaif
diff options
context:
space:
mode:
authorLauri Aarnio <Lauri.Aarnio@iki.fi>2008-11-07 13:58:56 +0200
committerLauri Leukkunen <lle@rahina.org>2008-12-07 04:32:46 +0200
commitab2e89761025a9f3830988bf8a72e217d7c5018e (patch)
tree1c53e3e8958488d41361937ca2225425098bcdee /luaif
parentdaf3b68da1ece0b3ca29ea365b313cc69abf1d38 (diff)
Fixes for dirfd handling for openat(), faccessat(), etc *at() functions
- Added a pathname cache/db, which keeps fd=>path mappings. Those are needed for correct operation of openat() and friends. - NOTE: This is an initial version; there are still features that missing! To be extended later..
Diffstat (limited to 'luaif')
-rw-r--r--luaif/luaif.c8
-rw-r--r--luaif/paths.c52
2 files changed, 59 insertions, 1 deletions
diff --git a/luaif/luaif.c b/luaif/luaif.c
index 614314b..21facef 100644
--- a/luaif/luaif.c
+++ b/luaif/luaif.c
@@ -62,6 +62,9 @@ static int (*pthread_setspecific_fnptr)(pthread_key_t key,
const void *value) = NULL;
static int (*pthread_once_fnptr)(pthread_once_t *, void (*)(void)) = NULL;
pthread_t (*pthread_self_fnptr)(void) = NULL;
+int (*pthread_mutex_lock_fnptr)(pthread_mutex_t *mutex) = NULL;
+int (*pthread_mutex_unlock_fnptr)(pthread_mutex_t *mutex) = NULL;
+
static void check_pthread_library()
{
@@ -76,6 +79,11 @@ static void check_pthread_library()
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,
diff --git a/luaif/paths.c b/luaif/paths.c
index 46e17db..8b76695 100644
--- a/luaif/paths.c
+++ b/luaif/paths.c
@@ -983,7 +983,7 @@ static char *scratchbox_path_internal(
/* can't map, but still need to leave "rule"
* (string) and "policy" (nil) to the stack */
lua_pushstring(luaif->lua,
- "mapping failed (decolon path failed");
+ "mapping failed (decolon path failed)");
lua_pushnil(luaif->lua);
}
} else {
@@ -1075,6 +1075,56 @@ char *scratchbox_path(
path, ro_flagp, dont_resolve_final_symlink, 0));
}
+char *scratchbox_path_at(
+ const char *func_name,
+ int dirfd,
+ const char *path,
+ int *ro_flagp,
+ int dont_resolve_final_symlink)
+{
+ const char *dirfd_path;
+
+ if ((*path == '/') || (dirfd == AT_FDCWD)) {
+ /* same as scratchbox_path() */
+ return (scratchbox_path_internal(
+ (sbox_binary_name ? sbox_binary_name : "UNKNOWN"),
+ func_name,
+ path, ro_flagp, dont_resolve_final_symlink, 0));
+ }
+
+ /* relative to something else than CWD */
+ dirfd_path = fdpathdb_find_path(dirfd);
+
+ if (dirfd_path) {
+ /* pathname found */
+ char *ret;
+ char *at_full_path = NULL;
+
+ if (asprintf(&at_full_path, "%s/%s", dirfd_path, path) < 0) {
+ /* asprintf failed */
+ abort();
+ }
+ SB_LOG(SB_LOGLEVEL_DEBUG,
+ "Synthetic path for %s(%d,%s) => '%s'",
+ func_name, dirfd, path, at_full_path);
+
+ ret = scratchbox_path_internal(
+ (sbox_binary_name ? sbox_binary_name : "UNKNOWN"),
+ func_name,
+ at_full_path, ro_flagp, dont_resolve_final_symlink, 0);
+ free(at_full_path);
+ return(ret);
+ }
+
+ /* name not found. Can't do much here, log a warning and return
+ * the original relative path. That will work if we are lucky, but
+ * not always.. */
+ SB_LOG(SB_LOGLEVEL_WARNING, "Path not found for FD %d, for %s(%s)",
+ dirfd, func_name, path);
+
+ return (strdup(path));
+}
+
/* this maps the path and then leaves "rule" and "exec_policy" to the stack,
* because exec post-processing needs them
*/