chiark / gitweb /
terminal-util: minor, trivial fixes and improvements
authorLennart Poettering <lennart@poettering.net>
Tue, 13 Feb 2018 22:53:34 +0000 (23:53 +0100)
committerSven Eden <yamakuzure@gmx.net>
Wed, 30 May 2018 05:58:55 +0000 (07:58 +0200)
src/basic/terminal-util.c

index aff4e81601e5e75bdf2665491086d27cf45c3c76..7eb91a6e7e3197388e9fd99af24bb320f9f20d89 100644 (file)
@@ -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);