diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2016-10-20 00:27:46 -0400 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2016-10-20 09:12:42 -0400 |
commit | 6e3136b209679d88c4347ce2f6d5e22c031e4d3e (patch) | |
tree | d9148b74b9236bca3e156238348abb5fe7204995 /src/shared/install-printf.c | |
parent | 5368222db6093195dbbd5fc7418508b154b1b769 (diff) |
shared/install: fix DefaultInstance expansion in %i
We should substitute DefaultInstance if the instance is not specified.
Test case:
[Install]
DefaultInstance=bond1
WantedBy= foobar-i-%i.device
$ systemctl --root=/ enable testing4@.service
Created symlink /etc/systemd/system/foobar-i-bond1.device.wants/testing4@bond1.service
→ /etc/systemd/system/testing4@.service.
(before, the symlink would be created as
/etc/systemd/system/foobar-i-.device.wants/testing4@bond1.service)
Fixes #4411.
Diffstat (limited to 'src/shared/install-printf.c')
-rw-r--r-- | src/shared/install-printf.c | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/src/shared/install-printf.c b/src/shared/install-printf.c index 88143361da..9fc915d62e 100644 --- a/src/shared/install-printf.c +++ b/src/shared/install-printf.c @@ -27,6 +27,7 @@ #include "install.h" #include "macro.h" #include "specifier.h" +#include "string-util.h" #include "unit-name.h" #include "user-util.h" @@ -47,7 +48,7 @@ static int specifier_prefix(char specifier, void *data, void *userdata, char **r } static int specifier_instance(char specifier, void *data, void *userdata, char **ret) { - UnitFileInstallInfo *i = userdata; + const UnitFileInstallInfo *i = userdata; char *instance; int r; @@ -57,8 +58,8 @@ static int specifier_instance(char specifier, void *data, void *userdata, char * if (r < 0) return r; - if (!instance) { - instance = strdup(""); + if (isempty(instance)) { + instance = strdup(i->default_instance ?: ""); if (!instance) return -ENOMEM; } |