1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2025-09-01 14:17:37 +03:00

initctl: catch write error, use _cleanup_

!= operator always returns something nonnegative, so the
error condition was not caught.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2013-03-13 19:40:01 -04:00
parent 7199aa96ce
commit 427b47c4ab

View File

@ -5041,21 +5041,22 @@ finish:
} }
static int talk_initctl(void) { static int talk_initctl(void) {
struct init_request request; struct init_request request = {0};
int r, fd; int r;
int _cleanup_close_ fd = -1;
char rl; char rl;
if (!(rl = action_to_runlevel())) rl = action_to_runlevel();
if (!rl)
return 0; return 0;
zero(request);
request.magic = INIT_MAGIC; request.magic = INIT_MAGIC;
request.sleeptime = 0; request.sleeptime = 0;
request.cmd = INIT_CMD_RUNLVL; request.cmd = INIT_CMD_RUNLVL;
request.runlevel = rl; 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) if (errno == ENOENT)
return 0; return 0;
@ -5065,9 +5066,7 @@ static int talk_initctl(void) {
errno = 0; errno = 0;
r = loop_write(fd, &request, sizeof(request), false) != sizeof(request); r = loop_write(fd, &request, sizeof(request), false) != sizeof(request);
close_nointr_nofail(fd); if (r) {
if (r < 0) {
log_error("Failed to write to "INIT_FIFO": %m"); log_error("Failed to write to "INIT_FIFO": %m");
return errno ? -errno : -EIO; return errno ? -errno : -EIO;
} }