am f5579498: am 110166c1: Merge "liblog: introduce ANDROID_LOG_* flags"

* commit 'f5579498d93e1ba56aaf23765f3693dfddab8599':
  liblog: introduce ANDROID_LOG_* flags
This commit is contained in:
Mark Salyzyn 2015-02-25 18:16:47 +00:00 committed by Android Git Automerger
commit ac9471041e
9 changed files with 46 additions and 39 deletions

View file

@ -453,7 +453,7 @@ static void dump_log_file(
}
logger_list = android_logger_list_open(
android_name_to_log_id(filename), O_RDONLY | O_NONBLOCK, tail, pid);
android_name_to_log_id(filename), ANDROID_LOG_RDONLY | ANDROID_LOG_NONBLOCK, tail, pid);
if (!logger_list) {
ALOGE("Unable to open %s: %s\n", filename, strerror(errno));

View file

@ -154,6 +154,12 @@ ssize_t android_logger_get_prune_list(struct logger_list *logger_list,
int android_logger_set_prune_list(struct logger_list *logger_list,
char *buf, size_t len);
#define ANDROID_LOG_RDONLY O_RDONLY
#define ANDROID_LOG_WRONLY O_WRONLY
#define ANDROID_LOG_RDWR O_RDWR
#define ANDROID_LOG_ACCMODE O_ACCMODE
#define ANDROID_LOG_NONBLOCK O_NONBLOCK
struct logger_list *android_logger_list_alloc(int mode,
unsigned int tail,
pid_t pid);

View file

@ -111,20 +111,21 @@ DESCRIPTION
ger_list_alloc, calling in turn the android_logger_open for each log
id. Each entry can be retrieved with android_logger_list_read. The
log(s) can be closed with android_logger_list_free. The logs should be
opened with an O_RDONLY mode. O_NDELAY mode will report when the log
reading is done with an EAGAIN error return code, otherwise the
android_logger_list_read call will block for new entries.
opened with an ANDROID_LOG_RDONLY mode. ANDROID_LOG_NONBLOCK mode
will report when the log reading is done with an EAGAIN error return
code, otherwise the android_logger_list_read call will block for new
entries.
The value returned by android_logger_open can be used as a parameter to
the android_logger_clear function to empty the sub-log. It is recom
mended to only open log O_WRONLY.
mended to only open log ANDROID_LOG_WRONLY in that case.
The value returned by android_logger_open can be used as a parameter to
the android_logger_get_log_(size|readable_size|version) to retrieve the
sub-log maximum size, readable size and log buffer format protocol ver
sion respectively. android_logger_get_id returns the id that was used
when opening the sub-log. It is recommended to open the log O_RDONLY
in these cases.
when opening the sub-log. It is recommended to open the log
ANDROID_LOG_RDONLY in these cases.
SEE ALSO
syslogd(8)

View file

@ -582,7 +582,7 @@ int android_logger_list_read(struct logger_list *logger_list,
return -EINVAL;
}
if (logger_list->mode & O_NONBLOCK) {
if (logger_list->mode & ANDROID_LOG_NONBLOCK) {
memset(&ignore, 0, sizeof(ignore));
ignore.sa_handler = caught_signal;
sigemptyset(&ignore.sa_mask);
@ -602,7 +602,7 @@ int android_logger_list_read(struct logger_list *logger_list,
}
strcpy(buffer,
(logger_list->mode & O_NONBLOCK) ? "dumpAndClose" : "stream");
(logger_list->mode & ANDROID_LOG_NONBLOCK) ? "dumpAndClose" : "stream");
cp = buffer + strlen(buffer);
strcpy(cp, " lids");
@ -640,14 +640,14 @@ int android_logger_list_read(struct logger_list *logger_list,
cp += ret;
}
if (logger_list->mode & O_NONBLOCK) {
if (logger_list->mode & ANDROID_LOG_NONBLOCK) {
/* Deal with an unresponsive logd */
sigaction(SIGALRM, &ignore, &old_sigaction);
old_alarm = alarm(30);
}
ret = write(sock, buffer, cp - buffer);
e = errno;
if (logger_list->mode & O_NONBLOCK) {
if (logger_list->mode & ANDROID_LOG_NONBLOCK) {
if (e == EINTR) {
e = ETIMEDOUT;
}
@ -673,7 +673,7 @@ int android_logger_list_read(struct logger_list *logger_list,
while(1) {
memset(log_msg, 0, sizeof(*log_msg));
if (logger_list->mode & O_NONBLOCK) {
if (logger_list->mode & ANDROID_LOG_NONBLOCK) {
/* particularily useful if tombstone is reporting for logd */
sigaction(SIGALRM, &ignore, &old_sigaction);
old_alarm = alarm(30);
@ -681,7 +681,7 @@ int android_logger_list_read(struct logger_list *logger_list,
/* NOTE: SOCK_SEQPACKET guarantees we read exactly one full entry */
ret = recv(logger_list->sock, log_msg, LOGGER_ENTRY_MAX_LEN, 0);
e = errno;
if (logger_list->mode & O_NONBLOCK) {
if (logger_list->mode & ANDROID_LOG_NONBLOCK) {
if ((ret == 0) || (e == EINTR)) {
e = EAGAIN;
ret = -1;

View file

@ -75,10 +75,10 @@ const char *android_log_id_to_name(log_id_t log_id)
static int accessmode(int mode)
{
if ((mode & O_ACCMODE) == O_WRONLY) {
if ((mode & ANDROID_LOG_ACCMODE) == ANDROID_LOG_WRONLY) {
return W_OK;
}
if ((mode & O_ACCMODE) == O_RDWR) {
if ((mode & ANDROID_LOG_ACCMODE) == ANDROID_LOG_RDWR) {
return R_OK | W_OK;
}
return R_OK;
@ -117,7 +117,7 @@ log_id_t android_name_to_log_id(const char *logName)
++b;
}
ret = check_allocate_accessible(&n, b, O_RDONLY);
ret = check_allocate_accessible(&n, b, ANDROID_LOG_RDONLY);
free(n);
if (ret) {
return ret;
@ -201,8 +201,8 @@ static int logger_ioctl(struct logger *logger, int cmd, int mode)
return -EFAULT;
}
if (((mode & O_ACCMODE) == O_RDWR)
|| (((mode ^ logger->top->mode) & O_ACCMODE) == 0)) {
if (((mode & ANDROID_LOG_ACCMODE) == ANDROID_LOG_RDWR)
|| (((mode ^ logger->top->mode) & ANDROID_LOG_ACCMODE) == 0)) {
return ioctl(logger->fd, cmd);
}
@ -227,13 +227,13 @@ static int logger_ioctl(struct logger *logger, int cmd, int mode)
int android_logger_clear(struct logger *logger)
{
return logger_ioctl(logger, LOGGER_FLUSH_LOG, O_WRONLY);
return logger_ioctl(logger, LOGGER_FLUSH_LOG, ANDROID_LOG_WRONLY);
}
/* returns the total size of the log's ring buffer */
long android_logger_get_log_size(struct logger *logger)
{
return logger_ioctl(logger, LOGGER_GET_LOG_BUF_SIZE, O_RDWR);
return logger_ioctl(logger, LOGGER_GET_LOG_BUF_SIZE, ANDROID_LOG_RDWR);
}
int android_logger_set_log_size(struct logger *logger __unused,
@ -248,7 +248,7 @@ int android_logger_set_log_size(struct logger *logger __unused,
*/
long android_logger_get_log_readable_size(struct logger *logger)
{
return logger_ioctl(logger, LOGGER_GET_LOG_LEN, O_RDONLY);
return logger_ioctl(logger, LOGGER_GET_LOG_LEN, ANDROID_LOG_RDONLY);
}
/*
@ -256,7 +256,7 @@ long android_logger_get_log_readable_size(struct logger *logger)
*/
int android_logger_get_log_version(struct logger *logger)
{
int ret = logger_ioctl(logger, LOGGER_GET_VERSION, O_RDWR);
int ret = logger_ioctl(logger, LOGGER_GET_VERSION, ANDROID_LOG_RDWR);
return (ret < 0) ? 1 : ret;
}
@ -342,7 +342,7 @@ struct logger *android_logger_open(struct logger_list *logger_list,
goto err_name;
}
logger->fd = open(n, logger_list->mode);
logger->fd = open(n, logger_list->mode & (ANDROID_LOG_ACCMODE | ANDROID_LOG_NONBLOCK));
if (logger->fd < 0) {
goto err_name;
}
@ -565,7 +565,7 @@ int android_logger_list_read(struct logger_list *logger_list,
if (result <= 0) {
if (result) {
error = errno;
} else if (logger_list->mode & O_NDELAY) {
} else if (logger_list->mode & ANDROID_LOG_NONBLOCK) {
error = EAGAIN;
} else {
logger_list->timeout_ms = LOG_TIMEOUT_NEVER;

View file

@ -39,7 +39,7 @@ TEST(libc, __libc_android_log_event_int) {
pid_t pid = getpid();
ASSERT_TRUE(NULL != (logger_list = android_logger_list_open(
LOG_ID_EVENTS, O_RDONLY | O_NDELAY, 1000, pid)));
LOG_ID_EVENTS, ANDROID_LOG_RDONLY | ANDROID_LOG_NONBLOCK, 1000, pid)));
struct timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts);
@ -99,7 +99,7 @@ TEST(libc, __libc_fatal_no_abort) {
pid_t pid = getpid();
ASSERT_TRUE(NULL != (logger_list = android_logger_list_open(
(log_id_t)LOG_ID_CRASH, O_RDONLY | O_NDELAY, 1000, pid)));
(log_id_t)LOG_ID_CRASH, ANDROID_LOG_RDONLY | ANDROID_LOG_NONBLOCK, 1000, pid)));
char b[80];
struct timespec ts;

View file

@ -130,7 +130,7 @@ static void BM_log_latency(int iters) {
pid_t pid = getpid();
struct logger_list * logger_list = android_logger_list_open(LOG_ID_EVENTS,
O_RDONLY, 0, pid);
ANDROID_LOG_RDONLY, 0, pid);
if (!logger_list) {
fprintf(stderr, "Unable to open events log: %s\n", strerror(errno));
@ -208,7 +208,7 @@ static void BM_log_delay(int iters) {
pid_t pid = getpid();
struct logger_list * logger_list = android_logger_list_open(LOG_ID_EVENTS,
O_RDONLY, 0, pid);
ANDROID_LOG_RDONLY, 0, pid);
if (!logger_list) {
fprintf(stderr, "Unable to open events log: %s\n", strerror(errno));

View file

@ -122,7 +122,7 @@ TEST(liblog, __android_log_btwrite__android_logger_list_read) {
pid_t pid = getpid();
ASSERT_TRUE(NULL != (logger_list = android_logger_list_open(
LOG_ID_EVENTS, O_RDONLY | O_NDELAY, 1000, pid)));
LOG_ID_EVENTS, ANDROID_LOG_RDONLY | ANDROID_LOG_NONBLOCK, 1000, pid)));
log_time ts(CLOCK_MONOTONIC);
@ -223,7 +223,7 @@ TEST(liblog, android_logger_list_read__cpu) {
v += pid & 0xFFFF;
ASSERT_TRUE(NULL != (logger_list = android_logger_list_open(
LOG_ID_EVENTS, O_RDONLY, 1000, pid)));
LOG_ID_EVENTS, ANDROID_LOG_RDONLY, 1000, pid)));
int count = 0;
@ -443,7 +443,7 @@ TEST(liblog, max_payload) {
struct logger_list *logger_list;
ASSERT_TRUE(NULL != (logger_list = android_logger_list_open(
LOG_ID_SYSTEM, O_RDONLY, 100, 0)));
LOG_ID_SYSTEM, ANDROID_LOG_RDONLY, 100, 0)));
bool matches = false;
ssize_t max_len = 0;
@ -505,7 +505,7 @@ TEST(liblog, too_big_payload) {
struct logger_list *logger_list;
ASSERT_TRUE(NULL != (logger_list = android_logger_list_open(
LOG_ID_SYSTEM, O_RDONLY | O_NDELAY, 100, 0)));
LOG_ID_SYSTEM, ANDROID_LOG_RDONLY | ANDROID_LOG_NONBLOCK, 100, 0)));
ssize_t max_len = 0;
@ -552,12 +552,12 @@ TEST(liblog, dual_reader) {
// >25 messages due to liblog.__android_log_buf_print__concurrentXX above.
ASSERT_TRUE(NULL != (logger_list1 = android_logger_list_open(
LOG_ID_MAIN, O_RDONLY | O_NDELAY, 25, 0)));
LOG_ID_MAIN, ANDROID_LOG_RDONLY | ANDROID_LOG_NONBLOCK, 25, 0)));
struct logger_list *logger_list2;
if (NULL == (logger_list2 = android_logger_list_open(
LOG_ID_MAIN, O_RDONLY | O_NDELAY, 15, 0))) {
LOG_ID_MAIN, ANDROID_LOG_RDONLY | ANDROID_LOG_NONBLOCK, 15, 0))) {
android_logger_list_close(logger_list1);
ASSERT_TRUE(NULL != logger_list2);
}
@ -595,7 +595,7 @@ TEST(liblog, dual_reader) {
}
TEST(liblog, android_logger_get_) {
struct logger_list * logger_list = android_logger_list_alloc(O_WRONLY, 0, 0);
struct logger_list * logger_list = android_logger_list_alloc(ANDROID_LOG_WRONLY, 0, 0);
for(int i = LOG_ID_MIN; i < LOG_ID_MAX; ++i) {
log_id_t id = static_cast<log_id_t>(i);

View file

@ -324,7 +324,7 @@ int main(int argc, char **argv)
int getPruneList = 0;
char *setPruneList = NULL;
int printStatistics = 0;
int mode = O_RDONLY;
int mode = ANDROID_LOG_RDONLY;
const char *forceFilters = NULL;
log_device_t* devices = NULL;
log_device_t* dev;
@ -359,15 +359,15 @@ int main(int argc, char **argv)
case 'c':
clearLog = 1;
mode = O_WRONLY;
mode |= ANDROID_LOG_WRONLY;
break;
case 'd':
mode = O_RDONLY | O_NDELAY;
mode |= ANDROID_LOG_RDONLY | ANDROID_LOG_NONBLOCK;
break;
case 't':
mode = O_RDONLY | O_NDELAY;
mode |= ANDROID_LOG_RDONLY | ANDROID_LOG_NONBLOCK;
/* FALLTHRU */
case 'T':
if (strspn(optarg, "0123456789") != strlen(optarg)) {