Skip to content

Commit 2c8fcc9

Browse files
committed
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 <mhu@nicira.com> Bug #8457.
1 parent 2c5a683 commit 2c8fcc9

2 files changed

Lines changed: 26 additions & 15 deletions

File tree

lib/daemon.c

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -250,16 +250,21 @@ fork_and_wait_for_startup(int *fdp)
250250
retval = waitpid(pid, &status, 0);
251251
} while (retval == -1 && errno == EINTR);
252252

253-
if (retval == pid
254-
&& WIFEXITED(status)
255-
&& WEXITSTATUS(status)) {
256-
/* Child exited with an error. Convey the same error to
257-
* our parent process as a courtesy. */
258-
exit(WEXITSTATUS(status));
253+
if (retval == pid) {
254+
if (WIFEXITED(status) && WEXITSTATUS(status)) {
255+
/* Child exited with an error. Convey the same error
256+
* to our parent process as a courtesy. */
257+
exit(WEXITSTATUS(status));
258+
} else {
259+
char *status_msg = process_status_msg(status);
260+
VLOG_FATAL("fork child died before signaling startup (%s)",
261+
status_msg);
262+
}
263+
} else if (retval < 0) {
264+
VLOG_FATAL("waitpid failed (%s)", strerror(errno));
265+
} else {
266+
NOT_REACHED();
259267
}
260-
261-
VLOG_FATAL("fork child failed to signal startup (%s)",
262-
strerror(errno));
263268
}
264269
close(fds[0]);
265270
*fdp = -1;

python/ovs/daemon.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -245,13 +245,19 @@ def _fork_and_wait_for_startup():
245245
break
246246
if len(s) != 1:
247247
retval, status = _waitpid(pid, 0)
248-
if (retval == pid and
249-
os.WIFEXITED(status) and os.WEXITSTATUS(status)):
250-
# Child exited with an error. Convey the same error to
251-
# our parent process as a courtesy.
252-
sys.exit(os.WEXITSTATUS(status))
248+
if retval == pid:
249+
if os.WIFEXITED(status) and os.WEXITSTATUS(status):
250+
# Child exited with an error. Convey the same error to
251+
# our parent process as a courtesy.
252+
sys.exit(os.WEXITSTATUS(status))
253+
else:
254+
sys.stderr.write("fork child failed to signal "
255+
"startup (%s)\n"
256+
% ovs.process.status_msg(status))
253257
else:
254-
sys.stderr.write("fork child failed to signal startup\n")
258+
assert retval < 0
259+
sys.stderr.write("waitpid failed (%s)\n"
260+
% os.strerror(-retval))
255261
sys.exit(1)
256262

257263
os.close(rfd)

0 commit comments

Comments
 (0)