summaryrefslogtreecommitdiff
path: root/src/shared/utmp-wtmp.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/utmp-wtmp.c
parent3c8bed4ee061f96acb4d70a591a9849bddd2a659 (diff)
Modernization
Use _cleanup_ and wrap lines to ~80 chars and such.
Diffstat (limited to 'src/shared/utmp-wtmp.c')
-rw-r--r--src/shared/utmp-wtmp.c39
1 files changed, 13 insertions, 26 deletions
diff --git a/src/shared/utmp-wtmp.c b/src/shared/utmp-wtmp.c
index c9b986fc08..3494b56908 100644
--- a/src/shared/utmp-wtmp.c
+++ b/src/shared/utmp-wtmp.c
@@ -292,7 +292,7 @@ int utmp_put_runlevel(int runlevel, int previous) {
#define TIMEOUT_MSEC 50
static int write_to_terminal(const char *tty, const char *message) {
- int fd, r;
+ int _cleanup_close_ fd = -1;
const char *p;
size_t left;
usec_t end;
@@ -300,14 +300,10 @@ static int write_to_terminal(const char *tty, const char *message) {
assert(tty);
assert(message);
- if ((fd = open(tty, O_WRONLY|O_NDELAY|O_NOCTTY|O_CLOEXEC)) < 0)
+ fd = open(tty, O_WRONLY|O_NDELAY|O_NOCTTY|O_CLOEXEC);
+ if (fd < 0 || !isatty(fd))
return -errno;
- if (!isatty(fd)) {
- r = -errno;
- goto finish;
- }
-
p = message;
left = strlen(message);
@@ -321,30 +317,26 @@ static int write_to_terminal(const char *tty, const char *message) {
t = now(CLOCK_MONOTONIC);
- if (t >= end) {
- r = -ETIME;
- goto finish;
- }
+ if (t >= end)
+ return -ETIME;
zero(pollfd);
pollfd.fd = fd;
pollfd.events = POLLOUT;
- if ((k = poll(&pollfd, 1, (end - t) / USEC_PER_MSEC)) < 0)
+ k = poll(&pollfd, 1, (end - t) / USEC_PER_MSEC);
+ if (k < 0)
return -errno;
- if (k <= 0) {
- r = -ETIME;
- goto finish;
- }
-
- if ((n = write(fd, p, left)) < 0) {
+ if (k == 0)
+ return -ETIME;
+ n = write(fd, p, left);
+ if (n < 0) {
if (errno == EAGAIN)
continue;
- r = -errno;
- goto finish;
+ return -errno;
}
assert((size_t) n <= left);
@@ -353,12 +345,7 @@ static int write_to_terminal(const char *tty, const char *message) {
left -= n;
}
- r = 0;
-
-finish:
- close_nointr_nofail(fd);
-
- return r;
+ return 0;
}
int utmp_wall(const char *message, bool (*match_tty)(const char *tty)) {