blob: 3d847f14811967653f697cf4c4e85980fef41c8b [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 Salyzyn7a809402015-01-16 13:38:07 -080042#include <private/android_logger.h>
Mark Salyzyne9c41962014-01-02 13:52:29 -080043
Mark Salyzyncf4aa032013-11-22 07:54:30 -080044#define LOG_BUF_SIZE 1024
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080045
46#if FAKE_LOG_DEVICE
Mark Salyzyn154f4602014-02-20 14:59:07 -080047/* This will be defined when building for the host. */
Kristian Monsenb5a98902014-01-28 11:26:56 -080048#include "fake_log_device.h"
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080049#endif
50
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080051static int __write_to_log_init(log_id_t, struct iovec *vec, size_t nr);
Joe Onoratoe2bf2ea2010-03-01 09:11:54 -080052static 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 -080053#ifdef HAVE_PTHREADS
54static pthread_mutex_t log_init_lock = PTHREAD_MUTEX_INITIALIZER;
55#endif
56
Mark Salyzyna04464a2014-04-30 08:50:53 -070057#ifndef __unused
58#define __unused __attribute__((__unused__))
59#endif
Kristian Monsenb5a98902014-01-28 11:26:56 -080060
Mark Salyzyn154f4602014-02-20 14:59:07 -080061#if FAKE_LOG_DEVICE
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 Salyzyn7a809402015-01-16 13:38:07 -0800159 static const unsigned header_length = 1;
Mark Salyzyn8444eb82014-04-24 09:43:23 -0700160 struct iovec newVec[nr + header_length];
Mark Salyzyn7a809402015-01-16 13:38:07 -0800161 struct android_log_header_t header;
Mark Salyzyn8444eb82014-04-24 09:43:23 -0700162 struct timespec ts;
Mark Salyzyn8444eb82014-04-24 09:43:23 -0700163 size_t i, payload_size;
Mark Salyzyn076ba812014-05-29 17:53:41 -0700164 static uid_t last_uid = AID_ROOT; /* logd *always* starts up as AID_ROOT */
Mark Salyzyn8444eb82014-04-24 09:43:23 -0700165
Mark Salyzyn076ba812014-05-29 17:53:41 -0700166 if (last_uid == AID_ROOT) { /* have we called to get the UID yet? */
167 last_uid = getuid();
168 }
169 if (last_uid == AID_LOGD) { /* logd, after initialization and priv drop */
Mark Salyzyn154f4602014-02-20 14:59:07 -0800170 /*
Mark Salyzyn076ba812014-05-29 17:53:41 -0700171 * ignore log messages we send to ourself (logd).
Mark Salyzyn154f4602014-02-20 14:59:07 -0800172 * Such log messages are often generated by libraries we depend on
173 * which use standard Android logging.
174 */
175 return 0;
176 }
Mark Salyzyn8245af12014-03-25 13:45:33 -0700177
178 if (logd_fd < 0) {
179 return -EBADF;
180 }
181
Mark Salyzynb992d0d2014-03-20 16:09:38 -0700182 /*
183 * struct {
184 * // what we provide
Mark Salyzyn7a809402015-01-16 13:38:07 -0800185 * android_log_header_t header;
Mark Salyzynb992d0d2014-03-20 16:09:38 -0700186 * // 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);
Mark Salyzyn076ba812014-05-29 17:53:41 -0700201
Mark Salyzyn7a809402015-01-16 13:38:07 -0800202 header.id = log_id;
203 header.tid = gettid();
204 header.realtime.tv_sec = ts.tv_sec;
205 header.realtime.tv_nsec = ts.tv_nsec;
Mark Salyzyn154f4602014-02-20 14:59:07 -0800206
Mark Salyzyn7a809402015-01-16 13:38:07 -0800207 newVec[0].iov_base = (unsigned char *) &header;
208 newVec[0].iov_len = sizeof(header);
Mark Salyzyn154f4602014-02-20 14:59:07 -0800209
Mark Salyzyn8444eb82014-04-24 09:43:23 -0700210 for (payload_size = 0, i = header_length; i < nr + header_length; i++) {
211 newVec[i].iov_base = vec[i - header_length].iov_base;
212 payload_size += newVec[i].iov_len = vec[i - header_length].iov_len;
213
214 if (payload_size > LOGGER_ENTRY_MAX_PAYLOAD) {
215 newVec[i].iov_len -= payload_size - LOGGER_ENTRY_MAX_PAYLOAD;
216 if (newVec[i].iov_len) {
217 ++i;
218 }
219 break;
220 }
Mark Salyzyn154f4602014-02-20 14:59:07 -0800221 }
222
Mark Salyzyn8245af12014-03-25 13:45:33 -0700223 /*
224 * The write below could be lost, but will never block.
225 *
226 * ENOTCONN occurs if logd dies.
227 * EAGAIN occurs if logd is overloaded.
228 */
Mark Salyzyn8444eb82014-04-24 09:43:23 -0700229 ret = writev(logd_fd, newVec, i);
Mark Salyzyn8245af12014-03-25 13:45:33 -0700230 if (ret < 0) {
231 ret = -errno;
232 if (ret == -ENOTCONN) {
233#ifdef HAVE_PTHREADS
234 pthread_mutex_lock(&log_init_lock);
235#endif
236 ret = __write_to_log_initialize();
237#ifdef HAVE_PTHREADS
238 pthread_mutex_unlock(&log_init_lock);
239#endif
240
241 if (ret < 0) {
242 return ret;
243 }
244
Mark Salyzyn7a809402015-01-16 13:38:07 -0800245 ret = writev(logd_fd, newVec, i);
Mark Salyzyn8245af12014-03-25 13:45:33 -0700246 if (ret < 0) {
247 ret = -errno;
248 }
249 }
250 }
Mark Salyzyn8444eb82014-04-24 09:43:23 -0700251
Mark Salyzyn7a809402015-01-16 13:38:07 -0800252 if (ret > (ssize_t)sizeof(header)) {
253 ret -= sizeof(header);
Mark Salyzyn8444eb82014-04-24 09:43:23 -0700254 }
Mark Salyzyn154f4602014-02-20 14:59:07 -0800255#endif
Mark Salyzyn8444eb82014-04-24 09:43:23 -0700256
257 return ret;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800258}
259
Mark Salyzyn154f4602014-02-20 14:59:07 -0800260#if FAKE_LOG_DEVICE
261static const char *LOG_NAME[LOG_ID_MAX] = {
262 [LOG_ID_MAIN] = "main",
263 [LOG_ID_RADIO] = "radio",
264 [LOG_ID_EVENTS] = "events",
Mark Salyzyn99f47a92014-04-07 14:58:08 -0700265 [LOG_ID_SYSTEM] = "system",
266 [LOG_ID_CRASH] = "crash"
Mark Salyzyn154f4602014-02-20 14:59:07 -0800267};
268
Adam Lesinskia1ac84c2014-10-20 12:31:30 -0700269const char *android_log_id_to_name(log_id_t log_id)
Mark Salyzyn154f4602014-02-20 14:59:07 -0800270{
271 if (log_id >= LOG_ID_MAX) {
272 log_id = LOG_ID_MAIN;
273 }
274 return LOG_NAME[log_id];
275}
276#endif
277
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800278static int __write_to_log_init(log_id_t log_id, struct iovec *vec, size_t nr)
279{
280#ifdef HAVE_PTHREADS
281 pthread_mutex_lock(&log_init_lock);
282#endif
283
284 if (write_to_log == __write_to_log_init) {
Mark Salyzyn8245af12014-03-25 13:45:33 -0700285 int ret;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800286
Mark Salyzyn8245af12014-03-25 13:45:33 -0700287 ret = __write_to_log_initialize();
288 if (ret < 0) {
289#ifdef HAVE_PTHREADS
290 pthread_mutex_unlock(&log_init_lock);
Mark Salyzyn154f4602014-02-20 14:59:07 -0800291#endif
Mark Salyzyn8245af12014-03-25 13:45:33 -0700292 return ret;
293 }
294
295 write_to_log = __write_to_log_kernel;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800296 }
297
298#ifdef HAVE_PTHREADS
299 pthread_mutex_unlock(&log_init_lock);
300#endif
301
302 return write_to_log(log_id, vec, nr);
303}
304
305int __android_log_write(int prio, const char *tag, const char *msg)
306{
307 struct iovec vec[3];
308 log_id_t log_id = LOG_ID_MAIN;
Wink Saville3761e962012-11-28 12:20:19 -0800309 char tmp_tag[32];
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800310
311 if (!tag)
312 tag = "";
313
314 /* XXX: This needs to go! */
315 if (!strcmp(tag, "HTC_RIL") ||
John Michelaued7ccae2009-08-19 10:01:55 -0500316 !strncmp(tag, "RIL", 3) || /* Any log tag with "RIL" as the prefix */
Jeff Sharkey84dcf092012-08-13 11:27:30 -0700317 !strncmp(tag, "IMS", 3) || /* Any log tag with "IMS" as the prefix */
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800318 !strcmp(tag, "AT") ||
319 !strcmp(tag, "GSM") ||
Wink Saville89efdc92009-04-02 11:00:57 -0700320 !strcmp(tag, "STK") ||
321 !strcmp(tag, "CDMA") ||
322 !strcmp(tag, "PHONE") ||
Wink Saville3761e962012-11-28 12:20:19 -0800323 !strcmp(tag, "SMS")) {
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800324 log_id = LOG_ID_RADIO;
Mark Salyzyn8245af12014-03-25 13:45:33 -0700325 /* Inform third party apps/ril/radio.. to use Rlog or RLOG */
Wink Saville3761e962012-11-28 12:20:19 -0800326 snprintf(tmp_tag, sizeof(tmp_tag), "use-Rlog/RLOG-%s", tag);
327 tag = tmp_tag;
328 }
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800329
Elliott Hughes26864bf2014-05-06 20:40:15 -0700330#if __BIONIC__
331 if (prio == ANDROID_LOG_FATAL) {
Dan Albertc68fedc2014-08-18 17:29:34 -0700332 android_set_abort_message(msg);
Elliott Hughes26864bf2014-05-06 20:40:15 -0700333 }
334#endif
335
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800336 vec[0].iov_base = (unsigned char *) &prio;
337 vec[0].iov_len = 1;
338 vec[1].iov_base = (void *) tag;
339 vec[1].iov_len = strlen(tag) + 1;
340 vec[2].iov_base = (void *) msg;
341 vec[2].iov_len = strlen(msg) + 1;
342
343 return write_to_log(log_id, vec, 3);
344}
345
Joe Onoratoe2bf2ea2010-03-01 09:11:54 -0800346int __android_log_buf_write(int bufID, int prio, const char *tag, const char *msg)
347{
348 struct iovec vec[3];
Wink Saville3761e962012-11-28 12:20:19 -0800349 char tmp_tag[32];
Joe Onoratoe2bf2ea2010-03-01 09:11:54 -0800350
351 if (!tag)
352 tag = "";
353
354 /* XXX: This needs to go! */
Wink Saville3761e962012-11-28 12:20:19 -0800355 if ((bufID != LOG_ID_RADIO) &&
356 (!strcmp(tag, "HTC_RIL") ||
Joe Onoratoe2bf2ea2010-03-01 09:11:54 -0800357 !strncmp(tag, "RIL", 3) || /* Any log tag with "RIL" as the prefix */
Jeff Sharkey84dcf092012-08-13 11:27:30 -0700358 !strncmp(tag, "IMS", 3) || /* Any log tag with "IMS" as the prefix */
Joe Onoratoe2bf2ea2010-03-01 09:11:54 -0800359 !strcmp(tag, "AT") ||
360 !strcmp(tag, "GSM") ||
361 !strcmp(tag, "STK") ||
362 !strcmp(tag, "CDMA") ||
363 !strcmp(tag, "PHONE") ||
Wink Saville3761e962012-11-28 12:20:19 -0800364 !strcmp(tag, "SMS"))) {
Joe Onoratoe2bf2ea2010-03-01 09:11:54 -0800365 bufID = LOG_ID_RADIO;
Mark Salyzyn8245af12014-03-25 13:45:33 -0700366 /* Inform third party apps/ril/radio.. to use Rlog or RLOG */
Wink Saville3761e962012-11-28 12:20:19 -0800367 snprintf(tmp_tag, sizeof(tmp_tag), "use-Rlog/RLOG-%s", tag);
368 tag = tmp_tag;
369 }
Joe Onoratoe2bf2ea2010-03-01 09:11:54 -0800370
371 vec[0].iov_base = (unsigned char *) &prio;
372 vec[0].iov_len = 1;
373 vec[1].iov_base = (void *) tag;
374 vec[1].iov_len = strlen(tag) + 1;
375 vec[2].iov_base = (void *) msg;
376 vec[2].iov_len = strlen(msg) + 1;
377
378 return write_to_log(bufID, vec, 3);
379}
380
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800381int __android_log_vprint(int prio, const char *tag, const char *fmt, va_list ap)
382{
Chris Pearson19299902010-06-02 16:25:35 -0700383 char buf[LOG_BUF_SIZE];
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800384
385 vsnprintf(buf, LOG_BUF_SIZE, fmt, ap);
386
387 return __android_log_write(prio, tag, buf);
388}
389
390int __android_log_print(int prio, const char *tag, const char *fmt, ...)
391{
392 va_list ap;
Joe Onoratoe2bf2ea2010-03-01 09:11:54 -0800393 char buf[LOG_BUF_SIZE];
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800394
395 va_start(ap, fmt);
396 vsnprintf(buf, LOG_BUF_SIZE, fmt, ap);
397 va_end(ap);
398
399 return __android_log_write(prio, tag, buf);
400}
401
Joe Onoratoe2bf2ea2010-03-01 09:11:54 -0800402int __android_log_buf_print(int bufID, int prio, const char *tag, const char *fmt, ...)
403{
404 va_list ap;
405 char buf[LOG_BUF_SIZE];
406
407 va_start(ap, fmt);
408 vsnprintf(buf, LOG_BUF_SIZE, fmt, ap);
409 va_end(ap);
410
411 return __android_log_buf_write(bufID, prio, tag, buf);
412}
413
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800414void __android_log_assert(const char *cond, const char *tag,
Mark Salyzyncf4aa032013-11-22 07:54:30 -0800415 const char *fmt, ...)
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800416{
Chris Pearson19299902010-06-02 16:25:35 -0700417 char buf[LOG_BUF_SIZE];
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800418
Chris Pearson19299902010-06-02 16:25:35 -0700419 if (fmt) {
420 va_list ap;
421 va_start(ap, fmt);
422 vsnprintf(buf, LOG_BUF_SIZE, fmt, ap);
423 va_end(ap);
424 } else {
425 /* Msg not provided, log condition. N.B. Do not use cond directly as
426 * format string as it could contain spurious '%' syntax (e.g.
427 * "%d" in "blocks%devs == 0").
428 */
429 if (cond)
430 snprintf(buf, LOG_BUF_SIZE, "Assertion failed: %s", cond);
431 else
432 strcpy(buf, "Unspecified assertion failed");
433 }
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800434
435 __android_log_write(ANDROID_LOG_FATAL, tag, buf);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800436 __builtin_trap(); /* trap so we have a chance to debug the situation */
Elliott Hughesda6b2e22014-04-23 14:57:32 -0700437 /* NOTREACHED */
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800438}
439
440int __android_log_bwrite(int32_t tag, const void *payload, size_t len)
441{
442 struct iovec vec[2];
443
444 vec[0].iov_base = &tag;
445 vec[0].iov_len = sizeof(tag);
446 vec[1].iov_base = (void*)payload;
447 vec[1].iov_len = len;
448
449 return write_to_log(LOG_ID_EVENTS, vec, 2);
450}
451
452/*
453 * Like __android_log_bwrite, but takes the type as well. Doesn't work
454 * for the general case where we're generating lists of stuff, but very
455 * handy if we just want to dump an integer into the log.
456 */
457int __android_log_btwrite(int32_t tag, char type, const void *payload,
Mark Salyzyn154f4602014-02-20 14:59:07 -0800458 size_t len)
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800459{
460 struct iovec vec[3];
461
462 vec[0].iov_base = &tag;
463 vec[0].iov_len = sizeof(tag);
464 vec[1].iov_base = &type;
465 vec[1].iov_len = sizeof(type);
466 vec[2].iov_base = (void*)payload;
467 vec[2].iov_len = len;
468
469 return write_to_log(LOG_ID_EVENTS, vec, 3);
470}
Nick Kralevich2a4d05a2014-07-01 10:57:16 -0700471
472/*
473 * Like __android_log_bwrite, but used for writing strings to the
474 * event log.
475 */
476int __android_log_bswrite(int32_t tag, const char *payload)
477{
478 struct iovec vec[4];
479 char type = EVENT_TYPE_STRING;
480 uint32_t len = strlen(payload);
481
482 vec[0].iov_base = &tag;
483 vec[0].iov_len = sizeof(tag);
484 vec[1].iov_base = &type;
485 vec[1].iov_len = sizeof(type);
486 vec[2].iov_base = &len;
487 vec[2].iov_len = sizeof(len);
488 vec[3].iov_base = (void*)payload;
489 vec[3].iov_len = len;
490
491 return write_to_log(LOG_ID_EVENTS, vec, 4);
492}