summaryrefslogtreecommitdiff
path: root/util.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2010-04-10 23:36:43 +0200
committerLennart Poettering <lennart@poettering.net>2010-04-10 23:36:43 +0200
commit601f6a1e820462b1df6ff632d112bef241d556b1 (patch)
tree9157f26ccfc1397cc6bed3070dd8af8dc37ce56d /util.c
parent4fc935cad4026516035e16484fd359c778ec0acb (diff)
main: switch to primary console vt on crash
Diffstat (limited to 'util.c')
-rw-r--r--util.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/util.c b/util.c
index f3161bd7f3..f9eae6bba1 100644
--- a/util.c
+++ b/util.c
@@ -34,6 +34,9 @@
#include <sys/stat.h>
#include <fcntl.h>
#include <dirent.h>
+#include <sys/ioctl.h>
+#include <linux/vt.h>
+#include <linux/tiocl.h>
#include "macro.h"
#include "util.h"
@@ -1294,6 +1297,31 @@ bool fstype_is_network(const char *fstype) {
return false;
}
+int chvt(int vt) {
+ int fd, r = 0;
+
+ if ((fd = open("/dev/tty0", O_RDWR|O_NOCTTY|O_CLOEXEC)) < 0)
+ return -errno;
+
+ if (vt < 0) {
+ int tiocl[2] = {
+ TIOCL_GETKMSGREDIRECT,
+ 0
+ };
+
+ if (ioctl(fd, TIOCLINUX, tiocl) < 0)
+ return -errno;
+
+ vt = tiocl[0] <= 0 ? 1 : tiocl[0];
+ }
+
+ if (ioctl(fd, VT_ACTIVATE, vt) < 0)
+ r = -errno;
+
+ close_nointr(r);
+ return r;
+}
+
static const char *const ioprio_class_table[] = {
[IOPRIO_CLASS_NONE] = "none",
[IOPRIO_CLASS_RT] = "realtime",