Merge "Revert "Enable multiple consoles""

This commit is contained in:
Elliott Hughes 2016-03-21 15:15:03 +00:00 committed by Gerrit Code Review
commit ba44383197
5 changed files with 38 additions and 32 deletions

View file

@ -74,7 +74,8 @@ static int property_triggers_enabled = 0;
static char qemu[32]; static char qemu[32];
std::vector<std::string> console_names; int have_console;
std::string console_name = "/dev/console";
static time_t process_needs_restart; static time_t process_needs_restart;
const char *ENV[32]; const char *ENV[32];
@ -297,23 +298,38 @@ static int keychord_init_action(const std::vector<std::string>& args)
static int console_init_action(const std::vector<std::string>& args) static int console_init_action(const std::vector<std::string>& args)
{ {
std::vector<std::string> consoles; std::string console = property_get("ro.boot.console");
std::string c_prop = property_get("ro.boot.console"); if (!console.empty()) {
if (c_prop.empty()) { console_name = "/dev/" + console;
// Property is missing, so check the system console by default.
consoles.emplace_back(DEFAULT_CONSOLE);
} else {
consoles = android::base::Split(c_prop, ":");
} }
for (const auto& c : consoles) { int fd = open(console_name.c_str(), O_RDWR | O_CLOEXEC);
std::string console = "/dev/" + c; if (fd >= 0)
int fd = open(console.c_str(), O_RDWR | O_CLOEXEC); have_console = 1;
if (fd != -1) { close(fd);
console_names.emplace_back(c);
close(fd); fd = open("/dev/tty0", O_WRONLY | O_CLOEXEC);
} if (fd >= 0) {
const char *msg;
msg = "\n"
"\n"
"\n"
"\n"
"\n"
"\n"
"\n" // console is 40 cols x 30 lines
"\n"
"\n"
"\n"
"\n"
"\n"
"\n"
"\n"
" A N D R O I D ";
write(fd, msg, strlen(msg));
close(fd);
} }
return 0; return 0;
} }

View file

@ -18,17 +18,16 @@
#define _INIT_INIT_H #define _INIT_INIT_H
#include <string> #include <string>
#include <vector>
class Action; class Action;
class Service; class Service;
#define COMMAND_RETRY_TIMEOUT 5 #define COMMAND_RETRY_TIMEOUT 5
#define DEFAULT_CONSOLE "console"
extern const char *ENV[32]; extern const char *ENV[32];
extern bool waiting_for_exec; extern bool waiting_for_exec;
extern std::vector<std::string> console_names; extern int have_console;
extern std::string console_name;
extern struct selabel_handle *sehandle; extern struct selabel_handle *sehandle;
extern struct selabel_handle *sehandle_prop; extern struct selabel_handle *sehandle_prop;

View file

@ -115,11 +115,6 @@ Options
Options are modifiers to services. They affect how and when init Options are modifiers to services. They affect how and when init
runs the service. runs the service.
console [<console>]
This service needs a console. The optional second parameter chooses a
specific console instead of the default "/dev/console". The leading "/dev/"
should be omitted, so "/dev/tty0" would be specified as just "console tty0".
critical critical
This is a device-critical service. If it exits more than four times in This is a device-critical service. If it exits more than four times in
four minutes, the device will reboot into recovery mode. four minutes, the device will reboot into recovery mode.

View file

@ -172,7 +172,6 @@ bool Service::HandleClass(const std::vector<std::string>& args, std::string* err
bool Service::HandleConsole(const std::vector<std::string>& args, std::string* err) { bool Service::HandleConsole(const std::vector<std::string>& args, std::string* err) {
flags_ |= SVC_CONSOLE; flags_ |= SVC_CONSOLE;
console_ = args.size() > 1 ? args[1] : DEFAULT_CONSOLE;
return true; return true;
} }
@ -283,7 +282,7 @@ Service::OptionHandlerMap::Map& Service::OptionHandlerMap::map() const {
constexpr std::size_t kMax = std::numeric_limits<std::size_t>::max(); constexpr std::size_t kMax = std::numeric_limits<std::size_t>::max();
static const Map option_handlers = { static const Map option_handlers = {
{"class", {1, 1, &Service::HandleClass}}, {"class", {1, 1, &Service::HandleClass}},
{"console", {0, 1, &Service::HandleConsole}}, {"console", {0, 0, &Service::HandleConsole}},
{"critical", {0, 0, &Service::HandleCritical}}, {"critical", {0, 0, &Service::HandleCritical}},
{"disabled", {0, 0, &Service::HandleDisabled}}, {"disabled", {0, 0, &Service::HandleDisabled}},
{"group", {1, NR_SVC_SUPP_GIDS + 1, &Service::HandleGroup}}, {"group", {1, NR_SVC_SUPP_GIDS + 1, &Service::HandleGroup}},
@ -330,7 +329,7 @@ bool Service::Start(const std::vector<std::string>& dynamic_args) {
} }
bool needs_console = (flags_ & SVC_CONSOLE); bool needs_console = (flags_ & SVC_CONSOLE);
if (needs_console && console_names.empty()) { if (needs_console && !have_console) {
ERROR("service '%s' requires console\n", name_.c_str()); ERROR("service '%s' requires console\n", name_.c_str());
flags_ |= SVC_DISABLED; flags_ |= SVC_DISABLED;
return false; return false;
@ -607,12 +606,10 @@ void Service::ZapStdio() const {
} }
void Service::OpenConsole() const { void Service::OpenConsole() const {
int fd = -1; int fd;
if (std::find(console_names.begin(), console_names.end(), console_) != console_names.end()) { if ((fd = open(console_name.c_str(), O_RDWR)) < 0) {
std::string c_path = "/dev/" + console_; fd = open("/dev/null", O_RDWR);
fd = open(c_path.c_str(), O_RDWR);
} }
if (fd == -1) fd = open("/dev/null", O_RDWR);
ioctl(fd, TIOCSCTTY, 0); ioctl(fd, TIOCSCTTY, 0);
dup2(fd, 0); dup2(fd, 0);
dup2(fd, 1); dup2(fd, 1);

View file

@ -129,7 +129,6 @@ private:
std::string name_; std::string name_;
std::string classname_; std::string classname_;
std::string console_;
unsigned flags_; unsigned flags_;
pid_t pid_; pid_t pid_;