blob: 2886c98ccc0d022dfd79bfd3f15c2906aba372bc [file] [log] [blame]
James Kuszmaul3224b8e2022-01-07 19:00:39 -08001#include "aos/starter/subprocess.h"
2
3#include <grp.h>
4#include <pwd.h>
5#include <sys/prctl.h>
6#include <sys/types.h>
7#include <sys/wait.h>
8
9#include "glog/logging.h"
10
11namespace aos::starter {
12
Austin Schuhbbeb37e2022-08-17 16:19:27 -070013// RAII class to become root and restore back to the original user and group
14// afterwards.
15class Sudo {
16 public:
17 Sudo() {
18 // Save what we were.
19 PCHECK(getresuid(&ruid_, &euid_, &suid_) == 0);
20 PCHECK(getresgid(&rgid_, &egid_, &sgid_) == 0);
21
22 // Become root.
23 PCHECK(setresuid(/* ruid */ 0 /* root */, /* euid */ 0, /* suid */ 0) == 0)
24 << ": Failed to become root";
25 PCHECK(setresgid(/* ruid */ 0 /* root */, /* euid */ 0, /* suid */ 0) == 0)
26 << ": Failed to become root";
27 }
28
29 ~Sudo() {
30 // And recover.
31 PCHECK(setresgid(rgid_, egid_, sgid_) == 0);
32 PCHECK(setresuid(ruid_, euid_, suid_) == 0);
33 }
34
35 uid_t ruid_, euid_, suid_;
36 gid_t rgid_, egid_, sgid_;
37};
38
39MemoryCGroup::MemoryCGroup(std::string_view name)
40 : cgroup_(absl::StrCat("/sys/fs/cgroup/memory/aos_", name)) {
41 Sudo sudo;
42 int ret = mkdir(cgroup_.c_str(), 0755);
43
44 if (ret != 0) {
45 if (errno == EEXIST) {
46 PCHECK(remove(cgroup_.c_str()) == 0)
47 << ": Failed to remove previous cgroup " << cgroup_;
48 ret = mkdir(cgroup_.c_str(), 0755);
49 }
50 }
51
52 if (ret != 0) {
53 PLOG(FATAL) << ": Failed to create cgroup aos_" << cgroup_
54 << ", do you have permission?";
55 }
56}
57
58void MemoryCGroup::AddTid(pid_t pid) {
59 if (pid == 0) {
60 pid = getpid();
61 }
62 Sudo sudo;
63 util::WriteStringToFileOrDie(absl::StrCat(cgroup_, "/tasks").c_str(),
64 std::to_string(pid));
65}
66
67void MemoryCGroup::SetLimit(std::string_view limit_name, uint64_t limit_value) {
68 Sudo sudo;
69 util::WriteStringToFileOrDie(absl::StrCat(cgroup_, "/", limit_name).c_str(),
70 std::to_string(limit_value));
71}
72
73MemoryCGroup::~MemoryCGroup() {
74 Sudo sudo;
75 PCHECK(rmdir(absl::StrCat(cgroup_).c_str()) == 0);
76}
77
James Kuszmaul3224b8e2022-01-07 19:00:39 -080078SignalListener::SignalListener(aos::ShmEventLoop *loop,
79 std::function<void(signalfd_siginfo)> callback)
80 : SignalListener(loop, callback,
81 {SIGHUP, SIGINT, SIGQUIT, SIGABRT, SIGFPE, SIGSEGV,
82 SIGPIPE, SIGTERM, SIGBUS, SIGXCPU, SIGCHLD}) {}
83
84SignalListener::SignalListener(aos::ShmEventLoop *loop,
85 std::function<void(signalfd_siginfo)> callback,
86 std::initializer_list<unsigned int> signals)
87 : loop_(loop), callback_(std::move(callback)), signalfd_(signals) {
88 loop->epoll()->OnReadable(signalfd_.fd(), [this] {
89 signalfd_siginfo info = signalfd_.Read();
90
91 if (info.ssi_signo == 0) {
92 LOG(WARNING) << "Could not read " << sizeof(signalfd_siginfo) << " bytes";
93 return;
94 }
95
96 callback_(info);
97 });
98}
99
100SignalListener::~SignalListener() { loop_->epoll()->DeleteFd(signalfd_.fd()); }
101
James Kuszmauld42edb42022-01-07 18:00:16 -0800102Application::Application(std::string_view name,
103 std::string_view executable_name,
James Kuszmaul3224b8e2022-01-07 19:00:39 -0800104 aos::EventLoop *event_loop,
105 std::function<void()> on_change)
James Kuszmauld42edb42022-01-07 18:00:16 -0800106 : name_(name),
107 path_(executable_name),
James Kuszmaul3224b8e2022-01-07 19:00:39 -0800108 event_loop_(event_loop),
109 start_timer_(event_loop_->AddTimer([this] {
110 status_ = aos::starter::State::RUNNING;
111 LOG(INFO) << "Started '" << name_ << "' pid: " << pid_;
112 })),
113 restart_timer_(event_loop_->AddTimer([this] { DoStart(); })),
114 stop_timer_(event_loop_->AddTimer([this] {
115 if (kill(pid_, SIGKILL) == 0) {
116 LOG(WARNING) << "Failed to stop, sending SIGKILL to '" << name_
117 << "' pid: " << pid_;
118 }
119 })),
James Kuszmauld42edb42022-01-07 18:00:16 -0800120 pipe_timer_(event_loop_->AddTimer([this]() { FetchOutputs(); })),
121 child_status_handler_(
122 event_loop_->AddTimer([this]() { MaybeHandleSignal(); })),
123 on_change_(on_change) {
124 event_loop_->OnRun([this]() {
125 // Every second poll to check if the child is dead. This is used as a
126 // default for the case where the user is not directly catching SIGCHLD and
127 // calling MaybeHandleSignal for us.
128 child_status_handler_->Setup(event_loop_->monotonic_now(),
129 std::chrono::seconds(1));
130 });
131}
132
133Application::Application(const aos::Application *application,
134 aos::EventLoop *event_loop,
135 std::function<void()> on_change)
136 : Application(application->name()->string_view(),
137 application->has_executable_name()
138 ? application->executable_name()->string_view()
139 : application->name()->string_view(),
140 event_loop, on_change) {
141 user_name_ = application->has_user() ? application->user()->str() : "";
142 user_ = application->has_user() ? FindUid(user_name_.c_str()) : std::nullopt;
143 group_ = application->has_user() ? FindPrimaryGidForUser(user_name_.c_str())
144 : std::nullopt;
145 autostart_ = application->autostart();
146 autorestart_ = application->autorestart();
147 if (application->has_args()) {
148 set_args(*application->args());
149 }
Austin Schuhbbeb37e2022-08-17 16:19:27 -0700150
151 if (application->has_memory_limit() && application->memory_limit() > 0) {
152 SetMemoryLimit(application->memory_limit());
153 }
James Kuszmauld42edb42022-01-07 18:00:16 -0800154}
James Kuszmaul3224b8e2022-01-07 19:00:39 -0800155
156void Application::DoStart() {
157 if (status_ != aos::starter::State::WAITING) {
158 return;
159 }
160
161 start_timer_->Disable();
162 restart_timer_->Disable();
163
James Kuszmauld42edb42022-01-07 18:00:16 -0800164 status_pipes_ = util::ScopedPipe::MakePipe();
165
166 if (capture_stdout_) {
167 stdout_pipes_ = util::ScopedPipe::MakePipe();
168 stdout_.clear();
169 }
170 if (capture_stderr_) {
171 stderr_pipes_ = util::ScopedPipe::MakePipe();
172 stderr_.clear();
173 }
174
175 pipe_timer_->Setup(event_loop_->monotonic_now(),
176 std::chrono::milliseconds(100));
James Kuszmaul3224b8e2022-01-07 19:00:39 -0800177
178 const pid_t pid = fork();
179
180 if (pid != 0) {
181 if (pid == -1) {
182 PLOG(WARNING) << "Failed to fork '" << name_ << "'";
183 stop_reason_ = aos::starter::LastStopReason::FORK_ERR;
184 status_ = aos::starter::State::STOPPED;
185 } else {
186 pid_ = pid;
187 id_ = next_id_++;
188 start_time_ = event_loop_->monotonic_now();
189 status_ = aos::starter::State::STARTING;
190 LOG(INFO) << "Starting '" << name_ << "' pid " << pid_;
191
192 // Setup timer which moves application to RUNNING state if it is still
193 // alive in 1 second.
194 start_timer_->Setup(event_loop_->monotonic_now() +
195 std::chrono::seconds(1));
James Kuszmauld42edb42022-01-07 18:00:16 -0800196 // Since we are the parent process, clear our write-side of all the pipes.
197 status_pipes_.write.reset();
198 stdout_pipes_.write.reset();
199 stderr_pipes_.write.reset();
James Kuszmaul3224b8e2022-01-07 19:00:39 -0800200 }
201 on_change_();
202 return;
203 }
204
Austin Schuhbbeb37e2022-08-17 16:19:27 -0700205 if (memory_cgroup_) {
206 memory_cgroup_->AddTid();
207 }
208
James Kuszmauld42edb42022-01-07 18:00:16 -0800209 // Since we are the child process, clear our read-side of all the pipes.
210 status_pipes_.read.reset();
211 stdout_pipes_.read.reset();
212 stderr_pipes_.read.reset();
213
214 // The status pipe will not be needed if the execve succeeds.
215 status_pipes_.write->SetCloexec();
216
James Kuszmaul3224b8e2022-01-07 19:00:39 -0800217 // Clear out signal mask of parent so forked process receives all signals
218 // normally.
219 sigset_t empty_mask;
220 sigemptyset(&empty_mask);
221 sigprocmask(SIG_SETMASK, &empty_mask, nullptr);
222
223 // Cleanup children if starter dies in a way that is not handled gracefully.
224 if (prctl(PR_SET_PDEATHSIG, SIGKILL) == -1) {
James Kuszmauld42edb42022-01-07 18:00:16 -0800225 status_pipes_.write->Write(
James Kuszmaul3224b8e2022-01-07 19:00:39 -0800226 static_cast<uint32_t>(aos::starter::LastStopReason::SET_PRCTL_ERR));
227 PLOG(FATAL) << "Could not set PR_SET_PDEATHSIG to SIGKILL";
228 }
229
230 if (group_) {
231 CHECK(!user_name_.empty());
232 // The manpage for setgroups says we just need CAP_SETGID, but empirically
233 // we also need the effective UID to be 0 to make it work. user_ must also
234 // be set so we change this effective UID back later.
235 CHECK(user_);
236 if (seteuid(0) == -1) {
James Kuszmauld42edb42022-01-07 18:00:16 -0800237 status_pipes_.write->Write(
James Kuszmaul3224b8e2022-01-07 19:00:39 -0800238 static_cast<uint32_t>(aos::starter::LastStopReason::SET_GRP_ERR));
239 PLOG(FATAL) << "Could not seteuid(0) for " << name_
240 << " in preparation for setting groups";
241 }
242 if (initgroups(user_name_.c_str(), *group_) == -1) {
James Kuszmauld42edb42022-01-07 18:00:16 -0800243 status_pipes_.write->Write(
James Kuszmaul3224b8e2022-01-07 19:00:39 -0800244 static_cast<uint32_t>(aos::starter::LastStopReason::SET_GRP_ERR));
245 PLOG(FATAL) << "Could not initialize normal groups for " << name_
246 << " as " << user_name_ << " with " << *group_;
247 }
248 if (setgid(*group_) == -1) {
James Kuszmauld42edb42022-01-07 18:00:16 -0800249 status_pipes_.write->Write(
James Kuszmaul3224b8e2022-01-07 19:00:39 -0800250 static_cast<uint32_t>(aos::starter::LastStopReason::SET_GRP_ERR));
251 PLOG(FATAL) << "Could not set group for " << name_ << " to " << *group_;
252 }
253 }
254
255 if (user_) {
256 if (setuid(*user_) == -1) {
James Kuszmauld42edb42022-01-07 18:00:16 -0800257 status_pipes_.write->Write(
James Kuszmaul3224b8e2022-01-07 19:00:39 -0800258 static_cast<uint32_t>(aos::starter::LastStopReason::SET_USR_ERR));
259 PLOG(FATAL) << "Could not set user for " << name_ << " to " << *user_;
260 }
261 }
262
James Kuszmauld42edb42022-01-07 18:00:16 -0800263 if (capture_stdout_) {
264 PCHECK(STDOUT_FILENO == dup2(stdout_pipes_.write->fd(), STDOUT_FILENO));
265 stdout_pipes_.write.reset();
266 }
James Kuszmaul3224b8e2022-01-07 19:00:39 -0800267
James Kuszmauld42edb42022-01-07 18:00:16 -0800268 if (capture_stderr_) {
269 PCHECK(STDERR_FILENO == dup2(stderr_pipes_.write->fd(), STDERR_FILENO));
270 stderr_pipes_.write.reset();
271 }
272
273 // argv[0] should be the program name
James Kuszmaul6f10b382022-03-11 22:31:38 -0800274 args_.insert(args_.begin(), path_);
James Kuszmauld42edb42022-01-07 18:00:16 -0800275
276 std::vector<char *> cargs = CArgs();
James Kuszmaul6f10b382022-03-11 22:31:38 -0800277 execvp(path_.c_str(), cargs.data());
James Kuszmaul3224b8e2022-01-07 19:00:39 -0800278
279 // If we got here, something went wrong
James Kuszmauld42edb42022-01-07 18:00:16 -0800280 status_pipes_.write->Write(
James Kuszmaul3224b8e2022-01-07 19:00:39 -0800281 static_cast<uint32_t>(aos::starter::LastStopReason::EXECV_ERR));
James Kuszmaul6f10b382022-03-11 22:31:38 -0800282 PLOG(WARNING) << "Could not execute " << name_ << " (" << path_ << ')';
James Kuszmaul3224b8e2022-01-07 19:00:39 -0800283
284 _exit(EXIT_FAILURE);
285}
286
James Kuszmauld42edb42022-01-07 18:00:16 -0800287void Application::FetchOutputs() {
288 if (capture_stdout_) {
289 stdout_pipes_.read->Read(&stdout_);
290 }
291 if (capture_stderr_) {
292 stderr_pipes_.read->Read(&stderr_);
293 }
294}
295
296const std::string &Application::GetStdout() {
297 CHECK(capture_stdout_);
298 FetchOutputs();
299 return stdout_;
300}
301
302const std::string &Application::GetStderr() {
303 CHECK(capture_stderr_);
304 FetchOutputs();
305 return stderr_;
306}
307
James Kuszmaul3224b8e2022-01-07 19:00:39 -0800308void Application::DoStop(bool restart) {
309 // If stop or restart received, the old state of these is no longer applicable
310 // so cancel both.
311 restart_timer_->Disable();
312 start_timer_->Disable();
313
James Kuszmauld42edb42022-01-07 18:00:16 -0800314 FetchOutputs();
315
James Kuszmaul3224b8e2022-01-07 19:00:39 -0800316 switch (status_) {
317 case aos::starter::State::STARTING:
318 case aos::starter::State::RUNNING: {
319 LOG(INFO) << "Stopping '" << name_ << "' pid: " << pid_ << " with signal "
320 << SIGINT;
321 status_ = aos::starter::State::STOPPING;
322
323 kill(pid_, SIGINT);
324
325 // Watchdog timer to SIGKILL application if it is still running 1 second
326 // after SIGINT
327 stop_timer_->Setup(event_loop_->monotonic_now() +
328 std::chrono::seconds(1));
329 queue_restart_ = restart;
330 on_change_();
331 break;
332 }
333 case aos::starter::State::WAITING: {
334 // If waiting to restart, and receives restart, skip the waiting period
335 // and restart immediately. If stop received, all we have to do is move
336 // to the STOPPED state.
337 if (restart) {
338 DoStart();
339 } else {
340 status_ = aos::starter::State::STOPPED;
341 on_change_();
342 }
343 break;
344 }
345 case aos::starter::State::STOPPING: {
346 // If the application is already stopping, then we just need to update the
347 // restart flag to the most recent status.
348 queue_restart_ = restart;
349 break;
350 }
351 case aos::starter::State::STOPPED: {
352 // Restart immediately if the application is already stopped
353 if (restart) {
354 status_ = aos::starter::State::WAITING;
355 DoStart();
356 }
357 break;
358 }
359 }
360}
361
362void Application::QueueStart() {
363 status_ = aos::starter::State::WAITING;
364
365 LOG(INFO) << "Restarting " << name_ << " in 3 seconds";
366 restart_timer_->Setup(event_loop_->monotonic_now() + std::chrono::seconds(3));
367 start_timer_->Disable();
368 stop_timer_->Disable();
369 on_change_();
370}
371
James Kuszmauld42edb42022-01-07 18:00:16 -0800372std::vector<char *> Application::CArgs() {
373 std::vector<char *> cargs;
374 std::transform(args_.begin(), args_.end(), std::back_inserter(cargs),
375 [](std::string &str) { return str.data(); });
376 cargs.push_back(nullptr);
377 return cargs;
378}
379
James Kuszmaul3224b8e2022-01-07 19:00:39 -0800380void Application::set_args(
381 const flatbuffers::Vector<flatbuffers::Offset<flatbuffers::String>> &v) {
382 args_.clear();
383 std::transform(v.begin(), v.end(), std::back_inserter(args_),
James Kuszmauld42edb42022-01-07 18:00:16 -0800384 [](const flatbuffers::String *str) { return str->str(); });
385}
386
387void Application::set_args(std::vector<std::string> args) {
388 args_ = std::move(args);
389}
390
391void Application::set_capture_stdout(bool capture) {
392 capture_stdout_ = capture;
393}
394
395void Application::set_capture_stderr(bool capture) {
396 capture_stderr_ = capture;
James Kuszmaul3224b8e2022-01-07 19:00:39 -0800397}
398
399std::optional<uid_t> Application::FindUid(const char *name) {
400 // TODO(austin): Use the reentrant version. This should be safe.
401 struct passwd *user_data = getpwnam(name);
402 if (user_data != nullptr) {
403 return user_data->pw_uid;
404 } else {
405 LOG(FATAL) << "Could not find user " << name;
406 return std::nullopt;
407 }
408}
409
410std::optional<gid_t> Application::FindPrimaryGidForUser(const char *name) {
411 // TODO(austin): Use the reentrant version. This should be safe.
412 struct passwd *user_data = getpwnam(name);
413 if (user_data != nullptr) {
414 return user_data->pw_gid;
415 } else {
416 LOG(FATAL) << "Could not find user " << name;
417 return std::nullopt;
418 }
419}
420
421flatbuffers::Offset<aos::starter::ApplicationStatus>
James Kuszmaul6295a642022-03-22 15:23:59 -0700422Application::PopulateStatus(flatbuffers::FlatBufferBuilder *builder,
423 util::Top *top) {
James Kuszmaul3224b8e2022-01-07 19:00:39 -0800424 CHECK_NOTNULL(builder);
425 auto name_fbs = builder->CreateString(name_);
426
James Kuszmaul6295a642022-03-22 15:23:59 -0700427 const bool valid_pid = pid_ > 0 && status_ != aos::starter::State::STOPPED;
428 const flatbuffers::Offset<util::ProcessInfo> process_info =
429 valid_pid ? top->InfoForProcess(builder, pid_)
430 : flatbuffers::Offset<util::ProcessInfo>();
431
James Kuszmaul3224b8e2022-01-07 19:00:39 -0800432 aos::starter::ApplicationStatus::Builder status_builder(*builder);
433 status_builder.add_name(name_fbs);
434 status_builder.add_state(status_);
James Kuszmauld42edb42022-01-07 18:00:16 -0800435 if (exit_code_.has_value()) {
436 status_builder.add_last_exit_code(exit_code_.value());
437 }
James Kuszmaul3224b8e2022-01-07 19:00:39 -0800438 status_builder.add_last_stop_reason(stop_reason_);
439 if (pid_ != -1) {
440 status_builder.add_pid(pid_);
441 status_builder.add_id(id_);
442 }
James Kuszmaul6295a642022-03-22 15:23:59 -0700443 // Note that even if process_info is null, calling add_process_info is fine.
444 status_builder.add_process_info(process_info);
James Kuszmaul3224b8e2022-01-07 19:00:39 -0800445 status_builder.add_last_start_time(start_time_.time_since_epoch().count());
446 return status_builder.Finish();
447}
448
449void Application::Terminate() {
450 stop_reason_ = aos::starter::LastStopReason::TERMINATE;
451 DoStop(false);
452 terminating_ = true;
453}
454
455void Application::HandleCommand(aos::starter::Command cmd) {
456 switch (cmd) {
457 case aos::starter::Command::START: {
458 switch (status_) {
459 case aos::starter::State::WAITING: {
460 restart_timer_->Disable();
461 DoStart();
462 break;
463 }
464 case aos::starter::State::STARTING: {
465 break;
466 }
467 case aos::starter::State::RUNNING: {
468 break;
469 }
470 case aos::starter::State::STOPPING: {
471 queue_restart_ = true;
472 break;
473 }
474 case aos::starter::State::STOPPED: {
475 status_ = aos::starter::State::WAITING;
476 DoStart();
477 break;
478 }
479 }
480 break;
481 }
482 case aos::starter::Command::STOP: {
483 stop_reason_ = aos::starter::LastStopReason::STOP_REQUESTED;
484 DoStop(false);
485 break;
486 }
487 case aos::starter::Command::RESTART: {
488 stop_reason_ = aos::starter::LastStopReason::RESTART_REQUESTED;
489 DoStop(true);
490 break;
491 }
492 }
493}
494
495bool Application::MaybeHandleSignal() {
496 int status;
497
Sarah Newman21c59202022-06-16 12:36:33 -0700498 if (status_ == aos::starter::State::WAITING ||
499 status_ == aos::starter::State::STOPPED) {
500 // We can't possibly have received a signal meant for this process.
501 return false;
502 }
503
James Kuszmaul3224b8e2022-01-07 19:00:39 -0800504 // Check if the status of this process has changed
Sarah Newman21c59202022-06-16 12:36:33 -0700505 // The PID won't be -1 if this application has ever been run successfully
James Kuszmaul3224b8e2022-01-07 19:00:39 -0800506 if (pid_ == -1 || waitpid(pid_, &status, WNOHANG) != pid_) {
507 return false;
508 }
509
510 // Check that the event was the process exiting
511 if (!WIFEXITED(status) && !WIFSIGNALED(status)) {
512 return false;
513 }
514
James Kuszmauld42edb42022-01-07 18:00:16 -0800515 start_timer_->Disable();
James Kuszmaul3224b8e2022-01-07 19:00:39 -0800516 exit_time_ = event_loop_->monotonic_now();
517 exit_code_ = WIFEXITED(status) ? WEXITSTATUS(status) : WTERMSIG(status);
518
James Kuszmauld42edb42022-01-07 18:00:16 -0800519 if (auto read_result = status_pipes_.read->Read()) {
James Kuszmaul3224b8e2022-01-07 19:00:39 -0800520 stop_reason_ = static_cast<aos::starter::LastStopReason>(*read_result);
521 }
522
523 switch (status_) {
524 case aos::starter::State::STARTING: {
James Kuszmauld42edb42022-01-07 18:00:16 -0800525 if (exit_code_.value() == 0) {
526 LOG(INFO) << "Application '" << name_ << "' pid " << pid_
527 << " exited with status " << exit_code_.value();
528 } else {
529 LOG(WARNING) << "Failed to start '" << name_ << "' on pid " << pid_
530 << " : Exited with status " << exit_code_.value();
531 }
James Kuszmaul6f10b382022-03-11 22:31:38 -0800532 if (autorestart()) {
533 QueueStart();
534 } else {
535 status_ = aos::starter::State::STOPPED;
536 on_change_();
537 }
James Kuszmaul3224b8e2022-01-07 19:00:39 -0800538 break;
539 }
540 case aos::starter::State::RUNNING: {
James Kuszmauld42edb42022-01-07 18:00:16 -0800541 if (exit_code_.value() == 0) {
James Kuszmaul3224b8e2022-01-07 19:00:39 -0800542 LOG(INFO) << "Application '" << name_ << "' pid " << pid_
James Kuszmauld42edb42022-01-07 18:00:16 -0800543 << " exited with status " << exit_code_.value();
James Kuszmaul3224b8e2022-01-07 19:00:39 -0800544 } else {
545 LOG(WARNING) << "Application '" << name_ << "' pid " << pid_
James Kuszmauld42edb42022-01-07 18:00:16 -0800546 << " exited unexpectedly with status "
547 << exit_code_.value();
James Kuszmaul3224b8e2022-01-07 19:00:39 -0800548 }
James Kuszmaul6f10b382022-03-11 22:31:38 -0800549 if (autorestart()) {
550 QueueStart();
551 } else {
552 status_ = aos::starter::State::STOPPED;
553 on_change_();
554 }
James Kuszmaul3224b8e2022-01-07 19:00:39 -0800555 break;
556 }
557 case aos::starter::State::STOPPING: {
558 LOG(INFO) << "Successfully stopped '" << name_ << "' pid: " << pid_
James Kuszmauld42edb42022-01-07 18:00:16 -0800559 << " with status " << exit_code_.value();
James Kuszmaul3224b8e2022-01-07 19:00:39 -0800560 status_ = aos::starter::State::STOPPED;
561
562 // Disable force stop timer since the process already died
563 stop_timer_->Disable();
564
565 on_change_();
566 if (terminating_) {
567 return true;
568 }
569
570 if (queue_restart_) {
571 queue_restart_ = false;
572 status_ = aos::starter::State::WAITING;
573 DoStart();
574 }
575 break;
576 }
577 case aos::starter::State::WAITING:
578 case aos::starter::State::STOPPED: {
Sarah Newman21c59202022-06-16 12:36:33 -0700579 __builtin_unreachable();
James Kuszmaul3224b8e2022-01-07 19:00:39 -0800580 break;
581 }
582 }
583
584 return false;
585}
586
587} // namespace aos::starter