From bfd7f1ec78e5351f10ab7dc82b1ff9b0db2a6544 Mon Sep 17 00:00:00 2001 From: Robert Swiecki Date: Tue, 24 Jul 2018 00:23:44 +0200 Subject: [PATCH] nsjail: clearer new_proc/reap_proc loop --- nsjail.cc | 45 ++++++++++++++++++++------------------------- 1 file changed, 20 insertions(+), 25 deletions(-) diff --git a/nsjail.cc b/nsjail.cc index e6c29a6..830f554 100644 --- a/nsjail.cc +++ b/nsjail.cc @@ -141,35 +141,30 @@ static int listenMode(nsjconf_t* nsjconf) { } static int standaloneMode(nsjconf_t* nsjconf) { - if (!subproc::runChild(nsjconf, STDIN_FILENO, STDOUT_FILENO, STDERR_FILENO)) { - LOG_E("Couldn't launch the child process"); - return 0xff; - } for (;;) { - int child_status = subproc::reapProc(nsjconf); - - if (subproc::countProc(nsjconf) == 0) { - if (nsjconf->mode == MODE_STANDALONE_ONCE) { - return child_status; + if (!subproc::runChild(nsjconf, STDIN_FILENO, STDOUT_FILENO, STDERR_FILENO)) { + LOG_E("Couldn't launch the child process"); + return 0xff; + } + for (;;) { + int child_status = subproc::reapProc(nsjconf); + if (subproc::countProc(nsjconf) == 0) { + if (nsjconf->mode == MODE_STANDALONE_ONCE) { + return child_status; + } + break; } - if (!subproc::runChild( - nsjconf, STDIN_FILENO, STDOUT_FILENO, STDERR_FILENO)) { - LOG_E("Couldn't launch the child process"); - return 0xff; + if (showProc) { + showProc = false; + subproc::displayProc(nsjconf); } - continue; - } - if (showProc) { - showProc = false; - subproc::displayProc(nsjconf); - } - if (sigFatal > 0) { - subproc::killAll(nsjconf); - logs::logStop(sigFatal); - return (128 + sigFatal); + if (sigFatal > 0) { + subproc::killAll(nsjconf); + logs::logStop(sigFatal); + return (128 + sigFatal); + } + pause(); } - - pause(); } // not reached } -- 2.7.4