Mark Salyzyn | 5ac5c6b | 2015-08-28 08:02:59 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012-2015 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #ifndef _LOGD_LOG_UTILS_H__ |
| 18 | #define _LOGD_LOG_UTILS_H__ |
| 19 | |
Mark Salyzyn | d048f11 | 2016-02-08 10:28:12 -0800 | [diff] [blame] | 20 | #include <sys/cdefs.h> |
Mark Salyzyn | 5ac5c6b | 2015-08-28 08:02:59 -0700 | [diff] [blame] | 21 | #include <sys/types.h> |
| 22 | |
Mark Salyzyn | aeaaf81 | 2016-09-30 13:30:33 -0700 | [diff] [blame] | 23 | #include <private/android_logger.h> |
Mark Salyzyn | 083b037 | 2015-12-04 10:59:45 -0800 | [diff] [blame] | 24 | #include <sysutils/SocketClient.h> |
Mark Salyzyn | 501c373 | 2017-03-10 14:31:54 -0800 | [diff] [blame] | 25 | #include <utils/FastStrcmp.h> |
Mark Salyzyn | 5ac5c6b | 2015-08-28 08:02:59 -0700 | [diff] [blame] | 26 | |
| 27 | // Hijack this header as a common include file used by most all sources |
| 28 | // to report some utilities defined here and there. |
| 29 | |
| 30 | namespace android { |
| 31 | |
| 32 | // Furnished in main.cpp. Caller must own and free returned value |
Mark Salyzyn | 501c373 | 2017-03-10 14:31:54 -0800 | [diff] [blame] | 33 | char* uidToName(uid_t uid); |
| 34 | void prdebug(const char* fmt, ...) __printflike(1, 2); |
Mark Salyzyn | 5ac5c6b | 2015-08-28 08:02:59 -0700 | [diff] [blame] | 35 | |
Mark Salyzyn | 3296291 | 2016-09-12 10:29:17 -0700 | [diff] [blame] | 36 | // Furnished in LogStatistics.cpp. |
| 37 | size_t sizesTotal(); |
| 38 | // Caller must own and free returned value |
Mark Salyzyn | 501c373 | 2017-03-10 14:31:54 -0800 | [diff] [blame] | 39 | char* pidToName(pid_t pid); |
| 40 | char* tidToName(pid_t tid); |
Mark Salyzyn | c4e4823 | 2017-05-04 13:54:46 -0700 | [diff] [blame] | 41 | uid_t pidToUid(pid_t pid); |
| 42 | pid_t tidToPid(pid_t tid); |
Mark Salyzyn | 5ac5c6b | 2015-08-28 08:02:59 -0700 | [diff] [blame] | 43 | |
Mark Salyzyn | 61e9ce6 | 2016-09-12 14:51:54 -0700 | [diff] [blame] | 44 | // Furnished in LogTags.cpp. Thread safe. |
Mark Salyzyn | 501c373 | 2017-03-10 14:31:54 -0800 | [diff] [blame] | 45 | const char* tagToName(uint32_t tag); |
Mark Salyzyn | 61e9ce6 | 2016-09-12 14:51:54 -0700 | [diff] [blame] | 46 | void ReReadEventLogTags(); |
Mark Salyzyn | 5ac5c6b | 2015-08-28 08:02:59 -0700 | [diff] [blame] | 47 | |
Mark Salyzyn | 0484b3b | 2016-08-11 08:02:06 -0700 | [diff] [blame] | 48 | // Furnished by LogKlog.cpp |
| 49 | char* log_strntok_r(char* s, ssize_t& len, char*& saveptr, ssize_t& sublen); |
| 50 | |
| 51 | // needle should reference a string longer than 1 character |
| 52 | static inline const char* strnstr(const char* s, ssize_t len, |
| 53 | const char* needle) { |
| 54 | if (len <= 0) return nullptr; |
| 55 | |
| 56 | const char c = *needle++; |
| 57 | const size_t needleLen = strlen(needle); |
| 58 | do { |
| 59 | do { |
| 60 | if (len <= (ssize_t)needleLen) return nullptr; |
| 61 | --len; |
| 62 | } while (*s++ != c); |
| 63 | } while (fastcmp<memcmp>(s, needle, needleLen)); |
| 64 | s--; |
| 65 | return s; |
| 66 | } |
Mark Salyzyn | 5ac5c6b | 2015-08-28 08:02:59 -0700 | [diff] [blame] | 67 | } |
| 68 | |
Mark Salyzyn | 083b037 | 2015-12-04 10:59:45 -0800 | [diff] [blame] | 69 | // Furnished in LogCommand.cpp |
| 70 | bool clientHasLogCredentials(uid_t uid, gid_t gid, pid_t pid); |
Mark Salyzyn | 501c373 | 2017-03-10 14:31:54 -0800 | [diff] [blame] | 71 | bool clientHasLogCredentials(SocketClient* cli); |
Mark Salyzyn | 083b037 | 2015-12-04 10:59:45 -0800 | [diff] [blame] | 72 | |
Mark Salyzyn | 5ac5c6b | 2015-08-28 08:02:59 -0700 | [diff] [blame] | 73 | static inline bool worstUidEnabledForLogid(log_id_t id) { |
Mark Salyzyn | 6a06694 | 2016-07-14 15:34:30 -0700 | [diff] [blame] | 74 | return (id == LOG_ID_MAIN) || (id == LOG_ID_SYSTEM) || |
Mark Salyzyn | 501c373 | 2017-03-10 14:31:54 -0800 | [diff] [blame] | 75 | (id == LOG_ID_RADIO) || (id == LOG_ID_EVENTS); |
Mark Salyzyn | 5ac5c6b | 2015-08-28 08:02:59 -0700 | [diff] [blame] | 76 | } |
| 77 | |
Mark Salyzyn | 501c373 | 2017-03-10 14:31:54 -0800 | [diff] [blame] | 78 | #endif // _LOGD_LOG_UTILS_H__ |