LogKlog.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. * Copyright (C) 2014 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. #ifndef _LOGD_LOG_KLOG_H__
  17. #define _LOGD_LOG_KLOG_H__
  18. #include <private/android_logger.h>
  19. #include <sysutils/SocketListener.h>
  20. class LogBuffer;
  21. class LogReader;
  22. class LogKlog : public SocketListener {
  23. LogBuffer* logbuf;
  24. LogReader* reader;
  25. const log_time signature;
  26. // Set once thread is started, separates KLOG_ACTION_READ_ALL
  27. // and KLOG_ACTION_READ phases.
  28. bool initialized;
  29. // Used during each of the above phases to control logging.
  30. bool enableLogging;
  31. // set if we are also running auditd, to filter out audit reports from
  32. // our copy of the kernel log
  33. bool auditd;
  34. static log_time correction;
  35. public:
  36. LogKlog(LogBuffer* buf, LogReader* reader, int fdWrite, int fdRead,
  37. bool auditd);
  38. int log(const char* buf, ssize_t len);
  39. void synchronize(const char* buf, ssize_t len);
  40. bool isMonotonic() {
  41. return logbuf->isMonotonic();
  42. }
  43. static void convertMonotonicToReal(log_time& real) {
  44. real += correction;
  45. }
  46. static void convertRealToMonotonic(log_time& real) {
  47. real -= correction;
  48. }
  49. protected:
  50. log_time sniffTime(const char*& buf, ssize_t len, bool reverse);
  51. pid_t sniffPid(const char*& buf, ssize_t len);
  52. void calculateCorrection(const log_time& monotonic, const char* real_string, ssize_t len);
  53. virtual bool onDataAvailable(SocketClient* cli);
  54. };
  55. #endif