platform_system_core/liblog/logger.h

52 lines
1.3 KiB
C
Raw Normal View History

/*
* Copyright (C) 2016 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 <stdatomic.h>
#include <sys/cdefs.h>
#include <log/log.h>
#include "uio.h"
__BEGIN_DECLS
struct logger_list {
atomic_int fd;
int mode;
unsigned int tail;
log_time start;
pid_t pid;
liblog: simplify logd 'command' functions and struct logger There are a set of functions, such as android_logger_get_log_size() and android_logger_get_prune_list() that talk to the logd command socket to perform their activities. There's a transport abstraction layer that handles these symbols to optionally route them to other transports, originally designed for pstore or local logger; however these functions fundamentally only make sense for logd. Ideally, these functions would be removed and new functions would be added that do not depend on struct logger_list or struct logger and more clearly indicate that they only work with logd. For example: android_logger_get_size(struct logger*) could be logd_get_buffer_size(log_id_t log_id). We would remove the need to 'open' the struct logger and make it clear that it only operates on logd. Since liblog is an llndk library however, we cannot change or remove these symbols. Since these symbols are not frequently used, it seems acceptable to keep them as is and not introduce improved versions. We, however, do want to simplify the code that handles them and this change removes the transport abstraction layer that handles them. They retain the behavior that unless the struct logger_list was opened for logd, that the functions return -EINVAL. The one exception to this is android_logger_clear(). If the struct logger provided to this function was opened from a struct logger_list that used pstore for its mode argument, this function will clear the entire pstore log. This function does not respect the 'logId' parameter of the struct logger, since that would not be possible. This change removes this android_logger_clear() behavior and makes it strictly for logd, for symmetry with the rest of the functions and due to the lack of clarity regarding the 'logId' parameter of its input. The only caller of this function, logcat, will clear pstore directly. struct logger was built to encapsulate the information needed to connect to a logger device from the old kernel logger. Now that we only support reading from pstore and from logd, there is much less information needed to be captured. Specifically, we only need to know the log_id and whether or not it was opened as part of a pstore or logd 'list'. Test: liblog-unit-test Test: logcat -c/-g/-G/-p/-P/-S work Test: logcat -c works with -L Test: logcat -g/-G/-p/-P/-S continue to fail with -L Change-Id: I2c549b6f8539de94510e223949ab209ecc40e2d0
2019-11-14 17:56:39 +01:00
uint32_t log_mask;
};
liblog: simplify logd 'command' functions and struct logger There are a set of functions, such as android_logger_get_log_size() and android_logger_get_prune_list() that talk to the logd command socket to perform their activities. There's a transport abstraction layer that handles these symbols to optionally route them to other transports, originally designed for pstore or local logger; however these functions fundamentally only make sense for logd. Ideally, these functions would be removed and new functions would be added that do not depend on struct logger_list or struct logger and more clearly indicate that they only work with logd. For example: android_logger_get_size(struct logger*) could be logd_get_buffer_size(log_id_t log_id). We would remove the need to 'open' the struct logger and make it clear that it only operates on logd. Since liblog is an llndk library however, we cannot change or remove these symbols. Since these symbols are not frequently used, it seems acceptable to keep them as is and not introduce improved versions. We, however, do want to simplify the code that handles them and this change removes the transport abstraction layer that handles them. They retain the behavior that unless the struct logger_list was opened for logd, that the functions return -EINVAL. The one exception to this is android_logger_clear(). If the struct logger provided to this function was opened from a struct logger_list that used pstore for its mode argument, this function will clear the entire pstore log. This function does not respect the 'logId' parameter of the struct logger, since that would not be possible. This change removes this android_logger_clear() behavior and makes it strictly for logd, for symmetry with the rest of the functions and due to the lack of clarity regarding the 'logId' parameter of its input. The only caller of this function, logcat, will clear pstore directly. struct logger was built to encapsulate the information needed to connect to a logger device from the old kernel logger. Now that we only support reading from pstore and from logd, there is much less information needed to be captured. Specifically, we only need to know the log_id and whether or not it was opened as part of a pstore or logd 'list'. Test: liblog-unit-test Test: logcat -c/-g/-G/-p/-P/-S work Test: logcat -c works with -L Test: logcat -g/-G/-p/-P/-S continue to fail with -L Change-Id: I2c549b6f8539de94510e223949ab209ecc40e2d0
2019-11-14 17:56:39 +01:00
// Format for a 'logger' entry: uintptr_t where only the bottom 32 bits are used.
// bit 31: Set if this 'logger' is for logd.
// bit 30: Set if this 'logger' is for pmsg
// bits 0-2: the decimal value of the log buffer.
// Other bits are unused.
#define LOGGER_LOGD (1U << 31)
#define LOGGER_PMSG (1U << 30)
#define LOGGER_LOG_ID_MASK ((1U << 3) - 1)
liblog: simplify logd 'command' functions and struct logger There are a set of functions, such as android_logger_get_log_size() and android_logger_get_prune_list() that talk to the logd command socket to perform their activities. There's a transport abstraction layer that handles these symbols to optionally route them to other transports, originally designed for pstore or local logger; however these functions fundamentally only make sense for logd. Ideally, these functions would be removed and new functions would be added that do not depend on struct logger_list or struct logger and more clearly indicate that they only work with logd. For example: android_logger_get_size(struct logger*) could be logd_get_buffer_size(log_id_t log_id). We would remove the need to 'open' the struct logger and make it clear that it only operates on logd. Since liblog is an llndk library however, we cannot change or remove these symbols. Since these symbols are not frequently used, it seems acceptable to keep them as is and not introduce improved versions. We, however, do want to simplify the code that handles them and this change removes the transport abstraction layer that handles them. They retain the behavior that unless the struct logger_list was opened for logd, that the functions return -EINVAL. The one exception to this is android_logger_clear(). If the struct logger provided to this function was opened from a struct logger_list that used pstore for its mode argument, this function will clear the entire pstore log. This function does not respect the 'logId' parameter of the struct logger, since that would not be possible. This change removes this android_logger_clear() behavior and makes it strictly for logd, for symmetry with the rest of the functions and due to the lack of clarity regarding the 'logId' parameter of its input. The only caller of this function, logcat, will clear pstore directly. struct logger was built to encapsulate the information needed to connect to a logger device from the old kernel logger. Now that we only support reading from pstore and from logd, there is much less information needed to be captured. Specifically, we only need to know the log_id and whether or not it was opened as part of a pstore or logd 'list'. Test: liblog-unit-test Test: logcat -c/-g/-G/-p/-P/-S work Test: logcat -c works with -L Test: logcat -g/-G/-p/-P/-S continue to fail with -L Change-Id: I2c549b6f8539de94510e223949ab209ecc40e2d0
2019-11-14 17:56:39 +01:00
inline bool android_logger_is_logd(struct logger* logger) {
return reinterpret_cast<uintptr_t>(logger) & LOGGER_LOGD;
}
__END_DECLS