blob: b2668cedb7a272f55e72c53e0bd11a6e2a2223a9 [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
Mark Salyzyn99f47a92014-04-07 14:58:08 -070061static int log_fds[(int)LOG_ID_MAX] = { -1, -1, -1, -1, -1 };
Mark Salyzyna04464a2014-04-30 08:50:53 -070062#else
63static int logd_fd = -1;
Mark Salyzyn154f4602014-02-20 14:59:07 -080064#endif
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080065
66/*
67 * This is used by the C++ code to decide if it should write logs through
Mark Salyzyn154f4602014-02-20 14:59:07 -080068 * the C code. Basically, if /dev/socket/logd is available, we're running in
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080069 * the simulator rather than a desktop tool and want to use the device.
70 */
71static enum {
Chris Pearson19299902010-06-02 16:25:35 -070072 kLogUninitialized, kLogNotAvailable, kLogAvailable
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080073} g_log_status = kLogUninitialized;
74int __android_log_dev_available(void)
75{
76 if (g_log_status == kLogUninitialized) {
Mark Salyzyn154f4602014-02-20 14:59:07 -080077 if (access("/dev/socket/logdw", W_OK) == 0)
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080078 g_log_status = kLogAvailable;
79 else
80 g_log_status = kLogNotAvailable;
81 }
82
83 return (g_log_status == kLogAvailable);
84}
85
Mark Salyzyna04464a2014-04-30 08:50:53 -070086#if !FAKE_LOG_DEVICE
Mark Salyzyn8245af12014-03-25 13:45:33 -070087/* give up, resources too limited */
Mark Salyzyna04464a2014-04-30 08:50:53 -070088static int __write_to_log_null(log_id_t log_fd __unused, struct iovec *vec __unused,
89 size_t nr __unused)
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080090{
91 return -1;
92}
Mark Salyzyna04464a2014-04-30 08:50:53 -070093#endif
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080094
Mark Salyzyn8245af12014-03-25 13:45:33 -070095/* log_init_lock assumed */
96static int __write_to_log_initialize()
97{
98 int i, ret = 0;
99
100#if FAKE_LOG_DEVICE
101 for (i = 0; i < LOG_ID_MAX; i++) {
102 char buf[sizeof("/dev/log_system")];
103 snprintf(buf, sizeof(buf), "/dev/log_%s", android_log_id_to_name(i));
104 log_fds[i] = fakeLogOpen(buf, O_WRONLY);
105 }
106#else
107 if (logd_fd >= 0) {
108 i = logd_fd;
109 logd_fd = -1;
110 close(i);
111 }
112
Nick Kralevich118d1b32014-07-02 22:30:39 -0700113 i = socket(PF_UNIX, SOCK_DGRAM | SOCK_CLOEXEC, 0);
Mark Salyzyn8245af12014-03-25 13:45:33 -0700114 if (i < 0) {
115 ret = -errno;
116 write_to_log = __write_to_log_null;
117 } else if (fcntl(i, F_SETFL, O_NONBLOCK) < 0) {
118 ret = -errno;
119 close(i);
120 i = -1;
121 write_to_log = __write_to_log_null;
122 } else {
123 struct sockaddr_un un;
124 memset(&un, 0, sizeof(struct sockaddr_un));
125 un.sun_family = AF_UNIX;
126 strcpy(un.sun_path, "/dev/socket/logdw");
127
128 if (connect(i, (struct sockaddr *)&un, sizeof(struct sockaddr_un)) < 0) {
129 ret = -errno;
130 close(i);
131 i = -1;
132 }
133 }
134 logd_fd = i;
135#endif
136
137 return ret;
138}
139
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800140static int __write_to_log_kernel(log_id_t log_id, struct iovec *vec, size_t nr)
141{
142 ssize_t ret;
Mark Salyzyn8245af12014-03-25 13:45:33 -0700143#if FAKE_LOG_DEVICE
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800144 int log_fd;
145
146 if (/*(int)log_id >= 0 &&*/ (int)log_id < (int)LOG_ID_MAX) {
147 log_fd = log_fds[(int)log_id];
148 } else {
Mark Salyzyn8245af12014-03-25 13:45:33 -0700149 return -EBADF;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800150 }
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800151 do {
Mark Salyzyn154f4602014-02-20 14:59:07 -0800152 ret = fakeLogWritev(log_fd, vec, nr);
Mark Salyzyn8245af12014-03-25 13:45:33 -0700153 if (ret < 0) {
154 ret = -errno;
155 }
156 } while (ret == -EINTR);
Mark Salyzyn154f4602014-02-20 14:59:07 -0800157#else
Mark Salyzyn8444eb82014-04-24 09:43:23 -0700158 static const unsigned header_length = 3;
159 struct iovec newVec[nr + header_length];
160 typeof_log_id_t log_id_buf;
161 uint16_t tid;
162 struct timespec ts;
163 log_time realtime_ts;
164 size_t i, payload_size;
Mark Salyzyn076ba812014-05-29 17:53:41 -0700165 static uid_t last_uid = AID_ROOT; /* logd *always* starts up as AID_ROOT */
Mark Salyzyn8444eb82014-04-24 09:43:23 -0700166
Mark Salyzyn076ba812014-05-29 17:53:41 -0700167 if (last_uid == AID_ROOT) { /* have we called to get the UID yet? */
168 last_uid = getuid();
169 }
170 if (last_uid == AID_LOGD) { /* logd, after initialization and priv drop */
Mark Salyzyn154f4602014-02-20 14:59:07 -0800171 /*
Mark Salyzyn076ba812014-05-29 17:53:41 -0700172 * ignore log messages we send to ourself (logd).
Mark Salyzyn154f4602014-02-20 14:59:07 -0800173 * Such log messages are often generated by libraries we depend on
174 * which use standard Android logging.
175 */
176 return 0;
177 }
Mark Salyzyn8245af12014-03-25 13:45:33 -0700178
179 if (logd_fd < 0) {
180 return -EBADF;
181 }
182
Mark Salyzynb992d0d2014-03-20 16:09:38 -0700183 /*
184 * struct {
185 * // what we provide
186 * typeof_log_id_t log_id;
187 * u16 tid;
188 * log_time realtime;
189 * // caller provides
190 * union {
191 * struct {
192 * char prio;
193 * char payload[];
194 * } string;
195 * struct {
196 * uint32_t tag
197 * char payload[];
198 * } binary;
199 * };
200 * };
201 */
Mark Salyzyn8444eb82014-04-24 09:43:23 -0700202
Mark Salyzyn076ba812014-05-29 17:53:41 -0700203 clock_gettime(CLOCK_REALTIME, &ts);
204 realtime_ts.tv_sec = ts.tv_sec;
205 realtime_ts.tv_nsec = ts.tv_nsec;
206
Mark Salyzyn8444eb82014-04-24 09:43:23 -0700207 log_id_buf = log_id;
208 tid = gettid();
Mark Salyzyn154f4602014-02-20 14:59:07 -0800209
210 newVec[0].iov_base = (unsigned char *) &log_id_buf;
211 newVec[0].iov_len = sizeof_log_id_t;
Mark Salyzynb992d0d2014-03-20 16:09:38 -0700212 newVec[1].iov_base = (unsigned char *) &tid;
213 newVec[1].iov_len = sizeof(tid);
Mark Salyzynb992d0d2014-03-20 16:09:38 -0700214 newVec[2].iov_base = (unsigned char *) &realtime_ts;
215 newVec[2].iov_len = sizeof(log_time);
Mark Salyzyn154f4602014-02-20 14:59:07 -0800216
Mark Salyzyn8444eb82014-04-24 09:43:23 -0700217 for (payload_size = 0, i = header_length; i < nr + header_length; i++) {
218 newVec[i].iov_base = vec[i - header_length].iov_base;
219 payload_size += newVec[i].iov_len = vec[i - header_length].iov_len;
220
221 if (payload_size > LOGGER_ENTRY_MAX_PAYLOAD) {
222 newVec[i].iov_len -= payload_size - LOGGER_ENTRY_MAX_PAYLOAD;
223 if (newVec[i].iov_len) {
224 ++i;
225 }
226 break;
227 }
Mark Salyzyn154f4602014-02-20 14:59:07 -0800228 }
229
Mark Salyzyn8245af12014-03-25 13:45:33 -0700230 /*
231 * The write below could be lost, but will never block.
232 *
233 * ENOTCONN occurs if logd dies.
234 * EAGAIN occurs if logd is overloaded.
235 */
Mark Salyzyn8444eb82014-04-24 09:43:23 -0700236 ret = writev(logd_fd, newVec, i);
Mark Salyzyn8245af12014-03-25 13:45:33 -0700237 if (ret < 0) {
238 ret = -errno;
239 if (ret == -ENOTCONN) {
240#ifdef HAVE_PTHREADS
241 pthread_mutex_lock(&log_init_lock);
242#endif
243 ret = __write_to_log_initialize();
244#ifdef HAVE_PTHREADS
245 pthread_mutex_unlock(&log_init_lock);
246#endif
247
248 if (ret < 0) {
249 return ret;
250 }
251
252 ret = writev(logd_fd, newVec, nr + header_length);
253 if (ret < 0) {
254 ret = -errno;
255 }
256 }
257 }
Mark Salyzyn8444eb82014-04-24 09:43:23 -0700258
259 if (ret > (ssize_t)(sizeof_log_id_t + sizeof(tid) + sizeof(log_time))) {
260 ret -= sizeof_log_id_t + sizeof(tid) + sizeof(log_time);
261 }
Mark Salyzyn154f4602014-02-20 14:59:07 -0800262#endif
Mark Salyzyn8444eb82014-04-24 09:43:23 -0700263
264 return ret;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800265}
266
Mark Salyzyn154f4602014-02-20 14:59:07 -0800267#if FAKE_LOG_DEVICE
268static const char *LOG_NAME[LOG_ID_MAX] = {
269 [LOG_ID_MAIN] = "main",
270 [LOG_ID_RADIO] = "radio",
271 [LOG_ID_EVENTS] = "events",
Mark Salyzyn99f47a92014-04-07 14:58:08 -0700272 [LOG_ID_SYSTEM] = "system",
273 [LOG_ID_CRASH] = "crash"
Mark Salyzyn154f4602014-02-20 14:59:07 -0800274};
275
Adam Lesinskia1ac84c2014-10-20 12:31:30 -0700276const char *android_log_id_to_name(log_id_t log_id)
Mark Salyzyn154f4602014-02-20 14:59:07 -0800277{
278 if (log_id >= LOG_ID_MAX) {
279 log_id = LOG_ID_MAIN;
280 }
281 return LOG_NAME[log_id];
282}
283#endif
284
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800285static int __write_to_log_init(log_id_t log_id, struct iovec *vec, size_t nr)
286{
287#ifdef HAVE_PTHREADS
288 pthread_mutex_lock(&log_init_lock);
289#endif
290
291 if (write_to_log == __write_to_log_init) {
Mark Salyzyn8245af12014-03-25 13:45:33 -0700292 int ret;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800293
Mark Salyzyn8245af12014-03-25 13:45:33 -0700294 ret = __write_to_log_initialize();
295 if (ret < 0) {
296#ifdef HAVE_PTHREADS
297 pthread_mutex_unlock(&log_init_lock);
Mark Salyzyn154f4602014-02-20 14:59:07 -0800298#endif
Mark Salyzyn8245af12014-03-25 13:45:33 -0700299 return ret;
300 }
301
302 write_to_log = __write_to_log_kernel;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800303 }
304
305#ifdef HAVE_PTHREADS
306 pthread_mutex_unlock(&log_init_lock);
307#endif
308
309 return write_to_log(log_id, vec, nr);
310}
311
312int __android_log_write(int prio, const char *tag, const char *msg)
313{
314 struct iovec vec[3];
315 log_id_t log_id = LOG_ID_MAIN;
Wink Saville3761e962012-11-28 12:20:19 -0800316 char tmp_tag[32];
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800317
318 if (!tag)
319 tag = "";
320
321 /* XXX: This needs to go! */
322 if (!strcmp(tag, "HTC_RIL") ||
John Michelaued7ccae2009-08-19 10:01:55 -0500323 !strncmp(tag, "RIL", 3) || /* Any log tag with "RIL" as the prefix */
Jeff Sharkey84dcf092012-08-13 11:27:30 -0700324 !strncmp(tag, "IMS", 3) || /* Any log tag with "IMS" as the prefix */
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800325 !strcmp(tag, "AT") ||
326 !strcmp(tag, "GSM") ||
Wink Saville89efdc92009-04-02 11:00:57 -0700327 !strcmp(tag, "STK") ||
328 !strcmp(tag, "CDMA") ||
329 !strcmp(tag, "PHONE") ||
Wink Saville3761e962012-11-28 12:20:19 -0800330 !strcmp(tag, "SMS")) {
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800331 log_id = LOG_ID_RADIO;
Mark Salyzyn8245af12014-03-25 13:45:33 -0700332 /* Inform third party apps/ril/radio.. to use Rlog or RLOG */
Wink Saville3761e962012-11-28 12:20:19 -0800333 snprintf(tmp_tag, sizeof(tmp_tag), "use-Rlog/RLOG-%s", tag);
334 tag = tmp_tag;
335 }
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800336
Elliott Hughes26864bf2014-05-06 20:40:15 -0700337#if __BIONIC__
338 if (prio == ANDROID_LOG_FATAL) {
Dan Albertc68fedc2014-08-18 17:29:34 -0700339 android_set_abort_message(msg);
Elliott Hughes26864bf2014-05-06 20:40:15 -0700340 }
341#endif
342
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800343 vec[0].iov_base = (unsigned char *) &prio;
344 vec[0].iov_len = 1;
345 vec[1].iov_base = (void *) tag;
346 vec[1].iov_len = strlen(tag) + 1;
347 vec[2].iov_base = (void *) msg;
348 vec[2].iov_len = strlen(msg) + 1;
349
350 return write_to_log(log_id, vec, 3);
351}
352
Joe Onoratoe2bf2ea2010-03-01 09:11:54 -0800353int __android_log_buf_write(int bufID, int prio, const char *tag, const char *msg)
354{
355 struct iovec vec[3];
Wink Saville3761e962012-11-28 12:20:19 -0800356 char tmp_tag[32];
Joe Onoratoe2bf2ea2010-03-01 09:11:54 -0800357
358 if (!tag)
359 tag = "";
360
361 /* XXX: This needs to go! */
Wink Saville3761e962012-11-28 12:20:19 -0800362 if ((bufID != LOG_ID_RADIO) &&
363 (!strcmp(tag, "HTC_RIL") ||
Joe Onoratoe2bf2ea2010-03-01 09:11:54 -0800364 !strncmp(tag, "RIL", 3) || /* Any log tag with "RIL" as the prefix */
Jeff Sharkey84dcf092012-08-13 11:27:30 -0700365 !strncmp(tag, "IMS", 3) || /* Any log tag with "IMS" as the prefix */
Joe Onoratoe2bf2ea2010-03-01 09:11:54 -0800366 !strcmp(tag, "AT") ||
367 !strcmp(tag, "GSM") ||
368 !strcmp(tag, "STK") ||
369 !strcmp(tag, "CDMA") ||
370 !strcmp(tag, "PHONE") ||
Wink Saville3761e962012-11-28 12:20:19 -0800371 !strcmp(tag, "SMS"))) {
Joe Onoratoe2bf2ea2010-03-01 09:11:54 -0800372 bufID = LOG_ID_RADIO;
Mark Salyzyn8245af12014-03-25 13:45:33 -0700373 /* Inform third party apps/ril/radio.. to use Rlog or RLOG */
Wink Saville3761e962012-11-28 12:20:19 -0800374 snprintf(tmp_tag, sizeof(tmp_tag), "use-Rlog/RLOG-%s", tag);
375 tag = tmp_tag;
376 }
Joe Onoratoe2bf2ea2010-03-01 09:11:54 -0800377
378 vec[0].iov_base = (unsigned char *) &prio;
379 vec[0].iov_len = 1;
380 vec[1].iov_base = (void *) tag;
381 vec[1].iov_len = strlen(tag) + 1;
382 vec[2].iov_base = (void *) msg;
383 vec[2].iov_len = strlen(msg) + 1;
384
385 return write_to_log(bufID, vec, 3);
386}
387
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800388int __android_log_vprint(int prio, const char *tag, const char *fmt, va_list ap)
389{
Chris Pearson19299902010-06-02 16:25:35 -0700390 char buf[LOG_BUF_SIZE];
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800391
392 vsnprintf(buf, LOG_BUF_SIZE, fmt, ap);
393
394 return __android_log_write(prio, tag, buf);
395}
396
397int __android_log_print(int prio, const char *tag, const char *fmt, ...)
398{
399 va_list ap;
Joe Onoratoe2bf2ea2010-03-01 09:11:54 -0800400 char buf[LOG_BUF_SIZE];
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800401
402 va_start(ap, fmt);
403 vsnprintf(buf, LOG_BUF_SIZE, fmt, ap);
404 va_end(ap);
405
406 return __android_log_write(prio, tag, buf);
407}
408
Joe Onoratoe2bf2ea2010-03-01 09:11:54 -0800409int __android_log_buf_print(int bufID, int prio, const char *tag, const char *fmt, ...)
410{
411 va_list ap;
412 char buf[LOG_BUF_SIZE];
413
414 va_start(ap, fmt);
415 vsnprintf(buf, LOG_BUF_SIZE, fmt, ap);
416 va_end(ap);
417
418 return __android_log_buf_write(bufID, prio, tag, buf);
419}
420
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800421void __android_log_assert(const char *cond, const char *tag,
Mark Salyzyncf4aa032013-11-22 07:54:30 -0800422 const char *fmt, ...)
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800423{
Chris Pearson19299902010-06-02 16:25:35 -0700424 char buf[LOG_BUF_SIZE];
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800425
Chris Pearson19299902010-06-02 16:25:35 -0700426 if (fmt) {
427 va_list ap;
428 va_start(ap, fmt);
429 vsnprintf(buf, LOG_BUF_SIZE, fmt, ap);
430 va_end(ap);
431 } else {
432 /* Msg not provided, log condition. N.B. Do not use cond directly as
433 * format string as it could contain spurious '%' syntax (e.g.
434 * "%d" in "blocks%devs == 0").
435 */
436 if (cond)
437 snprintf(buf, LOG_BUF_SIZE, "Assertion failed: %s", cond);
438 else
439 strcpy(buf, "Unspecified assertion failed");
440 }
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800441
442 __android_log_write(ANDROID_LOG_FATAL, tag, buf);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800443 __builtin_trap(); /* trap so we have a chance to debug the situation */
Elliott Hughesda6b2e22014-04-23 14:57:32 -0700444 /* NOTREACHED */
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800445}
446
447int __android_log_bwrite(int32_t tag, const void *payload, size_t len)
448{
449 struct iovec vec[2];
450
451 vec[0].iov_base = &tag;
452 vec[0].iov_len = sizeof(tag);
453 vec[1].iov_base = (void*)payload;
454 vec[1].iov_len = len;
455
456 return write_to_log(LOG_ID_EVENTS, vec, 2);
457}
458
459/*
460 * Like __android_log_bwrite, but takes the type as well. Doesn't work
461 * for the general case where we're generating lists of stuff, but very
462 * handy if we just want to dump an integer into the log.
463 */
464int __android_log_btwrite(int32_t tag, char type, const void *payload,
Mark Salyzyn154f4602014-02-20 14:59:07 -0800465 size_t len)
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800466{
467 struct iovec vec[3];
468
469 vec[0].iov_base = &tag;
470 vec[0].iov_len = sizeof(tag);
471 vec[1].iov_base = &type;
472 vec[1].iov_len = sizeof(type);
473 vec[2].iov_base = (void*)payload;
474 vec[2].iov_len = len;
475
476 return write_to_log(LOG_ID_EVENTS, vec, 3);
477}
Nick Kralevich2a4d05a2014-07-01 10:57:16 -0700478
479/*
480 * Like __android_log_bwrite, but used for writing strings to the
481 * event log.
482 */
483int __android_log_bswrite(int32_t tag, const char *payload)
484{
485 struct iovec vec[4];
486 char type = EVENT_TYPE_STRING;
487 uint32_t len = strlen(payload);
488
489 vec[0].iov_base = &tag;
490 vec[0].iov_len = sizeof(tag);
491 vec[1].iov_base = &type;
492 vec[1].iov_len = sizeof(type);
493 vec[2].iov_base = &len;
494 vec[2].iov_len = sizeof(len);
495 vec[3].iov_base = (void*)payload;
496 vec[3].iov_len = len;
497
498 return write_to_log(LOG_ID_EVENTS, vec, 4);
499}