2016-03-01 22:45:42 +01:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2007-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.
|
|
|
|
*/
|
|
|
|
|
2019-11-19 00:13:47 +01:00
|
|
|
#include "logd_reader.h"
|
|
|
|
|
2016-03-01 22:45:42 +01:00
|
|
|
#include <errno.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <inttypes.h>
|
|
|
|
#include <poll.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdatomic.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2019-10-02 21:27:03 +02:00
|
|
|
#include <sys/param.h>
|
2017-03-09 17:09:43 +01:00
|
|
|
#include <sys/socket.h>
|
2016-03-01 22:45:42 +01:00
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/un.h>
|
|
|
|
#include <time.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
2019-12-06 20:01:51 +01:00
|
|
|
#include <string>
|
|
|
|
|
2016-03-01 22:45:42 +01:00
|
|
|
#include <private/android_logger.h>
|
|
|
|
|
|
|
|
#include "logger.h"
|
|
|
|
|
2019-02-12 20:26:23 +01:00
|
|
|
// Connects to /dev/socket/<name> and returns the associated fd or returns -1 on error.
|
|
|
|
// O_CLOEXEC is always set.
|
|
|
|
static int socket_local_client(const std::string& name, int type) {
|
|
|
|
sockaddr_un addr = {.sun_family = AF_LOCAL};
|
2016-03-01 22:45:42 +01:00
|
|
|
|
2019-02-12 20:26:23 +01:00
|
|
|
std::string path = "/dev/socket/" + name;
|
|
|
|
if (path.size() + 1 > sizeof(addr.sun_path)) {
|
|
|
|
return -1;
|
2017-03-09 17:09:43 +01:00
|
|
|
}
|
2019-02-12 20:26:23 +01:00
|
|
|
strlcpy(addr.sun_path, path.c_str(), sizeof(addr.sun_path));
|
2016-03-01 22:45:42 +01:00
|
|
|
|
2019-02-12 20:26:23 +01:00
|
|
|
int fd = socket(AF_LOCAL, type | SOCK_CLOEXEC, 0);
|
2019-10-08 19:18:20 +02:00
|
|
|
if (fd == -1) {
|
2019-02-12 20:26:23 +01:00
|
|
|
return -1;
|
2017-03-09 17:09:43 +01:00
|
|
|
}
|
2016-03-01 22:45:42 +01:00
|
|
|
|
2019-02-12 20:26:23 +01:00
|
|
|
if (connect(fd, reinterpret_cast<sockaddr*>(&addr), sizeof(addr)) == -1) {
|
|
|
|
close(fd);
|
2017-03-09 17:09:43 +01:00
|
|
|
return -1;
|
|
|
|
}
|
2016-03-01 22:45:42 +01:00
|
|
|
|
2019-02-12 20:26:23 +01:00
|
|
|
return fd;
|
2016-03-01 22:45:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* worker for sending the command to the logger */
|
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
|
|
|
ssize_t SendLogdControlMessage(char* buf, size_t buf_size) {
|
2017-03-09 17:09:43 +01:00
|
|
|
ssize_t ret;
|
|
|
|
size_t len;
|
|
|
|
char* cp;
|
|
|
|
int errno_save = 0;
|
2019-02-12 20:26:23 +01:00
|
|
|
int sock = socket_local_client("logd", SOCK_STREAM);
|
2017-03-09 17:09:43 +01:00
|
|
|
if (sock < 0) {
|
|
|
|
return sock;
|
|
|
|
}
|
2016-03-01 22:45:42 +01:00
|
|
|
|
2017-03-09 17:09:43 +01:00
|
|
|
len = strlen(buf) + 1;
|
|
|
|
ret = TEMP_FAILURE_RETRY(write(sock, buf, len));
|
|
|
|
if (ret <= 0) {
|
|
|
|
goto done;
|
|
|
|
}
|
2016-03-01 22:45:42 +01:00
|
|
|
|
2017-03-09 17:09:43 +01:00
|
|
|
len = buf_size;
|
|
|
|
cp = buf;
|
|
|
|
while ((ret = TEMP_FAILURE_RETRY(read(sock, cp, len))) > 0) {
|
|
|
|
struct pollfd p;
|
2016-03-01 22:45:42 +01:00
|
|
|
|
2017-03-09 17:09:43 +01:00
|
|
|
if (((size_t)ret == len) || (buf_size < PAGE_SIZE)) {
|
|
|
|
break;
|
|
|
|
}
|
2016-03-01 22:45:42 +01:00
|
|
|
|
2017-03-09 17:09:43 +01:00
|
|
|
len -= ret;
|
|
|
|
cp += ret;
|
2016-03-01 22:45:42 +01:00
|
|
|
|
2017-03-09 17:09:43 +01:00
|
|
|
memset(&p, 0, sizeof(p));
|
|
|
|
p.fd = sock;
|
|
|
|
p.events = POLLIN;
|
2016-03-01 22:45:42 +01:00
|
|
|
|
2017-03-09 17:09:43 +01:00
|
|
|
/* Give other side 20ms to refill pipe */
|
|
|
|
ret = TEMP_FAILURE_RETRY(poll(&p, 1, 20));
|
2016-03-01 22:45:42 +01:00
|
|
|
|
2017-03-09 17:09:43 +01:00
|
|
|
if (ret <= 0) {
|
|
|
|
break;
|
2016-03-01 22:45:42 +01:00
|
|
|
}
|
|
|
|
|
2017-03-09 17:09:43 +01:00
|
|
|
if (!(p.revents & POLLIN)) {
|
|
|
|
ret = 0;
|
|
|
|
break;
|
2016-03-01 22:45:42 +01:00
|
|
|
}
|
2017-03-09 17:09:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (ret >= 0) {
|
|
|
|
ret += buf_size - len;
|
|
|
|
}
|
2016-03-01 22:45:42 +01:00
|
|
|
|
|
|
|
done:
|
2017-03-09 17:09:43 +01:00
|
|
|
if ((ret == -1) && errno) {
|
|
|
|
errno_save = errno;
|
|
|
|
}
|
|
|
|
close(sock);
|
|
|
|
if (errno_save) {
|
|
|
|
errno = errno_save;
|
|
|
|
}
|
|
|
|
return ret;
|
2016-03-01 22:45:42 +01:00
|
|
|
}
|
|
|
|
|
2017-03-09 17:09:43 +01:00
|
|
|
static int check_log_success(char* buf, ssize_t ret) {
|
|
|
|
if (ret < 0) {
|
|
|
|
return ret;
|
|
|
|
}
|
2016-03-01 22:45:42 +01:00
|
|
|
|
2017-03-09 17:09:43 +01:00
|
|
|
if (strncmp(buf, "success", 7)) {
|
|
|
|
errno = EINVAL;
|
|
|
|
return -1;
|
|
|
|
}
|
2016-03-01 22:45:42 +01:00
|
|
|
|
2017-03-09 17:09:43 +01:00
|
|
|
return 0;
|
2016-03-01 22:45:42 +01:00
|
|
|
}
|
|
|
|
|
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
|
|
|
int android_logger_clear(struct logger* logger) {
|
|
|
|
if (!android_logger_is_logd(logger)) {
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
uint32_t log_id = android_logger_get_id(logger);
|
2017-03-09 17:09:43 +01:00
|
|
|
char buf[512];
|
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
|
|
|
snprintf(buf, sizeof(buf), "clear %" PRIu32, log_id);
|
2016-03-01 22:45:42 +01:00
|
|
|
|
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
|
|
|
return check_log_success(buf, SendLogdControlMessage(buf, sizeof(buf)));
|
2016-03-01 22:45:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* returns the total size of the log's ring buffer */
|
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
|
|
|
long android_logger_get_log_size(struct logger* logger) {
|
|
|
|
if (!android_logger_is_logd(logger)) {
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t log_id = android_logger_get_id(logger);
|
2017-03-09 17:09:43 +01:00
|
|
|
char buf[512];
|
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
|
|
|
snprintf(buf, sizeof(buf), "getLogSize %" PRIu32, log_id);
|
2016-03-01 22:45:42 +01:00
|
|
|
|
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
|
|
|
ssize_t ret = SendLogdControlMessage(buf, sizeof(buf));
|
2017-03-09 17:09:43 +01:00
|
|
|
if (ret < 0) {
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((buf[0] < '0') || ('9' < buf[0])) {
|
|
|
|
return -1;
|
|
|
|
}
|
2016-03-01 22:45:42 +01:00
|
|
|
|
2017-03-09 17:09:43 +01:00
|
|
|
return atol(buf);
|
2016-03-01 22:45:42 +01:00
|
|
|
}
|
|
|
|
|
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
|
|
|
int android_logger_set_log_size(struct logger* logger, unsigned long size) {
|
|
|
|
if (!android_logger_is_logd(logger)) {
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
2016-03-01 22:45:42 +01:00
|
|
|
|
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_id = android_logger_get_id(logger);
|
|
|
|
char buf[512];
|
|
|
|
snprintf(buf, sizeof(buf), "setLogSize %" PRIu32 " %lu", log_id, size);
|
2016-03-01 22:45:42 +01:00
|
|
|
|
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
|
|
|
return check_log_success(buf, SendLogdControlMessage(buf, sizeof(buf)));
|
2016-03-01 22:45:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* returns the readable size of the log's ring buffer (that is, amount of the
|
|
|
|
* log consumed)
|
|
|
|
*/
|
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
|
|
|
long android_logger_get_log_readable_size(struct logger* logger) {
|
|
|
|
if (!android_logger_is_logd(logger)) {
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t log_id = android_logger_get_id(logger);
|
2017-03-09 17:09:43 +01:00
|
|
|
char buf[512];
|
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
|
|
|
snprintf(buf, sizeof(buf), "getLogSizeUsed %" PRIu32, log_id);
|
2016-03-01 22:45:42 +01:00
|
|
|
|
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
|
|
|
ssize_t ret = SendLogdControlMessage(buf, sizeof(buf));
|
2017-03-09 17:09:43 +01:00
|
|
|
if (ret < 0) {
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((buf[0] < '0') || ('9' < buf[0])) {
|
|
|
|
return -1;
|
|
|
|
}
|
2016-03-01 22:45:42 +01:00
|
|
|
|
2017-03-09 17:09:43 +01:00
|
|
|
return atol(buf);
|
2016-03-01 22:45:42 +01:00
|
|
|
}
|
|
|
|
|
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
|
|
|
int android_logger_get_log_version(struct logger*) {
|
|
|
|
return 4;
|
2016-03-01 22:45:42 +01:00
|
|
|
}
|
|
|
|
|
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
|
|
|
ssize_t android_logger_get_statistics(struct logger_list* logger_list, char* buf, size_t len) {
|
|
|
|
if (logger_list->mode & ANDROID_LOG_PSTORE) {
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2017-03-09 17:09:43 +01:00
|
|
|
char* cp = buf;
|
|
|
|
size_t remaining = len;
|
|
|
|
size_t n;
|
|
|
|
|
|
|
|
n = snprintf(cp, remaining, "getStatistics");
|
2019-10-02 21:27:03 +02:00
|
|
|
n = MIN(n, remaining);
|
2017-03-09 17:09:43 +01:00
|
|
|
remaining -= n;
|
|
|
|
cp += n;
|
|
|
|
|
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
|
|
|
for (size_t log_id = 0; log_id < LOG_ID_MAX; ++log_id) {
|
|
|
|
if ((1 << log_id) & logger_list->log_mask) {
|
|
|
|
n = snprintf(cp, remaining, " %zu", log_id);
|
|
|
|
n = MIN(n, remaining);
|
|
|
|
remaining -= n;
|
|
|
|
cp += n;
|
|
|
|
}
|
2017-03-09 17:09:43 +01:00
|
|
|
}
|
2016-03-01 22:45:42 +01:00
|
|
|
|
2017-03-09 17:09:43 +01:00
|
|
|
if (logger_list->pid) {
|
|
|
|
snprintf(cp, remaining, " pid=%u", logger_list->pid);
|
|
|
|
}
|
2016-03-01 22:45:42 +01:00
|
|
|
|
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
|
|
|
return SendLogdControlMessage(buf, len);
|
2016-03-01 22:45:42 +01:00
|
|
|
}
|
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
|
|
|
ssize_t android_logger_get_prune_list(struct logger_list* logger_list, char* buf, size_t len) {
|
|
|
|
if (logger_list->mode & ANDROID_LOG_PSTORE) {
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
2016-03-01 22:45:42 +01:00
|
|
|
|
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
|
|
|
snprintf(buf, len, "getPruneList");
|
|
|
|
return SendLogdControlMessage(buf, len);
|
2016-03-01 22:45:42 +01:00
|
|
|
}
|
|
|
|
|
2019-12-06 20:01:51 +01:00
|
|
|
int android_logger_set_prune_list(struct logger_list* logger_list, const char* buf, size_t len) {
|
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
|
|
|
if (logger_list->mode & ANDROID_LOG_PSTORE) {
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2019-12-06 20:01:51 +01:00
|
|
|
std::string cmd = "setPruneList " + std::string{buf, len};
|
2016-03-01 22:45:42 +01:00
|
|
|
|
2019-12-06 20:01:51 +01:00
|
|
|
return check_log_success(cmd.data(), SendLogdControlMessage(cmd.data(), cmd.size()));
|
2016-03-01 22:45:42 +01:00
|
|
|
}
|
|
|
|
|
2019-11-19 00:13:47 +01:00
|
|
|
static int logdOpen(struct logger_list* logger_list) {
|
2017-03-09 17:09:43 +01:00
|
|
|
char buffer[256], *cp, c;
|
2019-10-08 18:05:26 +02:00
|
|
|
int ret, remaining, sock;
|
2017-03-09 17:09:43 +01:00
|
|
|
|
2019-11-19 00:13:47 +01:00
|
|
|
sock = atomic_load(&logger_list->fd);
|
2017-03-09 17:09:43 +01:00
|
|
|
if (sock > 0) {
|
|
|
|
return sock;
|
|
|
|
}
|
|
|
|
|
2019-02-12 20:26:23 +01:00
|
|
|
sock = socket_local_client("logdr", SOCK_SEQPACKET);
|
2017-03-09 17:09:43 +01:00
|
|
|
if (sock <= 0) {
|
|
|
|
if ((sock == -1) && errno) {
|
|
|
|
return -errno;
|
2016-03-01 22:45:42 +01:00
|
|
|
}
|
2017-03-09 17:09:43 +01:00
|
|
|
return sock;
|
|
|
|
}
|
|
|
|
|
2019-01-10 19:37:36 +01:00
|
|
|
strcpy(buffer, (logger_list->mode & ANDROID_LOG_NONBLOCK) ? "dumpAndClose" : "stream");
|
2017-03-09 17:09:43 +01:00
|
|
|
cp = buffer + strlen(buffer);
|
|
|
|
|
|
|
|
strcpy(cp, " lids");
|
|
|
|
cp += 5;
|
|
|
|
c = '=';
|
|
|
|
remaining = sizeof(buffer) - (cp - buffer);
|
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
|
|
|
|
|
|
|
for (size_t log_id = 0; log_id < LOG_ID_MAX; ++log_id) {
|
|
|
|
if ((1 << log_id) & logger_list->log_mask) {
|
|
|
|
ret = snprintf(cp, remaining, "%c%zu", c, log_id);
|
|
|
|
ret = MIN(ret, remaining);
|
|
|
|
remaining -= ret;
|
|
|
|
cp += ret;
|
|
|
|
c = ',';
|
|
|
|
}
|
2017-03-09 17:09:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (logger_list->tail) {
|
|
|
|
ret = snprintf(cp, remaining, " tail=%u", logger_list->tail);
|
2019-10-02 21:27:03 +02:00
|
|
|
ret = MIN(ret, remaining);
|
2017-03-09 17:09:43 +01:00
|
|
|
remaining -= ret;
|
|
|
|
cp += ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (logger_list->start.tv_sec || logger_list->start.tv_nsec) {
|
|
|
|
if (logger_list->mode & ANDROID_LOG_WRAP) {
|
|
|
|
// ToDo: alternate API to allow timeout to be adjusted.
|
2019-01-10 19:37:36 +01:00
|
|
|
ret = snprintf(cp, remaining, " timeout=%u", ANDROID_LOG_WRAP_DEFAULT_TIMEOUT);
|
2019-10-02 21:27:03 +02:00
|
|
|
ret = MIN(ret, remaining);
|
2017-03-09 17:09:43 +01:00
|
|
|
remaining -= ret;
|
|
|
|
cp += ret;
|
|
|
|
}
|
2019-01-10 19:37:36 +01:00
|
|
|
ret = snprintf(cp, remaining, " start=%" PRIu32 ".%09" PRIu32, logger_list->start.tv_sec,
|
|
|
|
logger_list->start.tv_nsec);
|
2019-10-02 21:27:03 +02:00
|
|
|
ret = MIN(ret, remaining);
|
2017-03-09 17:09:43 +01:00
|
|
|
remaining -= ret;
|
|
|
|
cp += ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (logger_list->pid) {
|
|
|
|
ret = snprintf(cp, remaining, " pid=%u", logger_list->pid);
|
2019-10-02 21:27:03 +02:00
|
|
|
ret = MIN(ret, remaining);
|
2017-03-09 17:09:43 +01:00
|
|
|
cp += ret;
|
|
|
|
}
|
|
|
|
|
2019-10-08 18:05:26 +02:00
|
|
|
ret = TEMP_FAILURE_RETRY(write(sock, buffer, cp - buffer));
|
|
|
|
int write_errno = errno;
|
2017-03-09 17:09:43 +01:00
|
|
|
|
|
|
|
if (ret <= 0) {
|
|
|
|
close(sock);
|
2019-10-08 18:05:26 +02:00
|
|
|
if (ret == -1) {
|
|
|
|
return -write_errno;
|
2016-03-01 22:45:42 +01:00
|
|
|
}
|
2017-03-09 17:09:43 +01:00
|
|
|
if (ret == 0) {
|
|
|
|
return -EIO;
|
2016-03-01 22:45:42 +01:00
|
|
|
}
|
2017-03-09 17:09:43 +01:00
|
|
|
return ret;
|
|
|
|
}
|
2016-03-01 22:45:42 +01:00
|
|
|
|
2019-11-19 00:13:47 +01:00
|
|
|
ret = atomic_exchange(&logger_list->fd, sock);
|
2017-03-09 17:09:43 +01:00
|
|
|
if ((ret > 0) && (ret != sock)) {
|
|
|
|
close(ret);
|
|
|
|
}
|
|
|
|
return sock;
|
2016-03-01 22:45:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Read from the selected logs */
|
2019-11-19 00:13:47 +01:00
|
|
|
int LogdRead(struct logger_list* logger_list, struct log_msg* log_msg) {
|
|
|
|
int ret = logdOpen(logger_list);
|
2017-03-09 17:09:43 +01:00
|
|
|
if (ret < 0) {
|
2016-03-01 22:45:42 +01:00
|
|
|
return ret;
|
2017-03-09 17:09:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* NOTE: SOCK_SEQPACKET guarantees we read exactly one full entry */
|
2019-10-08 18:05:26 +02:00
|
|
|
ret = TEMP_FAILURE_RETRY(recv(ret, log_msg, LOGGER_ENTRY_MAX_LEN, 0));
|
|
|
|
if ((logger_list->mode & ANDROID_LOG_NONBLOCK) && ret == 0) {
|
|
|
|
return -EAGAIN;
|
2017-03-09 17:09:43 +01:00
|
|
|
}
|
|
|
|
|
2019-10-08 18:05:26 +02:00
|
|
|
if (ret == -1) {
|
|
|
|
return -errno;
|
2017-03-09 17:09:43 +01:00
|
|
|
}
|
|
|
|
return ret;
|
2016-03-01 22:45:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Close all the logs */
|
2019-11-19 00:13:47 +01:00
|
|
|
void LogdClose(struct logger_list* logger_list) {
|
|
|
|
int sock = atomic_exchange(&logger_list->fd, -1);
|
2017-03-09 17:09:43 +01:00
|
|
|
if (sock > 0) {
|
|
|
|
close(sock);
|
|
|
|
}
|
2016-03-01 22:45:42 +01:00
|
|
|
}
|