From d7a91f238b83f408fe2e2777bf1cf5c799c193dc Mon Sep 17 00:00:00 2001 From: =?utf8?q?=C5=81ukasz=20Stelmach?= Date: Thu, 30 Dec 2021 18:04:56 +0100 Subject: [PATCH] selftests/logger: check return values of open() and ioctl() MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Change-Id: I4948fa04096b15b390f2d3b5f8c701a461cfc899 Signed-off-by: Łukasz Stelmach --- tools/testing/selftests/logger/logger.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/tools/testing/selftests/logger/logger.c b/tools/testing/selftests/logger/logger.c index 35891a3..d6d4d77 100644 --- a/tools/testing/selftests/logger/logger.c +++ b/tools/testing/selftests/logger/logger.c @@ -34,7 +34,7 @@ int main(int ac, char *av[]) { .len = 6, .ptr = (uintptr_t)tag, }; - int c, fd, s; + int c, fd, s, ret; pid_t child; pthread_t tid; struct iovec vec[3]; @@ -74,6 +74,10 @@ int main(int ac, char *av[]) { setlinebuf(stdout); fd = open(device, O_WRONLY); + if (fd < 0) { + perror("open"); + exit(EXIT_FAILURE); + } if (test_mask & BIT(0)) { vec[0].iov_base = &prio; @@ -93,14 +97,22 @@ int main(int ac, char *av[]) { } } - ioctl(fd, LOGGER_SET_PRIO, prio); - ioctl(fd, LOGGER_SET_TAG, &struct_tag); + ret = ioctl(fd, LOGGER_SET_PRIO, prio); + if (ret < 0) { + perror("ioctl(SET_PRIO)"); + exit(EXIT_FAILURE); + } + ret = ioctl(fd, LOGGER_SET_TAG, &struct_tag); + if (ret < 0) { + perror("ioctl(SET_TAG)"); + exit(EXIT_FAILURE); + } if (test_mask & BIT(2)) { int count; count = write(fd, "The Foo From STDIO\n", 19); if (count != 19) - printf("count != 19\n"); + fprintf(stderr, "%d != 19\n", count); write(fd, "LINE #1\nLINE #2", 15); write(fd, " CONTINUED\nONCE", 15); -- 2.7.4