Merge "init: report createProcessGroup failure."
This commit is contained in:
commit
2d690a920f
2 changed files with 23 additions and 16 deletions
|
|
@ -99,11 +99,16 @@ void Service::NotifyStateChange(const std::string& new_state) const {
|
||||||
property_set(prop_name.c_str(), new_state.c_str());
|
property_set(prop_name.c_str(), new_state.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Service::KillProcessGroup(int signal) {
|
||||||
|
NOTICE("Sending signal %d to service '%s' (pid %d) process group...\n",
|
||||||
|
signal, name_.c_str(), pid_);
|
||||||
|
kill(pid_, signal);
|
||||||
|
killProcessGroup(uid_, pid_, signal);
|
||||||
|
}
|
||||||
|
|
||||||
bool Service::Reap() {
|
bool Service::Reap() {
|
||||||
if (!(flags_ & SVC_ONESHOT) || (flags_ & SVC_RESTART)) {
|
if (!(flags_ & SVC_ONESHOT) || (flags_ & SVC_RESTART)) {
|
||||||
NOTICE("Service '%s' (pid %d) killing any children in process group\n",
|
KillProcessGroup(SIGKILL);
|
||||||
name_.c_str(), pid_);
|
|
||||||
killProcessGroup(uid_, pid_, SIGKILL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove any sockets we may have created.
|
// Remove any sockets we may have created.
|
||||||
|
|
@ -524,7 +529,12 @@ bool Service::Start() {
|
||||||
time_started_ = gettime();
|
time_started_ = gettime();
|
||||||
pid_ = pid;
|
pid_ = pid;
|
||||||
flags_ |= SVC_RUNNING;
|
flags_ |= SVC_RUNNING;
|
||||||
createProcessGroup(uid_, pid_);
|
|
||||||
|
errno = -createProcessGroup(uid_, pid_);
|
||||||
|
if (errno != 0) {
|
||||||
|
ERROR("createProcessGroup(%d, %d) failed for service '%s': %s\n",
|
||||||
|
uid_, pid_, name_.c_str(), strerror(errno));
|
||||||
|
}
|
||||||
|
|
||||||
if ((flags_ & SVC_EXEC) != 0) {
|
if ((flags_ & SVC_EXEC) != 0) {
|
||||||
INFO("SVC_EXEC pid %d (uid %d gid %d+%zu context %s) started; waiting...\n",
|
INFO("SVC_EXEC pid %d (uid %d gid %d+%zu context %s) started; waiting...\n",
|
||||||
|
|
@ -565,9 +575,7 @@ void Service::Terminate() {
|
||||||
flags_ &= ~(SVC_RESTARTING | SVC_DISABLED_START);
|
flags_ &= ~(SVC_RESTARTING | SVC_DISABLED_START);
|
||||||
flags_ |= SVC_DISABLED;
|
flags_ |= SVC_DISABLED;
|
||||||
if (pid_) {
|
if (pid_) {
|
||||||
NOTICE("Sending SIGTERM to service '%s' (pid %d)...\n", name_.c_str(),
|
KillProcessGroup(SIGTERM);
|
||||||
pid_);
|
|
||||||
killProcessGroup(uid_, pid_, SIGTERM);
|
|
||||||
NotifyStateChange("stopping");
|
NotifyStateChange("stopping");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -597,19 +605,18 @@ void Service::RestartIfNeeded(time_t& process_needs_restart) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* The how field should be either SVC_DISABLED, SVC_RESET, or SVC_RESTART */
|
// The how field should be either SVC_DISABLED, SVC_RESET, or SVC_RESTART.
|
||||||
void Service::StopOrReset(int how) {
|
void Service::StopOrReset(int how) {
|
||||||
/* The service is still SVC_RUNNING until its process exits, but if it has
|
// The service is still SVC_RUNNING until its process exits, but if it has
|
||||||
* already exited it shoudn't attempt a restart yet. */
|
// already exited it shoudn't attempt a restart yet.
|
||||||
flags_ &= ~(SVC_RESTARTING | SVC_DISABLED_START);
|
flags_ &= ~(SVC_RESTARTING | SVC_DISABLED_START);
|
||||||
|
|
||||||
if ((how != SVC_DISABLED) && (how != SVC_RESET) && (how != SVC_RESTART)) {
|
if ((how != SVC_DISABLED) && (how != SVC_RESET) && (how != SVC_RESTART)) {
|
||||||
/* Hrm, an illegal flag. Default to SVC_DISABLED */
|
// An illegal flag: default to SVC_DISABLED.
|
||||||
how = SVC_DISABLED;
|
how = SVC_DISABLED;
|
||||||
}
|
}
|
||||||
/* if the service has not yet started, prevent
|
|
||||||
* it from auto-starting with its class
|
// If the service has not yet started, prevent it from auto-starting with its class.
|
||||||
*/
|
|
||||||
if (how == SVC_RESET) {
|
if (how == SVC_RESET) {
|
||||||
flags_ |= (flags_ & SVC_RC_DISABLED) ? SVC_DISABLED : SVC_RESET;
|
flags_ |= (flags_ & SVC_RC_DISABLED) ? SVC_DISABLED : SVC_RESET;
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -617,8 +624,7 @@ void Service::StopOrReset(int how) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pid_) {
|
if (pid_) {
|
||||||
NOTICE("Service '%s' is being killed...\n", name_.c_str());
|
KillProcessGroup(SIGKILL);
|
||||||
killProcessGroup(uid_, pid_, SIGKILL);
|
|
||||||
NotifyStateChange("stopping");
|
NotifyStateChange("stopping");
|
||||||
} else {
|
} else {
|
||||||
NotifyStateChange("stopped");
|
NotifyStateChange("stopped");
|
||||||
|
|
|
||||||
|
|
@ -111,6 +111,7 @@ private:
|
||||||
void ZapStdio() const;
|
void ZapStdio() const;
|
||||||
void OpenConsole() const;
|
void OpenConsole() const;
|
||||||
void PublishSocket(const std::string& name, int fd) const;
|
void PublishSocket(const std::string& name, int fd) const;
|
||||||
|
void KillProcessGroup(int signal);
|
||||||
|
|
||||||
bool HandleClass(const std::vector<std::string>& args, std::string* err);
|
bool HandleClass(const std::vector<std::string>& args, std::string* err);
|
||||||
bool HandleConsole(const std::vector<std::string>& args, std::string* err);
|
bool HandleConsole(const std::vector<std::string>& args, std::string* err);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue