From: Lennart Poettering Date: Tue, 13 Feb 2018 22:53:34 +0000 (+0100) Subject: terminal-util: minor, trivial fixes and improvements X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=230bfe18ff9552d549114168e805e21cc43d56f0;p=elogind.git terminal-util: minor, trivial fixes and improvements --- diff --git a/src/basic/terminal-util.c b/src/basic/terminal-util.c index aff4e8160..7eb91a6e7 100644 --- a/src/basic/terminal-util.c +++ b/src/basic/terminal-util.c @@ -331,8 +331,8 @@ int reset_terminal(const char *name) { #endif // 0 int open_terminal(const char *name, int mode) { - int fd, r; unsigned c = 0; + int fd; /* * If a TTY is in the process of being closed opening it might @@ -362,8 +362,7 @@ int open_terminal(const char *name, int mode) { c++; } - r = isatty(fd); - if (r == 0) { + if (isatty(fd) <= 0) { safe_close(fd); return -ENOTTY; } @@ -514,7 +513,7 @@ int release_terminal(void) { _cleanup_close_ int fd = -1; struct sigaction sa_old; - int r = 0; + int r; fd = open("/dev/tty", O_RDWR|O_NOCTTY|O_CLOEXEC|O_NONBLOCK); if (fd < 0) @@ -524,8 +523,7 @@ int release_terminal(void) { * by our own TIOCNOTTY */ assert_se(sigaction(SIGHUP, &sa_new, &sa_old) == 0); - if (ioctl(fd, TIOCNOTTY) < 0) - r = -errno; + r = ioctl(fd, TIOCNOTTY) < 0 ? -errno : 0; assert_se(sigaction(SIGHUP, &sa_old, NULL) == 0);