Skip to content

Commit 707a0a1

Browse files
reddevillgComixHe
authored andcommitted
fix: Correct the retrieval of the exit status
Signed-off-by: reddevillg <reddevillg@gmail.com>
1 parent 4994466 commit 707a0a1

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

apps/ll-init/src/ll-init.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,7 @@ int main(int argc, char **argv) // NOLINT
609609
print_info("Failed to run child process");
610610
return -1;
611611
}
612+
print_info("run child " + std::to_string(child));
612613

613614
auto epfd = create_epoll();
614615
if (!epfd) {
@@ -642,7 +643,7 @@ int main(int argc, char **argv) // NOLINT
642643
file_descriptor_wrapper timerfd;
643644
bool done{ false };
644645
std::array<struct epoll_event, 10> events{};
645-
WaitPidResult waitChild{ .pid = child };
646+
auto waitTarget = child;
646647
int childExitCode = 0;
647648
while (true) {
648649
ret = ::epoll_wait(epfd, events.data(), events.size(), -1);
@@ -658,18 +659,19 @@ int main(int argc, char **argv) // NOLINT
658659
for (auto i = 0; i < ret; ++i) {
659660
const auto event = events.at(i);
660661
if (event.data.fd == sigfd) {
661-
if (!handle_sigevent(sigfd, waitChild.pid, waitChild)) {
662+
WaitPidResult waitChild{ .pid = -1 };
663+
if (!handle_sigevent(sigfd, waitTarget, waitChild)) {
662664
return -1;
663665
}
664666

665667
if (waitChild.pid == child) {
666668
// Init process will propagate received signals to all child processes (using
667669
// pid -1) after initial child exits
668670
if (WIFEXITED(waitChild.status)) {
669-
waitChild.pid = -1;
671+
waitTarget = -1;
670672
childExitCode = WEXITSTATUS(waitChild.status);
671673
} else if (WIFSIGNALED(waitChild.status)) {
672-
waitChild.pid = -1;
674+
waitTarget = -1;
673675
childExitCode = 128 + WTERMSIG(waitChild.status);
674676
}
675677

@@ -711,5 +713,6 @@ int main(int argc, char **argv) // NOLINT
711713
}
712714
}
713715

716+
print_info("init exit with code " + std::to_string(childExitCode));
714717
return childExitCode;
715718
}

0 commit comments

Comments
 (0)