diff options
Diffstat (limited to 'init/service.cpp')
-rw-r--r-- | init/service.cpp | 30 |
1 files changed, 23 insertions, 7 deletions
diff --git a/init/service.cpp b/init/service.cpp index f95b67582..47f4db94e 100644 --- a/init/service.cpp +++ b/init/service.cpp @@ -31,6 +31,7 @@ #include <android-base/properties.h> #include <android-base/stringprintf.h> #include <android-base/strings.h> +#include <cutils/sockets.h> #include <processgroup/processgroup.h> #include <selinux/selinux.h> @@ -227,9 +228,11 @@ void Service::Reap(const siginfo_t& siginfo) { KillProcessGroup(SIGKILL); } - // Remove any descriptor resources we may have created. - std::for_each(descriptors_.begin(), descriptors_.end(), - std::bind(&DescriptorInfo::Clean, std::placeholders::_1)); + // Remove any socket resources we may have created. + for (const auto& socket : sockets_) { + auto path = ANDROID_SOCKET_DIR "/" + socket.name; + unlink(path.c_str()); + } for (const auto& f : reap_callbacks_) { f(siginfo); @@ -300,8 +303,12 @@ void Service::DumpState() const { LOG(INFO) << "service " << name_; LOG(INFO) << " class '" << Join(classnames_, " ") << "'"; LOG(INFO) << " exec " << Join(args_, " "); - std::for_each(descriptors_.begin(), descriptors_.end(), - [] (const auto& info) { LOG(INFO) << *info; }); + for (const auto& socket : sockets_) { + LOG(INFO) << " socket " << socket.name; + } + for (const auto& file : files_) { + LOG(INFO) << " file " << file.name; + } } @@ -419,8 +426,17 @@ Result<void> Service::Start() { setenv(key.c_str(), value.c_str(), 1); } - std::for_each(descriptors_.begin(), descriptors_.end(), - std::bind(&DescriptorInfo::CreateAndPublish, std::placeholders::_1, scon)); + for (const auto& socket : sockets_) { + if (auto result = socket.CreateAndPublish(scon); !result) { + LOG(INFO) << "Could not create socket '" << socket.name << "': " << result.error(); + } + } + + for (const auto& file : files_) { + if (auto result = file.CreateAndPublish(); !result) { + LOG(INFO) << "Could not open file '" << file.name << "': " << result.error(); + } + } if (auto result = WritePidToFiles(&writepid_files_); !result) { LOG(ERROR) << "failed to write pid to files: " << result.error(); |