diff options
| author | Mark Salyzyn <salyzyn@google.com> | 2016-09-08 13:16:59 -0700 |
|---|---|---|
| committer | Mark Salyzyn <salyzyn@google.com> | 2016-11-17 14:42:33 -0800 |
| commit | c8749d510819d0ea565640adfe38ace7669c7325 (patch) | |
| tree | 1ed74ee6ed325258a89f0e0830a79eed4df906d1 /logd | |
| parent | 3bde05d928fb74a75144ae0eeaa25891c91234d1 (diff) | |
| download | system_core-c8749d510819d0ea565640adfe38ace7669c7325.tar.gz system_core-c8749d510819d0ea565640adfe38ace7669c7325.tar.bz2 system_core-c8749d510819d0ea565640adfe38ace7669c7325.zip | |
logd: add EXIT command
Debugging aid. Allows us to run:
$ cat -n '<STUFF>\0EXIT\0' | nc -U /dev/socket/logd
and the pipeline will exit once done. Without the EXIT command
we will have to <CTRL+C> out to terminate the pipeline. This is
necessary since Android's netcat command does not support the -q
feature, and having the EXIT command is faster and cleaner anyways.
Test: manual as noted above.
Bug: 31456426
Change-Id: I65333358188db85e2eb1bb6a14deed1565826ac4
Diffstat (limited to 'logd')
| -rw-r--r-- | logd/CommandListener.cpp | 16 | ||||
| -rw-r--r-- | logd/CommandListener.h | 44 |
2 files changed, 46 insertions, 14 deletions
diff --git a/logd/CommandListener.cpp b/logd/CommandListener.cpp index 7394f1140..52c67424a 100644 --- a/logd/CommandListener.cpp +++ b/logd/CommandListener.cpp @@ -48,6 +48,7 @@ CommandListener::CommandListener(LogBuffer *buf, LogReader * /*reader*/, registerCmd(new SetPruneListCmd(buf)); registerCmd(new GetPruneListCmd(buf)); registerCmd(new ReinitCmd()); + registerCmd(new ExitCmd(this)); } CommandListener::ShutdownCmd::ShutdownCmd(LogReader *reader, @@ -297,6 +298,21 @@ int CommandListener::ReinitCmd::runCommand(SocketClient *cli, return 0; } +CommandListener::ExitCmd::ExitCmd(CommandListener *parent) : + LogCommand("EXIT"), + mParent(*parent) { +} + +int CommandListener::ExitCmd::runCommand(SocketClient * cli, + int /*argc*/, char ** /*argv*/) { + setname(); + + cli->sendMsg("success"); + release(cli); + + return 0; +} + int CommandListener::getLogSocket() { static const char socketName[] = "logd"; int sock = android_get_control_socket(socketName); diff --git a/logd/CommandListener.h b/logd/CommandListener.h index cbcd601a3..5d5017785 100644 --- a/logd/CommandListener.h +++ b/logd/CommandListener.h @@ -52,22 +52,38 @@ private: explicit name##Cmd(LogBuffer *buf); \ virtual ~name##Cmd() {} \ int runCommand(SocketClient *c, int argc, char ** argv); \ - }; + } - LogBufferCmd(Clear) - LogBufferCmd(GetBufSize) - LogBufferCmd(SetBufSize) - LogBufferCmd(GetBufSizeUsed) - LogBufferCmd(GetStatistics) - LogBufferCmd(GetPruneList) - LogBufferCmd(SetPruneList) + LogBufferCmd(Clear); + LogBufferCmd(GetBufSize); + LogBufferCmd(SetBufSize); + LogBufferCmd(GetBufSizeUsed); + LogBufferCmd(GetStatistics); + LogBufferCmd(GetPruneList); + LogBufferCmd(SetPruneList); - class ReinitCmd : public LogCommand { - public: - ReinitCmd(); - virtual ~ReinitCmd() {} - int runCommand(SocketClient *c, int argc, char ** argv); - }; +#define LogCmd(name) \ + class name##Cmd : public LogCommand { \ + public: \ + name##Cmd(); \ + virtual ~name##Cmd() {} \ + int runCommand(SocketClient *c, int argc, char ** argv); \ + } + + LogCmd(Reinit); + +#define LogParentCmd(name) \ + class name##Cmd : public LogCommand { \ + CommandListener &mParent; \ + public: \ + name##Cmd(); \ + explicit name##Cmd(CommandListener *parent); \ + virtual ~name##Cmd() {} \ + int runCommand(SocketClient *c, int argc, char ** argv); \ + void release(SocketClient *c) { mParent.release(c); } \ + } + + LogParentCmd(Exit); }; |
