summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTreehugger Robot2016-06-29 16:46:01 -0500
committerGerrit Code Review2016-06-29 16:46:02 -0500
commitb0d062a497bee38ff2a7c6c965e29af4199c3fe0 (patch)
tree1529498040e29d44af3b0ea7c102a99df869417f
parente71cedf4503b183fc82ae04b3d4889c08f181250 (diff)
parent177b27d4f5bfa498cc46aad24d9375d65630bea0 (diff)
downloadplatform-system-core-b0d062a497bee38ff2a7c6c965e29af4199c3fe0.tar.gz
platform-system-core-b0d062a497bee38ff2a7c6c965e29af4199c3fe0.tar.xz
platform-system-core-b0d062a497bee38ff2a7c6c965e29af4199c3fe0.zip
Merge "Rename "Handle(r)" to "Parse(r)" in Android init."
-rw-r--r--init/service.cpp86
-rw-r--r--init/service.h40
2 files changed, 63 insertions, 63 deletions
diff --git a/init/service.cpp b/init/service.cpp
index d23db32fb..03c00640f 100644
--- a/init/service.cpp
+++ b/init/service.cpp
@@ -221,29 +221,29 @@ void Service::DumpState() const {
221 } 221 }
222} 222}
223 223
224bool Service::HandleClass(const std::vector<std::string>& args, std::string* err) { 224bool Service::ParseClass(const std::vector<std::string>& args, std::string* err) {
225 classname_ = args[1]; 225 classname_ = args[1];
226 return true; 226 return true;
227} 227}
228 228
229bool Service::HandleConsole(const std::vector<std::string>& args, std::string* err) { 229bool Service::ParseConsole(const std::vector<std::string>& args, std::string* err) {
230 flags_ |= SVC_CONSOLE; 230 flags_ |= SVC_CONSOLE;
231 console_ = args.size() > 1 ? "/dev/" + args[1] : ""; 231 console_ = args.size() > 1 ? "/dev/" + args[1] : "";
232 return true; 232 return true;
233} 233}
234 234
235bool Service::HandleCritical(const std::vector<std::string>& args, std::string* err) { 235bool Service::ParseCritical(const std::vector<std::string>& args, std::string* err) {
236 flags_ |= SVC_CRITICAL; 236 flags_ |= SVC_CRITICAL;
237 return true; 237 return true;
238} 238}
239 239
240bool Service::HandleDisabled(const std::vector<std::string>& args, std::string* err) { 240bool Service::ParseDisabled(const std::vector<std::string>& args, std::string* err) {
241 flags_ |= SVC_DISABLED; 241 flags_ |= SVC_DISABLED;
242 flags_ |= SVC_RC_DISABLED; 242 flags_ |= SVC_RC_DISABLED;
243 return true; 243 return true;
244} 244}
245 245
246bool Service::HandleGroup(const std::vector<std::string>& args, std::string* err) { 246bool Service::ParseGroup(const std::vector<std::string>& args, std::string* err) {
247 gid_ = decode_uid(args[1].c_str()); 247 gid_ = decode_uid(args[1].c_str());
248 for (std::size_t n = 2; n < args.size(); n++) { 248 for (std::size_t n = 2; n < args.size(); n++) {
249 supp_gids_.emplace_back(decode_uid(args[n].c_str())); 249 supp_gids_.emplace_back(decode_uid(args[n].c_str()));
@@ -251,7 +251,7 @@ bool Service::HandleGroup(const std::vector<std::string>& args, std::string* err
251 return true; 251 return true;
252} 252}
253 253
254bool Service::HandlePriority(const std::vector<std::string>& args, std::string* err) { 254bool Service::ParsePriority(const std::vector<std::string>& args, std::string* err) {
255 priority_ = std::stoi(args[1]); 255 priority_ = std::stoi(args[1]);
256 256
257 if (priority_ < ANDROID_PRIORITY_HIGHEST || priority_ > ANDROID_PRIORITY_LOWEST) { 257 if (priority_ < ANDROID_PRIORITY_HIGHEST || priority_ > ANDROID_PRIORITY_LOWEST) {
@@ -264,7 +264,7 @@ bool Service::HandlePriority(const std::vector<std::string>& args, std::string*
264 return true; 264 return true;
265} 265}
266 266
267bool Service::HandleIoprio(const std::vector<std::string>& args, std::string* err) { 267bool Service::ParseIoprio(const std::vector<std::string>& args, std::string* err) {
268 ioprio_pri_ = std::stoul(args[2], 0, 8); 268 ioprio_pri_ = std::stoul(args[2], 0, 8);
269 269
270 if (ioprio_pri_ < 0 || ioprio_pri_ > 7) { 270 if (ioprio_pri_ < 0 || ioprio_pri_ > 7) {
@@ -286,25 +286,25 @@ bool Service::HandleIoprio(const std::vector<std::string>& args, std::string* er
286 return true; 286 return true;
287} 287}
288 288
289bool Service::HandleKeycodes(const std::vector<std::string>& args, std::string* err) { 289bool Service::ParseKeycodes(const std::vector<std::string>& args, std::string* err) {
290 for (std::size_t i = 1; i < args.size(); i++) { 290 for (std::size_t i = 1; i < args.size(); i++) {
291 keycodes_.emplace_back(std::stoi(args[i])); 291 keycodes_.emplace_back(std::stoi(args[i]));
292 } 292 }
293 return true; 293 return true;
294} 294}
295 295
296bool Service::HandleOneshot(const std::vector<std::string>& args, std::string* err) { 296bool Service::ParseOneshot(const std::vector<std::string>& args, std::string* err) {
297 flags_ |= SVC_ONESHOT; 297 flags_ |= SVC_ONESHOT;
298 return true; 298 return true;
299} 299}
300 300
301bool Service::HandleOnrestart(const std::vector<std::string>& args, std::string* err) { 301bool Service::ParseOnrestart(const std::vector<std::string>& args, std::string* err) {
302 std::vector<std::string> str_args(args.begin() + 1, args.end()); 302 std::vector<std::string> str_args(args.begin() + 1, args.end());
303 onrestart_.AddCommand(str_args, "", 0, err); 303 onrestart_.AddCommand(str_args, "", 0, err);
304 return true; 304 return true;
305} 305}
306 306
307bool Service::HandleNamespace(const std::vector<std::string>& args, std::string* err) { 307bool Service::ParseNamespace(const std::vector<std::string>& args, std::string* err) {
308 for (size_t i = 1; i < args.size(); i++) { 308 for (size_t i = 1; i < args.size(); i++) {
309 if (args[i] == "pid") { 309 if (args[i] == "pid") {
310 namespace_flags_ |= CLONE_NEWPID; 310 namespace_flags_ |= CLONE_NEWPID;
@@ -320,18 +320,18 @@ bool Service::HandleNamespace(const std::vector<std::string>& args, std::string*
320 return true; 320 return true;
321} 321}
322 322
323bool Service::HandleSeclabel(const std::vector<std::string>& args, std::string* err) { 323bool Service::ParseSeclabel(const std::vector<std::string>& args, std::string* err) {
324 seclabel_ = args[1]; 324 seclabel_ = args[1];
325 return true; 325 return true;
326} 326}
327 327
328bool Service::HandleSetenv(const std::vector<std::string>& args, std::string* err) { 328bool Service::ParseSetenv(const std::vector<std::string>& args, std::string* err) {
329 envvars_.emplace_back(args[1], args[2]); 329 envvars_.emplace_back(args[1], args[2]);
330 return true; 330 return true;
331} 331}
332 332
333/* name type perm [ uid gid context ] */ 333/* name type perm [ uid gid context ] */
334bool Service::HandleSocket(const std::vector<std::string>& args, std::string* err) { 334bool Service::ParseSocket(const std::vector<std::string>& args, std::string* err) {
335 if (args[2] != "dgram" && args[2] != "stream" && args[2] != "seqpacket") { 335 if (args[2] != "dgram" && args[2] != "stream" && args[2] != "seqpacket") {
336 *err = "socket type must be 'dgram', 'stream' or 'seqpacket'"; 336 *err = "socket type must be 'dgram', 'stream' or 'seqpacket'";
337 return false; 337 return false;
@@ -346,61 +346,61 @@ bool Service::HandleSocket(const std::vector<std::string>& args, std::string* er
346 return true; 346 return true;
347} 347}
348 348
349bool Service::HandleUser(const std::vector<std::string>& args, std::string* err) { 349bool Service::ParseUser(const std::vector<std::string>& args, std::string* err) {
350 uid_ = decode_uid(args[1].c_str()); 350 uid_ = decode_uid(args[1].c_str());
351 return true; 351 return true;
352} 352}
353 353
354bool Service::HandleWritepid(const std::vector<std::string>& args, std::string* err) { 354bool Service::ParseWritepid(const std::vector<std::string>& args, std::string* err) {
355 writepid_files_.assign(args.begin() + 1, args.end()); 355 writepid_files_.assign(args.begin() + 1, args.end());
356 return true; 356 return true;
357} 357}
358 358
359class Service::OptionHandlerMap : public KeywordMap<OptionHandler> { 359class Service::OptionParserMap : public KeywordMap<OptionParser> {
360public: 360public:
361 OptionHandlerMap() { 361 OptionParserMap() {
362 } 362 }
363private: 363private:
364 Map& map() const override; 364 Map& map() const override;
365}; 365};
366 366
367Service::OptionHandlerMap::Map& Service::OptionHandlerMap::map() const { 367Service::OptionParserMap::Map& Service::OptionParserMap::map() const {
368 constexpr std::size_t kMax = std::numeric_limits<std::size_t>::max(); 368 constexpr std::size_t kMax = std::numeric_limits<std::size_t>::max();
369 static const Map option_handlers = { 369 static const Map option_parsers = {
370 {"class", {1, 1, &Service::HandleClass}}, 370 {"class", {1, 1, &Service::ParseClass}},
371 {"console", {0, 1, &Service::HandleConsole}}, 371 {"console", {0, 1, &Service::ParseConsole}},
372 {"critical", {0, 0, &Service::HandleCritical}}, 372 {"critical", {0, 0, &Service::ParseCritical}},
373 {"disabled", {0, 0, &Service::HandleDisabled}}, 373 {"disabled", {0, 0, &Service::ParseDisabled}},
374 {"group", {1, NR_SVC_SUPP_GIDS + 1, &Service::HandleGroup}}, 374 {"group", {1, NR_SVC_SUPP_GIDS + 1, &Service::ParseGroup}},
375 {"ioprio", {2, 2, &Service::HandleIoprio}}, 375 {"ioprio", {2, 2, &Service::ParseIoprio}},
376 {"priority", {1, 1, &Service::HandlePriority}}, 376 {"priority", {1, 1, &Service::ParsePriority}},
377 {"keycodes", {1, kMax, &Service::HandleKeycodes}}, 377 {"keycodes", {1, kMax, &Service::ParseKeycodes}},
378 {"oneshot", {0, 0, &Service::HandleOneshot}}, 378 {"oneshot", {0, 0, &Service::ParseOneshot}},
379 {"onrestart", {1, kMax, &Service::HandleOnrestart}}, 379 {"onrestart", {1, kMax, &Service::ParseOnrestart}},
380 {"namespace", {1, 2, &Service::HandleNamespace}}, 380 {"namespace", {1, 2, &Service::ParseNamespace}},
381 {"seclabel", {1, 1, &Service::HandleSeclabel}}, 381 {"seclabel", {1, 1, &Service::ParseSeclabel}},
382 {"setenv", {2, 2, &Service::HandleSetenv}}, 382 {"setenv", {2, 2, &Service::ParseSetenv}},
383 {"socket", {3, 6, &Service::HandleSocket}}, 383 {"socket", {3, 6, &Service::ParseSocket}},
384 {"user", {1, 1, &Service::HandleUser}}, 384 {"user", {1, 1, &Service::ParseUser}},
385 {"writepid", {1, kMax, &Service::HandleWritepid}}, 385 {"writepid", {1, kMax, &Service::ParseWritepid}},
386 }; 386 };
387 return option_handlers; 387 return option_parsers;
388} 388}
389 389
390bool Service::HandleLine(const std::vector<std::string>& args, std::string* err) { 390bool Service::ParseLine(const std::vector<std::string>& args, std::string* err) {
391 if (args.empty()) { 391 if (args.empty()) {
392 *err = "option needed, but not provided"; 392 *err = "option needed, but not provided";
393 return false; 393 return false;
394 } 394 }
395 395
396 static const OptionHandlerMap handler_map; 396 static const OptionParserMap parser_map;
397 auto handler = handler_map.FindFunction(args[0], args.size() - 1, err); 397 auto parser = parser_map.FindFunction(args[0], args.size() - 1, err);
398 398
399 if (!handler) { 399 if (!parser) {
400 return false; 400 return false;
401 } 401 }
402 402
403 return (this->*handler)(args, err); 403 return (this->*parser)(args, err);
404} 404}
405 405
406bool Service::Start() { 406bool Service::Start() {
@@ -949,7 +949,7 @@ bool ServiceParser::ParseSection(const std::vector<std::string>& args,
949bool ServiceParser::ParseLineSection(const std::vector<std::string>& args, 949bool ServiceParser::ParseLineSection(const std::vector<std::string>& args,
950 const std::string& filename, int line, 950 const std::string& filename, int line,
951 std::string* err) const { 951 std::string* err) const {
952 return service_ ? service_->HandleLine(args, err) : false; 952 return service_ ? service_->ParseLine(args, err) : false;
953} 953}
954 954
955void ServiceParser::EndSection() { 955void ServiceParser::EndSection() {
diff --git a/init/service.h b/init/service.h
index bf2cf0958..38c5d64c6 100644
--- a/init/service.h
+++ b/init/service.h
@@ -76,7 +76,7 @@ public:
76 const std::vector<gid_t>& supp_gids, unsigned namespace_flags, 76 const std::vector<gid_t>& supp_gids, unsigned namespace_flags,
77 const std::string& seclabel, const std::vector<std::string>& args); 77 const std::string& seclabel, const std::vector<std::string>& args);
78 78
79 bool HandleLine(const std::vector<std::string>& args, std::string* err); 79 bool ParseLine(const std::vector<std::string>& args, std::string* err);
80 bool Start(); 80 bool Start();
81 bool StartIfNotDisabled(); 81 bool StartIfNotDisabled();
82 bool Enable(); 82 bool Enable();
@@ -103,9 +103,9 @@ public:
103 const std::vector<std::string>& args() const { return args_; } 103 const std::vector<std::string>& args() const { return args_; }
104 104
105private: 105private:
106 using OptionHandler = bool (Service::*) (const std::vector<std::string>& args, 106 using OptionParser = bool (Service::*) (const std::vector<std::string>& args,
107 std::string* err); 107 std::string* err);
108 class OptionHandlerMap; 108 class OptionParserMap;
109 109
110 void NotifyStateChange(const std::string& new_state) const; 110 void NotifyStateChange(const std::string& new_state) const;
111 void StopOrReset(int how); 111 void StopOrReset(int how);
@@ -114,22 +114,22 @@ private:
114 void PublishSocket(const std::string& name, int fd) const; 114 void PublishSocket(const std::string& name, int fd) const;
115 void KillProcessGroup(int signal); 115 void KillProcessGroup(int signal);
116 116
117 bool HandleClass(const std::vector<std::string>& args, std::string* err); 117 bool ParseClass(const std::vector<std::string>& args, std::string* err);
118 bool HandleConsole(const std::vector<std::string>& args, std::string* err); 118 bool ParseConsole(const std::vector<std::string>& args, std::string* err);
119 bool HandleCritical(const std::vector<std::string>& args, std::string* err); 119 bool ParseCritical(const std::vector<std::string>& args, std::string* err);
120 bool HandleDisabled(const std::vector<std::string>& args, std::string* err); 120 bool ParseDisabled(const std::vector<std::string>& args, std::string* err);
121 bool HandleGroup(const std::vector<std::string>& args, std::string* err); 121 bool ParseGroup(const std::vector<std::string>& args, std::string* err);
122 bool HandlePriority(const std::vector<std::string>& args, std::string* err); 122 bool ParsePriority(const std::vector<std::string>& args, std::string* err);
123 bool HandleIoprio(const std::vector<std::string>& args, std::string* err); 123 bool ParseIoprio(const std::vector<std::string>& args, std::string* err);
124 bool HandleKeycodes(const std::vector<std::string>& args, std::string* err); 124 bool ParseKeycodes(const std::vector<std::string>& args, std::string* err);
125 bool HandleOneshot(const std::vector<std::string>& args, std::string* err); 125 bool ParseOneshot(const std::vector<std::string>& args, std::string* err);
126 bool HandleOnrestart(const std::vector<std::string>& args, std::string* err); 126 bool ParseOnrestart(const std::vector<std::string>& args, std::string* err);
127 bool HandleNamespace(const std::vector<std::string>& args, std::string* err); 127 bool ParseNamespace(const std::vector<std::string>& args, std::string* err);
128 bool HandleSeclabel(const std::vector<std::string>& args, std::string* err); 128 bool ParseSeclabel(const std::vector<std::string>& args, std::string* err);
129 bool HandleSetenv(const std::vector<std::string>& args, std::string* err); 129 bool ParseSetenv(const std::vector<std::string>& args, std::string* err);
130 bool HandleSocket(const std::vector<std::string>& args, std::string* err); 130 bool ParseSocket(const std::vector<std::string>& args, std::string* err);
131 bool HandleUser(const std::vector<std::string>& args, std::string* err); 131 bool ParseUser(const std::vector<std::string>& args, std::string* err);
132 bool HandleWritepid(const std::vector<std::string>& args, std::string* err); 132 bool ParseWritepid(const std::vector<std::string>& args, std::string* err);
133 133
134 std::string name_; 134 std::string name_;
135 std::string classname_; 135 std::string classname_;