diff options
author | Michal Schmidt <mschmidt@redhat.com> | 2013-02-28 01:30:38 +0100 |
---|---|---|
committer | Michal Schmidt <mschmidt@redhat.com> | 2013-02-28 02:23:53 +0100 |
commit | 21baf21ae526d0180177cf4a26ce82d45b6103e2 (patch) | |
tree | 0716715dba6b8ee9f7cd65e723cc8c80c9f7c4b4 /src | |
parent | 546ac4f0078228ef0bdd764dc7566cacf684c562 (diff) |
util: split resolving of /dev/console into a new function
Diffstat (limited to 'src')
-rw-r--r-- | src/shared/util.c | 41 | ||||
-rw-r--r-- | src/shared/util.h | 1 |
2 files changed, 29 insertions, 13 deletions
diff --git a/src/shared/util.c b/src/shared/util.c index cc415894a5..e643cd367c 100644 --- a/src/shared/util.c +++ b/src/shared/util.c @@ -3509,6 +3509,29 @@ int vtnr_from_tty(const char *tty) { return i; } +char *resolve_dev_console(char **active) { + char *tty; + + /* Resolve where /dev/console is pointing to, if /sys is actually ours + * (i.e. not read-only-mounted which is a sign for container setups) */ + + if (path_is_read_only_fs("/sys") > 0) + return NULL; + + if (read_one_line_file("/sys/class/tty/console/active", active) < 0) + return NULL; + + /* If multiple log outputs are configured the last one is what + * /dev/console points to */ + tty = strrchr(*active, ' '); + if (tty) + tty++; + else + tty = *active; + + return tty; +} + bool tty_is_vc_resolve(const char *tty) { char *active = NULL; bool b; @@ -3518,19 +3541,11 @@ bool tty_is_vc_resolve(const char *tty) { if (startswith(tty, "/dev/")) tty += 5; - /* Resolve where /dev/console is pointing to, if /sys is - * actually ours (i.e. not read-only-mounted which is a sign - * for container setups) */ - if (streq(tty, "console") && path_is_read_only_fs("/sys") <= 0) - if (read_one_line_file("/sys/class/tty/console/active", &active) >= 0) { - /* If multiple log outputs are configured the - * last one is what /dev/console points to */ - tty = strrchr(active, ' '); - if (tty) - tty++; - else - tty = active; - } + if (streq(tty, "console")) { + tty = resolve_dev_console(&active); + if (!tty) + return false; + } b = tty_is_vc(tty); free(active); diff --git a/src/shared/util.h b/src/shared/util.h index f8957bca42..555e1d8665 100644 --- a/src/shared/util.h +++ b/src/shared/util.h @@ -389,6 +389,7 @@ DIR *xopendirat(int dirfd, const char *name, int flags); char *fstab_node_to_udev_node(const char *p); +char *resolve_dev_console(char **active); bool tty_is_vc(const char *tty); bool tty_is_vc_resolve(const char *tty); bool tty_is_console(const char *tty); |