diff options
author | Karel Zak | 2012-11-09 10:12:35 +0100 |
---|---|---|
committer | Karel Zak | 2012-11-09 10:12:35 +0100 |
commit | 82d11fbd0fd37cb4bf56afa25a071408de93b8f2 (patch) | |
tree | 782940cf5f9850c87dcceac1f17a6968f6dd10ff | |
parent | lib/consoles: remove global variable consoles (diff) | |
download | kernel-qcow2-util-linux-82d11fbd0fd37cb4bf56afa25a071408de93b8f2.tar.gz kernel-qcow2-util-linux-82d11fbd0fd37cb4bf56afa25a071408de93b8f2.tar.xz kernel-qcow2-util-linux-82d11fbd0fd37cb4bf56afa25a071408de93b8f2.zip |
lib/consoles: add test program
Signed-off-by: Karel Zak <kzak@redhat.com>
-rw-r--r-- | lib/Makemodule.am | 5 | ||||
-rw-r--r-- | lib/consoles.c | 27 |
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 |