2014-02-26 18:50:16 +01:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2012-2013 The Android Open Source Project
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <dirent.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <fcntl.h>
|
2019-06-06 22:41:20 +02:00
|
|
|
#include <linux/capability.h>
|
2015-03-11 00:45:17 +01:00
|
|
|
#include <poll.h>
|
2013-12-27 00:13:36 +01:00
|
|
|
#include <sched.h>
|
2015-03-11 00:45:17 +01:00
|
|
|
#include <semaphore.h>
|
|
|
|
#include <signal.h>
|
2014-02-26 18:50:16 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <sys/capability.h>
|
2014-10-13 18:59:37 +02:00
|
|
|
#include <sys/klog.h>
|
2014-07-19 02:39:41 +02:00
|
|
|
#include <sys/prctl.h>
|
2015-06-09 08:36:34 +02:00
|
|
|
#include <sys/resource.h>
|
2014-02-26 18:50:16 +01:00
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/types.h>
|
2015-03-12 20:25:35 +01:00
|
|
|
#include <syslog.h>
|
2014-02-20 02:18:31 +01:00
|
|
|
#include <unistd.h>
|
2014-02-26 18:50:16 +01:00
|
|
|
|
2015-06-12 23:59:42 +02:00
|
|
|
#include <memory>
|
|
|
|
|
2016-07-15 19:57:08 +02:00
|
|
|
#include <android-base/macros.h>
|
2016-11-07 18:39:30 +01:00
|
|
|
#include <cutils/android_get_control_file.h>
|
2014-02-20 02:18:31 +01:00
|
|
|
#include <cutils/properties.h>
|
2015-03-11 00:45:17 +01:00
|
|
|
#include <cutils/sockets.h>
|
2015-04-13 23:24:45 +02:00
|
|
|
#include <log/event_tag_map.h>
|
2015-07-31 22:10:36 +02:00
|
|
|
#include <packagelistparser/packagelistparser.h>
|
2015-03-17 15:56:32 +01:00
|
|
|
#include <private/android_filesystem_config.h>
|
2016-03-29 00:42:08 +02:00
|
|
|
#include <private/android_logger.h>
|
2018-12-21 21:30:16 +01:00
|
|
|
#include <processgroup/sched_policy.h>
|
2015-06-09 08:36:34 +02:00
|
|
|
#include <utils/threads.h>
|
2014-02-20 02:18:31 +01:00
|
|
|
|
2014-02-26 18:50:16 +01:00
|
|
|
#include "CommandListener.h"
|
2013-02-08 01:45:26 +01:00
|
|
|
#include "LogAudit.h"
|
2017-03-10 23:31:54 +01:00
|
|
|
#include "LogBuffer.h"
|
2014-10-15 17:49:39 +02:00
|
|
|
#include "LogKlog.h"
|
2017-03-10 23:31:54 +01:00
|
|
|
#include "LogListener.h"
|
2015-08-28 17:02:59 +02:00
|
|
|
#include "LogUtils.h"
|
2014-02-26 18:50:16 +01:00
|
|
|
|
2017-03-10 23:31:54 +01:00
|
|
|
#define KMSG_PRIORITY(PRI) \
|
|
|
|
'<', '0' + LOG_MAKEPRI(LOG_DAEMON, LOG_PRI(PRI)) / 10, \
|
|
|
|
'0' + LOG_MAKEPRI(LOG_DAEMON, LOG_PRI(PRI)) % 10, '>'
|
2015-03-12 20:25:35 +01:00
|
|
|
|
2019-06-06 22:41:20 +02:00
|
|
|
// The service is designed to be run by init, it does not respond well to starting up manually. Init
|
|
|
|
// has a 'sigstop' feature that sends SIGSTOP to a service immediately before calling exec(). This
|
|
|
|
// allows debuggers, etc to be attached to logd at the very beginning, while still having init
|
|
|
|
// handle the user, groups, capabilities, files, etc setup.
|
2016-10-29 00:11:46 +02:00
|
|
|
static int drop_privs(bool klogd, bool auditd) {
|
2018-06-13 19:33:45 +02:00
|
|
|
sched_param param = {};
|
2013-12-27 00:13:36 +01:00
|
|
|
|
2015-01-31 00:19:48 +01:00
|
|
|
if (set_sched_policy(0, SP_BACKGROUND) < 0) {
|
2016-10-29 00:51:03 +02:00
|
|
|
android::prdebug("failed to set background scheduling policy");
|
2018-06-13 19:33:45 +02:00
|
|
|
return -1;
|
2015-01-31 00:19:48 +01:00
|
|
|
}
|
|
|
|
|
2017-03-10 23:31:54 +01:00
|
|
|
if (sched_setscheduler((pid_t)0, SCHED_BATCH, ¶m) < 0) {
|
2016-10-29 00:51:03 +02:00
|
|
|
android::prdebug("failed to set batch scheduler");
|
2018-06-13 19:33:45 +02:00
|
|
|
return -1;
|
2013-12-27 00:13:36 +01:00
|
|
|
}
|
|
|
|
|
2018-08-15 21:17:18 +02:00
|
|
|
if (!__android_logger_property_get_bool("ro.debuggable",
|
|
|
|
BOOL_DEFAULT_FALSE) &&
|
2018-06-13 19:33:45 +02:00
|
|
|
prctl(PR_SET_DUMPABLE, 0) == -1) {
|
2016-10-28 23:49:53 +02:00
|
|
|
android::prdebug("failed to clear PR_SET_DUMPABLE");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2019-06-06 22:41:20 +02:00
|
|
|
std::unique_ptr<struct _cap_struct, int (*)(void*)> caps(cap_init(), cap_free);
|
|
|
|
if (cap_clear(caps.get()) < 0) {
|
2018-06-13 19:33:45 +02:00
|
|
|
return -1;
|
2016-10-28 23:49:53 +02:00
|
|
|
}
|
2019-06-06 22:41:20 +02:00
|
|
|
std::vector<cap_value_t> cap_value;
|
|
|
|
if (klogd) {
|
|
|
|
cap_value.emplace_back(CAP_SYSLOG);
|
2016-10-28 23:49:53 +02:00
|
|
|
}
|
2019-06-06 22:41:20 +02:00
|
|
|
if (auditd) {
|
|
|
|
cap_value.emplace_back(CAP_AUDIT_CONTROL);
|
2016-10-28 23:49:53 +02:00
|
|
|
}
|
|
|
|
|
2019-06-06 22:41:20 +02:00
|
|
|
if (cap_set_flag(caps.get(), CAP_PERMITTED, cap_value.size(), cap_value.data(), CAP_SET) < 0) {
|
2017-03-10 23:31:54 +01:00
|
|
|
return -1;
|
|
|
|
}
|
2019-06-06 22:41:20 +02:00
|
|
|
if (cap_set_flag(caps.get(), CAP_EFFECTIVE, cap_value.size(), cap_value.data(), CAP_SET) < 0) {
|
2017-03-10 23:31:54 +01:00
|
|
|
return -1;
|
|
|
|
}
|
2016-10-28 23:49:53 +02:00
|
|
|
if (cap_set_proc(caps.get()) < 0) {
|
2019-06-06 22:41:20 +02:00
|
|
|
android::prdebug("failed to set CAP_SYSLOG or CAP_AUDIT_CONTROL (%d)", errno);
|
2018-06-13 19:33:45 +02:00
|
|
|
return -1;
|
2016-10-28 23:49:53 +02:00
|
|
|
}
|
|
|
|
|
2014-02-26 18:50:16 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-04-29 01:39:04 +02:00
|
|
|
// Property helper
|
2017-03-10 23:31:54 +01:00
|
|
|
static bool check_flag(const char* prop, const char* flag) {
|
|
|
|
const char* cp = strcasestr(prop, flag);
|
2015-12-15 01:40:12 +01:00
|
|
|
if (!cp) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// We only will document comma (,)
|
|
|
|
static const char sep[] = ",:;|+ \t\f";
|
|
|
|
if ((cp != prop) && !strchr(sep, cp[-1])) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
cp += strlen(flag);
|
|
|
|
return !*cp || !!strchr(sep, *cp);
|
|
|
|
}
|
2014-04-29 01:39:04 +02:00
|
|
|
|
2015-03-12 20:25:35 +01:00
|
|
|
static int fdDmesg = -1;
|
2017-03-10 23:31:54 +01:00
|
|
|
void android::prdebug(const char* fmt, ...) {
|
2016-02-08 19:28:12 +01:00
|
|
|
if (fdDmesg < 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char message[] = {
|
|
|
|
KMSG_PRIORITY(LOG_DEBUG), 'l', 'o', 'g', 'd', ':', ' '
|
|
|
|
};
|
|
|
|
char buffer[256];
|
|
|
|
memcpy(buffer, message, sizeof(message));
|
|
|
|
|
|
|
|
va_list ap;
|
|
|
|
va_start(ap, fmt);
|
|
|
|
int n = vsnprintf(buffer + sizeof(message),
|
|
|
|
sizeof(buffer) - sizeof(message), fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
if (n > 0) {
|
|
|
|
buffer[sizeof(buffer) - 1] = '\0';
|
|
|
|
if (!strchr(buffer, '\n')) {
|
|
|
|
buffer[sizeof(buffer) - 2] = '\0';
|
|
|
|
strlcat(buffer, "\n", sizeof(buffer));
|
|
|
|
}
|
|
|
|
write(fdDmesg, buffer, strlen(buffer));
|
|
|
|
}
|
|
|
|
}
|
2015-03-12 20:25:35 +01:00
|
|
|
|
2015-03-11 00:45:17 +01:00
|
|
|
static sem_t reinit;
|
|
|
|
static bool reinit_running = false;
|
2016-08-11 17:02:06 +02:00
|
|
|
static LogBuffer* logBuf = nullptr;
|
2015-07-31 22:10:36 +02:00
|
|
|
|
2017-03-10 23:31:54 +01:00
|
|
|
static void* reinit_thread_start(void* /*obj*/) {
|
2015-03-11 00:45:17 +01:00
|
|
|
prctl(PR_SET_NAME, "logd.daemon");
|
2016-10-31 21:49:44 +01:00
|
|
|
|
2015-03-11 00:45:17 +01:00
|
|
|
while (reinit_running && !sem_wait(&reinit) && reinit_running) {
|
2015-03-12 20:25:35 +01:00
|
|
|
if (fdDmesg >= 0) {
|
|
|
|
static const char reinit_message[] = { KMSG_PRIORITY(LOG_INFO),
|
2017-03-10 23:31:54 +01:00
|
|
|
'l',
|
|
|
|
'o',
|
|
|
|
'g',
|
|
|
|
'd',
|
|
|
|
'.',
|
|
|
|
'd',
|
|
|
|
'a',
|
|
|
|
'e',
|
|
|
|
'm',
|
|
|
|
'o',
|
|
|
|
'n',
|
|
|
|
':',
|
|
|
|
' ',
|
|
|
|
'r',
|
|
|
|
'e',
|
|
|
|
'i',
|
|
|
|
'n',
|
|
|
|
'i',
|
|
|
|
't',
|
|
|
|
'\n' };
|
2015-03-12 20:25:35 +01:00
|
|
|
write(fdDmesg, reinit_message, sizeof(reinit_message));
|
|
|
|
}
|
|
|
|
|
2015-03-11 00:45:17 +01:00
|
|
|
// Anything that reads persist.<property>
|
|
|
|
if (logBuf) {
|
|
|
|
logBuf->init();
|
2016-08-11 17:02:06 +02:00
|
|
|
logBuf->initPrune(nullptr);
|
2015-03-11 00:45:17 +01:00
|
|
|
}
|
2016-09-12 23:51:54 +02:00
|
|
|
android::ReReadEventLogTags();
|
2015-03-11 00:45:17 +01:00
|
|
|
}
|
|
|
|
|
2016-08-11 17:02:06 +02:00
|
|
|
return nullptr;
|
2015-03-11 00:45:17 +01:00
|
|
|
}
|
|
|
|
|
2017-03-10 23:31:54 +01:00
|
|
|
char* android::uidToName(uid_t u) {
|
2017-09-06 19:07:37 +02:00
|
|
|
struct Userdata {
|
|
|
|
uid_t uid;
|
|
|
|
char* name;
|
|
|
|
} userdata = {
|
|
|
|
.uid = u,
|
|
|
|
.name = nullptr,
|
|
|
|
};
|
2015-04-20 16:26:27 +02:00
|
|
|
|
2017-09-06 19:07:37 +02:00
|
|
|
packagelist_parse(
|
|
|
|
[](pkg_info* info, void* callback_parameter) {
|
|
|
|
auto userdata = reinterpret_cast<Userdata*>(callback_parameter);
|
|
|
|
bool result = true;
|
|
|
|
if (info->uid == userdata->uid) {
|
|
|
|
userdata->name = strdup(info->name);
|
|
|
|
// false to stop processing
|
|
|
|
result = false;
|
|
|
|
}
|
|
|
|
packagelist_free(info);
|
|
|
|
return result;
|
|
|
|
},
|
|
|
|
&userdata);
|
|
|
|
|
|
|
|
return userdata.name;
|
2015-03-16 16:26:05 +01:00
|
|
|
}
|
|
|
|
|
2015-03-11 00:45:17 +01:00
|
|
|
// Serves as a global method to trigger reinitialization
|
|
|
|
// and as a function that can be provided to signal().
|
|
|
|
void reinit_signal_handler(int /*signal*/) {
|
|
|
|
sem_post(&reinit);
|
|
|
|
}
|
|
|
|
|
2017-03-10 23:31:54 +01:00
|
|
|
static void readDmesg(LogAudit* al, LogKlog* kl) {
|
2015-06-12 23:59:42 +02:00
|
|
|
if (!al && !kl) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-08-11 17:02:06 +02:00
|
|
|
int rc = klogctl(KLOG_SIZE_BUFFER, nullptr, 0);
|
2015-09-02 16:39:53 +02:00
|
|
|
if (rc <= 0) {
|
2015-06-12 23:59:42 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-08-11 17:02:06 +02:00
|
|
|
// Margin for additional input race or trailing nul
|
|
|
|
ssize_t len = rc + 1024;
|
2017-03-10 23:31:54 +01:00
|
|
|
std::unique_ptr<char[]> buf(new char[len]);
|
2015-06-12 23:59:42 +02:00
|
|
|
|
2015-09-02 16:39:53 +02:00
|
|
|
rc = klogctl(KLOG_READ_ALL, buf.get(), len);
|
2015-06-12 23:59:42 +02:00
|
|
|
if (rc <= 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-08-11 17:02:06 +02:00
|
|
|
if (rc < len) {
|
2015-06-12 23:59:42 +02:00
|
|
|
len = rc + 1;
|
|
|
|
}
|
2015-09-02 16:39:53 +02:00
|
|
|
buf[--len] = '\0';
|
2015-06-12 23:59:42 +02:00
|
|
|
|
2015-09-08 17:56:32 +02:00
|
|
|
if (kl && kl->isMonotonic()) {
|
2015-09-04 20:37:42 +02:00
|
|
|
kl->synchronize(buf.get(), len);
|
2015-06-12 23:59:42 +02:00
|
|
|
}
|
|
|
|
|
2016-08-11 17:02:06 +02:00
|
|
|
ssize_t sublen;
|
|
|
|
for (char *ptr = nullptr, *tok = buf.get();
|
|
|
|
(rc >= 0) && !!(tok = android::log_strntok_r(tok, len, ptr, sublen));
|
|
|
|
tok = nullptr) {
|
|
|
|
if ((sublen <= 0) || !*tok) continue;
|
2015-06-12 23:59:42 +02:00
|
|
|
if (al) {
|
2015-09-04 20:37:42 +02:00
|
|
|
rc = al->log(tok, sublen);
|
2015-06-12 23:59:42 +02:00
|
|
|
}
|
|
|
|
if (kl) {
|
2015-09-04 20:37:42 +02:00
|
|
|
rc = kl->log(tok, sublen);
|
2015-06-12 23:59:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-31 21:49:44 +01:00
|
|
|
static int issueReinit() {
|
2017-03-10 23:31:54 +01:00
|
|
|
int sock = TEMP_FAILURE_RETRY(socket_local_client(
|
|
|
|
"logd", ANDROID_SOCKET_NAMESPACE_RESERVED, SOCK_STREAM));
|
2016-10-31 21:49:44 +01:00
|
|
|
if (sock < 0) return -errno;
|
|
|
|
|
|
|
|
static const char reinitStr[] = "reinit";
|
|
|
|
ssize_t ret = TEMP_FAILURE_RETRY(write(sock, reinitStr, sizeof(reinitStr)));
|
|
|
|
if (ret < 0) return -errno;
|
|
|
|
|
|
|
|
struct pollfd p;
|
|
|
|
memset(&p, 0, sizeof(p));
|
|
|
|
p.fd = sock;
|
|
|
|
p.events = POLLIN;
|
|
|
|
ret = TEMP_FAILURE_RETRY(poll(&p, 1, 1000));
|
|
|
|
if (ret < 0) return -errno;
|
|
|
|
if ((ret == 0) || !(p.revents & POLLIN)) return -ETIME;
|
|
|
|
|
|
|
|
static const char success[] = "success";
|
|
|
|
char buffer[sizeof(success) - 1];
|
|
|
|
memset(buffer, 0, sizeof(buffer));
|
|
|
|
ret = TEMP_FAILURE_RETRY(read(sock, buffer, sizeof(buffer)));
|
|
|
|
if (ret < 0) return -errno;
|
|
|
|
|
|
|
|
return strncmp(buffer, success, sizeof(success) - 1) != 0;
|
|
|
|
}
|
|
|
|
|
2015-03-11 00:45:17 +01:00
|
|
|
// Foreground waits for exit of the main persistent threads
|
|
|
|
// that are started here. The threads are created to manage
|
|
|
|
// UNIX domain client sockets for writing, reading and
|
|
|
|
// controlling the user space logger, and for any additional
|
|
|
|
// logging plugins like auditd and restart control. Additional
|
|
|
|
// transitory per-client threads are created for each reader.
|
2017-03-10 23:31:54 +01:00
|
|
|
int main(int argc, char* argv[]) {
|
2017-03-29 10:41:17 +02:00
|
|
|
// logd is written under the assumption that the timezone is UTC.
|
|
|
|
// If TZ is not set, persist.sys.timezone is looked up in some time utility
|
|
|
|
// libc functions, including mktime. It confuses the logd time handling,
|
|
|
|
// so here explicitly set TZ to UTC, which overrides the property.
|
|
|
|
setenv("TZ", "UTC", 1);
|
2015-03-11 00:45:17 +01:00
|
|
|
// issue reinit command. KISS argument parsing.
|
|
|
|
if ((argc > 1) && argv[1] && !strcmp(argv[1], "--reinit")) {
|
2016-10-31 21:49:44 +01:00
|
|
|
return issueReinit();
|
2015-03-11 00:45:17 +01:00
|
|
|
}
|
|
|
|
|
2016-10-27 17:21:35 +02:00
|
|
|
static const char dev_kmsg[] = "/dev/kmsg";
|
|
|
|
fdDmesg = android_get_control_file(dev_kmsg);
|
|
|
|
if (fdDmesg < 0) {
|
|
|
|
fdDmesg = TEMP_FAILURE_RETRY(open(dev_kmsg, O_WRONLY | O_CLOEXEC));
|
|
|
|
}
|
|
|
|
|
|
|
|
int fdPmesg = -1;
|
2017-03-10 23:31:54 +01:00
|
|
|
bool klogd = __android_logger_property_get_bool(
|
2017-12-28 23:13:22 +01:00
|
|
|
"ro.logd.kernel",
|
|
|
|
BOOL_DEFAULT_TRUE | BOOL_DEFAULT_FLAG_ENG | BOOL_DEFAULT_FLAG_SVELTE);
|
2016-10-27 17:21:35 +02:00
|
|
|
if (klogd) {
|
|
|
|
static const char proc_kmsg[] = "/proc/kmsg";
|
|
|
|
fdPmesg = android_get_control_file(proc_kmsg);
|
|
|
|
if (fdPmesg < 0) {
|
2017-03-10 23:31:54 +01:00
|
|
|
fdPmesg = TEMP_FAILURE_RETRY(
|
|
|
|
open(proc_kmsg, O_RDONLY | O_NDELAY | O_CLOEXEC));
|
2016-10-27 17:21:35 +02:00
|
|
|
}
|
|
|
|
if (fdPmesg < 0) android::prdebug("Failed to open %s\n", proc_kmsg);
|
|
|
|
}
|
|
|
|
|
2019-06-06 22:41:20 +02:00
|
|
|
bool auditd = __android_logger_property_get_bool("ro.logd.auditd", BOOL_DEFAULT_TRUE);
|
|
|
|
if (drop_privs(klogd, auditd) != 0) {
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
|
2015-03-11 00:45:17 +01:00
|
|
|
// Reinit Thread
|
|
|
|
sem_init(&reinit, 0, 0);
|
|
|
|
pthread_attr_t attr;
|
|
|
|
if (!pthread_attr_init(&attr)) {
|
|
|
|
struct sched_param param;
|
|
|
|
|
|
|
|
memset(¶m, 0, sizeof(param));
|
|
|
|
pthread_attr_setschedparam(&attr, ¶m);
|
|
|
|
pthread_attr_setschedpolicy(&attr, SCHED_BATCH);
|
2017-03-10 23:31:54 +01:00
|
|
|
if (!pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED)) {
|
2015-03-11 00:45:17 +01:00
|
|
|
pthread_t thread;
|
|
|
|
reinit_running = true;
|
2016-08-11 17:02:06 +02:00
|
|
|
if (pthread_create(&thread, &attr, reinit_thread_start, nullptr)) {
|
2015-03-11 00:45:17 +01:00
|
|
|
reinit_running = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pthread_attr_destroy(&attr);
|
2014-04-03 18:55:26 +02:00
|
|
|
}
|
|
|
|
|
2014-02-26 18:50:16 +01:00
|
|
|
// Serves the purpose of managing the last logs times read on a
|
|
|
|
// socket connection, and as a reader lock on a range of log
|
|
|
|
// entries.
|
|
|
|
|
2017-03-10 23:31:54 +01:00
|
|
|
LastLogTimes* times = new LastLogTimes();
|
2014-02-26 18:50:16 +01:00
|
|
|
|
|
|
|
// LogBuffer is the object which is responsible for holding all
|
|
|
|
// log entries.
|
|
|
|
|
2015-03-11 00:45:17 +01:00
|
|
|
logBuf = new LogBuffer(times);
|
|
|
|
|
|
|
|
signal(SIGHUP, reinit_signal_handler);
|
2014-02-26 18:50:16 +01:00
|
|
|
|
2017-03-10 23:31:54 +01:00
|
|
|
if (__android_logger_property_get_bool(
|
|
|
|
"logd.statistics", BOOL_DEFAULT_TRUE | BOOL_DEFAULT_FLAG_PERSIST |
|
|
|
|
BOOL_DEFAULT_FLAG_ENG |
|
|
|
|
BOOL_DEFAULT_FLAG_SVELTE)) {
|
2014-10-15 17:49:39 +02:00
|
|
|
logBuf->enableStatistics();
|
2014-09-21 23:22:18 +02:00
|
|
|
}
|
2014-02-20 02:18:31 +01:00
|
|
|
|
2014-02-26 18:50:16 +01:00
|
|
|
// LogReader listens on /dev/socket/logdr. When a client
|
|
|
|
// connects, log entries in the LogBuffer are written to the client.
|
|
|
|
|
2017-03-10 23:31:54 +01:00
|
|
|
LogReader* reader = new LogReader(logBuf);
|
2014-02-26 18:50:16 +01:00
|
|
|
if (reader->startListener()) {
|
2018-06-13 19:33:45 +02:00
|
|
|
return EXIT_FAILURE;
|
2014-02-26 18:50:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// LogListener listens on /dev/socket/logdw for client
|
|
|
|
// initiated log messages. New log entries are added to LogBuffer
|
|
|
|
// and LogReader is notified to send updates to connected clients.
|
|
|
|
|
2017-03-10 23:31:54 +01:00
|
|
|
LogListener* swl = new LogListener(logBuf, reader);
|
2013-11-20 22:38:52 +01:00
|
|
|
// Backlog and /proc/sys/net/unix/max_dgram_qlen set to large value
|
2015-09-08 20:24:07 +02:00
|
|
|
if (swl->startListener(600)) {
|
2018-06-13 19:33:45 +02:00
|
|
|
return EXIT_FAILURE;
|
2014-02-26 18:50:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Command listener listens on /dev/socket/logd for incoming logd
|
|
|
|
// administrative commands.
|
|
|
|
|
2017-03-10 23:31:54 +01:00
|
|
|
CommandListener* cl = new CommandListener(logBuf, reader, swl);
|
2014-02-26 18:50:16 +01:00
|
|
|
if (cl->startListener()) {
|
2018-06-13 19:33:45 +02:00
|
|
|
return EXIT_FAILURE;
|
2014-02-26 18:50:16 +01:00
|
|
|
}
|
|
|
|
|
2013-02-08 01:45:26 +01:00
|
|
|
// LogAudit listens on NETLINK_AUDIT socket for selinux
|
|
|
|
// initiated log messages. New log entries are added to LogBuffer
|
|
|
|
// and LogReader is notified to send updates to connected clients.
|
|
|
|
|
2016-08-11 17:02:06 +02:00
|
|
|
LogAudit* al = nullptr;
|
2016-06-14 20:04:43 +02:00
|
|
|
if (auditd) {
|
|
|
|
al = new LogAudit(logBuf, reader,
|
2016-09-27 22:08:23 +02:00
|
|
|
__android_logger_property_get_bool(
|
2017-03-10 23:31:54 +01:00
|
|
|
"ro.logd.auditd.dmesg", BOOL_DEFAULT_TRUE)
|
|
|
|
? fdDmesg
|
|
|
|
: -1);
|
2016-06-14 20:04:43 +02:00
|
|
|
}
|
2015-03-11 00:45:17 +01:00
|
|
|
|
2016-08-11 17:02:06 +02:00
|
|
|
LogKlog* kl = nullptr;
|
2014-10-15 17:49:39 +02:00
|
|
|
if (klogd) {
|
2016-08-11 17:02:06 +02:00
|
|
|
kl = new LogKlog(logBuf, reader, fdDmesg, fdPmesg, al != nullptr);
|
2014-10-15 17:49:39 +02:00
|
|
|
}
|
2014-10-13 18:59:37 +02:00
|
|
|
|
2016-06-14 20:04:43 +02:00
|
|
|
readDmesg(al, kl);
|
2014-10-13 18:59:37 +02:00
|
|
|
|
2015-06-12 23:59:42 +02:00
|
|
|
// failure is an option ... messages are in dmesg (required by standard)
|
2014-10-15 17:49:39 +02:00
|
|
|
|
2015-06-12 23:59:42 +02:00
|
|
|
if (kl && kl->startListener()) {
|
|
|
|
delete kl;
|
|
|
|
}
|
2014-10-15 17:49:39 +02:00
|
|
|
|
2016-06-14 20:04:43 +02:00
|
|
|
if (al && al->startListener()) {
|
|
|
|
delete al;
|
2013-02-08 01:45:26 +01:00
|
|
|
}
|
|
|
|
|
2015-03-11 00:45:17 +01:00
|
|
|
TEMP_FAILURE_RETRY(pause());
|
|
|
|
|
2018-06-13 19:33:45 +02:00
|
|
|
return EXIT_SUCCESS;
|
2014-02-26 18:50:16 +01:00
|
|
|
}
|