From 2c8fcc9cd6a7bbb948f6c79879e89c7ed791c9b1 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Wed, 23 Nov 2011 12:15:42 -0800 Subject: [PATCH] daemon: Better log when fork child dies early from signals. On one machine, "/etc/init.d/openvswitch-switch start" failed to start with: ovs-vswitchd: fork child failed to signal startup (Success) Starting ovs-vswitchd ... failed! "strace" revealed that the fork child was actually segfaulting, but the message output didn't indicate that in any way. This commit fixes the log message (but not the segfault itself). Reported-by: Michael Hu Bug #8457. --- lib/daemon.c | 23 ++++++++++++++--------- python/ovs/daemon.py | 18 ++++++++++++------ 2 files changed, 26 insertions(+), 15 deletions(-) diff --git a/lib/daemon.c b/lib/daemon.c index ef1a24ef1..3dd5a1abb 100644 --- a/lib/daemon.c +++ b/lib/daemon.c @@ -250,16 +250,21 @@ fork_and_wait_for_startup(int *fdp) retval = waitpid(pid, &status, 0); } while (retval == -1 && errno == EINTR); - if (retval == pid - && WIFEXITED(status) - && WEXITSTATUS(status)) { - /* Child exited with an error. Convey the same error to - * our parent process as a courtesy. */ - exit(WEXITSTATUS(status)); + if (retval == pid) { + if (WIFEXITED(status) && WEXITSTATUS(status)) { + /* Child exited with an error. Convey the same error + * to our parent process as a courtesy. */ + exit(WEXITSTATUS(status)); + } else { + char *status_msg = process_status_msg(status); + VLOG_FATAL("fork child died before signaling startup (%s)", + status_msg); + } + } else if (retval < 0) { + VLOG_FATAL("waitpid failed (%s)", strerror(errno)); + } else { + NOT_REACHED(); } - - VLOG_FATAL("fork child failed to signal startup (%s)", - strerror(errno)); } close(fds[0]); *fdp = -1; diff --git a/python/ovs/daemon.py b/python/ovs/daemon.py index 5937877c3..0d119f202 100644 --- a/python/ovs/daemon.py +++ b/python/ovs/daemon.py @@ -245,13 +245,19 @@ def _fork_and_wait_for_startup(): break if len(s) != 1: retval, status = _waitpid(pid, 0) - if (retval == pid and - os.WIFEXITED(status) and os.WEXITSTATUS(status)): - # Child exited with an error. Convey the same error to - # our parent process as a courtesy. - sys.exit(os.WEXITSTATUS(status)) + if retval == pid: + if os.WIFEXITED(status) and os.WEXITSTATUS(status): + # Child exited with an error. Convey the same error to + # our parent process as a courtesy. + sys.exit(os.WEXITSTATUS(status)) + else: + sys.stderr.write("fork child failed to signal " + "startup (%s)\n" + % ovs.process.status_msg(status)) else: - sys.stderr.write("fork child failed to signal startup\n") + assert retval < 0 + sys.stderr.write("waitpid failed (%s)\n" + % os.strerror(-retval)) sys.exit(1) os.close(rfd) -- 2.43.0