From 4e9bf955d6a9aa6781bf130d161a111f11017727 Mon Sep 17 00:00:00 2001 From: Tom Cherry Date: Fri, 15 May 2020 10:13:38 -0700 Subject: [PATCH] logd: remove class LogCommand, rename LogCommand.cpp to LogPermissions.cpp class LogCommand isn't needed, so remove it. Since the rest of LogCommand.cpp only has to do with permissions, rename it appropriately. Test: logging unit tests Change-Id: I32d09c74d00b6e50083e46832eca3dd886b46682 --- logd/Android.bp | 2 +- logd/CommandListener.cpp | 2 +- logd/CommandListener.h | 30 ++++++++++----------- logd/LogBufferElement.cpp | 1 - logd/LogListener.cpp | 2 +- logd/{LogCommand.cpp => LogPermissions.cpp} | 8 ++---- logd/{LogCommand.h => LogPermissions.h} | 16 ++++------- logd/LogReader.cpp | 1 + logd/LogUtils.h | 4 --- 9 files changed, 26 insertions(+), 40 deletions(-) rename logd/{LogCommand.cpp => LogPermissions.cpp} (97%) rename logd/{LogCommand.h => LogPermissions.h} (74%) diff --git a/logd/Android.bp b/logd/Android.bp index ee86566a9..d20306274 100644 --- a/logd/Android.bp +++ b/logd/Android.bp @@ -32,10 +32,10 @@ cc_library_static { name: "liblogd", srcs: [ - "LogCommand.cpp", "ChattyLogBuffer.cpp", "CommandListener.cpp", "LogListener.cpp", + "LogPermissions.cpp", "LogReader.cpp", "LogReaderList.cpp", "LogReaderThread.cpp", diff --git a/logd/CommandListener.cpp b/logd/CommandListener.cpp index 0ff19f859..c6ab22deb 100644 --- a/logd/CommandListener.cpp +++ b/logd/CommandListener.cpp @@ -37,7 +37,7 @@ #include #include -#include "LogUtils.h" +#include "LogPermissions.h" CommandListener::CommandListener(LogBuffer* buf, LogTags* tags, PruneList* prune, LogStatistics* stats) diff --git a/logd/CommandListener.h b/logd/CommandListener.h index d81a1b724..a55a39382 100644 --- a/logd/CommandListener.h +++ b/logd/CommandListener.h @@ -16,10 +16,10 @@ #pragma once +#include #include #include "LogBuffer.h" -#include "LogCommand.h" #include "LogListener.h" #include "LogStatistics.h" #include "LogTags.h" @@ -38,20 +38,20 @@ class CommandListener : public FrameworkListener { PruneList* prune_; LogStatistics* stats_; -#define LogCmd(name, command_string) \ - class name##Cmd : public LogCommand { \ - public: \ - explicit name##Cmd(CommandListener* parent) \ - : LogCommand(#command_string), parent_(parent) {} \ - virtual ~name##Cmd() {} \ - int runCommand(SocketClient* c, int argc, char** argv); \ - \ - private: \ - LogBuffer* buf() const { return parent_->buf_; } \ - LogTags* tags() const { return parent_->tags_; } \ - PruneList* prune() const { return parent_->prune_; } \ - LogStatistics* stats() const { return parent_->stats_; } \ - CommandListener* parent_; \ +#define LogCmd(name, command_string) \ + class name##Cmd : public FrameworkCommand { \ + public: \ + explicit name##Cmd(CommandListener* parent) \ + : FrameworkCommand(#command_string), parent_(parent) {} \ + virtual ~name##Cmd() {} \ + int runCommand(SocketClient* c, int argc, char** argv); \ + \ + private: \ + LogBuffer* buf() const { return parent_->buf_; } \ + LogTags* tags() const { return parent_->tags_; } \ + PruneList* prune() const { return parent_->prune_; } \ + LogStatistics* stats() const { return parent_->stats_; } \ + CommandListener* parent_; \ } LogCmd(Clear, clear); diff --git a/logd/LogBufferElement.cpp b/logd/LogBufferElement.cpp index 0f17cc680..849971559 100644 --- a/logd/LogBufferElement.cpp +++ b/logd/LogBufferElement.cpp @@ -27,7 +27,6 @@ #include #include -#include "LogCommand.h" #include "LogStatistics.h" #include "LogUtils.h" diff --git a/logd/LogListener.cpp b/logd/LogListener.cpp index d2e2efa9e..a6ab50b8a 100644 --- a/logd/LogListener.cpp +++ b/logd/LogListener.cpp @@ -30,7 +30,7 @@ #include "LogBuffer.h" #include "LogListener.h" -#include "LogUtils.h" +#include "LogPermissions.h" LogListener::LogListener(LogBuffer* buf) : socket_(GetLogSocket()), logbuf_(buf) {} diff --git a/logd/LogCommand.cpp b/logd/LogPermissions.cpp similarity index 97% rename from logd/LogCommand.cpp rename to logd/LogPermissions.cpp index 8bff9da46..8f02d5a89 100644 --- a/logd/LogCommand.cpp +++ b/logd/LogPermissions.cpp @@ -14,6 +14,8 @@ * limitations under the License. */ +#include "LogPermissions.h" + #include #include #include @@ -21,12 +23,6 @@ #include -#include "LogCommand.h" -#include "LogUtils.h" - -LogCommand::LogCommand(const char* cmd) : FrameworkCommand(cmd) { -} - // gets a list of supplementary group IDs associated with // the socket peer. This is implemented by opening // /proc/PID/status and look for the "Group:" line. diff --git a/logd/LogCommand.h b/logd/LogPermissions.h similarity index 74% rename from logd/LogCommand.h rename to logd/LogPermissions.h index e10ffa0e6..3130db5f3 100644 --- a/logd/LogCommand.h +++ b/logd/LogPermissions.h @@ -14,17 +14,11 @@ * limitations under the License. */ -#ifndef _LOGD_COMMAND_H -#define _LOGD_COMMAND_H +#pragma once + +#include -#include #include -class LogCommand : public FrameworkCommand { - public: - explicit LogCommand(const char* cmd); - virtual ~LogCommand() { - } -}; - -#endif +bool clientHasLogCredentials(uid_t uid, gid_t gid, pid_t pid); +bool clientHasLogCredentials(SocketClient* cli); diff --git a/logd/LogReader.cpp b/logd/LogReader.cpp index c69e4bd53..89562a414 100644 --- a/logd/LogReader.cpp +++ b/logd/LogReader.cpp @@ -30,6 +30,7 @@ #include "LogBuffer.h" #include "LogBufferElement.h" +#include "LogPermissions.h" #include "LogReader.h" #include "LogUtils.h" #include "LogWriter.h" diff --git a/logd/LogUtils.h b/logd/LogUtils.h index 3fe1bbeff..ce82b4158 100644 --- a/logd/LogUtils.h +++ b/logd/LogUtils.h @@ -60,10 +60,6 @@ static inline const char* strnstr(const char* s, ssize_t len, } } -// Furnished in LogCommand.cpp -bool clientHasLogCredentials(uid_t uid, gid_t gid, pid_t pid); -bool clientHasLogCredentials(SocketClient* cli); - static inline bool worstUidEnabledForLogid(log_id_t id) { return (id == LOG_ID_MAIN) || (id == LOG_ID_SYSTEM) || (id == LOG_ID_RADIO) || (id == LOG_ID_EVENTS);