X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Fshared%2Futil.c;h=b516b9b0532e5163593487e7fc7f6a1e41aa5029;hp=760013c1fb5b95128391e140845389e61436dc8e;hb=e62d8c3944745ed276e6d4f33153009860e5cfc5;hpb=3c8bed4ee061f96acb4d70a591a9849bddd2a659 diff --git a/src/shared/util.c b/src/shared/util.c index 760013c1f..b516b9b05 100644 --- a/src/shared/util.c +++ b/src/shared/util.c @@ -1873,18 +1873,18 @@ int flush_fd(int fd) { ssize_t l; int r; - if ((r = poll(&pollfd, 1, 0)) < 0) { - + r = poll(&pollfd, 1, 0); + if (r < 0) { if (errno == EINTR) continue; return -errno; - } - if (r == 0) + } else if (r == 0) return 0; - if ((l = read(fd, buf, sizeof(buf))) < 0) { + l = read(fd, buf, sizeof(buf)); + if (l < 0) { if (errno == EINTR) continue; @@ -1893,9 +1893,7 @@ int flush_fd(int fd) { return 0; return -errno; - } - - if (l <= 0) + } else if (l == 0) return 0; } } @@ -2068,10 +2066,12 @@ fail: } int release_terminal(void) { - int r = 0, fd; + int r = 0; struct sigaction sa_old, sa_new; + int _cleanup_close_ fd; - if ((fd = open("/dev/tty", O_RDWR|O_NOCTTY|O_NDELAY|O_CLOEXEC)) < 0) + fd = open("/dev/tty", O_RDWR|O_NOCTTY|O_NDELAY|O_CLOEXEC); + if (fd < 0) return -errno; /* Temporarily ignore SIGHUP, so that we don't get SIGHUP'ed @@ -2087,7 +2087,6 @@ int release_terminal(void) { assert_se(sigaction(SIGHUP, &sa_old, NULL) == 0); - close_nointr_nofail(fd); return r; }