Hi Thang & Vu, Thanks for your comments !
I will check and send V2 later. Best Regards, Phuc Chau -----Original Message----- From: Thang [mailto:thang.d.ngu...@dektech.com.au] Sent: Monday, January 6, 2020 02:46 PM To: 'phuc.h.chau' <phuc.h.c...@dektech.com.au>; minh.c...@dektech.com.au; gary....@dektech.com.au; vu.m.ngu...@dektech.com.au Cc: opensaf-devel@lists.sourceforge.net Subject: RE: [devel] [PATCH 1/1] dtm: rotate all logtraces on demand [#3133] Hi Phuc, See my comment inline. -----Original Message----- From: phuc.h.chau <phuc.h.c...@dektech.com.au> Sent: Saturday, January 4, 2020 2:53 PM To: minh.c...@dektech.com.au; gary....@dektech.com.au; vu.m.ngu...@dektech.com.au Cc: opensaf-devel@lists.sourceforge.net Subject: [devel] [PATCH 1/1] dtm: rotate all logtraces on demand [#3133] Adding a new option '--all' that means to rotate all existing logtrace if given along with the '--rotate' option. --- src/dtm/tools/osaflog.cc | 37 ++++++++++++++++++++++++++++--------- src/dtm/transport/log_server.cc | 11 +++++++++++ src/dtm/transport/log_server.h | 1 + 3 files changed, 40 insertions(+), 9 deletions(-) mode change 100644 => 100755 src/dtm/tools/osaflog.cc mode change 100644 => 100755 src/dtm/transport/log_server.cc mode change 100644 => 100755 src/dtm/transport/log_server.h diff --git a/src/dtm/tools/osaflog.cc b/src/dtm/tools/osaflog.cc old mode 100644 new mode 100755 index f6fa168..0efc989 --- a/src/dtm/tools/osaflog.cc +++ b/src/dtm/tools/osaflog.cc @@ -55,6 +55,7 @@ uint64_t Random64Bits(uint64_t seed); bool PrettyPrint(const std::string& log_stream); bool Delete(const std::string& log_stream); bool Rotate(const std::string& log_stream); +bool RotateAll(); std::list<int> OpenLogFiles(const std::string& log_stream); std::string PathName(const std::string& log_stream, int suffix); uint64_t GetInode(int fd); @@ -72,6 +73,7 @@ int main(int argc, char** argv) { {"print", no_argument, nullptr, 'p'}, {"delete", no_argument, nullptr, 'd'}, {"rotate", no_argument, nullptr, 'r'}, + {"all", no_argument, nullptr, 'a'}, {"extract-trace", required_argument, 0, 'e'}, {"max-idle", required_argument, 0, 'i'}, {0, 0, 0, 0}}; @@ -86,6 +88,7 @@ int main(int argc, char** argv) { bool print_result = true; bool delete_result = true; bool rotate_result = true; + bool rotateall_result = true; [Thang]: Maybe no need. Just use existed one, rotate_result bool max_file_size_result = true; bool number_of_backups_result = true; bool max_idle_result = true; @@ -93,6 +96,7 @@ int main(int argc, char** argv) { bool pretty_print_set = false; bool delete_set = false; bool rotate_set = false; + bool rotate_all = false; bool max_file_size_set = false; bool max_backups_set = false; bool max_idle_set = false; @@ -105,7 +109,7 @@ int main(int argc, char** argv) { exit(EXIT_FAILURE); } - while ((option = getopt_long(argc, argv, "m:b:p:f:e:i:r", + while ((option = getopt_long(argc, argv, "m:b:p:f:e:i:r:a", long_options, &long_index)) != -1) { switch (option) { case 'p': @@ -121,6 +125,9 @@ int main(int argc, char** argv) { case 'r': rotate_set = true; break; + case 'a': + rotate_all = true; + break; case 'm': max_file_size = base::StrToUint64(optarg, &max_file_size_set); @@ -176,8 +183,10 @@ int main(int argc, char** argv) { flush_set = true; } - if ((argc <= optind && (pretty_print_set || delete_set || rotate_set)) || - (pretty_print_set && delete_set)) { + if ((argc <= optind && (pretty_print_set || delete_set)) || + (pretty_print_set && delete_set) || + (rotate_all && !rotate_set) || + (argc == optind && rotate_set && !rotate_all)) { PrintUsage(argv[0]); exit(EXIT_FAILURE); } @@ -195,10 +204,12 @@ int main(int argc, char** argv) { delete_result = Delete(argv[optind++]); } } - if (rotate_set == true) { - while (rotate_result && optind < argc) { - rotate_result = Rotate(argv[optind++]); - } + if (rotate_all == true && rotate_set == true) { [Thang]: with above check, maybe only need if (rotate_all == true) { + rotateall_result = RotateAll(); + } else { + while (rotate_result && optind < argc) { + rotate_result = Rotate(argv[optind++]); + } } if (max_backups_set == true) { number_of_backups_result = NoOfBackupFiles(max_backups); @@ -209,8 +220,10 @@ int main(int argc, char** argv) { if (max_idle_set == true) { max_idle_result = SetMaxIdleTime(max_idle); } - if (flush_result && print_result && max_file_size_result && rotate_result && - delete_result && number_of_backups_result && max_idle_result) + + if (flush_result && print_result && max_file_size_result && + rotate_result && delete_result && number_of_backups_result && + max_idle_result && rotateall_result) exit(EXIT_SUCCESS); exit(EXIT_FAILURE); } @@ -237,6 +250,8 @@ void PrintUsage(const char* program_name) { " removing allocated resources in the log\n" " server. Does not delete log files from disk.\n" "--rotate Rotate the specified LOGSTREAM(s).\n" + "--all Rotate all existing LOGSTREAM(s)\n" + " if given along with the '--rotate' option.\n" "--max-file-size=SIZE Set the maximum size of the log file to\n" " SIZE bytes. The log file will be rotated\n" " when it exceeds this size. Suffixes k, M and\n" @@ -398,6 +413,10 @@ bool Rotate(const std::string& log_stream) { return SendCommand(std::string("rotate ") + log_stream); } +bool RotateAll() { + return SendCommand(std::string("rotate-all")); +} + std::list<int> OpenLogFiles(const std::string& log_stream) { std::list<int> result{}; bool last_open_failed = false; diff --git a/src/dtm/transport/log_server.cc b/src/dtm/transport/log_server.cc old mode 100644 new mode 100755 index 201ed26..c022d84 --- a/src/dtm/transport/log_server.cc +++ b/src/dtm/transport/log_server.cc @@ -339,6 +339,16 @@ std::string LogServer::RotateCmd(const std::string& cmd, return std::string{"!rotate " + arg}; } +std::string LogServer::RotateAllCmd(const std::string& cmd, + const std::string& arg) { + syslog(LOG_INFO, "Command is called: %s", cmd.c_str()); + for (const auto& s : log_streams_) { + LogStream* stream = s.second; + stream->Rotate(); + } + return std::string{"!rotate-all" + arg}; } + std::string LogServer::ExecuteCommand(const std::string& command, const std::string& argument) { using CmdPtr = std::string (LogServer::*)(const std::string&, @@ -349,6 +359,7 @@ std::string LogServer::ExecuteCommand(const std::string& command, {"?delete", &LogServer::DeleteCmd}, {"?flush", &LogServer::FlushCmd}, {"?max-idle-time", &LogServer::MaxIdleCmd}, + {"?rotate-all", &LogServer::RotateAllCmd}, {"?rotate", &LogServer::RotateCmd} }; diff --git a/src/dtm/transport/log_server.h b/src/dtm/transport/log_server.h old mode 100644 new mode 100755 index 884a851..9d9c165 --- a/src/dtm/transport/log_server.h +++ b/src/dtm/transport/log_server.h @@ -103,6 +103,7 @@ class LogServer { std::string FlushCmd(const std::string& cmd, const std::string& arg); std::string MaxIdleCmd(const std::string& cmd, const std::string& arg); std::string RotateCmd(const std::string& cmd, const std::string& arg); + std::string RotateAllCmd(const std::string& cmd, const std::string& + arg); int term_fd_; // Configuration for LogServer -- 2.7.4 _______________________________________________ Opensaf-devel mailing list Opensaf-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/opensaf-devel _______________________________________________ Opensaf-devel mailing list Opensaf-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/opensaf-devel