summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMark Salyzyn2016-10-10 09:27:42 -0500
committerMark Salyzyn2016-10-13 16:43:42 -0500
commitdb8a266aea6c12b0fb8ee3587d72333662b05266 (patch)
treec10491cebcf0b69c99aa0e8ed56611a50d0080b4 /liblog/logd_reader.c
parentbf0cf4e22d594db03c1dcef57fd18d3ae038eefb (diff)
downloadplatform-system-core-db8a266aea6c12b0fb8ee3587d72333662b05266.tar.gz
platform-system-core-db8a266aea6c12b0fb8ee3587d72333662b05266.tar.xz
platform-system-core-db8a266aea6c12b0fb8ee3587d72333662b05266.zip
liblog: __android_log_pmsg_file_write() cleanup
__android_log_pmsg_file_write() will open /dev/pmsg0 if not already, and will close it if we opened it. Added atomic access to the android_log_context as insurance. Fortify and correct pmsg tests. Test: gTest liblog-unit-tests --gtest_filter=liblog.__android_log_pmsg_file_* Bug: 31958686 Change-Id: I2cf6f971b6968938f471fda67367efe20dae3004
Diffstat (limited to 'liblog/logd_reader.c')
-rw-r--r--liblog/logd_reader.c24
1 files changed, 14 insertions, 10 deletions
diff --git a/liblog/logd_reader.c b/liblog/logd_reader.c
index 563b5c750..71ff0752a 100644
--- a/liblog/logd_reader.c
+++ b/liblog/logd_reader.c
@@ -482,17 +482,17 @@ static int logdOpen(struct android_log_logger_list *logger_list,
482 struct sigaction old_sigaction; 482 struct sigaction old_sigaction;
483 unsigned int old_alarm = 0; 483 unsigned int old_alarm = 0;
484 char buffer[256], *cp, c; 484 char buffer[256], *cp, c;
485 int e, ret, remaining; 485 int e, ret, remaining, sock;
486
487 int sock = transp->context.sock;
488 if (sock > 0) {
489 return sock;
490 }
491 486
492 if (!logger_list) { 487 if (!logger_list) {
493 return -EINVAL; 488 return -EINVAL;
494 } 489 }
495 490
491 sock = atomic_load(&transp->context.sock);
492 if (sock > 0) {
493 return sock;
494 }
495
496 sock = socket_local_client("logdr", 496 sock = socket_local_client("logdr",
497 ANDROID_SOCKET_NAMESPACE_RESERVED, 497 ANDROID_SOCKET_NAMESPACE_RESERVED,
498 SOCK_SEQPACKET); 498 SOCK_SEQPACKET);
@@ -587,7 +587,11 @@ static int logdOpen(struct android_log_logger_list *logger_list,
587 return ret; 587 return ret;
588 } 588 }
589 589
590 return transp->context.sock = sock; 590 ret = atomic_exchange(&transp->context.sock, sock);
591 if ((ret > 0) && (ret != sock)) {
592 close(ret);
593 }
594 return sock;
591} 595}
592 596
593/* Read from the selected logs */ 597/* Read from the selected logs */
@@ -662,8 +666,8 @@ static int logdPoll(struct android_log_logger_list *logger_list,
662static void logdClose(struct android_log_logger_list *logger_list __unused, 666static void logdClose(struct android_log_logger_list *logger_list __unused,
663 struct android_log_transport_context *transp) 667 struct android_log_transport_context *transp)
664{ 668{
665 if (transp->context.sock > 0) { 669 int sock = atomic_exchange(&transp->context.sock, -1);
666 close (transp->context.sock); 670 if (sock > 0) {
667 transp->context.sock = -1; 671 close (sock);
668 } 672 }
669} 673}