[systemd-devel] [feature request] allow instances in file.preset

Damien Robert damien.olivier.robert+systemd at gmail.com
Thu Sep 25 16:31:22 PDT 2014


[Resending to the list since I was not posting through gmane but through
gmail this time and my post was rejected because I was not subscribed to
the list. Sorry for the spam]

>From Zbigniew Jędrzejewski-Szmek, Fri 26 Sep 2014 at 01:00:11 (+0200) :
> > +                <para><literallayout><filename>$XDG_CONFIG_HOME/systemd/user-preset/*</filename>
> You seem to open an xml element, without closing it.

Oups! A hasty copy and paste from systemd.unit

> > +        _cleanup_free_ char *user_preset = NULL;
> You can define this below, where it is used.

According to CODING_STYLE it is better to declare all variables at the top
of the function.

> > -        else
> > +                if (user_config_home(&user_preset) >= 0) {
> > +                        user_preset = strappend(user_preset, "-preset");
> > +                        if (!user_preset)
> > +                                return -ENOMEM;
> > +                        r = conf_files_list(&files, ".preset", root_dir,
> > +                                            user_preset,
> > +                                            "/etc/systemd/user-preset",
> > +                                            "/usr/local/lib/systemd/user-preset",
> > +                                            "/usr/lib/systemd/user-preset",
> > +                                            NULL);
> > +                }
> > +                else
> > +                        r = conf_files_list(&files, ".preset", root_dir,
> > +                                            "/etc/systemd/user-preset",
> > +                                            "/usr/local/lib/systemd/user-preset",
> > +                                            "/usr/lib/systemd/user-preset",
> > +                                            NULL);
> Please align all the if's at the same level, not nested.

In fact they are part of the outer 'else if () {' and i was missing some
brackets. Here is an updated patch, but I really need to test it inside a
container first; I'll send you a real version asap.

Thanks for your comments!

-------------- 8< -------------------
From: Damien Robert <damien.olivier.robert+git at gmail.com>
Date: Fri, 26 Sep 2014 00:34:46 +0200
Subject: [PATCH 1/1] preset: read files in $XDG_CONFIG_HOME/systemd/user-preset/*

This is the only way for a user to modify preset files as the other
directory read
       /run/systemd/user-preset/*.preset
       /usr/lib/systemd/user-preset/*.preset
are not user owned.

Signed-off-by: Damien Robert <damien.olivier.robert+git at gmail.com>
---
 man/systemd.preset.xml |  1 +
 src/shared/install.c   | 26 ++++++++++++++++++++------
 2 files changed, 21 insertions(+), 6 deletions(-)

diff --git a/man/systemd.preset.xml b/man/systemd.preset.xml
index 55cb4de..3a45cbd 100644
--- a/man/systemd.preset.xml
+++ b/man/systemd.preset.xml
@@ -49,6 +49,7 @@
                 <para><filename>/etc/systemd/system-preset/*.preset</filename></para>
                 <para><filename>/run/systemd/system-preset/*.preset</filename></para>
                 <para><filename>/usr/lib/systemd/system-preset/*.preset</filename></para>
+                <para><literallayout><filename>$XDG_CONFIG_HOME/systemd/user-preset/*</filename></literallayout></para>
                 <para><filename>/etc/systemd/user-preset/*.preset</filename></para>
                 <para><filename>/run/systemd/user-preset/*.preset</filename></para>
                 <para><filename>/usr/lib/systemd/user-preset/*.preset</filename></para>
diff --git a/src/shared/install.c b/src/shared/install.c
index 61e572b..b666b96 100644
--- a/src/shared/install.c
+++ b/src/shared/install.c
@@ -1769,6 +1769,7 @@ UnitFileState unit_file_get_state(
 
 int unit_file_query_preset(UnitFileScope scope, const char *root_dir, const char *name) {
         _cleanup_strv_free_ char **files = NULL;
+        _cleanup_free_ char *user_preset = NULL;
         char **p;
         int r;
 
@@ -1785,12 +1786,25 @@ int unit_file_query_preset(UnitFileScope scope, const char *root_dir, const char
                                     "/lib/systemd/system-preset",
 #endif
                                     NULL);
-        else if (scope == UNIT_FILE_GLOBAL)
-                r = conf_files_list(&files, ".preset", root_dir,
-                                    "/etc/systemd/user-preset",
-                                    "/usr/local/lib/systemd/user-preset",
-                                    "/usr/lib/systemd/user-preset",
-                                    NULL);
+        else if (scope == UNIT_FILE_GLOBAL) {
+                if (user_config_home(&user_preset) >= 0) {
+                        user_preset = strappend(user_preset, "-preset");
+                        if (!user_preset)
+                                return -ENOMEM;
+                        r = conf_files_list(&files, ".preset", root_dir,
+                                            user_preset,
+                                            "/etc/systemd/user-preset",
+                                            "/usr/local/lib/systemd/user-preset",
+                                            "/usr/lib/systemd/user-preset",
+                                            NULL);
+                }
+                else
+                        r = conf_files_list(&files, ".preset", root_dir,
+                                            "/etc/systemd/user-preset",
+                                            "/usr/local/lib/systemd/user-preset",
+                                            "/usr/lib/systemd/user-preset",
+                                            NULL);
+        }
         else
                 return 1;
 
-- 
Patched on top of v216-385-g79d80fc (git version 2.1.0)


More information about the systemd-devel mailing list