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)) |
Mark Salyzyn | 99f47a9 | 2014-04-07 14:58:08 -0700 | [diff] [blame] | 57 | static int log_fds[(int)LOG_ID_MAX] = { -1, -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 | |
Mark Salyzyn | 8245af1 | 2014-03-25 13:45:33 -0700 | [diff] [blame] | 80 | /* give up, resources too limited */ |
Kristian Monsen | 7ddca5a | 2014-01-28 13:18:24 -0800 | [diff] [blame] | 81 | 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] | 82 | size_t nr UNUSED) |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 83 | { |
| 84 | return -1; |
| 85 | } |
| 86 | |
Mark Salyzyn | 8245af1 | 2014-03-25 13:45:33 -0700 | [diff] [blame] | 87 | /* log_init_lock assumed */ |
| 88 | static int __write_to_log_initialize() |
| 89 | { |
| 90 | int i, ret = 0; |
| 91 | |
| 92 | #if FAKE_LOG_DEVICE |
| 93 | for (i = 0; i < LOG_ID_MAX; i++) { |
| 94 | char buf[sizeof("/dev/log_system")]; |
| 95 | snprintf(buf, sizeof(buf), "/dev/log_%s", android_log_id_to_name(i)); |
| 96 | log_fds[i] = fakeLogOpen(buf, O_WRONLY); |
| 97 | } |
| 98 | #else |
| 99 | if (logd_fd >= 0) { |
| 100 | i = logd_fd; |
| 101 | logd_fd = -1; |
| 102 | close(i); |
| 103 | } |
| 104 | |
| 105 | i = socket(PF_UNIX, SOCK_DGRAM, 0); |
| 106 | if (i < 0) { |
| 107 | ret = -errno; |
| 108 | write_to_log = __write_to_log_null; |
| 109 | } else if (fcntl(i, F_SETFL, O_NONBLOCK) < 0) { |
| 110 | ret = -errno; |
| 111 | close(i); |
| 112 | i = -1; |
| 113 | write_to_log = __write_to_log_null; |
| 114 | } else { |
| 115 | struct sockaddr_un un; |
| 116 | memset(&un, 0, sizeof(struct sockaddr_un)); |
| 117 | un.sun_family = AF_UNIX; |
| 118 | strcpy(un.sun_path, "/dev/socket/logdw"); |
| 119 | |
| 120 | if (connect(i, (struct sockaddr *)&un, sizeof(struct sockaddr_un)) < 0) { |
| 121 | ret = -errno; |
| 122 | close(i); |
| 123 | i = -1; |
| 124 | } |
| 125 | } |
| 126 | logd_fd = i; |
| 127 | #endif |
| 128 | |
| 129 | return ret; |
| 130 | } |
| 131 | |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 132 | static int __write_to_log_kernel(log_id_t log_id, struct iovec *vec, size_t nr) |
| 133 | { |
| 134 | ssize_t ret; |
Mark Salyzyn | 8245af1 | 2014-03-25 13:45:33 -0700 | [diff] [blame] | 135 | #if FAKE_LOG_DEVICE |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 136 | int log_fd; |
| 137 | |
| 138 | if (/*(int)log_id >= 0 &&*/ (int)log_id < (int)LOG_ID_MAX) { |
| 139 | log_fd = log_fds[(int)log_id]; |
| 140 | } else { |
Mark Salyzyn | 8245af1 | 2014-03-25 13:45:33 -0700 | [diff] [blame] | 141 | return -EBADF; |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 142 | } |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 143 | do { |
Mark Salyzyn | 154f460 | 2014-02-20 14:59:07 -0800 | [diff] [blame] | 144 | ret = fakeLogWritev(log_fd, vec, nr); |
Mark Salyzyn | 8245af1 | 2014-03-25 13:45:33 -0700 | [diff] [blame] | 145 | if (ret < 0) { |
| 146 | ret = -errno; |
| 147 | } |
| 148 | } while (ret == -EINTR); |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 149 | |
| 150 | return ret; |
Mark Salyzyn | 154f460 | 2014-02-20 14:59:07 -0800 | [diff] [blame] | 151 | #else |
Mark Salyzyn | 154f460 | 2014-02-20 14:59:07 -0800 | [diff] [blame] | 152 | if (getuid() == AID_LOGD) { |
| 153 | /* |
| 154 | * ignore log messages we send to ourself. |
| 155 | * Such log messages are often generated by libraries we depend on |
| 156 | * which use standard Android logging. |
| 157 | */ |
| 158 | return 0; |
| 159 | } |
Mark Salyzyn | 8245af1 | 2014-03-25 13:45:33 -0700 | [diff] [blame] | 160 | |
| 161 | if (logd_fd < 0) { |
| 162 | return -EBADF; |
| 163 | } |
| 164 | |
Mark Salyzyn | b992d0d | 2014-03-20 16:09:38 -0700 | [diff] [blame] | 165 | /* |
| 166 | * struct { |
| 167 | * // what we provide |
| 168 | * typeof_log_id_t log_id; |
| 169 | * u16 tid; |
| 170 | * log_time realtime; |
| 171 | * // caller provides |
| 172 | * union { |
| 173 | * struct { |
| 174 | * char prio; |
| 175 | * char payload[]; |
| 176 | * } string; |
| 177 | * struct { |
| 178 | * uint32_t tag |
| 179 | * char payload[]; |
| 180 | * } binary; |
| 181 | * }; |
| 182 | * }; |
| 183 | */ |
| 184 | static const unsigned header_length = 3; |
| 185 | struct iovec newVec[nr + header_length]; |
Mark Salyzyn | 154f460 | 2014-02-20 14:59:07 -0800 | [diff] [blame] | 186 | typeof_log_id_t log_id_buf = log_id; |
Mark Salyzyn | b992d0d | 2014-03-20 16:09:38 -0700 | [diff] [blame] | 187 | uint16_t tid = gettid(); |
Mark Salyzyn | 154f460 | 2014-02-20 14:59:07 -0800 | [diff] [blame] | 188 | |
| 189 | newVec[0].iov_base = (unsigned char *) &log_id_buf; |
| 190 | newVec[0].iov_len = sizeof_log_id_t; |
Mark Salyzyn | b992d0d | 2014-03-20 16:09:38 -0700 | [diff] [blame] | 191 | newVec[1].iov_base = (unsigned char *) &tid; |
| 192 | newVec[1].iov_len = sizeof(tid); |
Mark Salyzyn | 154f460 | 2014-02-20 14:59:07 -0800 | [diff] [blame] | 193 | |
Mark Salyzyn | 7e2f83c | 2014-03-05 07:41:49 -0800 | [diff] [blame] | 194 | struct timespec ts; |
| 195 | clock_gettime(CLOCK_REALTIME, &ts); |
Mark Salyzyn | 154f460 | 2014-02-20 14:59:07 -0800 | [diff] [blame] | 196 | log_time realtime_ts; |
Mark Salyzyn | 7e2f83c | 2014-03-05 07:41:49 -0800 | [diff] [blame] | 197 | realtime_ts.tv_sec = ts.tv_sec; |
| 198 | realtime_ts.tv_nsec = ts.tv_nsec; |
Mark Salyzyn | 154f460 | 2014-02-20 14:59:07 -0800 | [diff] [blame] | 199 | |
Mark Salyzyn | b992d0d | 2014-03-20 16:09:38 -0700 | [diff] [blame] | 200 | newVec[2].iov_base = (unsigned char *) &realtime_ts; |
| 201 | newVec[2].iov_len = sizeof(log_time); |
Mark Salyzyn | 154f460 | 2014-02-20 14:59:07 -0800 | [diff] [blame] | 202 | |
| 203 | size_t i; |
Mark Salyzyn | b992d0d | 2014-03-20 16:09:38 -0700 | [diff] [blame] | 204 | for (i = header_length; i < nr + header_length; i++) { |
| 205 | newVec[i].iov_base = vec[i-header_length].iov_base; |
| 206 | newVec[i].iov_len = vec[i-header_length].iov_len; |
Mark Salyzyn | 154f460 | 2014-02-20 14:59:07 -0800 | [diff] [blame] | 207 | } |
| 208 | |
Mark Salyzyn | 8245af1 | 2014-03-25 13:45:33 -0700 | [diff] [blame] | 209 | /* |
| 210 | * The write below could be lost, but will never block. |
| 211 | * |
| 212 | * ENOTCONN occurs if logd dies. |
| 213 | * EAGAIN occurs if logd is overloaded. |
| 214 | */ |
| 215 | ret = writev(logd_fd, newVec, nr + header_length); |
| 216 | if (ret < 0) { |
| 217 | ret = -errno; |
| 218 | if (ret == -ENOTCONN) { |
| 219 | #ifdef HAVE_PTHREADS |
| 220 | pthread_mutex_lock(&log_init_lock); |
| 221 | #endif |
| 222 | ret = __write_to_log_initialize(); |
| 223 | #ifdef HAVE_PTHREADS |
| 224 | pthread_mutex_unlock(&log_init_lock); |
| 225 | #endif |
| 226 | |
| 227 | if (ret < 0) { |
| 228 | return ret; |
| 229 | } |
| 230 | |
| 231 | ret = writev(logd_fd, newVec, nr + header_length); |
| 232 | if (ret < 0) { |
| 233 | ret = -errno; |
| 234 | } |
| 235 | } |
| 236 | } |
| 237 | return ret; |
Mark Salyzyn | 154f460 | 2014-02-20 14:59:07 -0800 | [diff] [blame] | 238 | #endif |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 239 | } |
| 240 | |
Mark Salyzyn | 154f460 | 2014-02-20 14:59:07 -0800 | [diff] [blame] | 241 | #if FAKE_LOG_DEVICE |
| 242 | static const char *LOG_NAME[LOG_ID_MAX] = { |
| 243 | [LOG_ID_MAIN] = "main", |
| 244 | [LOG_ID_RADIO] = "radio", |
| 245 | [LOG_ID_EVENTS] = "events", |
Mark Salyzyn | 99f47a9 | 2014-04-07 14:58:08 -0700 | [diff] [blame] | 246 | [LOG_ID_SYSTEM] = "system", |
| 247 | [LOG_ID_CRASH] = "crash" |
Mark Salyzyn | 154f460 | 2014-02-20 14:59:07 -0800 | [diff] [blame] | 248 | }; |
| 249 | |
| 250 | const WEAK char *android_log_id_to_name(log_id_t log_id) |
| 251 | { |
| 252 | if (log_id >= LOG_ID_MAX) { |
| 253 | log_id = LOG_ID_MAIN; |
| 254 | } |
| 255 | return LOG_NAME[log_id]; |
| 256 | } |
| 257 | #endif |
| 258 | |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 259 | static int __write_to_log_init(log_id_t log_id, struct iovec *vec, size_t nr) |
| 260 | { |
| 261 | #ifdef HAVE_PTHREADS |
| 262 | pthread_mutex_lock(&log_init_lock); |
| 263 | #endif |
| 264 | |
| 265 | if (write_to_log == __write_to_log_init) { |
Mark Salyzyn | 8245af1 | 2014-03-25 13:45:33 -0700 | [diff] [blame] | 266 | int ret; |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 267 | |
Mark Salyzyn | 8245af1 | 2014-03-25 13:45:33 -0700 | [diff] [blame] | 268 | ret = __write_to_log_initialize(); |
| 269 | if (ret < 0) { |
| 270 | #ifdef HAVE_PTHREADS |
| 271 | pthread_mutex_unlock(&log_init_lock); |
Mark Salyzyn | 154f460 | 2014-02-20 14:59:07 -0800 | [diff] [blame] | 272 | #endif |
Mark Salyzyn | 8245af1 | 2014-03-25 13:45:33 -0700 | [diff] [blame] | 273 | return ret; |
| 274 | } |
| 275 | |
| 276 | write_to_log = __write_to_log_kernel; |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 277 | } |
| 278 | |
| 279 | #ifdef HAVE_PTHREADS |
| 280 | pthread_mutex_unlock(&log_init_lock); |
| 281 | #endif |
| 282 | |
| 283 | return write_to_log(log_id, vec, nr); |
| 284 | } |
| 285 | |
| 286 | int __android_log_write(int prio, const char *tag, const char *msg) |
| 287 | { |
| 288 | struct iovec vec[3]; |
| 289 | log_id_t log_id = LOG_ID_MAIN; |
Wink Saville | 3761e96 | 2012-11-28 12:20:19 -0800 | [diff] [blame] | 290 | char tmp_tag[32]; |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 291 | |
| 292 | if (!tag) |
| 293 | tag = ""; |
| 294 | |
| 295 | /* XXX: This needs to go! */ |
| 296 | if (!strcmp(tag, "HTC_RIL") || |
John Michelau | ed7ccae | 2009-08-19 10:01:55 -0500 | [diff] [blame] | 297 | !strncmp(tag, "RIL", 3) || /* Any log tag with "RIL" as the prefix */ |
Jeff Sharkey | 84dcf09 | 2012-08-13 11:27:30 -0700 | [diff] [blame] | 298 | !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] | 299 | !strcmp(tag, "AT") || |
| 300 | !strcmp(tag, "GSM") || |
Wink Saville | 89efdc9 | 2009-04-02 11:00:57 -0700 | [diff] [blame] | 301 | !strcmp(tag, "STK") || |
| 302 | !strcmp(tag, "CDMA") || |
| 303 | !strcmp(tag, "PHONE") || |
Wink Saville | 3761e96 | 2012-11-28 12:20:19 -0800 | [diff] [blame] | 304 | !strcmp(tag, "SMS")) { |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 305 | log_id = LOG_ID_RADIO; |
Mark Salyzyn | 8245af1 | 2014-03-25 13:45:33 -0700 | [diff] [blame] | 306 | /* Inform third party apps/ril/radio.. to use Rlog or RLOG */ |
Wink Saville | 3761e96 | 2012-11-28 12:20:19 -0800 | [diff] [blame] | 307 | snprintf(tmp_tag, sizeof(tmp_tag), "use-Rlog/RLOG-%s", tag); |
| 308 | tag = tmp_tag; |
| 309 | } |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 310 | |
| 311 | vec[0].iov_base = (unsigned char *) &prio; |
| 312 | vec[0].iov_len = 1; |
| 313 | vec[1].iov_base = (void *) tag; |
| 314 | vec[1].iov_len = strlen(tag) + 1; |
| 315 | vec[2].iov_base = (void *) msg; |
| 316 | vec[2].iov_len = strlen(msg) + 1; |
| 317 | |
| 318 | return write_to_log(log_id, vec, 3); |
| 319 | } |
| 320 | |
Joe Onorato | e2bf2ea | 2010-03-01 09:11:54 -0800 | [diff] [blame] | 321 | int __android_log_buf_write(int bufID, int prio, const char *tag, const char *msg) |
| 322 | { |
| 323 | struct iovec vec[3]; |
Wink Saville | 3761e96 | 2012-11-28 12:20:19 -0800 | [diff] [blame] | 324 | char tmp_tag[32]; |
Joe Onorato | e2bf2ea | 2010-03-01 09:11:54 -0800 | [diff] [blame] | 325 | |
| 326 | if (!tag) |
| 327 | tag = ""; |
| 328 | |
| 329 | /* XXX: This needs to go! */ |
Wink Saville | 3761e96 | 2012-11-28 12:20:19 -0800 | [diff] [blame] | 330 | if ((bufID != LOG_ID_RADIO) && |
| 331 | (!strcmp(tag, "HTC_RIL") || |
Joe Onorato | e2bf2ea | 2010-03-01 09:11:54 -0800 | [diff] [blame] | 332 | !strncmp(tag, "RIL", 3) || /* Any log tag with "RIL" as the prefix */ |
Jeff Sharkey | 84dcf09 | 2012-08-13 11:27:30 -0700 | [diff] [blame] | 333 | !strncmp(tag, "IMS", 3) || /* Any log tag with "IMS" as the prefix */ |
Joe Onorato | e2bf2ea | 2010-03-01 09:11:54 -0800 | [diff] [blame] | 334 | !strcmp(tag, "AT") || |
| 335 | !strcmp(tag, "GSM") || |
| 336 | !strcmp(tag, "STK") || |
| 337 | !strcmp(tag, "CDMA") || |
| 338 | !strcmp(tag, "PHONE") || |
Wink Saville | 3761e96 | 2012-11-28 12:20:19 -0800 | [diff] [blame] | 339 | !strcmp(tag, "SMS"))) { |
Joe Onorato | e2bf2ea | 2010-03-01 09:11:54 -0800 | [diff] [blame] | 340 | bufID = LOG_ID_RADIO; |
Mark Salyzyn | 8245af1 | 2014-03-25 13:45:33 -0700 | [diff] [blame] | 341 | /* Inform third party apps/ril/radio.. to use Rlog or RLOG */ |
Wink Saville | 3761e96 | 2012-11-28 12:20:19 -0800 | [diff] [blame] | 342 | snprintf(tmp_tag, sizeof(tmp_tag), "use-Rlog/RLOG-%s", tag); |
| 343 | tag = tmp_tag; |
| 344 | } |
Joe Onorato | e2bf2ea | 2010-03-01 09:11:54 -0800 | [diff] [blame] | 345 | |
| 346 | vec[0].iov_base = (unsigned char *) &prio; |
| 347 | vec[0].iov_len = 1; |
| 348 | vec[1].iov_base = (void *) tag; |
| 349 | vec[1].iov_len = strlen(tag) + 1; |
| 350 | vec[2].iov_base = (void *) msg; |
| 351 | vec[2].iov_len = strlen(msg) + 1; |
| 352 | |
| 353 | return write_to_log(bufID, vec, 3); |
| 354 | } |
| 355 | |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 356 | int __android_log_vprint(int prio, const char *tag, const char *fmt, va_list ap) |
| 357 | { |
Chris Pearson | 1929990 | 2010-06-02 16:25:35 -0700 | [diff] [blame] | 358 | char buf[LOG_BUF_SIZE]; |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 359 | |
| 360 | vsnprintf(buf, LOG_BUF_SIZE, fmt, ap); |
| 361 | |
| 362 | return __android_log_write(prio, tag, buf); |
| 363 | } |
| 364 | |
| 365 | int __android_log_print(int prio, const char *tag, const char *fmt, ...) |
| 366 | { |
| 367 | va_list ap; |
Joe Onorato | e2bf2ea | 2010-03-01 09:11:54 -0800 | [diff] [blame] | 368 | char buf[LOG_BUF_SIZE]; |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 369 | |
| 370 | va_start(ap, fmt); |
| 371 | vsnprintf(buf, LOG_BUF_SIZE, fmt, ap); |
| 372 | va_end(ap); |
| 373 | |
| 374 | return __android_log_write(prio, tag, buf); |
| 375 | } |
| 376 | |
Joe Onorato | e2bf2ea | 2010-03-01 09:11:54 -0800 | [diff] [blame] | 377 | int __android_log_buf_print(int bufID, int prio, const char *tag, const char *fmt, ...) |
| 378 | { |
| 379 | va_list ap; |
| 380 | char buf[LOG_BUF_SIZE]; |
| 381 | |
| 382 | va_start(ap, fmt); |
| 383 | vsnprintf(buf, LOG_BUF_SIZE, fmt, ap); |
| 384 | va_end(ap); |
| 385 | |
| 386 | return __android_log_buf_write(bufID, prio, tag, buf); |
| 387 | } |
| 388 | |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 389 | void __android_log_assert(const char *cond, const char *tag, |
Mark Salyzyn | cf4aa03 | 2013-11-22 07:54:30 -0800 | [diff] [blame] | 390 | const char *fmt, ...) |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 391 | { |
Chris Pearson | 1929990 | 2010-06-02 16:25:35 -0700 | [diff] [blame] | 392 | char buf[LOG_BUF_SIZE]; |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 393 | |
Chris Pearson | 1929990 | 2010-06-02 16:25:35 -0700 | [diff] [blame] | 394 | if (fmt) { |
| 395 | va_list ap; |
| 396 | va_start(ap, fmt); |
| 397 | vsnprintf(buf, LOG_BUF_SIZE, fmt, ap); |
| 398 | va_end(ap); |
| 399 | } else { |
| 400 | /* Msg not provided, log condition. N.B. Do not use cond directly as |
| 401 | * format string as it could contain spurious '%' syntax (e.g. |
| 402 | * "%d" in "blocks%devs == 0"). |
| 403 | */ |
| 404 | if (cond) |
| 405 | snprintf(buf, LOG_BUF_SIZE, "Assertion failed: %s", cond); |
| 406 | else |
| 407 | strcpy(buf, "Unspecified assertion failed"); |
| 408 | } |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 409 | |
Elliott Hughes | da6b2e2 | 2014-04-23 14:57:32 -0700 | [diff] [blame^] | 410 | #if __BIONIC__ |
| 411 | // Ensure debuggerd gets to see what went wrong by keeping the C library in the loop. |
| 412 | extern __noreturn void __android_fatal(const char* tag, const char* format, ...) __printflike(2, 3); |
| 413 | __android_fatal(tag ? tag : "", "%s", buf); |
| 414 | #else |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 415 | __android_log_write(ANDROID_LOG_FATAL, tag, buf); |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 416 | __builtin_trap(); /* trap so we have a chance to debug the situation */ |
Elliott Hughes | da6b2e2 | 2014-04-23 14:57:32 -0700 | [diff] [blame^] | 417 | #endif |
| 418 | /* NOTREACHED */ |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 419 | } |
| 420 | |
| 421 | int __android_log_bwrite(int32_t tag, const void *payload, size_t len) |
| 422 | { |
| 423 | struct iovec vec[2]; |
| 424 | |
| 425 | vec[0].iov_base = &tag; |
| 426 | vec[0].iov_len = sizeof(tag); |
| 427 | vec[1].iov_base = (void*)payload; |
| 428 | vec[1].iov_len = len; |
| 429 | |
| 430 | return write_to_log(LOG_ID_EVENTS, vec, 2); |
| 431 | } |
| 432 | |
| 433 | /* |
| 434 | * Like __android_log_bwrite, but takes the type as well. Doesn't work |
| 435 | * for the general case where we're generating lists of stuff, but very |
| 436 | * handy if we just want to dump an integer into the log. |
| 437 | */ |
| 438 | int __android_log_btwrite(int32_t tag, char type, const void *payload, |
Mark Salyzyn | 154f460 | 2014-02-20 14:59:07 -0800 | [diff] [blame] | 439 | size_t len) |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 440 | { |
| 441 | struct iovec vec[3]; |
| 442 | |
| 443 | vec[0].iov_base = &tag; |
| 444 | vec[0].iov_len = sizeof(tag); |
| 445 | vec[1].iov_base = &type; |
| 446 | vec[1].iov_len = sizeof(type); |
| 447 | vec[2].iov_base = (void*)payload; |
| 448 | vec[2].iov_len = len; |
| 449 | |
| 450 | return write_to_log(LOG_ID_EVENTS, vec, 3); |
| 451 | } |