summaryrefslogtreecommitdiff
path: root/src/getty-generator/getty-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/getty-generator/getty-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/getty-generator/getty-generator.c')
-rw-r--r--src/getty-generator/getty-generator.c22
1 files changed, 11 insertions, 11 deletions
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);
}