Re: [devel] [PATCH 1/2] base: Add support to direct OpenSAF logging to local node file [#2306]

2018-04-17 Thread Minh Hon Chau

Hi,

If you have time, can you please review the patch?

I have done self review, a few things I think it needs to update

- The redundant headers file in mds_log.cc that were needed for MdsLog 
class should be removed


- The TraceLog::Init needs to return if the Init() has been already done.

- With the support of #2838, the log/trace can be written if application 
is running as non-root user, the new OSAF_LOCAL_NODE_LOG env also needs 
to be documented in a PR doc.


- Another thing, if application uses 2 or more services (say NTF, AMF) 
and enables both NTFSV_TRACE_PATHNAME and AVA_TRACE_PATHNAME as in two 
different paths, but only the first variable path is used for both 
agents' tracing. This seems to be there before #2306, changing this may 
cause a NBC, so maybe just document it somehow


Regards,
Minh
On 12/04/18 09:12, Minh Chau wrote:

Unify TraceLog and MdsLog class to one class (TraceLog) so it can be
used as a common log client.
Add new instance TraceLog for OpenSAF logging to local file, which can
be enabled/disabled via environment variable OSAF_LOCAL_NODE_LOG
---
  src/base/logtrace.cc | 167 ++-
  src/base/logtrace.h  |  50 +--
  src/mds/mds_log.cc   | 114 +++
  3 files changed, 140 insertions(+), 191 deletions(-)

diff --git a/src/base/logtrace.cc b/src/base/logtrace.cc
index b046fab..857e31c 100644
--- a/src/base/logtrace.cc
+++ b/src/base/logtrace.cc
@@ -36,15 +36,10 @@
  #include 
  #include 
  #include 
-#include "base/buffer.h"
-#include "base/conf.h"
-#include "base/log_message.h"
-#include "base/macros.h"
-#include "base/mutex.h"
+#include "base/getenv.h"
  #include "base/ncsgl_defs.h"
  #include "base/osaf_utility.h"
  #include "base/time.h"
-#include "base/unix_client_socket.h"
  #include "dtm/common/osaflog_protocol.h"
  
  namespace global {

@@ -55,65 +50,38 @@ const char *const prefix_name[] = {"EM", "AL", "CR", "ER", "WA", 
"NO", "IN",
 "T6", "T7", "T8", ">>", "<<"};
  char *msg_id;
  int logmask;
+const char* osaf_log_file = "osaf.log";
+bool enable_osaf_log = false;
  
  }  // namespace global
  
-class TraceLog {

- public:
-  static bool Init();
-  static void Log(base::LogMessage::Severity severity, const char *fmt,
-  va_list ap);
-
- private:
-  TraceLog(const std::string , const std::string _name,
-   uint32_t proc_id, const std::string _id,
-   const std::string _name);
-  void LogInternal(base::LogMessage::Severity severity, const char *fmt,
-   va_list ap);
-  static constexpr const uint32_t kMaxSequenceId = uint32_t{0x7fff};
-  static TraceLog *instance_;
-  const base::LogMessage::HostName fqdn_;
-  const base::LogMessage::AppName app_name_;
-  const base::LogMessage::ProcId proc_id_;
-  const base::LogMessage::MsgId msg_id_;
-  uint32_t sequence_id_;
-  base::UnixClientSocket log_socket_;
-  base::Buffer<512> buffer_;
-  base::Mutex mutex_;
-
-  DELETE_COPY_AND_MOVE_OPERATORS(TraceLog);
-};
-
-TraceLog *TraceLog::instance_ = nullptr;
-
-TraceLog::TraceLog(const std::string , const std::string _name,
-   uint32_t proc_id, const std::string _id,
-   const std::string _name)
-: fqdn_{base::LogMessage::HostName{fqdn}},
-  app_name_{base::LogMessage::AppName{app_name}},
-  proc_id_{base::LogMessage::ProcId{std::to_string(proc_id)}},
-  msg_id_{base::LogMessage::MsgId{msg_id}},
-  sequence_id_{1},
-  log_socket_{socket_name, base::UnixSocket::kBlocking},
-  buffer_{},
-  mutex_{} {}
-
-bool TraceLog::Init() {
-  if (instance_ != nullptr) return false;
-  char app_name[49];
-  char pid_path[1024];
+static TraceLog gl_trace;
+static TraceLog gl_osaflog;
+TraceLog::TraceLog()
+: sequence_id_{1}, buffer_{} {
+  mutex_ = nullptr;
+  log_socket_ = nullptr;
+}
+
+TraceLog::~TraceLog() {
+  if (mutex_) delete mutex_;
+  if (log_socket_) delete log_socket_;
+}
+bool TraceLog::Init(const char *msg_id, WriteMode mode) {
+  char app_name[NAME_MAX];
+  char pid_path[PATH_MAX];
uint32_t process_id = getpid();
char *token, *saveptr;
char *pid_name = nullptr;
  
-  memset(app_name, 0, 49);

-  memset(pid_path, 0, 1024);
+  memset(app_name, 0, NAME_MAX);
+  memset(pid_path, 0, PATH_MAX);
  
snprintf(pid_path, sizeof(pid_path), "/proc/%" PRIu32 "/cmdline", process_id);

FILE *f = fopen(pid_path, "r");
if (f != nullptr) {
  size_t size;
-size = fread(pid_path, sizeof(char), 1024, f);
+size = fread(pid_path, sizeof(char), PATH_MAX, f);
  if (size > 0) {
if ('\n' == pid_path[size - 1]) pid_path[size - 1] = '\0';
  }
@@ -131,19 +99,28 @@ bool TraceLog::Init() {
}
base::Conf::InitFullyQualifiedDomainName();
const std::string  = base::Conf::FullyQualifiedDomainName();
-  instance_ = new TraceLog{fqdn, app_name, process_id, global::msg_id,
-   

Re: [devel] [PATCH 0/1] Review Request for base: Re-factor the timer implementation [#2440]

2018-04-17 Thread Ravi Sekhar Reddy Konda
Hi Anders,

I see you have provided an alternate implementation based on AIS TMR API 
instead of legacy NCS Timer API, this is  good.
I hope you have completely taken care of backward compatibility,  cases like in 
the current OpenSAF Services we are using NCS Timer API, can I use new AIS TMR 
API for the new timers, that is at a time can  SAF Service use different timer 
implementations for different Timers?

Me and Syam are reviewing code, we need couple of more days to complete the 
review. Will let you our review comments once done.

This enhancement needs PR doc update also, while we complete the review, can 
you provide the PR doc update also
  
Thanks,
Ravi


-Original Message-
From: Anders Widell [mailto:anders.wid...@ericsson.com] 
Sent: Monday, April 09, 2018 10:00 PM
To: Ravi Sekhar Reddy Konda 
Cc: opensaf-devel@lists.sourceforge.net; Anders Widell 

Subject: [PATCH 0/1] Review Request for base: Re-factor the timer 
implementation [#2440]

Summary: base: Re-factor the timer implementation [#2440] Review request for 
Ticket(s): 2440 Peer Reviewer(s): Ravi Pull request to: 
Affected branch(es): develop
Development branch: ticket-2440
Base revision: b83be452a25a37c7f5b568b436d1af544afb7350
Personal repository: git://git.code.sf.net/u/anders-w/review


Impacted area   Impact y/n

 Docsn
 Build systemn
 RPM/packaging   n
 Configuration files n
 Startup scripts n
 SAF servicesn
 OpenSAF servicesn
 Core libraries  y
 Samples n
 Tests   n
 Other   n


Comments (indicate scope for each "y" above):
-

revision 49be7d5f610fb7e23d8df575007fa3b21a5e0946
Author: Anders Widell 
Date:   Mon, 9 Apr 2018 16:10:41 +0200

base: Re-factor the timer implementation [#2440]

Re-factor the NCS timer implementation and provide the AIS TMR API as an 
alternative way to use the timer implementation, alongside with the old NCS 
API. The AIS TMR API is intended for internal use in OpenSAF services for now, 
but it could be exported as an official OpenSAF API later if it turns out to be 
working well. OpenSAF services using the TMR API instead of the NCS API will no 
longer need a dedicated timer thread.

The new timer implementation is using a C++ STL multiset for the timer queue, 
and a Linux timerfd for the selection object.



Added Files:

 src/ais/include/saTmr.h
 src/base/handle/external_mutex.h
 src/base/handle/handle.cc
 src/base/handle/handle.h
 src/base/handle/object_db.cc
 src/base/handle/object_db.h
 src/base/handle/object.h
 src/base/ncssysf_tmr.cc
 src/base/tests/sa_tmr_test.cc
 src/base/timer/saTmr.cc
 src/base/timer/timer.h
 src/base/timer/timer_handle.cc
 src/base/timer/timer_handle.h


Removed Files:
--
 src/base/sysf_tmr.c


Complete diffstat:
--
 cppcheck_append.cc   |   12 +
 src/ais/Makefile.am  |3 +
 src/ais/include/saTmr.h  |  148 ++
 src/base/Makefile.am |   13 +-
 src/base/handle/external_mutex.h |   66 +++
 src/base/handle/handle.cc|   63 +++
 src/base/handle/handle.h |  107 
 src/base/handle/object.h |   52 ++
 src/base/handle/object_db.cc |   91 
 src/base/handle/object_db.h  |  109 
 src/base/ncssysf_tmr.cc  |  254 +
 src/base/ncssysf_tmr.h   |  135 +++--
 src/base/ncssysf_tsk.h   |4 +-
 src/base/sysf_tmr.c  | 1085 --
 src/base/tests/sa_tmr_test.cc| 1079 +
 src/base/tests/sysf_tmr_test.cc  |  205 +--
 src/base/timer/saTmr.cc  |  569 
 src/base/timer/timer.h   |   55 ++
 src/base/timer/timer_handle.cc   |  190 +++
 src/base/timer/timer_handle.h|  101 
 20 files changed, 3149 insertions(+), 1192 deletions(-)


Testing Commands:
-

make check


Testing, Expected Results:
--

Unit tests shall pass


Conditions of Submission:
-

Ack from reviewer(s), or on 2018-04-16 if no comments have been received.


Arch  Built StartedLinux distro
---
mipsn  n
mips64  n  n
x86 n  n
x86_64  y  y
powerpc n  n
powerpc64   n  n


Reviewer Checklist:
---
[Submitters: make sure that your review doesn't trigger any checkmarks!]


Your checkin has not passed review because (see checked entries):

___ Your RR template is generally incomplete; it has too many blank entries
that need proper data filled in.

___ You have failed to nominate the proper persons for review and push.