]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lib/consoles: add test program
authorKarel Zak <kzak@redhat.com>
Fri, 9 Nov 2012 09:12:35 +0000 (10:12 +0100)
committerKarel Zak <kzak@redhat.com>
Fri, 9 Nov 2012 09:12:35 +0000 (10:12 +0100)
Signed-off-by: Karel Zak <kzak@redhat.com>
lib/Makemodule.am
lib/consoles.c

index 8e2b4eea4dad9eea9e564ccf42d6fd1dec0c0852..bfe6471b2d0301d3ccff88c0f37aeb8ef8c838cf 100644 (file)
@@ -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
index cd6a17ad8395ab2969adf660cf939832c4c96281..c9a9f0ba585f70f371e642503f6f77622292be4a 100644 (file)
@@ -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