From 126223453108185fbdd51733122dd1a418c86c33 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Fri, 23 Feb 2018 11:25:29 -0800 Subject: [PATCH] conmon: Respect start-pipe read errors MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Avoid: $ make clean && make conmon.o 2>&1 rm -f conmon.o cmsg.o ../bin/conmon cc -std=c99 -Os -Wall -Wextra -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include -DVERSION=\"1.9.0-dev\" -DGIT_COMMIT=\""74cd1ec97c13a9784ce5e67a9e50e8977b5d2f38"\" -c -o conmon.o conmon.c conmon.c: In function ‘main’: conmon.c:1175:3: warning: ignoring return value of ‘read’, declared with attribute warn_unused_result [-Wunused-result] read(start_pipe_fd, buf, BUF_SIZE); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ by catching and exiting on any read errors. A read error here would be because the caller died before writing to the start pipe, and we don't want to continue in those cases because it would reopen the cgroup race discussed in af4fbcd9 (conmon: Don't leave zombies and fix cgroup race, 2017-06-09, #583). af4fbcd9 is where this line originally landed, and it didn't have error checking then. Signed-off-by: W. Trevor King --- conmon/conmon.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/conmon/conmon.c b/conmon/conmon.c index 31b0d63a..dd8ffa4b 100644 --- a/conmon/conmon.c +++ b/conmon/conmon.c @@ -1172,7 +1172,10 @@ int main(int argc, char *argv[]) /* Block for an initial write to the start pipe before spawning any childred or exiting, to ensure the parent can put us in the right cgroup. */ - read(start_pipe_fd, buf, BUF_SIZE); + num_read = read(start_pipe_fd, buf, BUF_SIZE); + if (num_read < 0) { + pexit("start-pipe read failed"); + } close(start_pipe_fd); }