Skip to content

Commit f83aa34

Browse files
committed
run_cvd exits immediately on SIGINT
When running in daemon mode run_cvd doesn't receive the interrupt. It only exited after the boot completes, it tries to write the exit code to the foreground launcher and receives a SIGPIPE. By checking the pipe to the foreground launcher on the boot state machine loop it can notice the foreground launcher terminating early and terminate itself. Bug: b/467794263
1 parent c30be71 commit f83aa34

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

base/cvd/cuttlefish/host/commands/run_cvd/boot_state_machine.cc

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,13 @@ class CvdBootStateMachine : public SetupFeature, public KernelLogPipeConsumer {
420420
.events = POLLIN | POLLHUP,
421421
},
422422
};
423+
// fg_launcher_pipe will be closed after the exit code is reported.
424+
if (fg_launcher_pipe_->IsOpen()) {
425+
poll_shared_fd.emplace_back(PollSharedFd{
426+
.fd = fg_launcher_pipe_,
427+
.events = POLLERR,
428+
});
429+
}
423430
int result = SharedFD::Poll(poll_shared_fd, -1);
424431
// interrupt_fd_read_
425432
if (poll_shared_fd[2].revents & POLLIN) {
@@ -437,6 +444,15 @@ class CvdBootStateMachine : public SetupFeature, public KernelLogPipeConsumer {
437444
break;
438445
}
439446
}
447+
// fg_launcher_pipe_
448+
if (poll_shared_fd.size() >= 4 && poll_shared_fd[3].revents & POLLERR) {
449+
LOG(ERROR)
450+
<< "Foreground launcher closed the pipe, launch is cancelled";
451+
// The foreground process was cancelled (possibly through a SIGINT) if
452+
// the pipe was closed. This process needs to exit as result so the
453+
// other processes in the group also terminate.
454+
std::exit(kPipeIOError);
455+
}
440456
if (poll_shared_fd[0].revents & POLLIN) {
441457
auto sent_code = OnBootEvtReceived(boot_events_pipe);
442458
if (sent_code) {

0 commit comments

Comments
 (0)