summaryrefslogtreecommitdiff
path: root/src/shared/util.c
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2013-03-24 19:45:16 -0400
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2013-03-31 14:36:12 -0400
commite62d8c3944745ed276e6d4f33153009860e5cfc5 (patch)
treee7f70ed3b80581017b6340723ab6f1d6b9c30bad /src/shared/util.c
parent3c8bed4ee061f96acb4d70a591a9849bddd2a659 (diff)
Modernization
Use _cleanup_ and wrap lines to ~80 chars and such.
Diffstat (limited to 'src/shared/util.c')
-rw-r--r--src/shared/util.c21
1 files changed, 10 insertions, 11 deletions
diff --git a/src/shared/util.c b/src/shared/util.c
index 760013c1fb..b516b9b053 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;
}