aboutsummaryrefslogtreecommitdiffstats
path: root/src/xdg-autostart-generator/xdg-autostart-service.c
diff options
context:
space:
mode:
authorDavid Edmundson <kde@davidedmundson.co.uk>2022-09-14 19:21:00 +0100
committerYu Watanabe <watanabe.yu+github@gmail.com>2022-09-16 03:43:17 +0900
commit8c0a6a96fe04f97966b86ec91ee4502f5d4fa8d8 (patch)
treed65d81dcaabaaa6862054f6ce72c8de3cb72b66c /src/xdg-autostart-generator/xdg-autostart-service.c
parentunit: drop ProtectClock=yes from systemd-udevd.service (diff)
downloadsystemd-8c0a6a96fe04f97966b86ec91ee4502f5d4fa8d8.tar.xz
systemd-8c0a6a96fe04f97966b86ec91ee4502f5d4fa8d8.zip
xdg-autostart-service: expand tilde in Exec lines
In typical desktop file parsing it is expected that "~" expands to a home directory. Users may write an autostart file with "Exec=myCoolService ~/.someSpecialConfig" which worked before the systemd migration.
Diffstat (limited to 'src/xdg-autostart-generator/xdg-autostart-service.c')
-rw-r--r--src/xdg-autostart-generator/xdg-autostart-service.c20
1 files changed, 18 insertions, 2 deletions
diff --git a/src/xdg-autostart-generator/xdg-autostart-service.c b/src/xdg-autostart-generator/xdg-autostart-service.c
index 56cc4ceeb9a..5aa74fe37a4 100644
--- a/src/xdg-autostart-generator/xdg-autostart-service.c
+++ b/src/xdg-autostart-generator/xdg-autostart-service.c
@@ -18,6 +18,7 @@
#include "string-util.h"
#include "strv.h"
#include "unit-name.h"
+#include "user-util.h"
XdgAutostartService* xdg_autostart_service_free(XdgAutostartService *s) {
if (!s)
@@ -392,7 +393,7 @@ int xdg_autostart_format_exec_start(
first_arg = true;
for (i = n = 0; exec_split[i]; i++) {
- _cleanup_free_ char *c = NULL, *raw = NULL, *percent = NULL;
+ _cleanup_free_ char *c = NULL, *raw = NULL, *percent = NULL, *tilde_expanded = NULL;
ssize_t l;
l = cunescape(exec_split[i], 0, &c);
@@ -441,7 +442,22 @@ int xdg_autostart_format_exec_start(
if (!percent)
return log_oom();
- free_and_replace(exec_split[n++], percent);
+ /*
+ * Expand ~ if it comes at the beginning of an argument to form a path
+ */
+ if (percent[0] == '~' && (isempty(percent + 1) || path_is_absolute(percent + 1))) {
+ _cleanup_free_ char *home = NULL;
+
+ r = get_home_dir(&home);
+ if (r < 0)
+ return r;
+
+ tilde_expanded = strjoin(home, &percent[1]);
+ if (!tilde_expanded)
+ return log_oom();
+ free_and_replace(exec_split[n++], tilde_expanded);
+ } else
+ free_and_replace(exec_split[n++], percent);
}
for (; exec_split[n]; n++)
exec_split[n] = mfree(exec_split[n]);