已开启
feat(hidumper): raise concurrent request limit for shell dev caller #804
LWH创建于 11 天前
feat(hidumper): raise concurrent request limit for shell dev caller #804
已开启
共 2 个文件变更+23-2
| @@ -84,6 +84,7 @@ private: | |||
| 84 | int32_t StartRequest(const std::shared_ptr<RawParam> rawParam); | 84 | int32_t StartRequest(const std::shared_ptr<RawParam> rawParam); |
| 85 | void RequestMain(const std::shared_ptr<RawParam> rawParam); | 85 | void RequestMain(const std::shared_ptr<RawParam> rawParam); |
| 86 | bool HasDumpPermission() const; | 86 | bool HasDumpPermission() const; |
| 87 | + bool IsShellCaller(int32_t pid); | ||
| 87 | uint32_t GetFileDescriptorNums(int32_t pid, std::string requestType) const; | 88 | uint32_t GetFileDescriptorNums(int32_t pid, std::string requestType) const; |
| 88 | std::string GetFdLink(const std::string &linkPath) const; | 89 | std::string GetFdLink(const std::string &linkPath) const; |
| 89 | std::vector<std::string> GetFdLinks(int pid); | 90 | std::vector<std::string> GetFdLinks(int pid); |
| @@ -35,6 +35,7 @@ | |||
| 35 | 35 | ||
| 36 | 36 | ||
| 37 | 37 | ||
| 38 | + | ||
| 38 | 39 | ||
| 39 | 40 | ||
| 40 | 41 | ||
| @@ -49,8 +50,10 @@ const std::string DUMPMGR_SERVICE_NAME = "HiDumperManagerService"; | |||
| 49 | auto dumpManagerService = DumpDelayedSpSingleton<DumpManagerService>::GetInstance(); | 50 | auto dumpManagerService = DumpDelayedSpSingleton<DumpManagerService>::GetInstance(); |
| 50 | const bool G_REGISTER_RESULT = SystemAbility::MakeAndRegisterAbility(dumpManagerService.GetRefPtr()); | 51 | const bool G_REGISTER_RESULT = SystemAbility::MakeAndRegisterAbility(dumpManagerService.GetRefPtr()); |
| 51 | static const int32_t HIPORFILER_UID = 3063; | 52 | static const int32_t HIPORFILER_UID = 3063; |
| 53 | +static const int32_t SHELL_UID = 2000; | ||
| 52 | static const int32_t STOP_WAIT = 3; | 54 | static const int32_t STOP_WAIT = 3; |
| 53 | static const int32_t REQUEST_MAX = 5; | 55 | static const int32_t REQUEST_MAX = 5; |
| 56 | +static const int32_t REQUEST_MAX_DEV = 20; | ||
| 54 | static const uint32_t REQUESTID_MAX = 100000; | 57 | static const uint32_t REQUESTID_MAX = 100000; |
| 55 | const std::string TASK_ID = "unload"; | 58 | const std::string TASK_ID = "unload"; |
| 56 | constexpr int32_t DYNAMIC_EXIT_DELAY_TIME = 120000; | 59 | constexpr int32_t DYNAMIC_EXIT_DELAY_TIME = 120000; |
| @@ -183,8 +186,11 @@ int32_t DumpManagerService::Request(std::vector<std::u16string> &args, int outfd | |||
| 183 | } | 186 | } |
| 184 | int sum = GetRequestSum(); | 187 | int sum = GetRequestSum(); |
| 185 | DUMPER_HILOGD(MODULE_SERVICE, "debug|sum=%{public}d", sum); | 188 | DUMPER_HILOGD(MODULE_SERVICE, "debug|sum=%{public}d", sum); |
| 186 | - if (sum >= REQUEST_MAX) { | 189 | + int32_t maxLimit = IsShellCaller(IPCSkeleton::GetCallingPid()) ? REQUEST_MAX_DEV : REQUEST_MAX; |
| 187 | - DUMPER_HILOGE(MODULE_SERVICE, "sum is greater than the request max, sum:%{public}d.", sum); | 190 | + DUMPER_HILOGD(MODULE_SERVICE, "debug|maxLimit=%{public}d", maxLimit); |
| 191 | + if (sum >= maxLimit) { | ||
| 192 | + DUMPER_HILOGE(MODULE_SERVICE, "sum is greater than the request max, sum:%{public}d, maxLimit:%{public}d.", | ||
| 193 | + sum, maxLimit); | ||
| 188 | HandleRequestError(args, outfd, static_cast<int32_t>(DumpStatus::DUMP_FAIL), "request sum reached max"); | 194 | HandleRequestError(args, outfd, static_cast<int32_t>(DumpStatus::DUMP_FAIL), "request sum reached max"); |
| 189 | return DumpStatus::DUMP_REQUEST_MAX; | 195 | return DumpStatus::DUMP_REQUEST_MAX; |
| 190 | } else if (sum == 0) { | 196 | } else if (sum == 0) { |
| @@ -210,6 +216,20 @@ bool DumpManagerService::HasDumpPermission() const | |||
| 210 | return true; | 216 | return true; |
| 211 | } | 217 | } |
| 212 | 218 | ||
| 219 | +bool DumpManagerService::IsShellCaller(int32_t pid) | ||
| 220 | +{ | ||
| 221 | + std::string path = "/proc/" + std::to_string(pid) + "/status"; | ||
| 222 | + std::string groups = FileUtils::GetInstance().GetProcValue(pid, path, "Groups"); | ||
| 223 | + std::istringstream iss(groups); | ||
| 224 | + int32_t gid = 0; | ||
| 225 | + while (iss >> gid) { | ||
| 226 | + if (gid == SHELL_UID) { | ||
| 227 | + return true; | ||
| 228 | + } | ||
| 229 | + } | ||
| 230 | + return false; | ||
| 231 | +} | ||
| 232 | + | ||
| 213 | uint32_t DumpManagerService::GetFileDescriptorNums(int32_t pid, std::string requestType) const | 233 | uint32_t DumpManagerService::GetFileDescriptorNums(int32_t pid, std::string requestType) const |
| 214 | { | 234 | { |
| 215 | if (requestType.find("..") != std::string::npos || requestType.find('/') != std::string::npos) { | 235 | if (requestType.find("..") != std::string::npos || requestType.find('/') != std::string::npos) { |