Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 245c5225 authored by Tao Bao's avatar Tao Bao
Browse files

rotate_logs: Clean up the header includes.

Also clang-format rotate_logs.cpp to get consistent style.

Test: mmma bootable/recovery
Test: recovery_manual_test works on marlin.
Change-Id: I1210a346b97bbf0e1a8c3f8e3e73a7c114858ca8
parent bab1e8ef
Loading
Loading
Loading
Loading
+56 −64
Original line number Diff line number Diff line
@@ -31,29 +31,21 @@
static const std::string LAST_KMSG_FILTER = "recovery/last_kmsg";
static const std::string LAST_LOG_FILTER = "recovery/last_log";

ssize_t logbasename(
        log_id_t /* logId */,
        char /* prio */,
        const char *filename,
        const char * /* buf */, size_t len,
        void *arg) {
    bool* doRotate  = static_cast<bool*>(arg);
ssize_t logbasename(log_id_t /* id */, char /* prio */, const char* filename, const char* /* buf */,
                    size_t len, void* arg) {
  bool* do_rotate = static_cast<bool*>(arg);
  if (LAST_KMSG_FILTER.find(filename) != std::string::npos ||
      LAST_LOG_FILTER.find(filename) != std::string::npos) {
        *doRotate = true;
    *do_rotate = true;
  }
  return len;
}

ssize_t logrotate(
        log_id_t logId,
        char prio,
        const char *filename,
        const char *buf, size_t len,
ssize_t logrotate(log_id_t id, char prio, const char* filename, const char* buf, size_t len,
                  void* arg) {
    bool* doRotate  = static_cast<bool*>(arg);
    if (!*doRotate) {
        return __android_log_pmsg_file_write(logId, prio, filename, buf, len);
  bool* do_rotate = static_cast<bool*>(arg);
  if (!*do_rotate) {
    return __android_log_pmsg_file_write(id, prio, filename, buf, len);
  }

  std::string name(filename);
@@ -62,7 +54,7 @@ ssize_t logrotate(

  if (LAST_KMSG_FILTER.find(sub) == std::string::npos &&
      LAST_LOG_FILTER.find(sub) == std::string::npos) {
        return __android_log_pmsg_file_write(logId, prio, filename, buf, len);
    return __android_log_pmsg_file_write(id, prio, filename, buf, len);
  }

  // filename rotation
@@ -82,7 +74,7 @@ ssize_t logrotate(
    }
  }

    return __android_log_pmsg_file_write(logId, prio, name.c_str(), buf, len);
  return __android_log_pmsg_file_write(id, prio, name.c_str(), buf, len);
}

// Rename last_log -> last_log.1 -> last_log.2 -> ... -> last_log.$max.
+8 −14
Original line number Diff line number Diff line
@@ -17,23 +17,17 @@
#ifndef _ROTATE_LOGS_H
#define _ROTATE_LOGS_H

#include <string>
#include <stddef.h>
#include <sys/types.h>

#include <private/android_logger.h> /* private pmsg functions */
#include <log/log_id.h>

constexpr int KEEP_LOG_COUNT = 10;
static constexpr int KEEP_LOG_COUNT = 10;

ssize_t logbasename(log_id_t /* logId */,
        char /* prio */,
        const char *filename,
        const char * /* buf */, size_t len,
ssize_t logbasename(log_id_t id, char prio, const char* filename, const char* buf, size_t len,
                    void* arg);

ssize_t logrotate(
        log_id_t logId,
        char prio,
        const char *filename,
        const char *buf, size_t len,
ssize_t logrotate(log_id_t id, char prio, const char* filename, const char* buf, size_t len,
                  void* arg);

// Rename last_log -> last_log.1 -> last_log.2 -> ... -> last_log.$max.