blob: 3171c78e11a4fb41490274d8c01ab541b3c8c3eb [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
Colin Cross9227bd32013-07-23 16:59:20 -070034#include <log/logd.h>
Mark Salyzyn154f4602014-02-20 14:59:07 -080035#include <log/logger.h>
36#include <log/log_read.h>
37#include <private/android_filesystem_config.h>
Mark Salyzyne9c41962014-01-02 13:52:29 -080038
Mark Salyzyncf4aa032013-11-22 07:54:30 -080039#define LOG_BUF_SIZE 1024
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080040
41#if FAKE_LOG_DEVICE
Mark Salyzyn154f4602014-02-20 14:59:07 -080042/* This will be defined when building for the host. */
Kristian Monsenb5a98902014-01-28 11:26:56 -080043#include "fake_log_device.h"
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080044#endif
45
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080046static int __write_to_log_init(log_id_t, struct iovec *vec, size_t nr);
Joe Onoratoe2bf2ea2010-03-01 09:11:54 -080047static 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 -080048#ifdef HAVE_PTHREADS
49static pthread_mutex_t log_init_lock = PTHREAD_MUTEX_INITIALIZER;
50#endif
51
Mark Salyzyna04464a2014-04-30 08:50:53 -070052#ifndef __unused
53#define __unused __attribute__((__unused__))
54#endif
Kristian Monsenb5a98902014-01-28 11:26:56 -080055
Mark Salyzyn154f4602014-02-20 14:59:07 -080056#if FAKE_LOG_DEVICE
57#define WEAK __attribute__((weak))
Mark Salyzyn99f47a92014-04-07 14:58:08 -070058static int log_fds[(int)LOG_ID_MAX] = { -1, -1, -1, -1, -1 };
Mark Salyzyna04464a2014-04-30 08:50:53 -070059#else
60static int logd_fd = -1;
Mark Salyzyn154f4602014-02-20 14:59:07 -080061#endif
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080062
63/*
64 * This is used by the C++ code to decide if it should write logs through
Mark Salyzyn154f4602014-02-20 14:59:07 -080065 * the C code. Basically, if /dev/socket/logd is available, we're running in
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080066 * the simulator rather than a desktop tool and want to use the device.
67 */
68static enum {
Chris Pearson19299902010-06-02 16:25:35 -070069 kLogUninitialized, kLogNotAvailable, kLogAvailable
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080070} g_log_status = kLogUninitialized;
71int __android_log_dev_available(void)
72{
73 if (g_log_status == kLogUninitialized) {
Mark Salyzyn154f4602014-02-20 14:59:07 -080074 if (access("/dev/socket/logdw", W_OK) == 0)
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080075 g_log_status = kLogAvailable;
76 else
77 g_log_status = kLogNotAvailable;
78 }
79
80 return (g_log_status == kLogAvailable);
81}
82
Mark Salyzyna04464a2014-04-30 08:50:53 -070083#if !FAKE_LOG_DEVICE
Mark Salyzyn8245af12014-03-25 13:45:33 -070084/* give up, resources too limited */
Mark Salyzyna04464a2014-04-30 08:50:53 -070085static int __write_to_log_null(log_id_t log_fd __unused, struct iovec *vec __unused,
86 size_t nr __unused)
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080087{
88 return -1;
89}
Mark Salyzyna04464a2014-04-30 08:50:53 -070090#endif
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080091
Mark Salyzyn8245af12014-03-25 13:45:33 -070092/* log_init_lock assumed */
93static int __write_to_log_initialize()
94{
95 int i, ret = 0;
96
97#if FAKE_LOG_DEVICE
98 for (i = 0; i < LOG_ID_MAX; i++) {
99 char buf[sizeof("/dev/log_system")];
100 snprintf(buf, sizeof(buf), "/dev/log_%s", android_log_id_to_name(i));
101 log_fds[i] = fakeLogOpen(buf, O_WRONLY);
102 }
103#else
104 if (logd_fd >= 0) {
105 i = logd_fd;
106 logd_fd = -1;
107 close(i);
108 }
109
Nick Kralevich118d1b32014-07-02 22:30:39 -0700110 i = socket(PF_UNIX, SOCK_DGRAM | SOCK_CLOEXEC, 0);
Mark Salyzyn8245af12014-03-25 13:45:33 -0700111 if (i < 0) {
112 ret = -errno;
113 write_to_log = __write_to_log_null;
114 } else if (fcntl(i, F_SETFL, O_NONBLOCK) < 0) {
115 ret = -errno;
116 close(i);
117 i = -1;
118 write_to_log = __write_to_log_null;
119 } else {
120 struct sockaddr_un un;
121 memset(&un, 0, sizeof(struct sockaddr_un));
122 un.sun_family = AF_UNIX;
123 strcpy(un.sun_path, "/dev/socket/logdw");
124
125 if (connect(i, (struct sockaddr *)&un, sizeof(struct sockaddr_un)) < 0) {
126 ret = -errno;
127 close(i);
128 i = -1;
129 }
130 }
131 logd_fd = i;
132#endif
133
134 return ret;
135}
136
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800137static int __write_to_log_kernel(log_id_t log_id, struct iovec *vec, size_t nr)
138{
139 ssize_t ret;
Mark Salyzyn8245af12014-03-25 13:45:33 -0700140#if FAKE_LOG_DEVICE
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800141 int log_fd;
142
143 if (/*(int)log_id >= 0 &&*/ (int)log_id < (int)LOG_ID_MAX) {
144 log_fd = log_fds[(int)log_id];
145 } else {
Mark Salyzyn8245af12014-03-25 13:45:33 -0700146 return -EBADF;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800147 }
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800148 do {
Mark Salyzyn154f4602014-02-20 14:59:07 -0800149 ret = fakeLogWritev(log_fd, vec, nr);
Mark Salyzyn8245af12014-03-25 13:45:33 -0700150 if (ret < 0) {
151 ret = -errno;
152 }
153 } while (ret == -EINTR);
Mark Salyzyn154f4602014-02-20 14:59:07 -0800154#else
Mark Salyzyn8444eb82014-04-24 09:43:23 -0700155 static const unsigned header_length = 3;
156 struct iovec newVec[nr + header_length];
157 typeof_log_id_t log_id_buf;
158 uint16_t tid;
159 struct timespec ts;
160 log_time realtime_ts;
161 size_t i, payload_size;
Mark Salyzyn076ba812014-05-29 17:53:41 -0700162 static uid_t last_uid = AID_ROOT; /* logd *always* starts up as AID_ROOT */
Mark Salyzyn8444eb82014-04-24 09:43:23 -0700163
Mark Salyzyn076ba812014-05-29 17:53:41 -0700164 if (last_uid == AID_ROOT) { /* have we called to get the UID yet? */
165 last_uid = getuid();
166 }
167 if (last_uid == AID_LOGD) { /* logd, after initialization and priv drop */
Mark Salyzyn154f4602014-02-20 14:59:07 -0800168 /*
Mark Salyzyn076ba812014-05-29 17:53:41 -0700169 * ignore log messages we send to ourself (logd).
Mark Salyzyn154f4602014-02-20 14:59:07 -0800170 * Such log messages are often generated by libraries we depend on
171 * which use standard Android logging.
172 */
173 return 0;
174 }
Mark Salyzyn8245af12014-03-25 13:45:33 -0700175
176 if (logd_fd < 0) {
177 return -EBADF;
178 }
179
Mark Salyzynb992d0d2014-03-20 16:09:38 -0700180 /*
181 * struct {
182 * // what we provide
183 * typeof_log_id_t log_id;
184 * u16 tid;
185 * log_time realtime;
186 * // caller provides
187 * union {
188 * struct {
189 * char prio;
190 * char payload[];
191 * } string;
192 * struct {
193 * uint32_t tag
194 * char payload[];
195 * } binary;
196 * };
197 * };
198 */
Mark Salyzyn8444eb82014-04-24 09:43:23 -0700199
Mark Salyzyn076ba812014-05-29 17:53:41 -0700200 clock_gettime(CLOCK_REALTIME, &ts);
201 realtime_ts.tv_sec = ts.tv_sec;
202 realtime_ts.tv_nsec = ts.tv_nsec;
203
Mark Salyzyn8444eb82014-04-24 09:43:23 -0700204 log_id_buf = log_id;
205 tid = gettid();
Mark Salyzyn154f4602014-02-20 14:59:07 -0800206
207 newVec[0].iov_base = (unsigned char *) &log_id_buf;
208 newVec[0].iov_len = sizeof_log_id_t;
Mark Salyzynb992d0d2014-03-20 16:09:38 -0700209 newVec[1].iov_base = (unsigned char *) &tid;
210 newVec[1].iov_len = sizeof(tid);
Mark Salyzynb992d0d2014-03-20 16:09:38 -0700211 newVec[2].iov_base = (unsigned char *) &realtime_ts;
212 newVec[2].iov_len = sizeof(log_time);
Mark Salyzyn154f4602014-02-20 14:59:07 -0800213
Mark Salyzyn8444eb82014-04-24 09:43:23 -0700214 for (payload_size = 0, i = header_length; i < nr + header_length; i++) {
215 newVec[i].iov_base = vec[i - header_length].iov_base;
216 payload_size += newVec[i].iov_len = vec[i - header_length].iov_len;
217
218 if (payload_size > LOGGER_ENTRY_MAX_PAYLOAD) {
219 newVec[i].iov_len -= payload_size - LOGGER_ENTRY_MAX_PAYLOAD;
220 if (newVec[i].iov_len) {
221 ++i;
222 }
223 break;
224 }
Mark Salyzyn154f4602014-02-20 14:59:07 -0800225 }
226
Mark Salyzyn8245af12014-03-25 13:45:33 -0700227 /*
228 * The write below could be lost, but will never block.
229 *
230 * ENOTCONN occurs if logd dies.
231 * EAGAIN occurs if logd is overloaded.
232 */
Mark Salyzyn8444eb82014-04-24 09:43:23 -0700233 ret = writev(logd_fd, newVec, i);
Mark Salyzyn8245af12014-03-25 13:45:33 -0700234 if (ret < 0) {
235 ret = -errno;
236 if (ret == -ENOTCONN) {
237#ifdef HAVE_PTHREADS
238 pthread_mutex_lock(&log_init_lock);
239#endif
240 ret = __write_to_log_initialize();
241#ifdef HAVE_PTHREADS
242 pthread_mutex_unlock(&log_init_lock);
243#endif
244
245 if (ret < 0) {
246 return ret;
247 }
248
249 ret = writev(logd_fd, newVec, nr + header_length);
250 if (ret < 0) {
251 ret = -errno;
252 }
253 }
254 }
Mark Salyzyn8444eb82014-04-24 09:43:23 -0700255
256 if (ret > (ssize_t)(sizeof_log_id_t + sizeof(tid) + sizeof(log_time))) {
257 ret -= sizeof_log_id_t + sizeof(tid) + sizeof(log_time);
258 }
Mark Salyzyn154f4602014-02-20 14:59:07 -0800259#endif
Mark Salyzyn8444eb82014-04-24 09:43:23 -0700260
261 return ret;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800262}
263
Mark Salyzyn154f4602014-02-20 14:59:07 -0800264#if FAKE_LOG_DEVICE
265static const char *LOG_NAME[LOG_ID_MAX] = {
266 [LOG_ID_MAIN] = "main",
267 [LOG_ID_RADIO] = "radio",
268 [LOG_ID_EVENTS] = "events",
Mark Salyzyn99f47a92014-04-07 14:58:08 -0700269 [LOG_ID_SYSTEM] = "system",
270 [LOG_ID_CRASH] = "crash"
Mark Salyzyn154f4602014-02-20 14:59:07 -0800271};
272
273const WEAK char *android_log_id_to_name(log_id_t log_id)
274{
275 if (log_id >= LOG_ID_MAX) {
276 log_id = LOG_ID_MAIN;
277 }
278 return LOG_NAME[log_id];
279}
280#endif
281
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800282static int __write_to_log_init(log_id_t log_id, struct iovec *vec, size_t nr)
283{
284#ifdef HAVE_PTHREADS
285 pthread_mutex_lock(&log_init_lock);
286#endif
287
288 if (write_to_log == __write_to_log_init) {
Mark Salyzyn8245af12014-03-25 13:45:33 -0700289 int ret;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800290
Mark Salyzyn8245af12014-03-25 13:45:33 -0700291 ret = __write_to_log_initialize();
292 if (ret < 0) {
293#ifdef HAVE_PTHREADS
294 pthread_mutex_unlock(&log_init_lock);
Mark Salyzyn154f4602014-02-20 14:59:07 -0800295#endif
Mark Salyzyn8245af12014-03-25 13:45:33 -0700296 return ret;
297 }
298
299 write_to_log = __write_to_log_kernel;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800300 }
301
302#ifdef HAVE_PTHREADS
303 pthread_mutex_unlock(&log_init_lock);
304#endif
305
306 return write_to_log(log_id, vec, nr);
307}
308
309int __android_log_write(int prio, const char *tag, const char *msg)
310{
311 struct iovec vec[3];
312 log_id_t log_id = LOG_ID_MAIN;
Wink Saville3761e962012-11-28 12:20:19 -0800313 char tmp_tag[32];
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800314
315 if (!tag)
316 tag = "";
317
318 /* XXX: This needs to go! */
319 if (!strcmp(tag, "HTC_RIL") ||
John Michelaued7ccae2009-08-19 10:01:55 -0500320 !strncmp(tag, "RIL", 3) || /* Any log tag with "RIL" as the prefix */
Jeff Sharkey84dcf092012-08-13 11:27:30 -0700321 !strncmp(tag, "IMS", 3) || /* Any log tag with "IMS" as the prefix */
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800322 !strcmp(tag, "AT") ||
323 !strcmp(tag, "GSM") ||
Wink Saville89efdc92009-04-02 11:00:57 -0700324 !strcmp(tag, "STK") ||
325 !strcmp(tag, "CDMA") ||
326 !strcmp(tag, "PHONE") ||
Wink Saville3761e962012-11-28 12:20:19 -0800327 !strcmp(tag, "SMS")) {
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800328 log_id = LOG_ID_RADIO;
Mark Salyzyn8245af12014-03-25 13:45:33 -0700329 /* Inform third party apps/ril/radio.. to use Rlog or RLOG */
Wink Saville3761e962012-11-28 12:20:19 -0800330 snprintf(tmp_tag, sizeof(tmp_tag), "use-Rlog/RLOG-%s", tag);
331 tag = tmp_tag;
332 }
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800333
Elliott Hughes26864bf2014-05-06 20:40:15 -0700334#if __BIONIC__
335 if (prio == ANDROID_LOG_FATAL) {
336 extern void __android_set_abort_message(const char*);
337 __android_set_abort_message(msg);
338 }
339#endif
340
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800341 vec[0].iov_base = (unsigned char *) &prio;
342 vec[0].iov_len = 1;
343 vec[1].iov_base = (void *) tag;
344 vec[1].iov_len = strlen(tag) + 1;
345 vec[2].iov_base = (void *) msg;
346 vec[2].iov_len = strlen(msg) + 1;
347
348 return write_to_log(log_id, vec, 3);
349}
350
Joe Onoratoe2bf2ea2010-03-01 09:11:54 -0800351int __android_log_buf_write(int bufID, int prio, const char *tag, const char *msg)
352{
353 struct iovec vec[3];
Wink Saville3761e962012-11-28 12:20:19 -0800354 char tmp_tag[32];
Joe Onoratoe2bf2ea2010-03-01 09:11:54 -0800355
356 if (!tag)
357 tag = "";
358
359 /* XXX: This needs to go! */
Wink Saville3761e962012-11-28 12:20:19 -0800360 if ((bufID != LOG_ID_RADIO) &&
361 (!strcmp(tag, "HTC_RIL") ||
Joe Onoratoe2bf2ea2010-03-01 09:11:54 -0800362 !strncmp(tag, "RIL", 3) || /* Any log tag with "RIL" as the prefix */
Jeff Sharkey84dcf092012-08-13 11:27:30 -0700363 !strncmp(tag, "IMS", 3) || /* Any log tag with "IMS" as the prefix */
Joe Onoratoe2bf2ea2010-03-01 09:11:54 -0800364 !strcmp(tag, "AT") ||
365 !strcmp(tag, "GSM") ||
366 !strcmp(tag, "STK") ||
367 !strcmp(tag, "CDMA") ||
368 !strcmp(tag, "PHONE") ||
Wink Saville3761e962012-11-28 12:20:19 -0800369 !strcmp(tag, "SMS"))) {
Joe Onoratoe2bf2ea2010-03-01 09:11:54 -0800370 bufID = LOG_ID_RADIO;
Mark Salyzyn8245af12014-03-25 13:45:33 -0700371 /* Inform third party apps/ril/radio.. to use Rlog or RLOG */
Wink Saville3761e962012-11-28 12:20:19 -0800372 snprintf(tmp_tag, sizeof(tmp_tag), "use-Rlog/RLOG-%s", tag);
373 tag = tmp_tag;
374 }
Joe Onoratoe2bf2ea2010-03-01 09:11:54 -0800375
376 vec[0].iov_base = (unsigned char *) &prio;
377 vec[0].iov_len = 1;
378 vec[1].iov_base = (void *) tag;
379 vec[1].iov_len = strlen(tag) + 1;
380 vec[2].iov_base = (void *) msg;
381 vec[2].iov_len = strlen(msg) + 1;
382
383 return write_to_log(bufID, vec, 3);
384}
385
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800386int __android_log_vprint(int prio, const char *tag, const char *fmt, va_list ap)
387{
Chris Pearson19299902010-06-02 16:25:35 -0700388 char buf[LOG_BUF_SIZE];
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800389
390 vsnprintf(buf, LOG_BUF_SIZE, fmt, ap);
391
392 return __android_log_write(prio, tag, buf);
393}
394
395int __android_log_print(int prio, const char *tag, const char *fmt, ...)
396{
397 va_list ap;
Joe Onoratoe2bf2ea2010-03-01 09:11:54 -0800398 char buf[LOG_BUF_SIZE];
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800399
400 va_start(ap, fmt);
401 vsnprintf(buf, LOG_BUF_SIZE, fmt, ap);
402 va_end(ap);
403
404 return __android_log_write(prio, tag, buf);
405}
406
Joe Onoratoe2bf2ea2010-03-01 09:11:54 -0800407int __android_log_buf_print(int bufID, int prio, const char *tag, const char *fmt, ...)
408{
409 va_list ap;
410 char buf[LOG_BUF_SIZE];
411
412 va_start(ap, fmt);
413 vsnprintf(buf, LOG_BUF_SIZE, fmt, ap);
414 va_end(ap);
415
416 return __android_log_buf_write(bufID, prio, tag, buf);
417}
418
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800419void __android_log_assert(const char *cond, const char *tag,
Mark Salyzyncf4aa032013-11-22 07:54:30 -0800420 const char *fmt, ...)
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800421{
Chris Pearson19299902010-06-02 16:25:35 -0700422 char buf[LOG_BUF_SIZE];
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800423
Chris Pearson19299902010-06-02 16:25:35 -0700424 if (fmt) {
425 va_list ap;
426 va_start(ap, fmt);
427 vsnprintf(buf, LOG_BUF_SIZE, fmt, ap);
428 va_end(ap);
429 } else {
430 /* Msg not provided, log condition. N.B. Do not use cond directly as
431 * format string as it could contain spurious '%' syntax (e.g.
432 * "%d" in "blocks%devs == 0").
433 */
434 if (cond)
435 snprintf(buf, LOG_BUF_SIZE, "Assertion failed: %s", cond);
436 else
437 strcpy(buf, "Unspecified assertion failed");
438 }
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800439
440 __android_log_write(ANDROID_LOG_FATAL, tag, buf);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800441 __builtin_trap(); /* trap so we have a chance to debug the situation */
Elliott Hughesda6b2e22014-04-23 14:57:32 -0700442 /* NOTREACHED */
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800443}
444
445int __android_log_bwrite(int32_t tag, const void *payload, size_t len)
446{
447 struct iovec vec[2];
448
449 vec[0].iov_base = &tag;
450 vec[0].iov_len = sizeof(tag);
451 vec[1].iov_base = (void*)payload;
452 vec[1].iov_len = len;
453
454 return write_to_log(LOG_ID_EVENTS, vec, 2);
455}
456
457/*
458 * Like __android_log_bwrite, but takes the type as well. Doesn't work
459 * for the general case where we're generating lists of stuff, but very
460 * handy if we just want to dump an integer into the log.
461 */
462int __android_log_btwrite(int32_t tag, char type, const void *payload,
Mark Salyzyn154f4602014-02-20 14:59:07 -0800463 size_t len)
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800464{
465 struct iovec vec[3];
466
467 vec[0].iov_base = &tag;
468 vec[0].iov_len = sizeof(tag);
469 vec[1].iov_base = &type;
470 vec[1].iov_len = sizeof(type);
471 vec[2].iov_base = (void*)payload;
472 vec[2].iov_len = len;
473
474 return write_to_log(LOG_ID_EVENTS, vec, 3);
475}
Nick Kralevich2a4d05a2014-07-01 10:57:16 -0700476
477/*
478 * Like __android_log_bwrite, but used for writing strings to the
479 * event log.
480 */
481int __android_log_bswrite(int32_t tag, const char *payload)
482{
483 struct iovec vec[4];
484 char type = EVENT_TYPE_STRING;
485 uint32_t len = strlen(payload);
486
487 vec[0].iov_base = &tag;
488 vec[0].iov_len = sizeof(tag);
489 vec[1].iov_base = &type;
490 vec[1].iov_len = sizeof(type);
491 vec[2].iov_base = &len;
492 vec[2].iov_len = sizeof(len);
493 vec[3].iov_base = (void*)payload;
494 vec[3].iov_len = len;
495
496 return write_to_log(LOG_ID_EVENTS, vec, 4);
497}