summaryrefslogtreecommitdiff
path: root/src/systemctl
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2013-03-13 19:40:01 -0400
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2013-03-13 19:53:45 -0400
commit427b47c4abaf4b5820e3532bf6993c7abe66703c (patch)
tree404b7b500cb1ecfaff07a161a555d9cc80b56982 /src/systemctl
parent7199aa96ce19468d9ce4cb21a13e32a3792fde41 (diff)
initctl: catch write error, use _cleanup_
!= operator always returns something nonnegative, so the error condition was not caught.
Diffstat (limited to 'src/systemctl')
-rw-r--r--src/systemctl/systemctl.c17
1 files changed, 8 insertions, 9 deletions
diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
index 5902a3798d..84b7c8ee2d 100644
--- a/src/systemctl/systemctl.c
+++ b/src/systemctl/systemctl.c
@@ -5041,21 +5041,22 @@ finish:
}
static int talk_initctl(void) {
- struct init_request request;
- int r, fd;
+ struct init_request request = {0};
+ int r;
+ int _cleanup_close_ fd = -1;
char rl;
- if (!(rl = action_to_runlevel()))
+ rl = action_to_runlevel();
+ if (!rl)
return 0;
- zero(request);
request.magic = INIT_MAGIC;
request.sleeptime = 0;
request.cmd = INIT_CMD_RUNLVL;
request.runlevel = rl;
- if ((fd = open(INIT_FIFO, O_WRONLY|O_NDELAY|O_CLOEXEC|O_NOCTTY)) < 0) {
-
+ fd = open(INIT_FIFO, O_WRONLY|O_NDELAY|O_CLOEXEC|O_NOCTTY);
+ if (fd < 0) {
if (errno == ENOENT)
return 0;
@@ -5065,9 +5066,7 @@ static int talk_initctl(void) {
errno = 0;
r = loop_write(fd, &request, sizeof(request), false) != sizeof(request);
- close_nointr_nofail(fd);
-
- if (r < 0) {
+ if (r) {
log_error("Failed to write to "INIT_FIFO": %m");
return errno ? -errno : -EIO;
}