summaryrefslogtreecommitdiff
path: root/src/shared/install-printf.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/shared/install-printf.c')
-rw-r--r--src/shared/install-printf.c46
1 files changed, 24 insertions, 22 deletions
diff --git a/src/shared/install-printf.c b/src/shared/install-printf.c
index aaab2e6665..078d5734be 100644
--- a/src/shared/install-printf.c
+++ b/src/shared/install-printf.c
@@ -1,22 +1,4 @@
/* SPDX-License-Identifier: LGPL-2.1+ */
-/***
- This file is part of systemd.
-
- Copyright 2013 Zbigniew Jędrzejewski-Szmek
-
- systemd is free software; you can redistribute it and/or modify it
- under the terms of the GNU Lesser General Public License as published by
- the Free Software Foundation; either version 2.1 of the License, or
- (at your option) any later version.
-
- systemd is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public License
- along with systemd; If not, see <http://www.gnu.org/licenses/>.
-***/
#include <errno.h>
#include <stdio.h>
@@ -50,10 +32,8 @@ static int specifier_prefix_and_instance(char specifier, void *data, void *userd
if (!ans)
return -ENOMEM;
*ret = ans;
- } else {
- *ret = prefix;
- prefix = NULL;
- }
+ } else
+ *ret = TAKE_PTR(prefix);
return 0;
}
@@ -103,6 +83,27 @@ static int specifier_instance(char specifier, void *data, void *userdata, char *
return 0;
}
+static int specifier_last_component(char specifier, void *data, void *userdata, char **ret) {
+ _cleanup_free_ char *prefix = NULL;
+ char *dash;
+ int r;
+
+ r = specifier_prefix(specifier, data, userdata, &prefix);
+ if (r < 0)
+ return r;
+
+ dash = strrchr(prefix, '-');
+ if (dash) {
+ dash = strdup(dash + 1);
+ if (!dash)
+ return -ENOMEM;
+ *ret = dash;
+ } else
+ *ret = TAKE_PTR(prefix);
+
+ return 0;
+}
+
int install_full_printf(UnitFileInstallInfo *i, const char *format, char **ret) {
/* This is similar to unit_full_printf() but does not support
@@ -126,6 +127,7 @@ int install_full_printf(UnitFileInstallInfo *i, const char *format, char **ret)
{ 'N', specifier_prefix_and_instance, NULL },
{ 'p', specifier_prefix, NULL },
{ 'i', specifier_instance, NULL },
+ { 'j', specifier_last_component, NULL },
{ 'U', specifier_user_id, NULL },
{ 'u', specifier_user_name, NULL },