summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/Makemodule.am5
-rw-r--r--lib/consoles.c27
2 files changed, 32 insertions, 0 deletions
diff --git a/lib/Makemodule.am b/lib/Makemodule.am
index 8e2b4eea4..bfe6471b2 100644
--- a/lib/Makemodule.am
+++ b/lib/Makemodule.am
@@ -60,6 +60,7 @@ endif
check_PROGRAMS += \
test_sysfs \
test_loopdev \
+ test_consoles \
test_pager
endif
@@ -102,6 +103,10 @@ test_pager_CFLAGS = -DTEST_PROGRAM
test_loopdev_SOURCES = lib/loopdev.c
test_loopdev_CFLAGS = -DTEST_PROGRAM_LOOPDEV
test_loopdev_LDADD = libcommon.la
+
+test_consoles_SOURCES = lib/consoles.c
+test_consoles_CFLAGS = -DTEST_PROGRAM
+test_consoles_LDADD = libcommon.la
endif
test_fileutils_SOURCES = lib/fileutils.c
diff --git a/lib/consoles.c b/lib/consoles.c
index cd6a17ad8..c9a9f0ba5 100644
--- a/lib/consoles.c
+++ b/lib/consoles.c
@@ -498,3 +498,30 @@ fallback:
return ret;
}
+
+#ifdef TEST_PROGRAM
+int main(int argc, char *argv[])
+{
+ char *name = NULL;
+ int fd, re;
+ struct console *p, *consoles = NULL;
+
+ if (argc == 2) {
+ name = argv[1];
+ fd = open(name, O_RDWR);
+ } else {
+ name = ttyname(STDIN_FILENO);
+ fd = STDIN_FILENO;
+ }
+
+ if (!name)
+ errx(EXIT_FAILURE, "usage: %s [<tty>]\n", program_invocation_short_name);
+
+ re = detect_consoles(name, fd, &consoles);
+
+ for (p = consoles; p; p = p->next)
+ printf("%s: id=%d %s\n", p->tty, p->id, re ? "(reconnect) " : "");
+
+ return 0;
+}
+#endif