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.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user