blob: fa9f39895f5546b5938819434e9151db63716c7a [file] [log] [blame]
Mark Salyzyn5ac5c6b2015-08-28 08:02:59 -07001/*
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 Salyzynd048f112016-02-08 10:28:12 -080020#include <sys/cdefs.h>
Mark Salyzyn5ac5c6b2015-08-28 08:02:59 -070021#include <sys/types.h>
22
Mark Salyzynaeaaf812016-09-30 13:30:33 -070023#include <private/android_logger.h>
Mark Salyzyn083b0372015-12-04 10:59:45 -080024#include <sysutils/SocketClient.h>
Mark Salyzyn501c3732017-03-10 14:31:54 -080025#include <utils/FastStrcmp.h>
Mark Salyzyn5ac5c6b2015-08-28 08:02:59 -070026
27// Hijack this header as a common include file used by most all sources
28// to report some utilities defined here and there.
29
30namespace android {
31
32// Furnished in main.cpp. Caller must own and free returned value
Mark Salyzyn501c3732017-03-10 14:31:54 -080033char* uidToName(uid_t uid);
34void prdebug(const char* fmt, ...) __printflike(1, 2);
Mark Salyzyn5ac5c6b2015-08-28 08:02:59 -070035
Mark Salyzyn32962912016-09-12 10:29:17 -070036// Furnished in LogStatistics.cpp.
37size_t sizesTotal();
38// Caller must own and free returned value
Mark Salyzyn501c3732017-03-10 14:31:54 -080039char* pidToName(pid_t pid);
40char* tidToName(pid_t tid);
Mark Salyzyn5ac5c6b2015-08-28 08:02:59 -070041
Mark Salyzyn61e9ce62016-09-12 14:51:54 -070042// Furnished in LogTags.cpp. Thread safe.
Mark Salyzyn501c3732017-03-10 14:31:54 -080043const char* tagToName(uint32_t tag);
Mark Salyzyn61e9ce62016-09-12 14:51:54 -070044void ReReadEventLogTags();
Mark Salyzyn5ac5c6b2015-08-28 08:02:59 -070045
Mark Salyzyn0484b3b2016-08-11 08:02:06 -070046// Furnished by LogKlog.cpp
47char* log_strntok_r(char* s, ssize_t& len, char*& saveptr, ssize_t& sublen);
48
49// needle should reference a string longer than 1 character
50static inline const char* strnstr(const char* s, ssize_t len,
51 const char* needle) {
52 if (len <= 0) return nullptr;
53
54 const char c = *needle++;
55 const size_t needleLen = strlen(needle);
56 do {
57 do {
58 if (len <= (ssize_t)needleLen) return nullptr;
59 --len;
60 } while (*s++ != c);
61 } while (fastcmp<memcmp>(s, needle, needleLen));
62 s--;
63 return s;
64}
Mark Salyzyn5ac5c6b2015-08-28 08:02:59 -070065}
66
Mark Salyzyn083b0372015-12-04 10:59:45 -080067// Furnished in LogCommand.cpp
68bool clientHasLogCredentials(uid_t uid, gid_t gid, pid_t pid);
Mark Salyzyn501c3732017-03-10 14:31:54 -080069bool clientHasLogCredentials(SocketClient* cli);
Mark Salyzyn083b0372015-12-04 10:59:45 -080070
Mark Salyzyn5ac5c6b2015-08-28 08:02:59 -070071static inline bool worstUidEnabledForLogid(log_id_t id) {
Mark Salyzyn6a066942016-07-14 15:34:30 -070072 return (id == LOG_ID_MAIN) || (id == LOG_ID_SYSTEM) ||
Mark Salyzyn501c3732017-03-10 14:31:54 -080073 (id == LOG_ID_RADIO) || (id == LOG_ID_EVENTS);
Mark Salyzyn5ac5c6b2015-08-28 08:02:59 -070074}
75
Mark Salyzyn501c3732017-03-10 14:31:54 -080076#endif // _LOGD_LOG_UTILS_H__