Merge \\"Improve init Service logging.\\" am: c1d9ac1f85

am: b49e54b1d7

Change-Id: I70eb2755f6d33fd6a2d26c9a3889659e9c66da22
This commit is contained in:
Elliott Hughes 2016-07-26 15:24:34 +00:00 committed by android-build-merger
commit 3fca6fba2b

View file

@ -95,16 +95,16 @@ static void SetUpPidNamespace(const std::string& service_name) {
// It's OK to LOG(FATAL) in this function since it's running in the first // It's OK to LOG(FATAL) in this function since it's running in the first
// child process. // child process.
if (mount("", "/proc", "proc", kSafeFlags | MS_REMOUNT, "") == -1) { if (mount("", "/proc", "proc", kSafeFlags | MS_REMOUNT, "") == -1) {
PLOG(FATAL) << "couldn't remount(/proc)"; PLOG(FATAL) << "couldn't remount(/proc) for " << service_name;
} }
if (prctl(PR_SET_NAME, service_name.c_str()) == -1) { if (prctl(PR_SET_NAME, service_name.c_str()) == -1) {
PLOG(FATAL) << "couldn't set name"; PLOG(FATAL) << "couldn't set name for " << service_name;
} }
pid_t child_pid = fork(); pid_t child_pid = fork();
if (child_pid == -1) { if (child_pid == -1) {
PLOG(FATAL) << "couldn't fork init inside the PID namespace"; PLOG(FATAL) << "couldn't fork init inside the PID namespace for " << service_name;
} }
if (child_pid > 0) { if (child_pid > 0) {
@ -219,31 +219,32 @@ void Service::CreateSockets(const std::string& context) {
} }
void Service::SetProcessAttributes() { void Service::SetProcessAttributes() {
setpgid(0, getpid()); // TODO: work out why this fails for `console` then upgrade to FATAL.
if (setpgid(0, getpid()) == -1) PLOG(ERROR) << "setpgid failed for " << name_;
if (gid_) { if (gid_) {
if (setgid(gid_) != 0) { if (setgid(gid_) != 0) {
PLOG(FATAL) << "setgid failed"; PLOG(FATAL) << "setgid failed for " << name_;
} }
} }
if (!supp_gids_.empty()) { if (!supp_gids_.empty()) {
if (setgroups(supp_gids_.size(), &supp_gids_[0]) != 0) { if (setgroups(supp_gids_.size(), &supp_gids_[0]) != 0) {
PLOG(FATAL) << "setgroups failed"; PLOG(FATAL) << "setgroups failed for " << name_;
} }
} }
if (uid_) { if (uid_) {
if (setuid(uid_) != 0) { if (setuid(uid_) != 0) {
PLOG(FATAL) << "setuid failed"; PLOG(FATAL) << "setuid failed for " << name_;
} }
} }
if (!seclabel_.empty()) { if (!seclabel_.empty()) {
if (setexeccon(seclabel_.c_str()) < 0) { if (setexeccon(seclabel_.c_str()) < 0) {
PLOG(FATAL) << "cannot setexeccon('" << seclabel_ << "')"; PLOG(FATAL) << "cannot setexeccon('" << seclabel_ << "') for " << name_;
} }
} }
if (priority_ != 0) { if (priority_ != 0) {
if (setpriority(PRIO_PROCESS, 0, priority_) != 0) { if (setpriority(PRIO_PROCESS, 0, priority_) != 0) {
PLOG(FATAL) << "setpriority failed"; PLOG(FATAL) << "setpriority failed for " << name_;
} }
} }
} }