Merge "rotate_logs: Clean up the header includes." am: 30ec005104

am: c8eba4a036

Change-Id: Ibac286ecec3c31a8aa6d1fb4cf47428c39549632
This commit is contained in:
Tao Bao
2017-10-18 20:31:56 +00:00
committed by android-build-merger
2 changed files with 65 additions and 79 deletions
+13 -21
View File
@@ -31,29 +31,21 @@
static const std::string LAST_KMSG_FILTER = "recovery/last_kmsg"; static const std::string LAST_KMSG_FILTER = "recovery/last_kmsg";
static const std::string LAST_LOG_FILTER = "recovery/last_log"; static const std::string LAST_LOG_FILTER = "recovery/last_log";
ssize_t logbasename( ssize_t logbasename(log_id_t /* id */, char /* prio */, const char* filename, const char* /* buf */,
log_id_t /* logId */, size_t len, void* arg) {
char /* prio */, bool* do_rotate = static_cast<bool*>(arg);
const char *filename,
const char * /* buf */, size_t len,
void *arg) {
bool* doRotate = static_cast<bool*>(arg);
if (LAST_KMSG_FILTER.find(filename) != std::string::npos || if (LAST_KMSG_FILTER.find(filename) != std::string::npos ||
LAST_LOG_FILTER.find(filename) != std::string::npos) { LAST_LOG_FILTER.find(filename) != std::string::npos) {
*doRotate = true; *do_rotate = true;
} }
return len; return len;
} }
ssize_t logrotate( ssize_t logrotate(log_id_t id, char prio, const char* filename, const char* buf, size_t len,
log_id_t logId, void* arg) {
char prio, bool* do_rotate = static_cast<bool*>(arg);
const char *filename, if (!*do_rotate) {
const char *buf, size_t len, return __android_log_pmsg_file_write(id, prio, filename, buf, len);
void *arg) {
bool* doRotate = static_cast<bool*>(arg);
if (!*doRotate) {
return __android_log_pmsg_file_write(logId, prio, filename, buf, len);
} }
std::string name(filename); std::string name(filename);
@@ -62,7 +54,7 @@ ssize_t logrotate(
if (LAST_KMSG_FILTER.find(sub) == std::string::npos && if (LAST_KMSG_FILTER.find(sub) == std::string::npos &&
LAST_LOG_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 // 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. // Rename last_log -> last_log.1 -> last_log.2 -> ... -> last_log.$max.
@@ -101,7 +93,7 @@ void rotate_logs(const char* last_log_file, const char* last_kmsg_file) {
if (i > 0) { if (i > 0) {
old_log += "." + std::to_string(i); old_log += "." + std::to_string(i);
} }
std::string new_log = android::base::StringPrintf("%s.%d", last_log_file, i+1); std::string new_log = android::base::StringPrintf("%s.%d", last_log_file, i + 1);
// Ignore errors if old_log doesn't exist. // Ignore errors if old_log doesn't exist.
rename(old_log.c_str(), new_log.c_str()); rename(old_log.c_str(), new_log.c_str());
@@ -109,7 +101,7 @@ void rotate_logs(const char* last_log_file, const char* last_kmsg_file) {
if (i > 0) { if (i > 0) {
old_kmsg += "." + std::to_string(i); old_kmsg += "." + std::to_string(i);
} }
std::string new_kmsg = android::base::StringPrintf("%s.%d", last_kmsg_file, i+1); std::string new_kmsg = android::base::StringPrintf("%s.%d", last_kmsg_file, i + 1);
rename(old_kmsg.c_str(), new_kmsg.c_str()); rename(old_kmsg.c_str(), new_kmsg.c_str());
} }
} }
+8 -14
View File
@@ -17,24 +17,18 @@
#ifndef _ROTATE_LOGS_H #ifndef _ROTATE_LOGS_H
#define _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 */, ssize_t logbasename(log_id_t id, char prio, const char* filename, const char* buf, size_t len,
char /* prio */, void* arg);
const char *filename,
const char * /* buf */, size_t len,
void *arg);
ssize_t logrotate( ssize_t logrotate(log_id_t id, char prio, const char* filename, const char* buf, size_t len,
log_id_t logId, void* arg);
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. // Rename last_log -> last_log.1 -> last_log.2 -> ... -> last_log.$max.
// Similarly rename last_kmsg -> last_kmsg.1 -> ... -> last_kmsg.$max. // Similarly rename last_kmsg -> last_kmsg.1 -> ... -> last_kmsg.$max.