From 7410616cd9dbbec97cf98d75324da5cda2b2f7a2 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 30 Apr 2015 20:21:00 +0200 Subject: 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 --- src/getty-generator/getty-generator.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'src/getty-generator') diff --git a/src/getty-generator/getty-generator.c b/src/getty-generator/getty-generator.c index d4688d304f..d23caab44a 100644 --- a/src/getty-generator/getty-generator.c +++ b/src/getty-generator/getty-generator.c @@ -50,13 +50,11 @@ static int add_symlink(const char *fservice, const char *tservice) { r = symlink(from, to); if (r < 0) { + /* In case console=hvc0 is passed this will very likely result in EEXIST */ if (errno == EEXIST) - /* In case console=hvc0 is passed this will very likely result in EEXIST */ return 0; - else { - log_error_errno(errno, "Failed to create symlink %s: %m", to); - return -errno; - } + + return log_error_errno(errno, "Failed to create symlink %s: %m", to); } return 0; @@ -64,28 +62,30 @@ static int add_symlink(const char *fservice, const char *tservice) { static int add_serial_getty(const char *tty) { _cleanup_free_ char *n = NULL; + int r; assert(tty); log_debug("Automatically adding serial getty for /dev/%s.", tty); - n = unit_name_from_path_instance("serial-getty", tty, ".service"); - if (!n) - return log_oom(); + r = unit_name_from_path_instance("serial-getty", tty, ".service", &n); + if (r < 0) + return log_error_errno(r, "Failed to generate service name: %m"); return add_symlink("serial-getty@.service", n); } static int add_container_getty(const char *tty) { _cleanup_free_ char *n = NULL; + int r; assert(tty); log_debug("Automatically adding container getty for /dev/pts/%s.", tty); - n = unit_name_from_path_instance("container-getty", tty, ".service"); - if (!n) - return log_oom(); + r = unit_name_from_path_instance("container-getty", tty, ".service", &n); + if (r < 0) + return log_error_errno(r, "Failed to generate service name: %m"); return add_symlink("container-getty@.service", n); } -- cgit v1.2.1