Introduce the Service::CheckConsole() method
The Service::Start() method is so long that its length negatively affects readability of the code. Hence this patch that splits Service::Start(). Test: Booted Android in Cuttlefish. Change-Id: Ib8e1e87fbd335520cbe3aac2a88d250fcf3b4ff0 Signed-off-by: Bart Van Assche <bvanassche@google.com>
This commit is contained in:
parent
b99ace4af1
commit
847b80a112
|
@ -405,6 +405,26 @@ static void ClosePipe(const std::array<int, 2>* pipe) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Result<void> Service::CheckConsole() {
|
||||||
|
if (!(flags_ & SVC_CONSOLE)) {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (proc_attr_.console.empty()) {
|
||||||
|
proc_attr_.console = "/dev/" + GetProperty("ro.boot.console", "console");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make sure that open call succeeds to ensure a console driver is
|
||||||
|
// properly registered for the device node
|
||||||
|
int console_fd = open(proc_attr_.console.c_str(), O_RDWR | O_CLOEXEC);
|
||||||
|
if (console_fd < 0) {
|
||||||
|
flags_ |= SVC_DISABLED;
|
||||||
|
return ErrnoError() << "Couldn't open console '" << proc_attr_.console << "'";
|
||||||
|
}
|
||||||
|
close(console_fd);
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
Result<void> Service::Start() {
|
Result<void> Service::Start() {
|
||||||
auto reboot_on_failure = make_scope_guard([this] {
|
auto reboot_on_failure = make_scope_guard([this] {
|
||||||
if (on_failure_reboot_target_) {
|
if (on_failure_reboot_target_) {
|
||||||
|
@ -442,20 +462,8 @@ Result<void> Service::Start() {
|
||||||
return ErrnoError() << "pipe()";
|
return ErrnoError() << "pipe()";
|
||||||
}
|
}
|
||||||
|
|
||||||
bool needs_console = (flags_ & SVC_CONSOLE);
|
if (Result<void> result = CheckConsole(); !result.ok()) {
|
||||||
if (needs_console) {
|
return result;
|
||||||
if (proc_attr_.console.empty()) {
|
|
||||||
proc_attr_.console = "/dev/" + GetProperty("ro.boot.console", "console");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Make sure that open call succeeds to ensure a console driver is
|
|
||||||
// properly registered for the device node
|
|
||||||
int console_fd = open(proc_attr_.console.c_str(), O_RDWR | O_CLOEXEC);
|
|
||||||
if (console_fd < 0) {
|
|
||||||
flags_ |= SVC_DISABLED;
|
|
||||||
return ErrnoError() << "Couldn't open console '" << proc_attr_.console << "'";
|
|
||||||
}
|
|
||||||
close(console_fd);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct stat sb;
|
struct stat sb;
|
||||||
|
|
|
@ -145,6 +145,7 @@ class Service {
|
||||||
void KillProcessGroup(int signal, bool report_oneshot = false);
|
void KillProcessGroup(int signal, bool report_oneshot = false);
|
||||||
void SetProcessAttributesAndCaps();
|
void SetProcessAttributesAndCaps();
|
||||||
void ResetFlagsForStart();
|
void ResetFlagsForStart();
|
||||||
|
Result<void> CheckConsole();
|
||||||
|
|
||||||
static unsigned long next_start_order_;
|
static unsigned long next_start_order_;
|
||||||
static bool is_exec_service_running_;
|
static bool is_exec_service_running_;
|
||||||
|
|
Loading…
Reference in New Issue