config_write.cpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*
  2. * Copyright (C) 2016 The Android Open Source Project
  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. */
  16. #include <log/log_transport.h>
  17. #include "config_write.h"
  18. #include "logger.h"
  19. struct listnode __android_log_transport_write = {&__android_log_transport_write,
  20. &__android_log_transport_write};
  21. struct listnode __android_log_persist_write = {&__android_log_persist_write,
  22. &__android_log_persist_write};
  23. static void __android_log_add_transport(struct listnode* list,
  24. struct android_log_transport_write* transport) {
  25. uint32_t i;
  26. /* Try to keep one functioning transport for each log buffer id */
  27. for (i = LOG_ID_MIN; i < LOG_ID_MAX; i++) {
  28. struct android_log_transport_write* transp;
  29. if (list_empty(list)) {
  30. if (!transport->available || ((*transport->available)(static_cast<log_id_t>(i)) >= 0)) {
  31. list_add_tail(list, &transport->node);
  32. return;
  33. }
  34. } else {
  35. write_transport_for_each(transp, list) {
  36. if (!transp->available) {
  37. return;
  38. }
  39. if (((*transp->available)(static_cast<log_id_t>(i)) < 0) &&
  40. (!transport->available || ((*transport->available)(static_cast<log_id_t>(i)) >= 0))) {
  41. list_add_tail(list, &transport->node);
  42. return;
  43. }
  44. }
  45. }
  46. }
  47. }
  48. void __android_log_config_write() {
  49. if ((__android_log_transport == LOGGER_DEFAULT) || (__android_log_transport & LOGGER_LOGD)) {
  50. #if (FAKE_LOG_DEVICE == 0)
  51. extern struct android_log_transport_write logdLoggerWrite;
  52. extern struct android_log_transport_write pmsgLoggerWrite;
  53. __android_log_add_transport(&__android_log_transport_write, &logdLoggerWrite);
  54. __android_log_add_transport(&__android_log_persist_write, &pmsgLoggerWrite);
  55. #else
  56. extern struct android_log_transport_write fakeLoggerWrite;
  57. __android_log_add_transport(&__android_log_transport_write, &fakeLoggerWrite);
  58. #endif
  59. }
  60. if (__android_log_transport & LOGGER_STDERR) {
  61. extern struct android_log_transport_write stderrLoggerWrite;
  62. /*
  63. * stderr logger should be primary if we can be the only one, or if
  64. * already in the primary list. Otherwise land in the persist list.
  65. * Remember we can be called here if we are already initialized.
  66. */
  67. if (list_empty(&__android_log_transport_write)) {
  68. __android_log_add_transport(&__android_log_transport_write, &stderrLoggerWrite);
  69. } else {
  70. struct android_log_transport_write* transp;
  71. write_transport_for_each(transp, &__android_log_transport_write) {
  72. if (transp == &stderrLoggerWrite) {
  73. return;
  74. }
  75. }
  76. __android_log_add_transport(&__android_log_persist_write, &stderrLoggerWrite);
  77. }
  78. }
  79. }
  80. void __android_log_config_write_close() {
  81. struct android_log_transport_write* transport;
  82. struct listnode* n;
  83. write_transport_for_each_safe(transport, n, &__android_log_transport_write) {
  84. transport->logMask = 0;
  85. list_remove(&transport->node);
  86. }
  87. write_transport_for_each_safe(transport, n, &__android_log_persist_write) {
  88. transport->logMask = 0;
  89. list_remove(&transport->node);
  90. }
  91. }