The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 1 | /* |
Mark Salyzyn | e9c4196 | 2014-01-02 13:52:29 -0800 | [diff] [blame] | 2 | * Copyright (C) 2007-2014 The Android Open Source Project |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 3 | * |
| 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 Salyzyn | 154f460 | 2014-02-20 14:59:07 -0800 | [diff] [blame] | 16 | #include <errno.h> |
| 17 | #include <fcntl.h> |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 18 | #ifdef HAVE_PTHREADS |
| 19 | #include <pthread.h> |
| 20 | #endif |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 21 | #include <stdarg.h> |
Mark Salyzyn | 154f460 | 2014-02-20 14:59:07 -0800 | [diff] [blame] | 22 | #include <stdio.h> |
| 23 | #include <stdlib.h> |
| 24 | #include <string.h> |
Nick Kralevich | a170322 | 2013-03-15 09:45:12 -0700 | [diff] [blame] | 25 | #include <sys/stat.h> |
Mark Salyzyn | 154f460 | 2014-02-20 14:59:07 -0800 | [diff] [blame] | 26 | #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 Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 33 | |
Colin Cross | 9227bd3 | 2013-07-23 16:59:20 -0700 | [diff] [blame] | 34 | #include <log/logd.h> |
Mark Salyzyn | 154f460 | 2014-02-20 14:59:07 -0800 | [diff] [blame] | 35 | #include <log/logger.h> |
| 36 | #include <log/log_read.h> |
| 37 | #include <private/android_filesystem_config.h> |
Mark Salyzyn | e9c4196 | 2014-01-02 13:52:29 -0800 | [diff] [blame] | 38 | |
Mark Salyzyn | cf4aa03 | 2013-11-22 07:54:30 -0800 | [diff] [blame] | 39 | #define LOG_BUF_SIZE 1024 |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 40 | |
| 41 | #if FAKE_LOG_DEVICE |
Mark Salyzyn | 154f460 | 2014-02-20 14:59:07 -0800 | [diff] [blame] | 42 | /* This will be defined when building for the host. */ |
Kristian Monsen | b5a9890 | 2014-01-28 11:26:56 -0800 | [diff] [blame] | 43 | #include "fake_log_device.h" |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 44 | #endif |
| 45 | |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 46 | static int __write_to_log_init(log_id_t, struct iovec *vec, size_t nr); |
Joe Onorato | e2bf2ea | 2010-03-01 09:11:54 -0800 | [diff] [blame] | 47 | static int (*write_to_log)(log_id_t, struct iovec *vec, size_t nr) = __write_to_log_init; |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 48 | #ifdef HAVE_PTHREADS |
| 49 | static pthread_mutex_t log_init_lock = PTHREAD_MUTEX_INITIALIZER; |
| 50 | #endif |
| 51 | |
Kristian Monsen | b5a9890 | 2014-01-28 11:26:56 -0800 | [diff] [blame] | 52 | #define UNUSED __attribute__((__unused__)) |
| 53 | |
Mark Salyzyn | 154f460 | 2014-02-20 14:59:07 -0800 | [diff] [blame] | 54 | static int logd_fd = -1; |
| 55 | #if FAKE_LOG_DEVICE |
| 56 | #define WEAK __attribute__((weak)) |
Joe Onorato | e2bf2ea | 2010-03-01 09:11:54 -0800 | [diff] [blame] | 57 | static int log_fds[(int)LOG_ID_MAX] = { -1, -1, -1, -1 }; |
Mark Salyzyn | 154f460 | 2014-02-20 14:59:07 -0800 | [diff] [blame] | 58 | #endif |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 59 | |
| 60 | /* |
| 61 | * This is used by the C++ code to decide if it should write logs through |
Mark Salyzyn | 154f460 | 2014-02-20 14:59:07 -0800 | [diff] [blame] | 62 | * the C code. Basically, if /dev/socket/logd is available, we're running in |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 63 | * the simulator rather than a desktop tool and want to use the device. |
| 64 | */ |
| 65 | static enum { |
Chris Pearson | 1929990 | 2010-06-02 16:25:35 -0700 | [diff] [blame] | 66 | kLogUninitialized, kLogNotAvailable, kLogAvailable |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 67 | } g_log_status = kLogUninitialized; |
| 68 | int __android_log_dev_available(void) |
| 69 | { |
| 70 | if (g_log_status == kLogUninitialized) { |
Mark Salyzyn | 154f460 | 2014-02-20 14:59:07 -0800 | [diff] [blame] | 71 | if (access("/dev/socket/logdw", W_OK) == 0) |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 72 | g_log_status = kLogAvailable; |
| 73 | else |
| 74 | g_log_status = kLogNotAvailable; |
| 75 | } |
| 76 | |
| 77 | return (g_log_status == kLogAvailable); |
| 78 | } |
| 79 | |
Kristian Monsen | 7ddca5a | 2014-01-28 13:18:24 -0800 | [diff] [blame] | 80 | static int __write_to_log_null(log_id_t log_fd UNUSED, struct iovec *vec UNUSED, |
Mark Salyzyn | 154f460 | 2014-02-20 14:59:07 -0800 | [diff] [blame] | 81 | size_t nr UNUSED) |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 82 | { |
| 83 | return -1; |
| 84 | } |
| 85 | |
| 86 | static int __write_to_log_kernel(log_id_t log_id, struct iovec *vec, size_t nr) |
| 87 | { |
Mark Salyzyn | 154f460 | 2014-02-20 14:59:07 -0800 | [diff] [blame] | 88 | #if FAKE_LOG_DEVICE |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 89 | ssize_t ret; |
| 90 | int log_fd; |
| 91 | |
| 92 | if (/*(int)log_id >= 0 &&*/ (int)log_id < (int)LOG_ID_MAX) { |
| 93 | log_fd = log_fds[(int)log_id]; |
| 94 | } else { |
| 95 | return EBADF; |
| 96 | } |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 97 | do { |
Mark Salyzyn | 154f460 | 2014-02-20 14:59:07 -0800 | [diff] [blame] | 98 | ret = fakeLogWritev(log_fd, vec, nr); |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 99 | } while (ret < 0 && errno == EINTR); |
| 100 | |
| 101 | return ret; |
Mark Salyzyn | 154f460 | 2014-02-20 14:59:07 -0800 | [diff] [blame] | 102 | #else |
| 103 | if (logd_fd == -1) { |
| 104 | return -1; |
| 105 | } |
| 106 | if (getuid() == AID_LOGD) { |
| 107 | /* |
| 108 | * ignore log messages we send to ourself. |
| 109 | * Such log messages are often generated by libraries we depend on |
| 110 | * which use standard Android logging. |
| 111 | */ |
| 112 | return 0; |
| 113 | } |
| 114 | struct iovec newVec[nr + 2]; |
| 115 | typeof_log_id_t log_id_buf = log_id; |
| 116 | |
| 117 | newVec[0].iov_base = (unsigned char *) &log_id_buf; |
| 118 | newVec[0].iov_len = sizeof_log_id_t; |
| 119 | |
Mark Salyzyn | 7e2f83c | 2014-03-05 07:41:49 -0800 | [diff] [blame^] | 120 | struct timespec ts; |
| 121 | clock_gettime(CLOCK_REALTIME, &ts); |
Mark Salyzyn | 154f460 | 2014-02-20 14:59:07 -0800 | [diff] [blame] | 122 | log_time realtime_ts; |
Mark Salyzyn | 7e2f83c | 2014-03-05 07:41:49 -0800 | [diff] [blame^] | 123 | realtime_ts.tv_sec = ts.tv_sec; |
| 124 | realtime_ts.tv_nsec = ts.tv_nsec; |
Mark Salyzyn | 154f460 | 2014-02-20 14:59:07 -0800 | [diff] [blame] | 125 | |
| 126 | newVec[1].iov_base = (unsigned char *) &realtime_ts; |
| 127 | newVec[1].iov_len = sizeof(log_time); |
| 128 | |
| 129 | size_t i; |
| 130 | for (i = 2; i < nr + 2; i++) { |
| 131 | newVec[i].iov_base = vec[i-2].iov_base; |
| 132 | newVec[i].iov_len = vec[i-2].iov_len; |
| 133 | } |
| 134 | |
| 135 | /* The write below could be lost, but will never block. */ |
| 136 | return writev(logd_fd, newVec, nr + 2); |
| 137 | #endif |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 138 | } |
| 139 | |
Mark Salyzyn | 154f460 | 2014-02-20 14:59:07 -0800 | [diff] [blame] | 140 | #if FAKE_LOG_DEVICE |
| 141 | static const char *LOG_NAME[LOG_ID_MAX] = { |
| 142 | [LOG_ID_MAIN] = "main", |
| 143 | [LOG_ID_RADIO] = "radio", |
| 144 | [LOG_ID_EVENTS] = "events", |
| 145 | [LOG_ID_SYSTEM] = "system" |
| 146 | }; |
| 147 | |
| 148 | const WEAK char *android_log_id_to_name(log_id_t log_id) |
| 149 | { |
| 150 | if (log_id >= LOG_ID_MAX) { |
| 151 | log_id = LOG_ID_MAIN; |
| 152 | } |
| 153 | return LOG_NAME[log_id]; |
| 154 | } |
| 155 | #endif |
| 156 | |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 157 | static int __write_to_log_init(log_id_t log_id, struct iovec *vec, size_t nr) |
| 158 | { |
| 159 | #ifdef HAVE_PTHREADS |
| 160 | pthread_mutex_lock(&log_init_lock); |
| 161 | #endif |
| 162 | |
| 163 | if (write_to_log == __write_to_log_init) { |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 164 | write_to_log = __write_to_log_kernel; |
| 165 | |
Mark Salyzyn | 154f460 | 2014-02-20 14:59:07 -0800 | [diff] [blame] | 166 | #if FAKE_LOG_DEVICE |
| 167 | int i; |
| 168 | for (i = 0; i < LOG_ID_MAX; i++) { |
| 169 | char buf[sizeof("/dev/log_system")]; |
| 170 | snprintf(buf, sizeof(buf), "/dev/log_%s", android_log_id_to_name(i)); |
| 171 | log_fds[i] = fakeLogOpen(buf, O_WRONLY); |
| 172 | } |
| 173 | #else |
| 174 | int sock = socket(PF_UNIX, SOCK_DGRAM, 0); |
| 175 | if (sock != -1) { |
| 176 | if (fcntl(sock, F_SETFL, O_NONBLOCK) == -1) { |
| 177 | /* NB: Loss of content */ |
| 178 | close(sock); |
| 179 | sock = -1; |
| 180 | } else { |
| 181 | struct sockaddr_un un; |
| 182 | memset(&un, 0, sizeof(struct sockaddr_un)); |
| 183 | un.sun_family = AF_UNIX; |
| 184 | strcpy(un.sun_path, "/dev/socket/logdw"); |
| 185 | |
| 186 | connect(sock, (struct sockaddr *)&un, sizeof(struct sockaddr_un)); |
| 187 | } |
| 188 | } else { |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 189 | write_to_log = __write_to_log_null; |
| 190 | } |
Mark Salyzyn | 154f460 | 2014-02-20 14:59:07 -0800 | [diff] [blame] | 191 | logd_fd = sock; |
| 192 | #endif |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 193 | } |
| 194 | |
| 195 | #ifdef HAVE_PTHREADS |
| 196 | pthread_mutex_unlock(&log_init_lock); |
| 197 | #endif |
| 198 | |
| 199 | return write_to_log(log_id, vec, nr); |
| 200 | } |
| 201 | |
| 202 | int __android_log_write(int prio, const char *tag, const char *msg) |
| 203 | { |
| 204 | struct iovec vec[3]; |
| 205 | log_id_t log_id = LOG_ID_MAIN; |
Wink Saville | 3761e96 | 2012-11-28 12:20:19 -0800 | [diff] [blame] | 206 | char tmp_tag[32]; |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 207 | |
| 208 | if (!tag) |
| 209 | tag = ""; |
| 210 | |
| 211 | /* XXX: This needs to go! */ |
| 212 | if (!strcmp(tag, "HTC_RIL") || |
John Michelau | ed7ccae | 2009-08-19 10:01:55 -0500 | [diff] [blame] | 213 | !strncmp(tag, "RIL", 3) || /* Any log tag with "RIL" as the prefix */ |
Jeff Sharkey | 84dcf09 | 2012-08-13 11:27:30 -0700 | [diff] [blame] | 214 | !strncmp(tag, "IMS", 3) || /* Any log tag with "IMS" as the prefix */ |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 215 | !strcmp(tag, "AT") || |
| 216 | !strcmp(tag, "GSM") || |
Wink Saville | 89efdc9 | 2009-04-02 11:00:57 -0700 | [diff] [blame] | 217 | !strcmp(tag, "STK") || |
| 218 | !strcmp(tag, "CDMA") || |
| 219 | !strcmp(tag, "PHONE") || |
Wink Saville | 3761e96 | 2012-11-28 12:20:19 -0800 | [diff] [blame] | 220 | !strcmp(tag, "SMS")) { |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 221 | log_id = LOG_ID_RADIO; |
Wink Saville | 3761e96 | 2012-11-28 12:20:19 -0800 | [diff] [blame] | 222 | // Inform third party apps/ril/radio.. to use Rlog or RLOG |
| 223 | snprintf(tmp_tag, sizeof(tmp_tag), "use-Rlog/RLOG-%s", tag); |
| 224 | tag = tmp_tag; |
| 225 | } |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 226 | |
| 227 | vec[0].iov_base = (unsigned char *) &prio; |
| 228 | vec[0].iov_len = 1; |
| 229 | vec[1].iov_base = (void *) tag; |
| 230 | vec[1].iov_len = strlen(tag) + 1; |
| 231 | vec[2].iov_base = (void *) msg; |
| 232 | vec[2].iov_len = strlen(msg) + 1; |
| 233 | |
| 234 | return write_to_log(log_id, vec, 3); |
| 235 | } |
| 236 | |
Joe Onorato | e2bf2ea | 2010-03-01 09:11:54 -0800 | [diff] [blame] | 237 | int __android_log_buf_write(int bufID, int prio, const char *tag, const char *msg) |
| 238 | { |
| 239 | struct iovec vec[3]; |
Wink Saville | 3761e96 | 2012-11-28 12:20:19 -0800 | [diff] [blame] | 240 | char tmp_tag[32]; |
Joe Onorato | e2bf2ea | 2010-03-01 09:11:54 -0800 | [diff] [blame] | 241 | |
| 242 | if (!tag) |
| 243 | tag = ""; |
| 244 | |
| 245 | /* XXX: This needs to go! */ |
Wink Saville | 3761e96 | 2012-11-28 12:20:19 -0800 | [diff] [blame] | 246 | if ((bufID != LOG_ID_RADIO) && |
| 247 | (!strcmp(tag, "HTC_RIL") || |
Joe Onorato | e2bf2ea | 2010-03-01 09:11:54 -0800 | [diff] [blame] | 248 | !strncmp(tag, "RIL", 3) || /* Any log tag with "RIL" as the prefix */ |
Jeff Sharkey | 84dcf09 | 2012-08-13 11:27:30 -0700 | [diff] [blame] | 249 | !strncmp(tag, "IMS", 3) || /* Any log tag with "IMS" as the prefix */ |
Joe Onorato | e2bf2ea | 2010-03-01 09:11:54 -0800 | [diff] [blame] | 250 | !strcmp(tag, "AT") || |
| 251 | !strcmp(tag, "GSM") || |
| 252 | !strcmp(tag, "STK") || |
| 253 | !strcmp(tag, "CDMA") || |
| 254 | !strcmp(tag, "PHONE") || |
Wink Saville | 3761e96 | 2012-11-28 12:20:19 -0800 | [diff] [blame] | 255 | !strcmp(tag, "SMS"))) { |
Joe Onorato | e2bf2ea | 2010-03-01 09:11:54 -0800 | [diff] [blame] | 256 | bufID = LOG_ID_RADIO; |
Wink Saville | 3761e96 | 2012-11-28 12:20:19 -0800 | [diff] [blame] | 257 | // Inform third party apps/ril/radio.. to use Rlog or RLOG |
| 258 | snprintf(tmp_tag, sizeof(tmp_tag), "use-Rlog/RLOG-%s", tag); |
| 259 | tag = tmp_tag; |
| 260 | } |
Joe Onorato | e2bf2ea | 2010-03-01 09:11:54 -0800 | [diff] [blame] | 261 | |
| 262 | vec[0].iov_base = (unsigned char *) &prio; |
| 263 | vec[0].iov_len = 1; |
| 264 | vec[1].iov_base = (void *) tag; |
| 265 | vec[1].iov_len = strlen(tag) + 1; |
| 266 | vec[2].iov_base = (void *) msg; |
| 267 | vec[2].iov_len = strlen(msg) + 1; |
| 268 | |
| 269 | return write_to_log(bufID, vec, 3); |
| 270 | } |
| 271 | |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 272 | int __android_log_vprint(int prio, const char *tag, const char *fmt, va_list ap) |
| 273 | { |
Chris Pearson | 1929990 | 2010-06-02 16:25:35 -0700 | [diff] [blame] | 274 | char buf[LOG_BUF_SIZE]; |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 275 | |
| 276 | vsnprintf(buf, LOG_BUF_SIZE, fmt, ap); |
| 277 | |
| 278 | return __android_log_write(prio, tag, buf); |
| 279 | } |
| 280 | |
| 281 | int __android_log_print(int prio, const char *tag, const char *fmt, ...) |
| 282 | { |
| 283 | va_list ap; |
Joe Onorato | e2bf2ea | 2010-03-01 09:11:54 -0800 | [diff] [blame] | 284 | char buf[LOG_BUF_SIZE]; |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 285 | |
| 286 | va_start(ap, fmt); |
| 287 | vsnprintf(buf, LOG_BUF_SIZE, fmt, ap); |
| 288 | va_end(ap); |
| 289 | |
| 290 | return __android_log_write(prio, tag, buf); |
| 291 | } |
| 292 | |
Joe Onorato | e2bf2ea | 2010-03-01 09:11:54 -0800 | [diff] [blame] | 293 | int __android_log_buf_print(int bufID, int prio, const char *tag, const char *fmt, ...) |
| 294 | { |
| 295 | va_list ap; |
| 296 | char buf[LOG_BUF_SIZE]; |
| 297 | |
| 298 | va_start(ap, fmt); |
| 299 | vsnprintf(buf, LOG_BUF_SIZE, fmt, ap); |
| 300 | va_end(ap); |
| 301 | |
| 302 | return __android_log_buf_write(bufID, prio, tag, buf); |
| 303 | } |
| 304 | |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 305 | void __android_log_assert(const char *cond, const char *tag, |
Mark Salyzyn | cf4aa03 | 2013-11-22 07:54:30 -0800 | [diff] [blame] | 306 | const char *fmt, ...) |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 307 | { |
Chris Pearson | 1929990 | 2010-06-02 16:25:35 -0700 | [diff] [blame] | 308 | char buf[LOG_BUF_SIZE]; |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 309 | |
Chris Pearson | 1929990 | 2010-06-02 16:25:35 -0700 | [diff] [blame] | 310 | if (fmt) { |
| 311 | va_list ap; |
| 312 | va_start(ap, fmt); |
| 313 | vsnprintf(buf, LOG_BUF_SIZE, fmt, ap); |
| 314 | va_end(ap); |
| 315 | } else { |
| 316 | /* Msg not provided, log condition. N.B. Do not use cond directly as |
| 317 | * format string as it could contain spurious '%' syntax (e.g. |
| 318 | * "%d" in "blocks%devs == 0"). |
| 319 | */ |
| 320 | if (cond) |
| 321 | snprintf(buf, LOG_BUF_SIZE, "Assertion failed: %s", cond); |
| 322 | else |
| 323 | strcpy(buf, "Unspecified assertion failed"); |
| 324 | } |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 325 | |
| 326 | __android_log_write(ANDROID_LOG_FATAL, tag, buf); |
| 327 | |
| 328 | __builtin_trap(); /* trap so we have a chance to debug the situation */ |
| 329 | } |
| 330 | |
| 331 | int __android_log_bwrite(int32_t tag, const void *payload, size_t len) |
| 332 | { |
| 333 | struct iovec vec[2]; |
| 334 | |
| 335 | vec[0].iov_base = &tag; |
| 336 | vec[0].iov_len = sizeof(tag); |
| 337 | vec[1].iov_base = (void*)payload; |
| 338 | vec[1].iov_len = len; |
| 339 | |
| 340 | return write_to_log(LOG_ID_EVENTS, vec, 2); |
| 341 | } |
| 342 | |
| 343 | /* |
| 344 | * Like __android_log_bwrite, but takes the type as well. Doesn't work |
| 345 | * for the general case where we're generating lists of stuff, but very |
| 346 | * handy if we just want to dump an integer into the log. |
| 347 | */ |
| 348 | int __android_log_btwrite(int32_t tag, char type, const void *payload, |
Mark Salyzyn | 154f460 | 2014-02-20 14:59:07 -0800 | [diff] [blame] | 349 | size_t len) |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 350 | { |
| 351 | struct iovec vec[3]; |
| 352 | |
| 353 | vec[0].iov_base = &tag; |
| 354 | vec[0].iov_len = sizeof(tag); |
| 355 | vec[1].iov_base = &type; |
| 356 | vec[1].iov_len = sizeof(type); |
| 357 | vec[2].iov_base = (void*)payload; |
| 358 | vec[2].iov_len = len; |
| 359 | |
| 360 | return write_to_log(LOG_ID_EVENTS, vec, 3); |
| 361 | } |