#include <string.h>
#include <errno.h>
#include <sys/types.h>
+#include <sys/stat.h>
#include <pwd.h>
#include <grp.h>
#include <security/pam_appl.h>
return 0;
}
+static gchar *
+redirect_path (const gchar *path)
+{
+ if (g_str_has_prefix (path, g_getenv ("LIGHTDM_TEST_ROOT")))
+ return g_strdup (path);
+ else if (strcmp (path, CONFIG_DIR "/lightdm.conf") == 0)
+ return g_build_filename (g_getenv ("LIGHTDM_TEST_ROOT"), "etc", "lightdm", "lightdm.conf", NULL);
+ else if (g_str_has_prefix (path, "/tmp/"))
+ return g_build_filename (g_getenv ("LIGHTDM_TEST_ROOT"), "tmp", path + 5, NULL);
+ else
+ return g_strdup (path);
+}
+
#ifdef __linux__
static int
open_wrapper (const char *func, const char *pathname, int flags, mode_t mode)
{
- int (*_open) (const char * pathname, int flags, mode_t mode);
+ int (*_open) (const char *pathname, int flags, mode_t mode);
+ gchar *new_path = NULL;
+ int fd;
+
+ _open = (int (*)(const char *pathname, int flags, mode_t mode)) dlsym (RTLD_NEXT, func);
- _open = (int (*)(const char * pathname, int flags, mode_t mode)) dlsym (RTLD_NEXT, func);
if (strcmp (pathname, "/dev/console") == 0)
{
if (console_fd < 0)
}
return console_fd;
}
- else if (strcmp (pathname, CONFIG_DIR "/lightdm.conf") == 0)
- {
- gchar *path;
- int fd;
- path = g_build_filename (g_getenv ("LIGHTDM_TEST_ROOT"), "etc", "lightdm", "lightdm.conf", NULL);
- fd = _open (path, flags, mode);
- g_free (path);
+ new_path = redirect_path (pathname);
+ fd = _open (new_path, flags, mode);
+ g_free (new_path);
- return fd;
- }
- else
- return _open (pathname, flags, mode);
+ return fd;
}
int
/* Set up a skeleton file system */
g_mkdir_with_parents (g_strdup_printf ("%s/etc", temp_dir), 0755);
g_mkdir_with_parents (g_strdup_printf ("%s/usr/share", temp_dir), 0755);
+ g_mkdir_with_parents (g_strdup_printf ("%s/usr/tmp", temp_dir), 0755);
/* Copy over the configuration */
g_mkdir_with_parents (g_strdup_printf ("%s/etc/lightdm", temp_dir), 0755);