blob: 3659676332ad0b8354907fa27b98887a228a2196 [file] [log] [blame]
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001/*
Mark Salyzyne9c41962014-01-02 13:52:29 -08002 * Copyright (C) 2007-2014 The Android Open Source Project
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Mark Salyzyn154f4602014-02-20 14:59:07 -080016#include <errno.h>
17#include <fcntl.h>
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080018#ifdef HAVE_PTHREADS
19#include <pthread.h>
20#endif
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080021#include <stdarg.h>
Mark Salyzyn154f4602014-02-20 14:59:07 -080022#include <stdio.h>
23#include <stdlib.h>
24#include <string.h>
Nick Kralevicha1703222013-03-15 09:45:12 -070025#include <sys/stat.h>
Mark Salyzyn154f4602014-02-20 14:59:07 -080026#include <sys/types.h>
27#if (FAKE_LOG_DEVICE == 0)
28#include <sys/socket.h>
29#include <sys/un.h>
30#endif
31#include <time.h>
32#include <unistd.h>
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080033
Dan Albertc68fedc2014-08-18 17:29:34 -070034#ifdef __BIONIC__
35#include <android/set_abort_message.h>
36#endif
37
Colin Cross9227bd32013-07-23 16:59:20 -070038#include <log/logd.h>
Mark Salyzyn154f4602014-02-20 14:59:07 -080039#include <log/logger.h>
40#include <log/log_read.h>
41#include <private/android_filesystem_config.h>
Mark Salyzyne9c41962014-01-02 13:52:29 -080042
Mark Salyzyncf4aa032013-11-22 07:54:30 -080043#define LOG_BUF_SIZE 1024
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080044
45#if FAKE_LOG_DEVICE
Mark Salyzyn154f4602014-02-20 14:59:07 -080046/* This will be defined when building for the host. */
Kristian Monsenb5a98902014-01-28 11:26:56 -080047#include "fake_log_device.h"
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080048#endif
49
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080050static int __write_to_log_init(log_id_t, struct iovec *vec, size_t nr);
Joe Onoratoe2bf2ea2010-03-01 09:11:54 -080051static int (*write_to_log)(log_id_t, struct iovec *vec, size_t nr) = __write_to_log_init;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080052#ifdef HAVE_PTHREADS
53static pthread_mutex_t log_init_lock = PTHREAD_MUTEX_INITIALIZER;
54#endif
55
Mark Salyzyna04464a2014-04-30 08:50:53 -070056#ifndef __unused
57#define __unused __attribute__((__unused__))
58#endif
Kristian Monsenb5a98902014-01-28 11:26:56 -080059
Mark Salyzyn154f4602014-02-20 14:59:07 -080060#if FAKE_LOG_DEVICE
61#define WEAK __attribute__((weak))
Mark Salyzyn99f47a92014-04-07 14:58:08 -070062static int log_fds[(int)LOG_ID_MAX] = { -1, -1, -1, -1, -1 };
Mark Salyzyna04464a2014-04-30 08:50:53 -070063#else
64static int logd_fd = -1;
Mark Salyzyn154f4602014-02-20 14:59:07 -080065#endif
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080066
67/*
68 * This is used by the C++ code to decide if it should write logs through
Mark Salyzyn154f4602014-02-20 14:59:07 -080069 * the C code. Basically, if /dev/socket/logd is available, we're running in
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080070 * the simulator rather than a desktop tool and want to use the device.
71 */
72static enum {
Chris Pearson19299902010-06-02 16:25:35 -070073 kLogUninitialized, kLogNotAvailable, kLogAvailable
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080074} g_log_status = kLogUninitialized;
75int __android_log_dev_available(void)
76{
77 if (g_log_status == kLogUninitialized) {
Mark Salyzyn154f4602014-02-20 14:59:07 -080078 if (access("/dev/socket/logdw", W_OK) == 0)
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080079 g_log_status = kLogAvailable;
80 else
81 g_log_status = kLogNotAvailable;
82 }
83
84 return (g_log_status == kLogAvailable);
85}
86
Mark Salyzyna04464a2014-04-30 08:50:53 -070087#if !FAKE_LOG_DEVICE
Mark Salyzyn8245af12014-03-25 13:45:33 -070088/* give up, resources too limited */
Mark Salyzyna04464a2014-04-30 08:50:53 -070089static int __write_to_log_null(log_id_t log_fd __unused, struct iovec *vec __unused,
90 size_t nr __unused)
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080091{
92 return -1;
93}
Mark Salyzyna04464a2014-04-30 08:50:53 -070094#endif
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080095
Mark Salyzyn8245af12014-03-25 13:45:33 -070096/* log_init_lock assumed */
97static int __write_to_log_initialize()
98{
99 int i, ret = 0;
100
101#if FAKE_LOG_DEVICE
102 for (i = 0; i < LOG_ID_MAX; i++) {
103 char buf[sizeof("/dev/log_system")];
104 snprintf(buf, sizeof(buf), "/dev/log_%s", android_log_id_to_name(i));
105 log_fds[i] = fakeLogOpen(buf, O_WRONLY);
106 }
107#else
108 if (logd_fd >= 0) {
109 i = logd_fd;
110 logd_fd = -1;
111 close(i);
112 }
113
Nick Kralevich118d1b32014-07-02 22:30:39 -0700114 i = socket(PF_UNIX, SOCK_DGRAM | SOCK_CLOEXEC, 0);
Mark Salyzyn8245af12014-03-25 13:45:33 -0700115 if (i < 0) {
116 ret = -errno;
117 write_to_log = __write_to_log_null;
118 } else if (fcntl(i, F_SETFL, O_NONBLOCK) < 0) {
119 ret = -errno;
120 close(i);
121 i = -1;
122 write_to_log = __write_to_log_null;
123 } else {
124 struct sockaddr_un un;
125 memset(&un, 0, sizeof(struct sockaddr_un));
126 un.sun_family = AF_UNIX;
127 strcpy(un.sun_path, "/dev/socket/logdw");
128
129 if (connect(i, (struct sockaddr *)&un, sizeof(struct sockaddr_un)) < 0) {
130 ret = -errno;
131 close(i);
132 i = -1;
133 }
134 }
135 logd_fd = i;
136#endif
137
138 return ret;
139}
140
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800141static int __write_to_log_kernel(log_id_t log_id, struct iovec *vec, size_t nr)
142{
143 ssize_t ret;
Mark Salyzyn8245af12014-03-25 13:45:33 -0700144#if FAKE_LOG_DEVICE
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800145 int log_fd;
146
147 if (/*(int)log_id >= 0 &&*/ (int)log_id < (int)LOG_ID_MAX) {
148 log_fd = log_fds[(int)log_id];
149 } else {
Mark Salyzyn8245af12014-03-25 13:45:33 -0700150 return -EBADF;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800151 }
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800152 do {
Mark Salyzyn154f4602014-02-20 14:59:07 -0800153 ret = fakeLogWritev(log_fd, vec, nr);
Mark Salyzyn8245af12014-03-25 13:45:33 -0700154 if (ret < 0) {
155 ret = -errno;
156 }
157 } while (ret == -EINTR);
Mark Salyzyn154f4602014-02-20 14:59:07 -0800158#else
Mark Salyzyn8444eb82014-04-24 09:43:23 -0700159 static const unsigned header_length = 3;
160 struct iovec newVec[nr + header_length];
161 typeof_log_id_t log_id_buf;
162 uint16_t tid;
163 struct timespec ts;
164 log_time realtime_ts;
165 size_t i, payload_size;
Mark Salyzyn076ba812014-05-29 17:53:41 -0700166 static uid_t last_uid = AID_ROOT; /* logd *always* starts up as AID_ROOT */
Mark Salyzyn8444eb82014-04-24 09:43:23 -0700167
Mark Salyzyn076ba812014-05-29 17:53:41 -0700168 if (last_uid == AID_ROOT) { /* have we called to get the UID yet? */
169 last_uid = getuid();
170 }
171 if (last_uid == AID_LOGD) { /* logd, after initialization and priv drop */
Mark Salyzyn154f4602014-02-20 14:59:07 -0800172 /*
Mark Salyzyn076ba812014-05-29 17:53:41 -0700173 * ignore log messages we send to ourself (logd).
Mark Salyzyn154f4602014-02-20 14:59:07 -0800174 * Such log messages are often generated by libraries we depend on
175 * which use standard Android logging.
176 */
177 return 0;
178 }
Mark Salyzyn8245af12014-03-25 13:45:33 -0700179
180 if (logd_fd < 0) {
181 return -EBADF;
182 }
183
Mark Salyzynb992d0d2014-03-20 16:09:38 -0700184 /*
185 * struct {
186 * // what we provide
187 * typeof_log_id_t log_id;
188 * u16 tid;
189 * log_time realtime;
190 * // caller provides
191 * union {
192 * struct {
193 * char prio;
194 * char payload[];
195 * } string;
196 * struct {
197 * uint32_t tag
198 * char payload[];
199 * } binary;
200 * };
201 * };
202 */
Mark Salyzyn8444eb82014-04-24 09:43:23 -0700203
Mark Salyzyn076ba812014-05-29 17:53:41 -0700204 clock_gettime(CLOCK_REALTIME, &ts);
205 realtime_ts.tv_sec = ts.tv_sec;
206 realtime_ts.tv_nsec = ts.tv_nsec;
207
Mark Salyzyn8444eb82014-04-24 09:43:23 -0700208 log_id_buf = log_id;
209 tid = gettid();
Mark Salyzyn154f4602014-02-20 14:59:07 -0800210
211 newVec[0].iov_base = (unsigned char *) &log_id_buf;
212 newVec[0].iov_len = sizeof_log_id_t;
Mark Salyzynb992d0d2014-03-20 16:09:38 -0700213 newVec[1].iov_base = (unsigned char *) &tid;
214 newVec[1].iov_len = sizeof(tid);
Mark Salyzynb992d0d2014-03-20 16:09:38 -0700215 newVec[2].iov_base = (unsigned char *) &realtime_ts;
216 newVec[2].iov_len = sizeof(log_time);
Mark Salyzyn154f4602014-02-20 14:59:07 -0800217
Mark Salyzyn8444eb82014-04-24 09:43:23 -0700218 for (payload_size = 0, i = header_length; i < nr + header_length; i++) {
219 newVec[i].iov_base = vec[i - header_length].iov_base;
220 payload_size += newVec[i].iov_len = vec[i - header_length].iov_len;
221
222 if (payload_size > LOGGER_ENTRY_MAX_PAYLOAD) {
223 newVec[i].iov_len -= payload_size - LOGGER_ENTRY_MAX_PAYLOAD;
224 if (newVec[i].iov_len) {
225 ++i;
226 }
227 break;
228 }
Mark Salyzyn154f4602014-02-20 14:59:07 -0800229 }
230
Mark Salyzyn8245af12014-03-25 13:45:33 -0700231 /*
232 * The write below could be lost, but will never block.
233 *
234 * ENOTCONN occurs if logd dies.
235 * EAGAIN occurs if logd is overloaded.
236 */
Mark Salyzyn8444eb82014-04-24 09:43:23 -0700237 ret = writev(logd_fd, newVec, i);
Mark Salyzyn8245af12014-03-25 13:45:33 -0700238 if (ret < 0) {
239 ret = -errno;
240 if (ret == -ENOTCONN) {
241#ifdef HAVE_PTHREADS
242 pthread_mutex_lock(&log_init_lock);
243#endif
244 ret = __write_to_log_initialize();
245#ifdef HAVE_PTHREADS
246 pthread_mutex_unlock(&log_init_lock);
247#endif
248
249 if (ret < 0) {
250 return ret;
251 }
252
253 ret = writev(logd_fd, newVec, nr + header_length);
254 if (ret < 0) {
255 ret = -errno;
256 }
257 }
258 }
Mark Salyzyn8444eb82014-04-24 09:43:23 -0700259
260 if (ret > (ssize_t)(sizeof_log_id_t + sizeof(tid) + sizeof(log_time))) {
261 ret -= sizeof_log_id_t + sizeof(tid) + sizeof(log_time);
262 }
Mark Salyzyn154f4602014-02-20 14:59:07 -0800263#endif
Mark Salyzyn8444eb82014-04-24 09:43:23 -0700264
265 return ret;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800266}
267
Mark Salyzyn154f4602014-02-20 14:59:07 -0800268#if FAKE_LOG_DEVICE
269static const char *LOG_NAME[LOG_ID_MAX] = {
270 [LOG_ID_MAIN] = "main",
271 [LOG_ID_RADIO] = "radio",
272 [LOG_ID_EVENTS] = "events",
Mark Salyzyn99f47a92014-04-07 14:58:08 -0700273 [LOG_ID_SYSTEM] = "system",
274 [LOG_ID_CRASH] = "crash"
Mark Salyzyn154f4602014-02-20 14:59:07 -0800275};
276
277const WEAK char *android_log_id_to_name(log_id_t log_id)
278{
279 if (log_id >= LOG_ID_MAX) {
280 log_id = LOG_ID_MAIN;
281 }
282 return LOG_NAME[log_id];
283}
284#endif
285
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800286static int __write_to_log_init(log_id_t log_id, struct iovec *vec, size_t nr)
287{
288#ifdef HAVE_PTHREADS
289 pthread_mutex_lock(&log_init_lock);
290#endif
291
292 if (write_to_log == __write_to_log_init) {
Mark Salyzyn8245af12014-03-25 13:45:33 -0700293 int ret;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800294
Mark Salyzyn8245af12014-03-25 13:45:33 -0700295 ret = __write_to_log_initialize();
296 if (ret < 0) {
297#ifdef HAVE_PTHREADS
298 pthread_mutex_unlock(&log_init_lock);
Mark Salyzyn154f4602014-02-20 14:59:07 -0800299#endif
Mark Salyzyn8245af12014-03-25 13:45:33 -0700300 return ret;
301 }
302
303 write_to_log = __write_to_log_kernel;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800304 }
305
306#ifdef HAVE_PTHREADS
307 pthread_mutex_unlock(&log_init_lock);
308#endif
309
310 return write_to_log(log_id, vec, nr);
311}
312
313int __android_log_write(int prio, const char *tag, const char *msg)
314{
315 struct iovec vec[3];
316 log_id_t log_id = LOG_ID_MAIN;
Wink Saville3761e962012-11-28 12:20:19 -0800317 char tmp_tag[32];
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800318
319 if (!tag)
320 tag = "";
321
322 /* XXX: This needs to go! */
323 if (!strcmp(tag, "HTC_RIL") ||
John Michelaued7ccae2009-08-19 10:01:55 -0500324 !strncmp(tag, "RIL", 3) || /* Any log tag with "RIL" as the prefix */
Jeff Sharkey84dcf092012-08-13 11:27:30 -0700325 !strncmp(tag, "IMS", 3) || /* Any log tag with "IMS" as the prefix */
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800326 !strcmp(tag, "AT") ||
327 !strcmp(tag, "GSM") ||
Wink Saville89efdc92009-04-02 11:00:57 -0700328 !strcmp(tag, "STK") ||
329 !strcmp(tag, "CDMA") ||
330 !strcmp(tag, "PHONE") ||
Wink Saville3761e962012-11-28 12:20:19 -0800331 !strcmp(tag, "SMS")) {
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800332 log_id = LOG_ID_RADIO;
Mark Salyzyn8245af12014-03-25 13:45:33 -0700333 /* Inform third party apps/ril/radio.. to use Rlog or RLOG */
Wink Saville3761e962012-11-28 12:20:19 -0800334 snprintf(tmp_tag, sizeof(tmp_tag), "use-Rlog/RLOG-%s", tag);
335 tag = tmp_tag;
336 }
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800337
Elliott Hughes26864bf2014-05-06 20:40:15 -0700338#if __BIONIC__
339 if (prio == ANDROID_LOG_FATAL) {
Dan Albertc68fedc2014-08-18 17:29:34 -0700340 android_set_abort_message(msg);
Elliott Hughes26864bf2014-05-06 20:40:15 -0700341 }
342#endif
343
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800344 vec[0].iov_base = (unsigned char *) &prio;
345 vec[0].iov_len = 1;
346 vec[1].iov_base = (void *) tag;
347 vec[1].iov_len = strlen(tag) + 1;
348 vec[2].iov_base = (void *) msg;
349 vec[2].iov_len = strlen(msg) + 1;
350
351 return write_to_log(log_id, vec, 3);
352}
353
Joe Onoratoe2bf2ea2010-03-01 09:11:54 -0800354int __android_log_buf_write(int bufID, int prio, const char *tag, const char *msg)
355{
356 struct iovec vec[3];
Wink Saville3761e962012-11-28 12:20:19 -0800357 char tmp_tag[32];
Joe Onoratoe2bf2ea2010-03-01 09:11:54 -0800358
359 if (!tag)
360 tag = "";
361
362 /* XXX: This needs to go! */
Wink Saville3761e962012-11-28 12:20:19 -0800363 if ((bufID != LOG_ID_RADIO) &&
364 (!strcmp(tag, "HTC_RIL") ||
Joe Onoratoe2bf2ea2010-03-01 09:11:54 -0800365 !strncmp(tag, "RIL", 3) || /* Any log tag with "RIL" as the prefix */
Jeff Sharkey84dcf092012-08-13 11:27:30 -0700366 !strncmp(tag, "IMS", 3) || /* Any log tag with "IMS" as the prefix */
Joe Onoratoe2bf2ea2010-03-01 09:11:54 -0800367 !strcmp(tag, "AT") ||
368 !strcmp(tag, "GSM") ||
369 !strcmp(tag, "STK") ||
370 !strcmp(tag, "CDMA") ||
371 !strcmp(tag, "PHONE") ||
Wink Saville3761e962012-11-28 12:20:19 -0800372 !strcmp(tag, "SMS"))) {
Joe Onoratoe2bf2ea2010-03-01 09:11:54 -0800373 bufID = LOG_ID_RADIO;
Mark Salyzyn8245af12014-03-25 13:45:33 -0700374 /* Inform third party apps/ril/radio.. to use Rlog or RLOG */
Wink Saville3761e962012-11-28 12:20:19 -0800375 snprintf(tmp_tag, sizeof(tmp_tag), "use-Rlog/RLOG-%s", tag);
376 tag = tmp_tag;
377 }
Joe Onoratoe2bf2ea2010-03-01 09:11:54 -0800378
379 vec[0].iov_base = (unsigned char *) &prio;
380 vec[0].iov_len = 1;
381 vec[1].iov_base = (void *) tag;
382 vec[1].iov_len = strlen(tag) + 1;
383 vec[2].iov_base = (void *) msg;
384 vec[2].iov_len = strlen(msg) + 1;
385
386 return write_to_log(bufID, vec, 3);
387}
388
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800389int __android_log_vprint(int prio, const char *tag, const char *fmt, va_list ap)
390{
Chris Pearson19299902010-06-02 16:25:35 -0700391 char buf[LOG_BUF_SIZE];
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800392
393 vsnprintf(buf, LOG_BUF_SIZE, fmt, ap);
394
395 return __android_log_write(prio, tag, buf);
396}
397
398int __android_log_print(int prio, const char *tag, const char *fmt, ...)
399{
400 va_list ap;
Joe Onoratoe2bf2ea2010-03-01 09:11:54 -0800401 char buf[LOG_BUF_SIZE];
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800402
403 va_start(ap, fmt);
404 vsnprintf(buf, LOG_BUF_SIZE, fmt, ap);
405 va_end(ap);
406
407 return __android_log_write(prio, tag, buf);
408}
409
Joe Onoratoe2bf2ea2010-03-01 09:11:54 -0800410int __android_log_buf_print(int bufID, int prio, const char *tag, const char *fmt, ...)
411{
412 va_list ap;
413 char buf[LOG_BUF_SIZE];
414
415 va_start(ap, fmt);
416 vsnprintf(buf, LOG_BUF_SIZE, fmt, ap);
417 va_end(ap);
418
419 return __android_log_buf_write(bufID, prio, tag, buf);
420}
421
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800422void __android_log_assert(const char *cond, const char *tag,
Mark Salyzyncf4aa032013-11-22 07:54:30 -0800423 const char *fmt, ...)
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800424{
Chris Pearson19299902010-06-02 16:25:35 -0700425 char buf[LOG_BUF_SIZE];
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800426
Chris Pearson19299902010-06-02 16:25:35 -0700427 if (fmt) {
428 va_list ap;
429 va_start(ap, fmt);
430 vsnprintf(buf, LOG_BUF_SIZE, fmt, ap);
431 va_end(ap);
432 } else {
433 /* Msg not provided, log condition. N.B. Do not use cond directly as
434 * format string as it could contain spurious '%' syntax (e.g.
435 * "%d" in "blocks%devs == 0").
436 */
437 if (cond)
438 snprintf(buf, LOG_BUF_SIZE, "Assertion failed: %s", cond);
439 else
440 strcpy(buf, "Unspecified assertion failed");
441 }
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800442
443 __android_log_write(ANDROID_LOG_FATAL, tag, buf);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800444 __builtin_trap(); /* trap so we have a chance to debug the situation */
Elliott Hughesda6b2e22014-04-23 14:57:32 -0700445 /* NOTREACHED */
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800446}
447
448int __android_log_bwrite(int32_t tag, const void *payload, size_t len)
449{
450 struct iovec vec[2];
451
452 vec[0].iov_base = &tag;
453 vec[0].iov_len = sizeof(tag);
454 vec[1].iov_base = (void*)payload;
455 vec[1].iov_len = len;
456
457 return write_to_log(LOG_ID_EVENTS, vec, 2);
458}
459
460/*
461 * Like __android_log_bwrite, but takes the type as well. Doesn't work
462 * for the general case where we're generating lists of stuff, but very
463 * handy if we just want to dump an integer into the log.
464 */
465int __android_log_btwrite(int32_t tag, char type, const void *payload,
Mark Salyzyn154f4602014-02-20 14:59:07 -0800466 size_t len)
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800467{
468 struct iovec vec[3];
469
470 vec[0].iov_base = &tag;
471 vec[0].iov_len = sizeof(tag);
472 vec[1].iov_base = &type;
473 vec[1].iov_len = sizeof(type);
474 vec[2].iov_base = (void*)payload;
475 vec[2].iov_len = len;
476
477 return write_to_log(LOG_ID_EVENTS, vec, 3);
478}
Nick Kralevich2a4d05a2014-07-01 10:57:16 -0700479
480/*
481 * Like __android_log_bwrite, but used for writing strings to the
482 * event log.
483 */
484int __android_log_bswrite(int32_t tag, const char *payload)
485{
486 struct iovec vec[4];
487 char type = EVENT_TYPE_STRING;
488 uint32_t len = strlen(payload);
489
490 vec[0].iov_base = &tag;
491 vec[0].iov_len = sizeof(tag);
492 vec[1].iov_base = &type;
493 vec[1].iov_len = sizeof(type);
494 vec[2].iov_base = &len;
495 vec[2].iov_len = sizeof(len);
496 vec[3].iov_base = (void*)payload;
497 vec[3].iov_len = len;
498
499 return write_to_log(LOG_ID_EVENTS, vec, 4);
500}