liblog: remove the last of the transport structs
Test: build, liblog unit tests Change-Id: I292662fc64e3163b570c5daeaa8f912fb6ca74e8
This commit is contained in:
parent
97186600b5
commit
21bb36c66a
|
@ -49,14 +49,6 @@
|
|||
#define TRACE(...) ((void)0)
|
||||
#endif
|
||||
|
||||
static void FakeClose();
|
||||
static int FakeWrite(log_id_t log_id, struct timespec* ts, struct iovec* vec, size_t nr);
|
||||
|
||||
struct android_log_transport_write fakeLoggerWrite = {
|
||||
.close = FakeClose,
|
||||
.write = FakeWrite,
|
||||
};
|
||||
|
||||
typedef struct LogState {
|
||||
bool initialized = false;
|
||||
/* global minimum priority */
|
||||
|
@ -453,7 +445,7 @@ static void ShowLog(int logPrio, const char* tag, const char* msg) {
|
|||
* tag (N bytes -- null-terminated ASCII string)
|
||||
* message (N bytes -- null-terminated ASCII string)
|
||||
*/
|
||||
static int FakeWrite(log_id_t log_id, struct timespec*, struct iovec* vector, size_t count) {
|
||||
int FakeWrite(log_id_t log_id, struct timespec*, struct iovec* vector, size_t count) {
|
||||
/* Make sure that no-one frees the LogState while we're using it.
|
||||
* Also guarantees that only one thread is in showLog() at a given
|
||||
* time (if it matters).
|
||||
|
@ -519,7 +511,7 @@ static int FakeWrite(log_id_t log_id, struct timespec*, struct iovec* vector, si
|
|||
* call is in the exit handler. Logging can continue in the exit handler to
|
||||
* help debug HOST tools ...
|
||||
*/
|
||||
static void FakeClose() {
|
||||
void FakeClose() {
|
||||
auto lock = std::lock_guard{*fake_log_mutex};
|
||||
|
||||
memset(&log_state, 0, sizeof(log_state));
|
||||
|
|
|
@ -18,16 +18,14 @@
|
|||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "log_portability.h"
|
||||
#include "uio.h"
|
||||
#include <android/log.h>
|
||||
|
||||
struct iovec;
|
||||
#include "log_portability.h"
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
||||
int fakeLogOpen(const char* pathName);
|
||||
int fakeLogClose(int fd);
|
||||
ssize_t fakeLogWritev(int fd, const struct iovec* vector, int count);
|
||||
void FakeClose();
|
||||
int FakeWrite(log_id_t log_id, struct timespec* ts, struct iovec* vec, size_t nr);
|
||||
|
||||
int __android_log_is_loggable(int prio, const char*, int def);
|
||||
int __android_log_is_loggable_len(int prio, const char*, size_t, int def);
|
||||
|
|
|
@ -14,6 +14,8 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "logd_writer.h"
|
||||
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <inttypes.h>
|
||||
|
@ -41,14 +43,6 @@
|
|||
#include "rwlock.h"
|
||||
#include "uio.h"
|
||||
|
||||
static int LogdWrite(log_id_t logId, struct timespec* ts, struct iovec* vec, size_t nr);
|
||||
static void LogdClose();
|
||||
|
||||
struct android_log_transport_write logdLoggerWrite = {
|
||||
.close = LogdClose,
|
||||
.write = LogdWrite,
|
||||
};
|
||||
|
||||
static int logd_socket;
|
||||
static RwLock logd_socket_lock;
|
||||
|
||||
|
@ -90,7 +84,7 @@ static void ResetSocket(int old_socket) {
|
|||
OpenSocketLocked();
|
||||
}
|
||||
|
||||
static void LogdClose() {
|
||||
void LogdClose() {
|
||||
auto lock = std::unique_lock{logd_socket_lock};
|
||||
if (logd_socket > 0) {
|
||||
close(logd_socket);
|
||||
|
@ -98,7 +92,7 @@ static void LogdClose() {
|
|||
logd_socket = 0;
|
||||
}
|
||||
|
||||
static int LogdWrite(log_id_t logId, struct timespec* ts, struct iovec* vec, size_t nr) {
|
||||
int LogdWrite(log_id_t logId, struct timespec* ts, struct iovec* vec, size_t nr) {
|
||||
ssize_t ret;
|
||||
static const unsigned headerLength = 1;
|
||||
struct iovec newVec[nr + headerLength];
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
/*
|
||||
* Copyright (C) 2020 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.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#include <android/log.h>
|
||||
|
||||
int LogdWrite(log_id_t logId, struct timespec* ts, struct iovec* vec, size_t nr);
|
||||
void LogdClose();
|
|
@ -26,13 +26,6 @@
|
|||
|
||||
__BEGIN_DECLS
|
||||
|
||||
struct android_log_transport_write {
|
||||
void (*close)(); /* free up resources */
|
||||
/* write log to transport, returns number of bytes propagated, or -errno */
|
||||
int (*write)(log_id_t logId, struct timespec* ts, struct iovec* vec,
|
||||
size_t nr);
|
||||
};
|
||||
|
||||
struct logger_list {
|
||||
atomic_int fd;
|
||||
int mode;
|
||||
|
|
|
@ -31,21 +31,15 @@
|
|||
#include "logger.h"
|
||||
#include "uio.h"
|
||||
|
||||
#define LOG_BUF_SIZE 1024
|
||||
|
||||
#if (FAKE_LOG_DEVICE == 0)
|
||||
extern struct android_log_transport_write logdLoggerWrite;
|
||||
extern struct android_log_transport_write pmsgLoggerWrite;
|
||||
|
||||
android_log_transport_write* android_log_write = &logdLoggerWrite;
|
||||
android_log_transport_write* android_log_persist_write = &pmsgLoggerWrite;
|
||||
#include "logd_writer.h"
|
||||
#include "pmsg_writer.h"
|
||||
#else
|
||||
extern android_log_transport_write fakeLoggerWrite;
|
||||
|
||||
android_log_transport_write* android_log_write = &fakeLoggerWrite;
|
||||
android_log_transport_write* android_log_persist_write = nullptr;
|
||||
#include "fake_log_device.h"
|
||||
#endif
|
||||
|
||||
#define LOG_BUF_SIZE 1024
|
||||
|
||||
#if defined(__ANDROID__)
|
||||
static int check_log_uid_permissions() {
|
||||
uid_t uid = __android_log_uid();
|
||||
|
@ -92,14 +86,12 @@ static int check_log_uid_permissions() {
|
|||
* Release any logger resources. A new log write will immediately re-acquire.
|
||||
*/
|
||||
void __android_log_close() {
|
||||
if (android_log_write != nullptr) {
|
||||
android_log_write->close();
|
||||
}
|
||||
|
||||
if (android_log_persist_write != nullptr) {
|
||||
android_log_persist_write->close();
|
||||
}
|
||||
|
||||
#if (FAKE_LOG_DEVICE == 0)
|
||||
LogdClose();
|
||||
PmsgClose();
|
||||
#else
|
||||
FakeClose();
|
||||
#endif
|
||||
}
|
||||
|
||||
static int write_to_log(log_id_t log_id, struct iovec* vec, size_t nr) {
|
||||
|
@ -158,17 +150,12 @@ static int write_to_log(log_id_t log_id, struct iovec* vec, size_t nr) {
|
|||
|
||||
ret = 0;
|
||||
|
||||
if (android_log_write != nullptr) {
|
||||
ssize_t retval;
|
||||
retval = android_log_write->write(log_id, &ts, vec, nr);
|
||||
if (ret >= 0) {
|
||||
ret = retval;
|
||||
}
|
||||
}
|
||||
|
||||
if (android_log_persist_write != nullptr) {
|
||||
android_log_persist_write->write(log_id, &ts, vec, nr);
|
||||
}
|
||||
#if (FAKE_LOG_DEVICE == 0)
|
||||
ret = LogdWrite(log_id, &ts, vec, nr);
|
||||
PmsgWrite(log_id, &ts, vec, nr);
|
||||
#else
|
||||
ret = FakeWrite(log_id, &ts, vec, nr);
|
||||
#endif
|
||||
|
||||
errno = save_errno;
|
||||
return ret;
|
||||
|
|
|
@ -14,9 +14,7 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* pmsg write handler
|
||||
*/
|
||||
#include "pmsg_writer.h"
|
||||
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
|
@ -36,14 +34,6 @@
|
|||
#include "rwlock.h"
|
||||
#include "uio.h"
|
||||
|
||||
static void PmsgClose();
|
||||
static int PmsgWrite(log_id_t logId, struct timespec* ts, struct iovec* vec, size_t nr);
|
||||
|
||||
struct android_log_transport_write pmsgLoggerWrite = {
|
||||
.close = PmsgClose,
|
||||
.write = PmsgWrite,
|
||||
};
|
||||
|
||||
static int pmsg_fd;
|
||||
static RwLock pmsg_fd_lock;
|
||||
|
||||
|
@ -57,7 +47,7 @@ static void PmsgOpen() {
|
|||
pmsg_fd = TEMP_FAILURE_RETRY(open("/dev/pmsg0", O_WRONLY | O_CLOEXEC));
|
||||
}
|
||||
|
||||
static void PmsgClose() {
|
||||
void PmsgClose() {
|
||||
auto lock = std::unique_lock{pmsg_fd_lock};
|
||||
if (pmsg_fd > 0) {
|
||||
close(pmsg_fd);
|
||||
|
@ -65,7 +55,7 @@ static void PmsgClose() {
|
|||
pmsg_fd = 0;
|
||||
}
|
||||
|
||||
static int PmsgWrite(log_id_t logId, struct timespec* ts, struct iovec* vec, size_t nr) {
|
||||
int PmsgWrite(log_id_t logId, struct timespec* ts, struct iovec* vec, size_t nr) {
|
||||
static const unsigned headerLength = 2;
|
||||
struct iovec newVec[nr + headerLength];
|
||||
android_log_header_t header;
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
/*
|
||||
* Copyright (C) 2020 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.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#include <android/log.h>
|
||||
|
||||
int PmsgWrite(log_id_t logId, struct timespec* ts, struct iovec* vec, size_t nr);
|
||||
void PmsgClose();
|
Loading…
Reference in New Issue