summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Ancell <robert.ancell@canonical.com>2013-06-18 14:10:44 +1200
committerRobert Ancell <robert.ancell@canonical.com>2013-06-18 14:10:44 +1200
commit6877dd60541c457855a43e006021a3f9ab701f0e (patch)
treea3d43914cac0013ed67a54a131250859382abfb3
parent55410b446ba62d8174dfdf62cc76129d63204b73 (diff)
downloadlightdm-6877dd60541c457855a43e006021a3f9ab701f0e.tar.gz
Load configuration from /etc/lightdm/lightdm.conf.d
-rw-r--r--src/configuration.c27
-rw-r--r--src/lightdm.c66
-rw-r--r--tests/Makefile.am4
-rw-r--r--tests/scripts/0-additional.conf2
-rw-r--r--tests/scripts/1-additional.conf2
-rw-r--r--tests/scripts/additional-config.conf26
-rw-r--r--tests/src/libsystem.c17
-rw-r--r--tests/src/test-runner.c16
-rwxr-xr-xtests/test-additional-config2
9 files changed, 154 insertions, 8 deletions
diff --git a/src/configuration.c b/src/configuration.c
index 4d2fca66..e3b15df8 100644
--- a/src/configuration.c
+++ b/src/configuration.c
@@ -31,7 +31,32 @@ config_get_instance (void)
gboolean
config_load_from_file (Configuration *config, const gchar *path, GError **error)
{
- return g_key_file_load_from_file (config->priv->key_file, path, G_KEY_FILE_NONE, error);
+ GKeyFile *key_file;
+ gchar **groups;
+ int i;
+
+ key_file = g_key_file_new ();
+ if (!g_key_file_load_from_file (key_file, path, G_KEY_FILE_NONE, error))
+ return FALSE;
+
+ groups = g_key_file_get_groups (key_file, NULL);
+ for (i = 0; groups[i]; i++)
+ {
+ gchar **keys;
+ int j;
+
+ keys = g_key_file_get_keys (key_file, groups[i], NULL, error);
+ if (!keys)
+ break;
+
+ for (j = 0; keys[j]; j++)
+ g_key_file_set_value (config->priv->key_file, groups[i], keys[j], g_key_file_get_value (key_file, groups[i], keys[j], NULL));
+
+ g_strfreev (keys);
+ }
+ g_strfreev (groups);
+
+ return TRUE;
}
gchar **
diff --git a/src/lightdm.c b/src/lightdm.c
index 6771bc69..11a51e3c 100644
--- a/src/lightdm.c
+++ b/src/lightdm.c
@@ -788,6 +788,12 @@ vnc_connection_cb (VNCServer *server, GSocket *connection)
g_object_unref (seat);
}
+static int
+compare_strings (gconstpointer a, gconstpointer b)
+{
+ return strcmp (a, b);
+}
+
int
main (int argc, char **argv)
{
@@ -802,7 +808,7 @@ main (int argc, char **argv)
gchar *xsessions_dir = NULL;
gchar *remote_sessions_dir = NULL;
gchar *xgreeters_dir = NULL;
- gchar *config_dir;
+ gchar *config_dir, *config_d_dir = NULL;
gchar *log_dir = NULL;
gchar *run_dir = NULL;
gchar *cache_dir = NULL;
@@ -810,6 +816,7 @@ main (int argc, char **argv)
gchar *default_run_dir = g_strdup (RUN_DIR);
gchar *default_cache_dir = g_strdup (CACHE_DIR);
gboolean show_version = FALSE;
+ GList *link, *messages = NULL;
GOptionEntry options[] =
{
{ "config", 'c', 0, G_OPTION_ARG_STRING, &config_path,
@@ -858,6 +865,8 @@ main (int argc, char **argv)
#endif
loop = g_main_loop_new (NULL, FALSE);
+ messages = g_list_append (messages, g_strdup_printf ("Starting Light Display Manager %s, UID=%i PID=%i", VERSION, getuid (), getpid ()));
+
g_signal_connect (process_get_current (), "got-signal", G_CALLBACK (signal_cb), NULL);
option_context = g_option_context_new (/* Arguments and description for --help test */
@@ -892,6 +901,7 @@ main (int argc, char **argv)
else
{
config_dir = g_strdup (CONFIG_DIR);
+ config_d_dir = g_build_filename (config_dir, "lightdm.conf.d", NULL);
config_path = g_build_filename (config_dir, "lightdm.conf", NULL);
}
config_set_string (config_get_instance (), "LightDM", "config-directory", config_dir);
@@ -955,7 +965,8 @@ main (int argc, char **argv)
default_cache_dir = g_build_filename (g_get_user_cache_dir (), "lightdm", "cache", NULL);
}
- /* Load config file */
+ /* Load config file(s) */
+ messages = g_list_append (messages, g_strdup_printf ("Loading configuration from %s", config_path));
if (!config_load_from_file (config_get_instance (), config_path, &error))
{
gboolean is_empty;
@@ -970,6 +981,49 @@ main (int argc, char **argv)
}
}
g_clear_error (&error);
+ g_free (config_path);
+ if (config_d_dir)
+ {
+ GDir *dir;
+ GList *files, *link;
+ GKeyFile *f;
+
+ /* Find configuration files */
+ dir = g_dir_open (config_d_dir, 0, &error);
+ if (error && !g_error_matches (error, G_FILE_ERROR, G_FILE_ERROR_NOENT))
+ g_printerr ("Failed to open configuration directory %s: %s\n", config_d_dir, error->message);
+ g_clear_error (&error);
+ if (dir)
+ {
+ const gchar *name;
+ while ((name = g_dir_read_name (dir)))
+ files = g_list_append (files, g_strdup (name));
+ g_dir_close (dir);
+ }
+
+ /* Sort alphabetically and load onto existing configuration */
+ files = g_list_sort (files, compare_strings);
+ for (link = files; link; link = link->next)
+ {
+ gchar *filename = link->data;
+ gchar *path;
+
+ path = g_build_filename (config_d_dir, filename, NULL);
+ if (g_str_has_suffix (filename, ".conf"))
+ {
+ messages = g_list_append (messages, g_strdup_printf ("Loading configuration from %s", path));
+ config_load_from_file (config_get_instance (), path, &error);
+ if (error && !g_error_matches (error, G_FILE_ERROR, G_FILE_ERROR_NOENT))
+ g_printerr ("Failed to load configuration from %s: %s\n", filename, error->message);
+ g_clear_error (&error);
+ }
+ else
+ g_debug ("Ignoring configuration file %s, it does not have .conf suffix", path);
+ g_free (path);
+ }
+ g_list_free_full (files, g_free);
+ }
+ g_free (config_d_dir);
/* Set default values */
if (!config_has_key (config_get_instance (), "LightDM", "start-default-seat"))
@@ -1052,10 +1106,10 @@ main (int argc, char **argv)
log_init ();
- g_debug ("Starting Light Display Manager %s, UID=%i PID=%i", VERSION, getuid (), getpid ());
-
- g_debug ("Loaded configuration from %s", config_path);
- g_free (config_path);
+ /* Show queued messages once logging is complete */
+ for (link = messages; link; link = link->next)
+ g_debug ("%s", link->data);
+ g_list_free_full (messages, g_free);
g_debug ("Using D-Bus name %s", LIGHTDM_BUS_NAME);
bus_id = g_bus_own_name (getuid () == 0 ? G_BUS_TYPE_SYSTEM : G_BUS_TYPE_SESSION,
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 2cc23bd6..bb2d6d7a 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -6,6 +6,7 @@ TESTS = \
test-greeter-not-installed \
test-greeter-xserver-crash \
test-no-config \
+ test-additional-config \
test-headless \
test-autologin \
test-autologin-in-background \
@@ -236,6 +237,9 @@ EXTRA_DIST = \
data/xgreeters/test-qt5-greeter.desktop \
data/xsessions/alternative.desktop \
data/xsessions/default.desktop \
+ scripts/0-additional.conf \
+ scripts/1-additional.conf \
+ scripts/additional-config.conf \
scripts/autologin.conf \
scripts/autologin-guest.conf \
scripts/autologin-guest-fail-setup-script.conf \
diff --git a/tests/scripts/0-additional.conf b/tests/scripts/0-additional.conf
new file mode 100644
index 00000000..16dd53c5
--- /dev/null
+++ b/tests/scripts/0-additional.conf
@@ -0,0 +1,2 @@
+[SeatDefaults]
+autologin-user=have-password1
diff --git a/tests/scripts/1-additional.conf b/tests/scripts/1-additional.conf
new file mode 100644
index 00000000..07fa3d93
--- /dev/null
+++ b/tests/scripts/1-additional.conf
@@ -0,0 +1,2 @@
+[SeatDefaults]
+autologin-user=have-password2
diff --git a/tests/scripts/additional-config.conf b/tests/scripts/additional-config.conf
new file mode 100644
index 00000000..a8097214
--- /dev/null
+++ b/tests/scripts/additional-config.conf
@@ -0,0 +1,26 @@
+#
+# Check LightDM runs without a config.d configuration
+#
+
+[test-runner-config]
+additional-config=0-additional.conf 1-additional.conf
+
+#?RUNNER DAEMON-START
+
+# X server starts
+#?XSERVER-0 START
+#?XSERVER-0 INDICATE-READY
+
+# LightDM connects to X server
+#?XSERVER-0 ACCEPT-CONNECT
+
+# Session starts
+#?SESSION-X-0 START USER=have-password2
+#?XSERVER-0 ACCEPT-CONNECT
+#?SESSION-X-0 CONNECT-XSERVER
+
+# Cleanup
+#?*STOP-DAEMON
+#?SESSION-X-0 TERMINATE SIGNAL=15
+#?XSERVER-0 TERMINATE SIGNAL=15
+#?RUNNER DAEMON-EXIT STATUS=0
diff --git a/tests/src/libsystem.c b/tests/src/libsystem.c
index 74a0d6ee..ff90bac9 100644
--- a/tests/src/libsystem.c
+++ b/tests/src/libsystem.c
@@ -5,6 +5,7 @@
#include <sys/stat.h>
#include <pwd.h>
#include <unistd.h>
+#include <dirent.h>
#include <grp.h>
#include <security/pam_appl.h>
#include <fcntl.h>
@@ -357,6 +358,22 @@ __xstat64 (int version, const char *path, struct stat *buf)
return ret;
}
+DIR *
+opendir (const char *name)
+{
+ DIR *(*_opendir) (const char *name);
+ gchar *new_path = NULL;
+ DIR *result;
+
+ _opendir = (DIR *(*)(const char *name)) dlsym (RTLD_NEXT, "opendir");
+
+ new_path = redirect_path (name);
+ result = _opendir (new_path);
+ g_free (new_path);
+
+ return result;
+}
+
int
mkdir (const char *pathname, mode_t mode)
{
diff --git a/tests/src/test-runner.c b/tests/src/test-runner.c
index 1d581558..4b93ffbd 100644
--- a/tests/src/test-runner.c
+++ b/tests/src/test-runner.c
@@ -1698,7 +1698,7 @@ main (int argc, char **argv)
{
GMainLoop *loop;
int i;
- gchar *greeter = NULL, *script_name, *config_file, *path, *path1, *path2, *ld_preload, *ld_library_path, *home_dir;
+ gchar *greeter = NULL, *script_name, *config_file, *additional_config, *path, *path1, *path2, *ld_preload, *ld_library_path, *home_dir;
GString *passwd_data, *group_data;
GSource *status_source;
gchar cwd[1024];
@@ -1832,6 +1832,20 @@ main (int argc, char **argv)
if (system (g_strdup_printf ("cp %s %s/etc/lightdm/lightdm.conf", config_path, temp_dir)))
perror ("Failed to copy configuration");
+ additional_config = g_key_file_get_string (config, "test-runner-config", "additional-config", NULL);
+ if (additional_config)
+ {
+ gchar **files;
+
+ g_mkdir_with_parents (g_strdup_printf ("%s/etc/lightdm/lightdm.conf.d", temp_dir), 0755);
+
+ files = g_strsplit (additional_config, " ", -1);
+ for (i = 0; files[i]; i++)
+ if (system (g_strdup_printf ("cp scripts/%s %s/etc/lightdm/lightdm.conf.d", files[i], temp_dir)))
+ perror ("Failed to copy configuration");
+ g_strfreev (files);
+ }
+
/* Always copy the script */
if (system (g_strdup_printf ("cp %s %s/script", config_path, temp_dir)))
perror ("Failed to copy configuration");
diff --git a/tests/test-additional-config b/tests/test-additional-config
new file mode 100755
index 00000000..61eecea5
--- /dev/null
+++ b/tests/test-additional-config
@@ -0,0 +1,2 @@
+#!/bin/sh
+./src/dbus-env ./src/test-runner additional-config test-gobject-greeter