summaryrefslogtreecommitdiff
path: root/src/shared/util.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2012-04-22 01:59:11 +0200
committerLennart Poettering <lennart@poettering.net>2012-04-22 01:59:11 +0200
commit3d9a412243035beeaaf3465a62065444a5adf21c (patch)
treeda4fbcd887a2baa3d514c33975a322226ba392ff /src/shared/util.c
parentd29b05a4619c000918cbb9f1b9661bc53659c0b2 (diff)
util: fix tty_is_vc_resolve() in a container where /sys/class/tty/console/active is misleading
Diffstat (limited to 'src/shared/util.c')
-rw-r--r--src/shared/util.c18
1 files changed, 16 insertions, 2 deletions
diff --git a/src/shared/util.c b/src/shared/util.c
index 15c7f4d325..43948ccbd8 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -56,6 +56,7 @@
#include <glob.h>
#include <grp.h>
#include <sys/mman.h>
+#include <sys/statvfs.h>
#include "macro.h"
#include "util.h"
@@ -4319,8 +4320,10 @@ bool tty_is_vc_resolve(const char *tty) {
if (startswith(tty, "/dev/"))
tty += 5;
- /* Resolve where /dev/console is pointing to */
- if (streq(tty, "console"))
+ /* 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 */
@@ -6145,3 +6148,14 @@ int setrlimit_closest(int resource, const struct rlimit *rlim) {
return 0;
}
+
+int path_is_read_only_fs(const char *path) {
+ struct statvfs st;
+
+ assert(path);
+
+ if (statvfs(path, &st) < 0)
+ return -errno;
+
+ return !!(st.f_flag & ST_RDONLY);
+}