2009-03-04 04:32:55 +01:00
|
|
|
/*
|
2014-01-02 22:52:29 +01:00
|
|
|
* Copyright (C) 2007-2014 The Android Open Source Project
|
2009-03-04 04:32:55 +01:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
2015-03-05 02:01:30 +01:00
|
|
|
#if (FAKE_LOG_DEVICE == 0)
|
2015-02-13 00:14:26 +01:00
|
|
|
#include <endian.h>
|
2015-03-05 02:01:30 +01:00
|
|
|
#endif
|
2014-02-20 23:59:07 +01:00
|
|
|
#include <errno.h>
|
|
|
|
#include <fcntl.h>
|
2015-01-27 04:48:54 +01:00
|
|
|
#if !defined(_WIN32)
|
2009-03-04 04:32:55 +01:00
|
|
|
#include <pthread.h>
|
|
|
|
#endif
|
|
|
|
#include <stdarg.h>
|
2015-02-13 00:14:26 +01:00
|
|
|
#include <stdatomic.h>
|
2014-02-20 23:59:07 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2013-03-15 17:45:12 +01:00
|
|
|
#include <sys/stat.h>
|
2014-02-20 23:59:07 +01:00
|
|
|
#include <sys/types.h>
|
|
|
|
#if (FAKE_LOG_DEVICE == 0)
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/un.h>
|
|
|
|
#endif
|
|
|
|
#include <time.h>
|
|
|
|
#include <unistd.h>
|
2009-03-04 04:32:55 +01:00
|
|
|
|
2014-08-19 02:29:34 +02:00
|
|
|
#ifdef __BIONIC__
|
|
|
|
#include <android/set_abort_message.h>
|
|
|
|
#endif
|
|
|
|
|
2013-07-24 01:59:20 +02:00
|
|
|
#include <log/logd.h>
|
2014-02-20 23:59:07 +01:00
|
|
|
#include <log/logger.h>
|
|
|
|
#include <log/log_read.h>
|
|
|
|
#include <private/android_filesystem_config.h>
|
2015-01-16 22:38:07 +01:00
|
|
|
#include <private/android_logger.h>
|
2014-01-02 22:52:29 +01:00
|
|
|
|
2013-11-22 16:54:30 +01:00
|
|
|
#define LOG_BUF_SIZE 1024
|
2009-03-04 04:32:55 +01:00
|
|
|
|
|
|
|
#if FAKE_LOG_DEVICE
|
2014-02-20 23:59:07 +01:00
|
|
|
/* This will be defined when building for the host. */
|
2014-01-28 20:26:56 +01:00
|
|
|
#include "fake_log_device.h"
|
2009-03-04 04:32:55 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
static int __write_to_log_init(log_id_t, struct iovec *vec, size_t nr);
|
2010-03-01 18:11:54 +01:00
|
|
|
static int (*write_to_log)(log_id_t, struct iovec *vec, size_t nr) = __write_to_log_init;
|
2015-01-27 04:48:54 +01:00
|
|
|
#if !defined(_WIN32)
|
2009-03-04 04:32:55 +01:00
|
|
|
static pthread_mutex_t log_init_lock = PTHREAD_MUTEX_INITIALIZER;
|
|
|
|
#endif
|
|
|
|
|
2014-04-30 17:50:53 +02:00
|
|
|
#ifndef __unused
|
|
|
|
#define __unused __attribute__((__unused__))
|
|
|
|
#endif
|
2014-01-28 20:26:56 +01:00
|
|
|
|
2014-02-20 23:59:07 +01:00
|
|
|
#if FAKE_LOG_DEVICE
|
2014-04-07 23:58:08 +02:00
|
|
|
static int log_fds[(int)LOG_ID_MAX] = { -1, -1, -1, -1, -1 };
|
2014-04-30 17:50:53 +02:00
|
|
|
#else
|
|
|
|
static int logd_fd = -1;
|
2014-12-15 19:52:12 +01:00
|
|
|
static int pstore_fd = -1;
|
2014-02-20 23:59:07 +01:00
|
|
|
#endif
|
2009-03-04 04:32:55 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* This is used by the C++ code to decide if it should write logs through
|
2014-02-20 23:59:07 +01:00
|
|
|
* the C code. Basically, if /dev/socket/logd is available, we're running in
|
2009-03-04 04:32:55 +01:00
|
|
|
* the simulator rather than a desktop tool and want to use the device.
|
|
|
|
*/
|
|
|
|
static enum {
|
2010-06-03 01:25:35 +02:00
|
|
|
kLogUninitialized, kLogNotAvailable, kLogAvailable
|
2009-03-04 04:32:55 +01:00
|
|
|
} g_log_status = kLogUninitialized;
|
2015-02-04 21:28:47 +01:00
|
|
|
|
2009-03-04 04:32:55 +01:00
|
|
|
int __android_log_dev_available(void)
|
|
|
|
{
|
|
|
|
if (g_log_status == kLogUninitialized) {
|
2014-02-20 23:59:07 +01:00
|
|
|
if (access("/dev/socket/logdw", W_OK) == 0)
|
2009-03-04 04:32:55 +01:00
|
|
|
g_log_status = kLogAvailable;
|
|
|
|
else
|
|
|
|
g_log_status = kLogNotAvailable;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (g_log_status == kLogAvailable);
|
|
|
|
}
|
|
|
|
|
2014-03-25 21:45:33 +01:00
|
|
|
/* log_init_lock assumed */
|
|
|
|
static int __write_to_log_initialize()
|
2009-03-04 04:32:55 +01:00
|
|
|
{
|
2014-03-25 21:45:33 +01:00
|
|
|
int i, ret = 0;
|
|
|
|
|
2014-02-20 23:59:07 +01:00
|
|
|
#if FAKE_LOG_DEVICE
|
2014-03-25 21:45:33 +01:00
|
|
|
for (i = 0; i < LOG_ID_MAX; i++) {
|
|
|
|
char buf[sizeof("/dev/log_system")];
|
|
|
|
snprintf(buf, sizeof(buf), "/dev/log_%s", android_log_id_to_name(i));
|
|
|
|
log_fds[i] = fakeLogOpen(buf, O_WRONLY);
|
|
|
|
}
|
|
|
|
#else
|
2015-03-13 20:15:57 +01:00
|
|
|
if (pstore_fd < 0) {
|
|
|
|
pstore_fd = TEMP_FAILURE_RETRY(open("/dev/pmsg0", O_WRONLY));
|
2014-03-25 21:45:33 +01:00
|
|
|
}
|
|
|
|
|
2015-03-13 20:15:57 +01:00
|
|
|
if (logd_fd < 0) {
|
|
|
|
i = TEMP_FAILURE_RETRY(socket(PF_UNIX, SOCK_DGRAM | SOCK_CLOEXEC, 0));
|
|
|
|
if (i < 0) {
|
|
|
|
ret = -errno;
|
|
|
|
} else if (TEMP_FAILURE_RETRY(fcntl(i, F_SETFL, O_NONBLOCK)) < 0) {
|
2014-03-25 21:45:33 +01:00
|
|
|
ret = -errno;
|
|
|
|
close(i);
|
2015-03-13 20:15:57 +01:00
|
|
|
} else {
|
|
|
|
struct sockaddr_un un;
|
|
|
|
memset(&un, 0, sizeof(struct sockaddr_un));
|
|
|
|
un.sun_family = AF_UNIX;
|
|
|
|
strcpy(un.sun_path, "/dev/socket/logdw");
|
|
|
|
|
|
|
|
if (TEMP_FAILURE_RETRY(connect(i, (struct sockaddr *)&un,
|
|
|
|
sizeof(struct sockaddr_un))) < 0) {
|
|
|
|
ret = -errno;
|
|
|
|
close(i);
|
|
|
|
} else {
|
|
|
|
logd_fd = i;
|
|
|
|
}
|
2014-03-25 21:45:33 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-02-04 21:28:47 +01:00
|
|
|
static int __write_to_log_daemon(log_id_t log_id, struct iovec *vec, size_t nr)
|
2014-03-25 21:45:33 +01:00
|
|
|
{
|
2009-03-04 04:32:55 +01:00
|
|
|
ssize_t ret;
|
2014-03-25 21:45:33 +01:00
|
|
|
#if FAKE_LOG_DEVICE
|
2009-03-04 04:32:55 +01:00
|
|
|
int log_fd;
|
|
|
|
|
|
|
|
if (/*(int)log_id >= 0 &&*/ (int)log_id < (int)LOG_ID_MAX) {
|
|
|
|
log_fd = log_fds[(int)log_id];
|
|
|
|
} else {
|
2014-03-25 21:45:33 +01:00
|
|
|
return -EBADF;
|
2009-03-04 04:32:55 +01:00
|
|
|
}
|
|
|
|
do {
|
2014-02-20 23:59:07 +01:00
|
|
|
ret = fakeLogWritev(log_fd, vec, nr);
|
2014-03-25 21:45:33 +01:00
|
|
|
if (ret < 0) {
|
|
|
|
ret = -errno;
|
|
|
|
}
|
|
|
|
} while (ret == -EINTR);
|
2014-02-20 23:59:07 +01:00
|
|
|
#else
|
2014-12-15 19:52:12 +01:00
|
|
|
static const unsigned header_length = 2;
|
2014-04-24 18:43:23 +02:00
|
|
|
struct iovec newVec[nr + header_length];
|
2014-12-15 19:52:12 +01:00
|
|
|
android_log_header_t header;
|
|
|
|
android_pmsg_log_header_t pmsg_header;
|
2014-04-24 18:43:23 +02:00
|
|
|
struct timespec ts;
|
|
|
|
size_t i, payload_size;
|
2014-05-30 02:53:41 +02:00
|
|
|
static uid_t last_uid = AID_ROOT; /* logd *always* starts up as AID_ROOT */
|
2014-12-15 19:52:12 +01:00
|
|
|
static pid_t last_pid = (pid_t) -1;
|
2015-02-13 00:14:26 +01:00
|
|
|
static atomic_int_fast32_t dropped;
|
2014-04-24 18:43:23 +02:00
|
|
|
|
2015-03-13 23:57:11 +01:00
|
|
|
if (!nr) {
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2014-05-30 02:53:41 +02:00
|
|
|
if (last_uid == AID_ROOT) { /* have we called to get the UID yet? */
|
|
|
|
last_uid = getuid();
|
|
|
|
}
|
2014-12-15 19:52:12 +01:00
|
|
|
if (last_pid == (pid_t) -1) {
|
|
|
|
last_pid = getpid();
|
2014-03-25 21:45:33 +01:00
|
|
|
}
|
2014-03-21 00:09:38 +01:00
|
|
|
/*
|
|
|
|
* struct {
|
2015-02-04 21:28:47 +01:00
|
|
|
* // what we provide to pstore
|
2014-12-15 19:52:12 +01:00
|
|
|
* android_pmsg_log_header_t pmsg_header;
|
|
|
|
* // what we provide to socket
|
2015-01-16 22:38:07 +01:00
|
|
|
* android_log_header_t header;
|
2014-03-21 00:09:38 +01:00
|
|
|
* // caller provides
|
|
|
|
* union {
|
|
|
|
* struct {
|
|
|
|
* char prio;
|
|
|
|
* char payload[];
|
|
|
|
* } string;
|
|
|
|
* struct {
|
|
|
|
* uint32_t tag
|
|
|
|
* char payload[];
|
|
|
|
* } binary;
|
|
|
|
* };
|
|
|
|
* };
|
|
|
|
*/
|
2014-04-24 18:43:23 +02:00
|
|
|
|
2014-05-30 02:53:41 +02:00
|
|
|
clock_gettime(CLOCK_REALTIME, &ts);
|
|
|
|
|
2014-12-15 19:52:12 +01:00
|
|
|
pmsg_header.magic = LOGGER_MAGIC;
|
|
|
|
pmsg_header.len = sizeof(pmsg_header) + sizeof(header);
|
|
|
|
pmsg_header.uid = last_uid;
|
|
|
|
pmsg_header.pid = last_pid;
|
|
|
|
|
2015-01-16 22:38:07 +01:00
|
|
|
header.tid = gettid();
|
|
|
|
header.realtime.tv_sec = ts.tv_sec;
|
|
|
|
header.realtime.tv_nsec = ts.tv_nsec;
|
2014-02-20 23:59:07 +01:00
|
|
|
|
2014-12-15 19:52:12 +01:00
|
|
|
newVec[0].iov_base = (unsigned char *) &pmsg_header;
|
|
|
|
newVec[0].iov_len = sizeof(pmsg_header);
|
|
|
|
newVec[1].iov_base = (unsigned char *) &header;
|
|
|
|
newVec[1].iov_len = sizeof(header);
|
2014-02-20 23:59:07 +01:00
|
|
|
|
2015-02-13 00:14:26 +01:00
|
|
|
if (logd_fd > 0) {
|
|
|
|
int32_t snapshot = atomic_exchange_explicit(&dropped, 0, memory_order_relaxed);
|
|
|
|
if (snapshot) {
|
|
|
|
android_log_event_int_t buffer;
|
|
|
|
|
|
|
|
header.id = LOG_ID_EVENTS;
|
|
|
|
buffer.header.tag = htole32(LIBLOG_LOG_TAG);
|
|
|
|
buffer.payload.type = EVENT_TYPE_INT;
|
|
|
|
buffer.payload.data = htole32(snapshot);
|
|
|
|
|
|
|
|
newVec[2].iov_base = &buffer;
|
|
|
|
newVec[2].iov_len = sizeof(buffer);
|
|
|
|
|
|
|
|
ret = TEMP_FAILURE_RETRY(writev(logd_fd, newVec + 1, 2));
|
|
|
|
if (ret != (ssize_t)(sizeof(header) + sizeof(buffer))) {
|
|
|
|
atomic_fetch_add_explicit(&dropped, snapshot, memory_order_relaxed);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
header.id = log_id;
|
|
|
|
|
2014-04-24 18:43:23 +02:00
|
|
|
for (payload_size = 0, i = header_length; i < nr + header_length; i++) {
|
|
|
|
newVec[i].iov_base = vec[i - header_length].iov_base;
|
|
|
|
payload_size += newVec[i].iov_len = vec[i - header_length].iov_len;
|
|
|
|
|
|
|
|
if (payload_size > LOGGER_ENTRY_MAX_PAYLOAD) {
|
|
|
|
newVec[i].iov_len -= payload_size - LOGGER_ENTRY_MAX_PAYLOAD;
|
|
|
|
if (newVec[i].iov_len) {
|
|
|
|
++i;
|
|
|
|
}
|
2014-12-15 19:52:12 +01:00
|
|
|
payload_size = LOGGER_ENTRY_MAX_PAYLOAD;
|
2014-04-24 18:43:23 +02:00
|
|
|
break;
|
|
|
|
}
|
2014-02-20 23:59:07 +01:00
|
|
|
}
|
2014-12-15 19:52:12 +01:00
|
|
|
pmsg_header.len += payload_size;
|
|
|
|
|
|
|
|
if (pstore_fd >= 0) {
|
|
|
|
TEMP_FAILURE_RETRY(writev(pstore_fd, newVec, i));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (last_uid == AID_LOGD) { /* logd, after initialization and priv drop */
|
|
|
|
/*
|
|
|
|
* ignore log messages we send to ourself (logd).
|
|
|
|
* Such log messages are often generated by libraries we depend on
|
|
|
|
* which use standard Android logging.
|
|
|
|
*/
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (logd_fd < 0) {
|
|
|
|
return -EBADF;
|
|
|
|
}
|
2014-02-20 23:59:07 +01:00
|
|
|
|
2014-03-25 21:45:33 +01:00
|
|
|
/*
|
|
|
|
* The write below could be lost, but will never block.
|
|
|
|
*
|
2014-12-15 19:52:12 +01:00
|
|
|
* To logd, we drop the pmsg_header
|
|
|
|
*
|
2014-03-25 21:45:33 +01:00
|
|
|
* ENOTCONN occurs if logd dies.
|
|
|
|
* EAGAIN occurs if logd is overloaded.
|
|
|
|
*/
|
2014-12-15 19:52:12 +01:00
|
|
|
ret = TEMP_FAILURE_RETRY(writev(logd_fd, newVec + 1, i - 1));
|
2014-03-25 21:45:33 +01:00
|
|
|
if (ret < 0) {
|
|
|
|
ret = -errno;
|
|
|
|
if (ret == -ENOTCONN) {
|
2015-01-27 04:48:54 +01:00
|
|
|
#if !defined(_WIN32)
|
2014-03-25 21:45:33 +01:00
|
|
|
pthread_mutex_lock(&log_init_lock);
|
|
|
|
#endif
|
2015-03-13 20:15:57 +01:00
|
|
|
close(logd_fd);
|
|
|
|
logd_fd = -1;
|
2014-03-25 21:45:33 +01:00
|
|
|
ret = __write_to_log_initialize();
|
2015-01-27 04:48:54 +01:00
|
|
|
#if !defined(_WIN32)
|
2014-03-25 21:45:33 +01:00
|
|
|
pthread_mutex_unlock(&log_init_lock);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (ret < 0) {
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-12-15 19:52:12 +01:00
|
|
|
ret = TEMP_FAILURE_RETRY(writev(logd_fd, newVec + 1, i - 1));
|
2014-03-25 21:45:33 +01:00
|
|
|
if (ret < 0) {
|
|
|
|
ret = -errno;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-04-24 18:43:23 +02:00
|
|
|
|
2015-01-16 22:38:07 +01:00
|
|
|
if (ret > (ssize_t)sizeof(header)) {
|
|
|
|
ret -= sizeof(header);
|
2015-02-13 00:14:26 +01:00
|
|
|
} else if (ret == -EAGAIN) {
|
|
|
|
atomic_fetch_add_explicit(&dropped, 1, memory_order_relaxed);
|
2014-04-24 18:43:23 +02:00
|
|
|
}
|
2014-02-20 23:59:07 +01:00
|
|
|
#endif
|
2014-04-24 18:43:23 +02:00
|
|
|
|
|
|
|
return ret;
|
2014-02-20 23:59:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#if FAKE_LOG_DEVICE
|
|
|
|
static const char *LOG_NAME[LOG_ID_MAX] = {
|
|
|
|
[LOG_ID_MAIN] = "main",
|
|
|
|
[LOG_ID_RADIO] = "radio",
|
|
|
|
[LOG_ID_EVENTS] = "events",
|
2014-04-07 23:58:08 +02:00
|
|
|
[LOG_ID_SYSTEM] = "system",
|
2014-10-11 00:13:15 +02:00
|
|
|
[LOG_ID_CRASH] = "crash",
|
|
|
|
[LOG_ID_KERNEL] = "kernel",
|
2014-02-20 23:59:07 +01:00
|
|
|
};
|
|
|
|
|
2014-10-20 21:31:30 +02:00
|
|
|
const char *android_log_id_to_name(log_id_t log_id)
|
2014-02-20 23:59:07 +01:00
|
|
|
{
|
|
|
|
if (log_id >= LOG_ID_MAX) {
|
|
|
|
log_id = LOG_ID_MAIN;
|
|
|
|
}
|
|
|
|
return LOG_NAME[log_id];
|
2009-03-04 04:32:55 +01:00
|
|
|
}
|
2014-02-20 23:59:07 +01:00
|
|
|
#endif
|
2009-03-04 04:32:55 +01:00
|
|
|
|
|
|
|
static int __write_to_log_init(log_id_t log_id, struct iovec *vec, size_t nr)
|
|
|
|
{
|
2015-01-27 04:48:54 +01:00
|
|
|
#if !defined(_WIN32)
|
2009-03-04 04:32:55 +01:00
|
|
|
pthread_mutex_lock(&log_init_lock);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (write_to_log == __write_to_log_init) {
|
2014-03-25 21:45:33 +01:00
|
|
|
int ret;
|
2009-03-04 04:32:55 +01:00
|
|
|
|
2014-03-25 21:45:33 +01:00
|
|
|
ret = __write_to_log_initialize();
|
|
|
|
if (ret < 0) {
|
2015-01-27 04:48:54 +01:00
|
|
|
#if !defined(_WIN32)
|
2014-03-25 21:45:33 +01:00
|
|
|
pthread_mutex_unlock(&log_init_lock);
|
2015-03-13 20:15:57 +01:00
|
|
|
#endif
|
|
|
|
#if (FAKE_LOG_DEVICE == 0)
|
|
|
|
if (pstore_fd >= 0) {
|
|
|
|
__write_to_log_daemon(log_id, vec, nr);
|
|
|
|
}
|
2014-02-20 23:59:07 +01:00
|
|
|
#endif
|
2014-03-25 21:45:33 +01:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-02-04 21:28:47 +01:00
|
|
|
write_to_log = __write_to_log_daemon;
|
2009-03-04 04:32:55 +01:00
|
|
|
}
|
|
|
|
|
2015-01-27 04:48:54 +01:00
|
|
|
#if !defined(_WIN32)
|
2009-03-04 04:32:55 +01:00
|
|
|
pthread_mutex_unlock(&log_init_lock);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return write_to_log(log_id, vec, nr);
|
|
|
|
}
|
|
|
|
|
|
|
|
int __android_log_write(int prio, const char *tag, const char *msg)
|
|
|
|
{
|
2015-04-02 19:32:44 +02:00
|
|
|
return __android_log_buf_write(LOG_ID_MAIN, prio, tag, msg);
|
2009-03-04 04:32:55 +01:00
|
|
|
}
|
|
|
|
|
2010-03-01 18:11:54 +01:00
|
|
|
int __android_log_buf_write(int bufID, int prio, const char *tag, const char *msg)
|
|
|
|
{
|
|
|
|
struct iovec vec[3];
|
2012-11-28 21:20:19 +01:00
|
|
|
char tmp_tag[32];
|
2010-03-01 18:11:54 +01:00
|
|
|
|
|
|
|
if (!tag)
|
|
|
|
tag = "";
|
|
|
|
|
|
|
|
/* XXX: This needs to go! */
|
2012-11-28 21:20:19 +01:00
|
|
|
if ((bufID != LOG_ID_RADIO) &&
|
|
|
|
(!strcmp(tag, "HTC_RIL") ||
|
2010-03-01 18:11:54 +01:00
|
|
|
!strncmp(tag, "RIL", 3) || /* Any log tag with "RIL" as the prefix */
|
2012-08-13 20:27:30 +02:00
|
|
|
!strncmp(tag, "IMS", 3) || /* Any log tag with "IMS" as the prefix */
|
2010-03-01 18:11:54 +01:00
|
|
|
!strcmp(tag, "AT") ||
|
|
|
|
!strcmp(tag, "GSM") ||
|
|
|
|
!strcmp(tag, "STK") ||
|
|
|
|
!strcmp(tag, "CDMA") ||
|
|
|
|
!strcmp(tag, "PHONE") ||
|
2012-11-28 21:20:19 +01:00
|
|
|
!strcmp(tag, "SMS"))) {
|
2010-03-01 18:11:54 +01:00
|
|
|
bufID = LOG_ID_RADIO;
|
2014-03-25 21:45:33 +01:00
|
|
|
/* Inform third party apps/ril/radio.. to use Rlog or RLOG */
|
2012-11-28 21:20:19 +01:00
|
|
|
snprintf(tmp_tag, sizeof(tmp_tag), "use-Rlog/RLOG-%s", tag);
|
|
|
|
tag = tmp_tag;
|
|
|
|
}
|
2010-03-01 18:11:54 +01:00
|
|
|
|
2015-04-02 19:32:44 +02:00
|
|
|
#if __BIONIC__
|
|
|
|
if (prio == ANDROID_LOG_FATAL) {
|
|
|
|
android_set_abort_message(msg);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-03-01 18:11:54 +01:00
|
|
|
vec[0].iov_base = (unsigned char *) &prio;
|
|
|
|
vec[0].iov_len = 1;
|
|
|
|
vec[1].iov_base = (void *) tag;
|
|
|
|
vec[1].iov_len = strlen(tag) + 1;
|
|
|
|
vec[2].iov_base = (void *) msg;
|
|
|
|
vec[2].iov_len = strlen(msg) + 1;
|
|
|
|
|
|
|
|
return write_to_log(bufID, vec, 3);
|
|
|
|
}
|
|
|
|
|
2009-03-04 04:32:55 +01:00
|
|
|
int __android_log_vprint(int prio, const char *tag, const char *fmt, va_list ap)
|
|
|
|
{
|
2010-06-03 01:25:35 +02:00
|
|
|
char buf[LOG_BUF_SIZE];
|
2009-03-04 04:32:55 +01:00
|
|
|
|
|
|
|
vsnprintf(buf, LOG_BUF_SIZE, fmt, ap);
|
|
|
|
|
|
|
|
return __android_log_write(prio, tag, buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
int __android_log_print(int prio, const char *tag, const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
2010-03-01 18:11:54 +01:00
|
|
|
char buf[LOG_BUF_SIZE];
|
2009-03-04 04:32:55 +01:00
|
|
|
|
|
|
|
va_start(ap, fmt);
|
|
|
|
vsnprintf(buf, LOG_BUF_SIZE, fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
|
|
|
|
return __android_log_write(prio, tag, buf);
|
|
|
|
}
|
|
|
|
|
2010-03-01 18:11:54 +01:00
|
|
|
int __android_log_buf_print(int bufID, int prio, const char *tag, const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
char buf[LOG_BUF_SIZE];
|
|
|
|
|
|
|
|
va_start(ap, fmt);
|
|
|
|
vsnprintf(buf, LOG_BUF_SIZE, fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
|
|
|
|
return __android_log_buf_write(bufID, prio, tag, buf);
|
|
|
|
}
|
|
|
|
|
2009-03-04 04:32:55 +01:00
|
|
|
void __android_log_assert(const char *cond, const char *tag,
|
2013-11-22 16:54:30 +01:00
|
|
|
const char *fmt, ...)
|
2009-03-04 04:32:55 +01:00
|
|
|
{
|
2010-06-03 01:25:35 +02:00
|
|
|
char buf[LOG_BUF_SIZE];
|
2009-03-04 04:32:55 +01:00
|
|
|
|
2010-06-03 01:25:35 +02:00
|
|
|
if (fmt) {
|
|
|
|
va_list ap;
|
|
|
|
va_start(ap, fmt);
|
|
|
|
vsnprintf(buf, LOG_BUF_SIZE, fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
} else {
|
|
|
|
/* Msg not provided, log condition. N.B. Do not use cond directly as
|
|
|
|
* format string as it could contain spurious '%' syntax (e.g.
|
|
|
|
* "%d" in "blocks%devs == 0").
|
|
|
|
*/
|
|
|
|
if (cond)
|
|
|
|
snprintf(buf, LOG_BUF_SIZE, "Assertion failed: %s", cond);
|
|
|
|
else
|
|
|
|
strcpy(buf, "Unspecified assertion failed");
|
|
|
|
}
|
2009-03-04 04:32:55 +01:00
|
|
|
|
|
|
|
__android_log_write(ANDROID_LOG_FATAL, tag, buf);
|
2015-03-07 20:21:37 +01:00
|
|
|
abort(); /* abort so we have a chance to debug the situation */
|
2014-04-23 23:57:32 +02:00
|
|
|
/* NOTREACHED */
|
2009-03-04 04:32:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int __android_log_bwrite(int32_t tag, const void *payload, size_t len)
|
|
|
|
{
|
|
|
|
struct iovec vec[2];
|
|
|
|
|
|
|
|
vec[0].iov_base = &tag;
|
|
|
|
vec[0].iov_len = sizeof(tag);
|
|
|
|
vec[1].iov_base = (void*)payload;
|
|
|
|
vec[1].iov_len = len;
|
|
|
|
|
|
|
|
return write_to_log(LOG_ID_EVENTS, vec, 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Like __android_log_bwrite, but takes the type as well. Doesn't work
|
|
|
|
* for the general case where we're generating lists of stuff, but very
|
|
|
|
* handy if we just want to dump an integer into the log.
|
|
|
|
*/
|
|
|
|
int __android_log_btwrite(int32_t tag, char type, const void *payload,
|
2014-02-20 23:59:07 +01:00
|
|
|
size_t len)
|
2009-03-04 04:32:55 +01:00
|
|
|
{
|
|
|
|
struct iovec vec[3];
|
|
|
|
|
|
|
|
vec[0].iov_base = &tag;
|
|
|
|
vec[0].iov_len = sizeof(tag);
|
|
|
|
vec[1].iov_base = &type;
|
|
|
|
vec[1].iov_len = sizeof(type);
|
|
|
|
vec[2].iov_base = (void*)payload;
|
|
|
|
vec[2].iov_len = len;
|
|
|
|
|
|
|
|
return write_to_log(LOG_ID_EVENTS, vec, 3);
|
|
|
|
}
|
2014-07-01 19:57:16 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Like __android_log_bwrite, but used for writing strings to the
|
|
|
|
* event log.
|
|
|
|
*/
|
|
|
|
int __android_log_bswrite(int32_t tag, const char *payload)
|
|
|
|
{
|
|
|
|
struct iovec vec[4];
|
|
|
|
char type = EVENT_TYPE_STRING;
|
|
|
|
uint32_t len = strlen(payload);
|
|
|
|
|
|
|
|
vec[0].iov_base = &tag;
|
|
|
|
vec[0].iov_len = sizeof(tag);
|
|
|
|
vec[1].iov_base = &type;
|
|
|
|
vec[1].iov_len = sizeof(type);
|
|
|
|
vec[2].iov_base = &len;
|
|
|
|
vec[2].iov_len = sizeof(len);
|
|
|
|
vec[3].iov_base = (void*)payload;
|
|
|
|
vec[3].iov_len = len;
|
|
|
|
|
|
|
|
return write_to_log(LOG_ID_EVENTS, vec, 4);
|
|
|
|
}
|