From 987391656f5d5fe97166f06ad71d48ceff67edf9 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Mon, 14 Nov 2022 16:54:03 -0800 Subject: [PATCH] init: Introduce RequiresConsole() Prepare for adding more code in the parent process that depends on whether or not a console is required. Bug: 213617178 Change-Id: I066ede32fcd4ce09d06be23158f3c1970064a697 Signed-off-by: Bart Van Assche --- init/service_utils.cpp | 2 +- init/service_utils.h | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/init/service_utils.cpp b/init/service_utils.cpp index 52e66153c..16eab9eb7 100644 --- a/init/service_utils.cpp +++ b/init/service_utils.cpp @@ -240,7 +240,7 @@ Result SetProcessAttributes(const ProcessAttributes& attr) { } } - if (!attr.console.empty()) { + if (RequiresConsole(attr)) { setsid(); OpenConsole(attr.console); } else { diff --git a/init/service_utils.h b/init/service_utils.h index 228ae2b35..5af779c42 100644 --- a/init/service_utils.h +++ b/init/service_utils.h @@ -95,6 +95,11 @@ struct ProcessAttributes { int priority; bool stdio_to_kmsg; }; + +inline bool RequiresConsole(const ProcessAttributes& attr) { + return !attr.console.empty(); +} + Result SetProcessAttributes(const ProcessAttributes& attr); Result WritePidToFiles(std::vector* files);