mirror of
https://github.com/clearlinux/systemd-stable.git
synced 2026-09-06 21:51:37 +00:00
sysv-generator: Handle .sh suffixes when translating Provides:
When deciding whether the provided name equals the file name in sysv_translate_facility(), also consider them equal if the file name has a ".sh" suffix. This was uncovered by commitb7e7184which then created a symlink "<name>.service" to itself for ".sh" suffixed init.d scripts. For additional robustness, refuse to create symlinks to itself in add_alias(). Add test case which reproduces the bug. https://bugs.debian.org/775889 (cherry picked from commit29e0e6d8c1) Conflicts: test/sysv-generator-test.py
This commit is contained in:
committed by
Zbigniew Jędrzejewski-Szmek
parent
260a413d76
commit
cd1694328b
@@ -119,6 +119,11 @@ static int add_alias(const char *service, const char *alias) {
|
||||
assert(service);
|
||||
assert(alias);
|
||||
|
||||
if (streq(service, alias)) {
|
||||
log_error("Ignoring creation of an alias %s for itself", service);
|
||||
return 0;
|
||||
}
|
||||
|
||||
link = strjoin(arg_dest, "/", alias, NULL);
|
||||
if (!link)
|
||||
return log_oom();
|
||||
@@ -268,6 +273,7 @@ static int sysv_translate_facility(const char *name, const char *filename, char
|
||||
unsigned i;
|
||||
char *r;
|
||||
const char *n;
|
||||
_cleanup_free_ char *filename_no_sh = NULL;
|
||||
|
||||
assert(name);
|
||||
assert(_r);
|
||||
@@ -289,6 +295,13 @@ static int sysv_translate_facility(const char *name, const char *filename, char
|
||||
goto finish;
|
||||
}
|
||||
|
||||
/* strip ".sh" suffix from file name for comparison */
|
||||
filename_no_sh = strdup(filename);
|
||||
if (!filename_no_sh)
|
||||
return -ENOMEM;
|
||||
if (endswith(filename, ".sh"))
|
||||
filename_no_sh[strlen(filename)-3] = '\0';
|
||||
|
||||
/* If we don't know this name, fallback heuristics to figure
|
||||
* out whether something is a target or a service alias. */
|
||||
|
||||
@@ -298,7 +311,7 @@ static int sysv_translate_facility(const char *name, const char *filename, char
|
||||
|
||||
/* Facilities starting with $ are most likely targets */
|
||||
r = unit_name_build(n, NULL, ".target");
|
||||
} else if (filename && streq(name, filename))
|
||||
} else if (filename && streq(name, filename_no_sh))
|
||||
/* Names equaling the file name of the services are redundant */
|
||||
return 0;
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user