[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH] poke: Prefer ${XDG_CONFIG_HOME:-$HOME/.config} to XDG_CONFIG
From: |
Jose E. Marchesi |
Subject: |
Re: [PATCH] poke: Prefer ${XDG_CONFIG_HOME:-$HOME/.config} to XDG_CONFIG_DIRS |
Date: |
Sun, 25 Sep 2022 12:57:00 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) |
Hello.
Thank you very much for the patch.
I just pushed it to master on your behalf.
> Some DEs (namely, KDE) set the latter without setting $XDG_CONFIG_HOME,
> because the XDG specification says:
>
> Specifications may reference this specification by specifying the
> location of a configuration file as
> $XDG_CONFIG_DIRS/subdir/filename. This implies that:
>
> ...
> - A user-specific version of the configuration file may be created
> in $XDG_CONFIG_HOME/subdir/filename, taking into account the
> default value for $XDG_CONFIG_HOME if $XDG_CONFIG_HOME is not set.
> ...
>
> It is implied (and also followed by other programs) that the default
> value of XDG_CONFIG_HOME should be preferred to $XDG_CONFIG_DIRS, even
> when the former is not set but the latter is. This also seems to be in
> the spirit of the standard, which treats XDG_CONFIG_HOME as a writable
> location (so, the program can modify it in accordance with the users
> wishes), while treating XDG_CONFIG_DIRS as read only locations, normally
> for default values or distro-provided overrides.
>
> 2022-09-24 Arsen Arsenović <arsen@aarsen.me>
>
> * poke/poke.c: Prefer $XDG_CONFIG_HOME to $XDG_CONFIG_DIRS, even
> when unset.
> ---
> Hey there,
>
> This is the fix for the minor bug I noticed today while in the BBB meeting.
>
> An implementation note: I chose to strdup () the getenv () result, so that it
> can be validly freed (normally, freeing a getenv result is at least UB) over
> carrying a "should free" value. This is slightly simpler, avoids a GCC warning
> about discarding const, and shouldn't have much of an impact, since it's early
> in the startup procedure.
>
> Thanks in advance!
>
> poke/poke.c | 22 +++++++++++++++++++---
> 1 file changed, 19 insertions(+), 3 deletions(-)
>
> diff --git a/poke/poke.c b/poke/poke.c
> index b3849664..7b258410 100644
> --- a/poke/poke.c
> +++ b/poke/poke.c
> @@ -698,16 +698,31 @@ initialize_user (void)
> use all the : separated paths in that variable to find
> pokerc.conf. Else, try to load /etc/xdg/poke/pokerc.conf. */
> {
> - const char *xdg_config_home = getenv ("XDG_CONFIG_HOME");
> + char *xdg_config_home = getenv ("XDG_CONFIG_HOME");
> const char *xdg_config_dirs = getenv ("XDG_CONFIG_DIRS");
>
> if (xdg_config_home == NULL)
> - xdg_config_home = "";
> + {
> + /* If unset, the default value of $HOME/.config should be preferred
> to
> + the paths in $XDG_CONFIG_DIRS. From the standard:
> +
> + A user-specific version of the configuration file may be created
> in
> + $XDG_CONFIG_HOME/subdir/filename, taking into account the default
> + value for $XDG_CONFIG_HOME if $XDG_CONFIG_HOME is not set. */
> + xdg_config_home = pk_str_concat (getenv("HOME"), "/.config", NULL);
> + pk_assert_alloc (xdg_config_home);
> + }
> + else
> + {
> + /* strdup() the user-provided value, to free it below. */
> + xdg_config_home = strdup(xdg_config_home);
> + pk_assert_alloc (xdg_config_home);
> + }
>
> if (xdg_config_dirs == NULL)
> xdg_config_dirs = "/etc/xdg";
>
> - char *config_path = pk_str_concat (xdg_config_dirs, ":",
> xdg_config_home, NULL);
> + char *config_path = pk_str_concat (xdg_config_home, ":",
> xdg_config_dirs, NULL);
> pk_assert_alloc (config_path);
>
> char *dir = strtok (config_path, ":");
> @@ -736,6 +751,7 @@ initialize_user (void)
> while ((dir = strtok (NULL, ":")) != NULL);
>
> free (config_path);
> + free (xdg_config_home);
> }
> }