lib/consoles: add test program

Signed-off-by: Karel Zak <kzak@redhat.com>
This commit is contained in:
Karel Zak 2012-11-09 10:12:35 +01:00
parent cf987d0aa7
commit 82d11fbd0f
2 changed files with 32 additions and 0 deletions

View 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

View 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