Merge \"Add process priority to service definition.\"
am: 14b00baaae
Change-Id: I0b5cfdce32afdbc47c10a8df015671de1bcb6ada
This commit is contained in:
commit
20cc2787cb
3 changed files with 32 additions and 2 deletions
|
|
@ -184,6 +184,9 @@ writepid <file...>
|
||||||
Write the child's pid to the given files when it forks. Meant for
|
Write the child's pid to the given files when it forks. Meant for
|
||||||
cgroup/cpuset usage.
|
cgroup/cpuset usage.
|
||||||
|
|
||||||
|
priority <priority>
|
||||||
|
Scheduling priority of the service process. This value has to be in range
|
||||||
|
-20 to 19. Default priority is 0. Priority is set via setpriority().
|
||||||
|
|
||||||
Triggers
|
Triggers
|
||||||
--------
|
--------
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,9 @@
|
||||||
#include "service.h"
|
#include "service.h"
|
||||||
|
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
#include <sys/resource.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
#include <sys/time.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
#include <termios.h>
|
#include <termios.h>
|
||||||
|
|
@ -29,6 +31,7 @@
|
||||||
#include <android-base/stringprintf.h>
|
#include <android-base/stringprintf.h>
|
||||||
#include <cutils/android_reboot.h>
|
#include <cutils/android_reboot.h>
|
||||||
#include <cutils/sockets.h>
|
#include <cutils/sockets.h>
|
||||||
|
#include <system/thread_defs.h>
|
||||||
|
|
||||||
#include <processgroup/processgroup.h>
|
#include <processgroup/processgroup.h>
|
||||||
|
|
||||||
|
|
@ -65,7 +68,7 @@ Service::Service(const std::string& name, const std::string& classname,
|
||||||
const std::vector<std::string>& args)
|
const std::vector<std::string>& args)
|
||||||
: name_(name), classname_(classname), flags_(0), pid_(0), time_started_(0),
|
: name_(name), classname_(classname), flags_(0), pid_(0), time_started_(0),
|
||||||
time_crashed_(0), nr_crashed_(0), uid_(0), gid_(0), seclabel_(""),
|
time_crashed_(0), nr_crashed_(0), uid_(0), gid_(0), seclabel_(""),
|
||||||
ioprio_class_(IoSchedClass_NONE), ioprio_pri_(0), args_(args) {
|
ioprio_class_(IoSchedClass_NONE), ioprio_pri_(0), priority_(0), args_(args) {
|
||||||
onrestart_.InitSingleTrigger("onrestart");
|
onrestart_.InitSingleTrigger("onrestart");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -74,7 +77,8 @@ Service::Service(const std::string& name, const std::string& classname,
|
||||||
const std::string& seclabel, const std::vector<std::string>& args)
|
const std::string& seclabel, const std::vector<std::string>& args)
|
||||||
: name_(name), classname_(classname), flags_(flags), pid_(0), time_started_(0),
|
: name_(name), classname_(classname), flags_(flags), pid_(0), time_started_(0),
|
||||||
time_crashed_(0), nr_crashed_(0), uid_(uid), gid_(gid), supp_gids_(supp_gids),
|
time_crashed_(0), nr_crashed_(0), uid_(uid), gid_(gid), supp_gids_(supp_gids),
|
||||||
seclabel_(seclabel), ioprio_class_(IoSchedClass_NONE), ioprio_pri_(0), args_(args) {
|
seclabel_(seclabel), ioprio_class_(IoSchedClass_NONE), ioprio_pri_(0), priority_(0),
|
||||||
|
args_(args) {
|
||||||
onrestart_.InitSingleTrigger("onrestart");
|
onrestart_.InitSingleTrigger("onrestart");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -197,6 +201,19 @@ bool Service::HandleGroup(const std::vector<std::string>& args, std::string* err
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Service::HandlePriority(const std::vector<std::string>& args, std::string* err) {
|
||||||
|
priority_ = std::stoi(args[1]);
|
||||||
|
|
||||||
|
if (priority_ < ANDROID_PRIORITY_HIGHEST || priority_ > ANDROID_PRIORITY_LOWEST) {
|
||||||
|
priority_ = 0;
|
||||||
|
*err = StringPrintf("process priority value must be range %d - %d",
|
||||||
|
ANDROID_PRIORITY_HIGHEST, ANDROID_PRIORITY_LOWEST);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bool Service::HandleIoprio(const std::vector<std::string>& args, std::string* err) {
|
bool Service::HandleIoprio(const std::vector<std::string>& args, std::string* err) {
|
||||||
ioprio_pri_ = std::stoul(args[2], 0, 8);
|
ioprio_pri_ = std::stoul(args[2], 0, 8);
|
||||||
|
|
||||||
|
|
@ -290,6 +307,7 @@ Service::OptionHandlerMap::Map& Service::OptionHandlerMap::map() const {
|
||||||
{"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}},
|
||||||
{"ioprio", {2, 2, &Service::HandleIoprio}},
|
{"ioprio", {2, 2, &Service::HandleIoprio}},
|
||||||
|
{"priority", {1, 1, &Service::HandlePriority}},
|
||||||
{"keycodes", {1, kMax, &Service::HandleKeycodes}},
|
{"keycodes", {1, kMax, &Service::HandleKeycodes}},
|
||||||
{"oneshot", {0, 0, &Service::HandleOneshot}},
|
{"oneshot", {0, 0, &Service::HandleOneshot}},
|
||||||
{"onrestart", {1, kMax, &Service::HandleOnrestart}},
|
{"onrestart", {1, kMax, &Service::HandleOnrestart}},
|
||||||
|
|
@ -470,6 +488,12 @@ bool Service::Start() {
|
||||||
_exit(127);
|
_exit(127);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (priority_ != 0) {
|
||||||
|
if (setpriority(PRIO_PROCESS, 0, priority_) != 0) {
|
||||||
|
ERROR("setpriority failed: %s\n", strerror(errno));
|
||||||
|
_exit(127);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<char*> strs;
|
std::vector<char*> strs;
|
||||||
for (const auto& s : args_) {
|
for (const auto& s : args_) {
|
||||||
|
|
|
||||||
|
|
@ -93,6 +93,7 @@ public:
|
||||||
pid_t pid() const { return pid_; }
|
pid_t pid() const { return pid_; }
|
||||||
uid_t uid() const { return uid_; }
|
uid_t uid() const { return uid_; }
|
||||||
gid_t gid() const { return gid_; }
|
gid_t gid() const { return gid_; }
|
||||||
|
int priority() const { return priority_; }
|
||||||
const std::vector<gid_t>& supp_gids() const { return supp_gids_; }
|
const std::vector<gid_t>& supp_gids() const { return supp_gids_; }
|
||||||
const std::string& seclabel() const { return seclabel_; }
|
const std::string& seclabel() const { return seclabel_; }
|
||||||
const std::vector<int>& keycodes() const { return keycodes_; }
|
const std::vector<int>& keycodes() const { return keycodes_; }
|
||||||
|
|
@ -116,6 +117,7 @@ private:
|
||||||
bool HandleCritical(const std::vector<std::string>& args, std::string* err);
|
bool HandleCritical(const std::vector<std::string>& args, std::string* err);
|
||||||
bool HandleDisabled(const std::vector<std::string>& args, std::string* err);
|
bool HandleDisabled(const std::vector<std::string>& args, std::string* err);
|
||||||
bool HandleGroup(const std::vector<std::string>& args, std::string* err);
|
bool HandleGroup(const std::vector<std::string>& args, std::string* err);
|
||||||
|
bool HandlePriority(const std::vector<std::string>& args, std::string* err);
|
||||||
bool HandleIoprio(const std::vector<std::string>& args, std::string* err);
|
bool HandleIoprio(const std::vector<std::string>& args, std::string* err);
|
||||||
bool HandleKeycodes(const std::vector<std::string>& args, std::string* err);
|
bool HandleKeycodes(const std::vector<std::string>& args, std::string* err);
|
||||||
bool HandleOneshot(const std::vector<std::string>& args, std::string* err);
|
bool HandleOneshot(const std::vector<std::string>& args, std::string* err);
|
||||||
|
|
@ -155,6 +157,7 @@ private:
|
||||||
|
|
||||||
IoSchedClass ioprio_class_;
|
IoSchedClass ioprio_class_;
|
||||||
int ioprio_pri_;
|
int ioprio_pri_;
|
||||||
|
int priority_;
|
||||||
|
|
||||||
std::vector<std::string> args_;
|
std::vector<std::string> args_;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue