summaryrefslogtreecommitdiff
path: root/src/shared/generator.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2015-04-30 20:21:00 +0200
committerLennart Poettering <lennart@poettering.net>2015-05-05 15:06:42 -0700
commit7410616cd9dbbec97cf98d75324da5cda2b2f7a2 (patch)
tree6d968995b3bdf961603ab4853bf078c0dbdce27c /src/shared/generator.c
parent6442185ab674cc202d63c18605057b9a51ca2722 (diff)
core: rework unit name validation and manipulation logic
A variety of changes: - Make sure all our calls distuingish OOM from other errors if OOM is not the only error possible. - Be much stricter when parsing escaped paths, do not accept trailing or leading escaped slashes. - Change unit validation to take a bit mask for allowing plain names, instance names or template names or an combination thereof. - Refuse manipulating invalid unit name
Diffstat (limited to 'src/shared/generator.c')
-rw-r--r--src/shared/generator.c18
1 files changed, 9 insertions, 9 deletions
diff --git a/src/shared/generator.c b/src/shared/generator.c
index 7b2f846175..2dc34bf738 100644
--- a/src/shared/generator.c
+++ b/src/shared/generator.c
@@ -37,6 +37,8 @@ int generator_write_fsck_deps(
const char *where,
const char *fstype) {
+ int r;
+
assert(f);
assert(dir);
assert(what);
@@ -48,7 +50,6 @@ int generator_write_fsck_deps(
}
if (!isempty(fstype) && !streq(fstype, "auto")) {
- int r;
r = fsck_exists(fstype);
if (r == -ENOENT) {
/* treat missing check as essentially OK */
@@ -70,9 +71,9 @@ int generator_write_fsck_deps(
} else {
_cleanup_free_ char *fsck = NULL;
- fsck = unit_name_from_path_instance("systemd-fsck", what, ".service");
- if (!fsck)
- return log_oom();
+ r = unit_name_from_path_instance("systemd-fsck", what, ".service", &fsck);
+ if (r < 0)
+ return log_error_errno(r, "Failed to create fsck service name: %m");
fprintf(f,
"RequiresOverridable=%1$s\n"
@@ -106,8 +107,7 @@ int generator_write_timeouts(
r = parse_sec(timeout, &u);
if (r < 0) {
- log_warning("Failed to parse timeout for %s, ignoring: %s",
- where, timeout);
+ log_warning("Failed to parse timeout for %s, ignoring: %s", where, timeout);
return 0;
}
@@ -115,9 +115,9 @@ int generator_write_timeouts(
if (!node)
return log_oom();
- unit = unit_name_from_path(node, ".device");
- if (!unit)
- return log_oom();
+ r = unit_name_from_path(node, ".device", &unit);
+ if (r < 0)
+ return log_error_errno(r, "Failed to make unit name from path: %m");
return write_drop_in_format(dir, unit, 50, "device-timeout",
"# Automatically generated by %s\n\n"