Skip to content

Commit da5e9ae

Browse files
committed
Also support loading config from /usr/share since Debian (stupidly) wont remove files from /etc on package uninstallation even if they've never been modified
1 parent da9a3e4 commit da5e9ae

8 files changed

+131
-40
lines changed

src/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ lightdm_CFLAGS = \
7979
-DLOG_DIR=\"$(localstatedir)/log/lightdm\" \
8080
-DRUN_DIR=\"$(localstatedir)/run/lightdm\" \
8181
-DCACHE_DIR=\"$(localstatedir)/cache/lightdm\" \
82+
-DSYSTEM_CONFIG_DIR=\"$(pkgdatadir)/lightdm.conf.d\" \
8283
-DSESSIONS_DIR=\"$(pkgdatadir)/sessions:$(datadir)/xsessions\" \
8384
-DREMOTE_SESSIONS_DIR=\"$(pkgdatadir)/remote-sessions\" \
8485
-DGREETERS_DIR=\"$(pkgdatadir)/greeters:$(datadir)/xgreeters\"

src/lightdm.c

Lines changed: 45 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -854,6 +854,49 @@ compare_strings (gconstpointer a, gconstpointer b)
854854
return strcmp (a, b);
855855
}
856856

857+
static void
858+
load_config_directory (const gchar *path, GList **messages)
859+
{
860+
GDir *dir;
861+
GList *files = NULL, *link;
862+
GError *error = NULL;
863+
864+
/* Find configuration files */
865+
dir = g_dir_open (path, 0, &error);
866+
if (error && !g_error_matches (error, G_FILE_ERROR, G_FILE_ERROR_NOENT))
867+
g_printerr ("Failed to open configuration directory %s: %s\n", path, error->message);
868+
g_clear_error (&error);
869+
if (dir)
870+
{
871+
const gchar *name;
872+
while ((name = g_dir_read_name (dir)))
873+
files = g_list_append (files, g_strdup (name));
874+
g_dir_close (dir);
875+
}
876+
877+
/* Sort alphabetically and load onto existing configuration */
878+
files = g_list_sort (files, compare_strings);
879+
for (link = files; link; link = link->next)
880+
{
881+
gchar *filename = link->data;
882+
gchar *conf_path;
883+
884+
conf_path = g_build_filename (path, filename, NULL);
885+
if (g_str_has_suffix (filename, ".conf"))
886+
{
887+
*messages = g_list_append (*messages, g_strdup_printf ("Loading configuration from %s", conf_path));
888+
config_load_from_file (config_get_instance (), conf_path, &error);
889+
if (error && !g_error_matches (error, G_FILE_ERROR, G_FILE_ERROR_NOENT))
890+
g_printerr ("Failed to load configuration from %s: %s\n", filename, error->message);
891+
g_clear_error (&error);
892+
}
893+
else
894+
g_debug ("Ignoring configuration file %s, it does not have .conf suffix", conf_path);
895+
g_free (conf_path);
896+
}
897+
g_list_free_full (files, g_free);
898+
}
899+
857900
int
858901
main (int argc, char **argv)
859902
{
@@ -1009,46 +1052,9 @@ main (int argc, char **argv)
10091052
}
10101053

10111054
/* Load config file(s) */
1055+
load_config_directory (SYSTEM_CONFIG_DIR, &messages);
10121056
if (config_d_dir)
1013-
{
1014-
GDir *dir;
1015-
GList *files = NULL, *link;
1016-
1017-
/* Find configuration files */
1018-
dir = g_dir_open (config_d_dir, 0, &error);
1019-
if (error && !g_error_matches (error, G_FILE_ERROR, G_FILE_ERROR_NOENT))
1020-
g_printerr ("Failed to open configuration directory %s: %s\n", config_d_dir, error->message);
1021-
g_clear_error (&error);
1022-
if (dir)
1023-
{
1024-
const gchar *name;
1025-
while ((name = g_dir_read_name (dir)))
1026-
files = g_list_append (files, g_strdup (name));
1027-
g_dir_close (dir);
1028-
}
1029-
1030-
/* Sort alphabetically and load onto existing configuration */
1031-
files = g_list_sort (files, compare_strings);
1032-
for (link = files; link; link = link->next)
1033-
{
1034-
gchar *filename = link->data;
1035-
gchar *path;
1036-
1037-
path = g_build_filename (config_d_dir, filename, NULL);
1038-
if (g_str_has_suffix (filename, ".conf"))
1039-
{
1040-
messages = g_list_append (messages, g_strdup_printf ("Loading configuration from %s", path));
1041-
config_load_from_file (config_get_instance (), path, &error);
1042-
if (error && !g_error_matches (error, G_FILE_ERROR, G_FILE_ERROR_NOENT))
1043-
g_printerr ("Failed to load configuration from %s: %s\n", filename, error->message);
1044-
g_clear_error (&error);
1045-
}
1046-
else
1047-
g_debug ("Ignoring configuration file %s, it does not have .conf suffix", path);
1048-
g_free (path);
1049-
}
1050-
g_list_free_full (files, g_free);
1051-
}
1057+
load_config_directory (config_d_dir, &messages);
10521058
g_free (config_d_dir);
10531059
messages = g_list_append (messages, g_strdup_printf ("Loading configuration from %s", config_path));
10541060
if (!config_load_from_file (config_get_instance (), config_path, &error))

tests/Makefile.am

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ TESTS = \
1414
test-no-config \
1515
test-additional-config \
1616
test-additional-config-priority \
17+
test-additional-system-config \
18+
test-additional-system-config-priority \
1719
test-headless \
1820
test-autologin \
1921
test-autologin-in-background \
@@ -280,6 +282,8 @@ EXTRA_DIST = \
280282
scripts/1-additional.conf \
281283
scripts/additional-config.conf \
282284
scripts/additional-config-priority.conf \
285+
scripts/additional-system-config.conf \
286+
scripts/additional-system-config-priority.conf \
283287
scripts/autologin.conf \
284288
scripts/autologin-guest.conf \
285289
scripts/autologin-guest-fail-setup-script.conf \
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#
2+
# Check LightDM runs with system config.d configuration and the value from /etc is used
3+
#
4+
5+
[test-runner-config]
6+
additional-system-config=0-additional.conf
7+
additional-config=1-additional.conf
8+
9+
[SeatDefaults]
10+
user-session=default
11+
12+
#?RUNNER DAEMON-START
13+
14+
# X server starts
15+
#?XSERVER-0 START VT=7
16+
17+
# Daemon connects when X server is ready
18+
#?*XSERVER-0 INDICATE-READY
19+
#?XSERVER-0 INDICATE-READY
20+
#?XSERVER-0 ACCEPT-CONNECT
21+
22+
# Session starts
23+
#?SESSION-X-0 START XDG_SEAT=seat0 XDG_VTNR=7 USER=have-password2
24+
#?XSERVER-0 ACCEPT-CONNECT
25+
#?SESSION-X-0 CONNECT-XSERVER
26+
27+
# Cleanup
28+
#?*STOP-DAEMON
29+
#?SESSION-X-0 TERMINATE SIGNAL=15
30+
#?XSERVER-0 TERMINATE SIGNAL=15
31+
#?RUNNER DAEMON-EXIT STATUS=0
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#
2+
# Check LightDM runs with system-config.d configuration and the value from the last file is used
3+
#
4+
5+
[test-runner-config]
6+
additional-system-config=0-additional.conf 1-additional.conf
7+
8+
[SeatDefaults]
9+
user-session=default
10+
11+
#?RUNNER DAEMON-START
12+
13+
# X server starts
14+
#?XSERVER-0 START VT=7
15+
16+
# Daemon connects when X server is ready
17+
#?*XSERVER-0 INDICATE-READY
18+
#?XSERVER-0 INDICATE-READY
19+
#?XSERVER-0 ACCEPT-CONNECT
20+
21+
# Session starts
22+
#?SESSION-X-0 START XDG_SEAT=seat0 XDG_VTNR=7 USER=have-password2
23+
#?XSERVER-0 ACCEPT-CONNECT
24+
#?SESSION-X-0 CONNECT-XSERVER
25+
26+
# Cleanup
27+
#?*STOP-DAEMON
28+
#?SESSION-X-0 TERMINATE SIGNAL=15
29+
#?XSERVER-0 TERMINATE SIGNAL=15
30+
#?RUNNER DAEMON-EXIT STATUS=0

tests/src/test-runner.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1806,7 +1806,8 @@ main (int argc, char **argv)
18061806
{
18071807
GMainLoop *loop;
18081808
int i;
1809-
gchar *greeter = NULL, *script_name, *config_file, *additional_config, *path, *path1, *path2, *ld_preload, *ld_library_path, *home_dir;
1809+
gchar *greeter = NULL, *script_name, *config_file, *additional_system_config;
1810+
gchar *additional_config, *path, *path1, *path2, *ld_preload, *ld_library_path, *home_dir;
18101811
GString *passwd_data, *group_data;
18111812
GSource *status_source;
18121813
gchar cwd[1024];
@@ -1940,6 +1941,20 @@ main (int argc, char **argv)
19401941
if (system (g_strdup_printf ("cp %s %s/etc/lightdm/lightdm.conf", config_path, temp_dir)))
19411942
perror ("Failed to copy configuration");
19421943

1944+
additional_system_config = g_key_file_get_string (config, "test-runner-config", "additional-system-config", NULL);
1945+
if (additional_system_config)
1946+
{
1947+
gchar **files;
1948+
1949+
g_mkdir_with_parents (g_strdup_printf ("%s/usr/share/lightdm/lightdm.conf.d", temp_dir), 0755);
1950+
1951+
files = g_strsplit (additional_system_config, " ", -1);
1952+
for (i = 0; files[i]; i++)
1953+
if (system (g_strdup_printf ("cp %s/tests/scripts/%s %s/usr/share/lightdm/lightdm.conf.d", SRCDIR, files[i], temp_dir)))
1954+
perror ("Failed to copy configuration");
1955+
g_strfreev (files);
1956+
}
1957+
19431958
additional_config = g_key_file_get_string (config, "test-runner-config", "additional-config", NULL);
19441959
if (additional_config)
19451960
{

tests/test-additional-system-config

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/sh
2+
./src/dbus-env ./src/test-runner additional-system-config test-gobject-greeter
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/sh
2+
./src/dbus-env ./src/test-runner additional-system-config-priority test-gobject-greeter

0 commit comments

Comments
 (0)