]> git.mdlowis.com Git - proto/labwc.git/commitdiff
session: sort directory entries in environment.d
authorAndrew J. Hesford <ajh@sideband.org>
Tue, 16 Apr 2024 11:11:18 +0000 (07:11 -0400)
committerConsolatis <35009135+Consolatis@users.noreply.github.com>
Tue, 16 Apr 2024 11:21:55 +0000 (13:21 +0200)
docs/labwc-config.5.scd
src/config/session.c

index e69608828347ecc3699609d59807bfbb94276af9..e3c6fcf7b1868deff5eb31f3ccb2ace2ba219f90 100644 (file)
@@ -43,11 +43,10 @@ specify keyboard layout settings and cursor size/theme here; see environment
 variable section below for details. Within an XDG Base Directory, a file named
 "environment" will be parsed first, followed by any file matching the glob
 "environment.d/\*.env". Files within the environment.d directory are parsed in
-an arbitrary order; any variables that must be set in a particular sequence
-should be set within the same file. Unless the --merge-config option is
-specified, labwc will consider a particular XDG Base Directory to have provided
-an environment file if that directory contains either the "environment"
-file or at least one "environment.d/\*.env" file.
+alphabetical order. Unless the --merge-config option is specified, labwc will
+consider a particular XDG Base Directory to have provided an environment file if
+that directory contains either the "environment" file or at least one
+"environment.d/\*.env" file.
 
 Note: environment files are treated differently by Openbox, which will simply
 source the file as a valid shell script before running the window manager. Files
index ee56b548991c6d169c9cb111e8b4000e91392bdf..f2d573f7ceb1de00716d67dc8b5fed880f4dd9fd 100644 (file)
@@ -86,11 +86,6 @@ strdup_env_path_validate(const char *prefix, struct dirent *dirent)
 {
        assert(prefix);
 
-       /* Valid environment files always end in '.env' */
-       if (!str_endswith(dirent->d_name, ".env")) {
-               return NULL;
-       }
-
        char *full_path = strdup_printf("%s/%s", prefix, dirent->d_name);
        if (!full_path) {
                return NULL;
@@ -106,16 +101,25 @@ strdup_env_path_validate(const char *prefix, struct dirent *dirent)
        return NULL;
 }
 
+static int
+env_file_filter(const struct dirent *dirent)
+{
+       /* Valid environment files always end in '.env' */
+       return str_endswith(dirent->d_name, ".env");
+}
+
 static bool
 read_environment_dir(const char *path_prefix)
 {
        bool success = false;
        char *path = strdup_printf("%s.d", path_prefix);
 
+       struct dirent **dirlist = NULL;
+
        errno = 0;
-       DIR *envdir = opendir(path);
+       int num_entries = scandir(path, &dirlist, env_file_filter, alphasort);
 
-       if (!envdir) {
+       if (num_entries < 0) {
                if (errno != ENOENT) {
                        const char *err_msg = strerror(errno);
                        wlr_log(WLR_INFO,
@@ -126,9 +130,10 @@ read_environment_dir(const char *path_prefix)
                goto env_dir_cleanup;
        }
 
-       struct dirent *dirent;
-       while ((dirent = readdir(envdir)) != NULL) {
-               char *env_file_path = strdup_env_path_validate(path, dirent);
+       for (int i = 0; i < num_entries; i++) {
+               char *env_file_path = strdup_env_path_validate(path, dirlist[i]);
+               free(dirlist[i]);
+
                if (!env_file_path) {
                        continue;
                }
@@ -140,7 +145,7 @@ read_environment_dir(const char *path_prefix)
                free(env_file_path);
        }
 
-       closedir(envdir);
+       free(dirlist);
 
 env_dir_cleanup:
        free(path);