summaryrefslogtreecommitdiffstats
path: root/liblog
diff options
context:
space:
mode:
authorMark Salyzyn2018-03-07 12:42:06 -0600
committerMark Salyzyn2018-03-07 12:56:51 -0600
commit72d3724ee57251e4056df95f58a55f0c9e2ab31c (patch)
tree766ffead891d45364b4108dcd351bc771745bbee /liblog
parent5be32c312c695b8d9abc7558e338e32ff047a9e6 (diff)
downloadplatform-system-core-72d3724ee57251e4056df95f58a55f0c9e2ab31c.tar.gz
platform-system-core-72d3724ee57251e4056df95f58a55f0c9e2ab31c.tar.xz
platform-system-core-72d3724ee57251e4056df95f58a55f0c9e2ab31c.zip
liblog: save errno through log writing
Test: compile Bug: 74258013 Change-Id: I5163527826855bc506ed324aaba47f8695aaf668
Diffstat (limited to 'liblog')
-rw-r--r--liblog/logger_write.c19
1 files changed, 15 insertions, 4 deletions
diff --git a/liblog/logger_write.c b/liblog/logger_write.c
index d03a2b674..2754e6e74 100644
--- a/liblog/logger_write.c
+++ b/liblog/logger_write.c
@@ -243,7 +243,7 @@ static inline uint32_t get4LE(const uint8_t* src) {
243 243
244static int __write_to_log_daemon(log_id_t log_id, struct iovec* vec, size_t nr) { 244static int __write_to_log_daemon(log_id_t log_id, struct iovec* vec, size_t nr) {
245 struct android_log_transport_write* node; 245 struct android_log_transport_write* node;
246 int ret; 246 int ret, save_errno;
247 struct timespec ts; 247 struct timespec ts;
248 size_t len, i; 248 size_t len, i;
249 249
@@ -254,20 +254,24 @@ static int __write_to_log_daemon(log_id_t log_id, struct iovec* vec, size_t nr)
254 return -EINVAL; 254 return -EINVAL;
255 } 255 }
256 256
257 save_errno = errno;
257#if defined(__ANDROID__) 258#if defined(__ANDROID__)
258 clock_gettime(android_log_clockid(), &ts); 259 clock_gettime(android_log_clockid(), &ts);
259 260
260 if (log_id == LOG_ID_SECURITY) { 261 if (log_id == LOG_ID_SECURITY) {
261 if (vec[0].iov_len < 4) { 262 if (vec[0].iov_len < 4) {
263 errno = save_errno;
262 return -EINVAL; 264 return -EINVAL;
263 } 265 }
264 266
265 ret = check_log_uid_permissions(); 267 ret = check_log_uid_permissions();
266 if (ret < 0) { 268 if (ret < 0) {
269 errno = save_errno;
267 return ret; 270 return ret;
268 } 271 }
269 if (!__android_log_security()) { 272 if (!__android_log_security()) {
270 /* If only we could reset downstream logd counter */ 273 /* If only we could reset downstream logd counter */
274 errno = save_errno;
271 return -EPERM; 275 return -EPERM;
272 } 276 }
273 } else if (log_id == LOG_ID_EVENTS || log_id == LOG_ID_STATS) { 277 } else if (log_id == LOG_ID_EVENTS || log_id == LOG_ID_STATS) {
@@ -276,6 +280,7 @@ static int __write_to_log_daemon(log_id_t log_id, struct iovec* vec, size_t nr)
276 EventTagMap *m, *f; 280 EventTagMap *m, *f;
277 281
278 if (vec[0].iov_len < 4) { 282 if (vec[0].iov_len < 4) {
283 errno = save_errno;
279 return -EINVAL; 284 return -EINVAL;
280 } 285 }
281 286
@@ -311,6 +316,7 @@ static int __write_to_log_daemon(log_id_t log_id, struct iovec* vec, size_t nr)
311 android_closeEventTagMap(f); 316 android_closeEventTagMap(f);
312 } 317 }
313 if (!ret) { 318 if (!ret) {
319 errno = save_errno;
314 return -EPERM; 320 return -EPERM;
315 } 321 }
316 } else { 322 } else {
@@ -340,6 +346,7 @@ static int __write_to_log_daemon(log_id_t log_id, struct iovec* vec, size_t nr)
340 } 346 }
341 347
342 if (!__android_log_is_loggable_len(prio, tag, len - 1, ANDROID_LOG_VERBOSE)) { 348 if (!__android_log_is_loggable_len(prio, tag, len - 1, ANDROID_LOG_VERBOSE)) {
349 errno = save_errno;
343 return -EPERM; 350 return -EPERM;
344 } 351 }
345 } 352 }
@@ -371,21 +378,23 @@ static int __write_to_log_daemon(log_id_t log_id, struct iovec* vec, size_t nr)
371 } 378 }
372 } 379 }
373 380
381 errno = save_errno;
374 return ret; 382 return ret;
375} 383}
376 384
377static int __write_to_log_init(log_id_t log_id, struct iovec* vec, size_t nr) { 385static int __write_to_log_init(log_id_t log_id, struct iovec* vec, size_t nr) {
386 int ret, save_errno = errno;
387
378 __android_log_lock(); 388 __android_log_lock();
379 389
380 if (write_to_log == __write_to_log_init) { 390 if (write_to_log == __write_to_log_init) {
381 int ret;
382
383 ret = __write_to_log_initialize(); 391 ret = __write_to_log_initialize();
384 if (ret < 0) { 392 if (ret < 0) {
385 __android_log_unlock(); 393 __android_log_unlock();
386 if (!list_empty(&__android_log_persist_write)) { 394 if (!list_empty(&__android_log_persist_write)) {
387 __write_to_log_daemon(log_id, vec, nr); 395 __write_to_log_daemon(log_id, vec, nr);
388 } 396 }
397 errno = save_errno;
389 return ret; 398 return ret;
390 } 399 }
391 400
@@ -394,7 +403,9 @@ static int __write_to_log_init(log_id_t log_id, struct iovec* vec, size_t nr) {
394 403
395 __android_log_unlock(); 404 __android_log_unlock();
396 405
397 return write_to_log(log_id, vec, nr); 406 ret = write_to_log(log_id, vec, nr);
407 errno = save_errno;
408 return ret;
398} 409}
399 410
400LIBLOG_ABI_PUBLIC int __android_log_write(int prio, const char* tag, 411LIBLOG_ABI_PUBLIC int __android_log_write(int prio, const char* tag,