]> rtime.felk.cvut.cz Git - sojka/lightdm.git/commitdiff
Correctly redirect /etc and /var - make distcheck now runs!
authorRobert Ancell <robert.ancell@canonical.com>
Thu, 13 Jun 2013 04:12:15 +0000 (16:12 +1200)
committerRobert Ancell <robert.ancell@canonical.com>
Thu, 13 Jun 2013 04:12:15 +0000 (16:12 +1200)
tests/src/Makefile.am
tests/src/libsystem.c

index cc25269b1897bf172b273846b1cca73c0fcbc407..0e202e946faf3657b7f4438ce6dc03e4998df29c 100644 (file)
@@ -8,6 +8,8 @@ libsystem_la_CFLAGS = \
        $(GIO_UNIX_CFLAGS) \
        -DSRCDIR=\"$(abs_top_srcdir)\" \
        -DBUILDDIR=\"$(abs_top_builddir)\" \
+       -DSYSCONFDIR=\"$(sysconfdir)\" \
+       -DLOCALSTATEDIR=\"$(localstatedir)\" \
        -DCONFIG_DIR=\"$(sysconfdir)/lightdm\"
 libsystem_la_LIBADD = -ldl $(GLIB_LIBS) $(GIO_UNIX_LIBS)
 
index e66e6f7ee2687c517314e2e7104e8876bd228231..95896883ba55506484c4e0fa55189395386cfca1 100644 (file)
@@ -151,16 +151,31 @@ setresuid (uid_t ruid, uid_t uuid, uid_t suid)
 static gchar *
 redirect_path (const gchar *path)
 { 
+    gchar *p;
+    gboolean matches;
+    size_t offset;
+
     if (g_str_has_prefix (path, g_getenv ("LIGHTDM_TEST_ROOT")))
         return g_strdup (path);
-    else if (strcmp (path, CONFIG_DIR "/lightdm.conf") == 0)
+
+    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/"))
+
+    p = g_strdup_printf ("%s/", SYSCONFDIR);
+    offset = strlen (p);
+    matches = g_str_has_prefix (path, p);
+    g_free (p);
+    if (g_str_has_prefix (path, "/tmp/"))
         return g_build_filename (g_getenv ("LIGHTDM_TEST_ROOT"), "tmp", path + 5, NULL);
-    else if (g_str_has_prefix (path, "/var/"))
-        return g_build_filename (g_getenv ("LIGHTDM_TEST_ROOT"), "var", path + 5, NULL);
-    else
-        return g_strdup (path);
+
+    p = g_strdup_printf ("%s/", LOCALSTATEDIR);
+    offset = strlen (p);
+    matches = g_str_has_prefix (path, p);
+    g_free (p);
+    if (matches)
+        return g_build_filename (g_getenv ("LIGHTDM_TEST_ROOT"), "var", path + offset, NULL);
+
+    return g_strdup (path);
 }
 
 #ifdef __linux__
@@ -282,6 +297,70 @@ access (const char *pathname, int mode)
     return ret;
 }
 
+int
+stat (const char *path, struct stat *buf)
+{
+    int (*_stat) (const char *path, struct stat *buf);
+    gchar *new_path = NULL;
+    int ret;
+  
+    _stat = (int (*)(const char *path, struct stat *buf)) dlsym (RTLD_NEXT, "stat");
+
+    new_path = redirect_path (path);
+    ret = _stat (new_path, buf);
+    g_free (new_path);
+
+    return ret;
+}
+
+int
+stat64 (const char *path, struct stat *buf)
+{
+    int (*_stat64) (const char *path, struct stat *buf);
+    gchar *new_path = NULL;
+    int ret;
+
+    _stat64 = (int (*)(const char *path, struct stat *buf)) dlsym (RTLD_NEXT, "stat64");
+
+    new_path = redirect_path (path);
+    ret = _stat (new_path, buf);
+    g_free (new_path);
+
+    return ret;
+}
+
+int
+__xstat (int version, const char *path, struct stat *buf)
+{
+    int (*___xstat) (int version, const char *path, struct stat *buf);
+    gchar *new_path = NULL;
+    int ret;
+  
+    ___xstat = (int (*)(int version, const char *path, struct stat *buf)) dlsym (RTLD_NEXT, "__xstat");
+
+    new_path = redirect_path (path);
+    ret = ___xstat (version, new_path, buf);
+    g_free (new_path);
+
+    return ret;
+}
+
+int
+__xstat64 (int version, const char *path, struct stat *buf)
+{
+    int (*___xstat64) (int version, const char *path, struct stat *buf);
+    gchar *new_path = NULL;
+    int ret;
+  
+    ___xstat64 = (int (*)(int version, const char *path, struct stat *buf)) dlsym (RTLD_NEXT, "__xstat64");
+
+    new_path = redirect_path (path);
+    ret = ___xstat64 (version, new_path, buf);
+    g_free (new_path);
+
+    return ret;
+}
+
 int
 mkdir (const char *pathname, mode_t mode)
 {