Added optional input for max logfile size
authorJustin Sobota <jsobota@ti.com>
Mon, 10 Mar 2014 20:52:39 +0000 (16:52 -0400)
committerJustin Sobota <jsobota@ti.com>
Mon, 10 Mar 2014 20:52:39 +0000 (16:52 -0400)
test/k2h/armv7/linux/README.txt
test/k2h/armv7/linux/rm_server.c
test/k2h/armv7/linux/rm_server_osal.c
test/k2h/armv7/linux/serverlogutil.h
test/k2k/armv7/linux/README.txt
test/k2k/armv7/linux/rm_server.c
test/k2k/armv7/linux/rm_server_osal.c
test/k2k/armv7/linux/serverlogutil.h

index 52f273b4bc500c7b6fddf85373c16d8f533751ce..0e7b9bc3a69c4a9c73b6cbf37e86d5dac9eb0ac8 100644 (file)
@@ -18,7 +18,7 @@ For information on how to create new GRLs and Policies please see:
 http://processors.wiki.ti.com/index.php/MCSDK_UG_Chapter_Developing_System_Mgmt#Resource_Manager
 
 To run the Server:
-$ ./rmServer_k2h.out global-resources.dtb server-policy.dtb linux-evm.dtb
+$ ./rmServer_k2h.out global-resources.dtb server-policy.dtb -l linux-evm.dtb
 
 The Server will wait for Client socket connections and service any requests received via those sockets.
 
index 450cdf44d9c79e08d23c035ca67058dda2e985b7..8f17c494410e46fd07a641158c49717bb18ee7fb 100644 (file)
 #include <ti/drv/rm/rm_transport.h>
 
 #define RMSERVER_DAEMON_PID_FILE_NAME "/var/run/rmServer/pid"
-#define RMSERVER_DAEMON_LOG_FILE_NAME "/var/log/rmServer.log"
-
-/* Socket timeout */
-#define SERVER_SOCK_TIMEOUT_USEC     (500)
 
 /* Error checking macro */
 #define ERROR_CHECK(checkVal, resultVal, rmInstName, printMsg)            \
 /* logging debug information */
 #define debug_msg(...) rmsrv_log(LOG_DEBUG, __func__, __FILE__, __LINE__, __VA_ARGS__);
 
-#define LOG_APPEND(x)                              \
-    do {                                           \
-        int len;                                   \
-        len = MAX_LOG_LEN - strlen(rmsrv_log_buf); \
-        if (len > 0) {                             \
-            strncat(rmsrv_log_buf, x, len);        \
-        }                                          \
-        else {                                     \
-            return;                                \
-        }                                          \
+#define LOG_APPEND(x)                                      \
+    do {                                                   \
+        int len;                                           \
+        len = MAX_PRE_LOG_BUF_LEN - strlen(rmsrv_log_buf); \
+        if (len > 0) {                                     \
+            strncat(rmsrv_log_buf, x, len);                \
+        }                                                  \
+        else {                                             \
+            return;                                        \
+        }                                                  \
     } while(0)
 
 /* RM registered transport mapping structure */
@@ -113,7 +109,7 @@ sock_h         server_sock = NULL;
 
 rmserver_cfg_t rmsrv_cfg;
 
-char           rmsrv_log_buf[MAX_LOG_LEN];
+char           rmsrv_log_buf[MAX_PRE_LOG_BUF_LEN];
 
 /**********************************************************************
  ********************** External Variables ****************************
@@ -129,9 +125,10 @@ extern char *optarg;
 /* RM Server logging utility (need to move it to another file) */
 void rmsrv_log(const int loglevel, const char* functionName, const char* fileName, const int lineNo, const char* format, ...)
 {
-    int len;
-    char lineno_a[32];
-    va_list args;
+    int         len;
+    char        lineno_a[32];
+    va_list     args;
+    struct stat fbuf;
 
     sprintf(lineno_a, "%d", lineNo);
 
@@ -144,7 +141,7 @@ void rmsrv_log(const int loglevel, const char* functionName, const char* fileNam
     LOG_APPEND(functionName);
     LOG_APPEND(":");
 
-    len = MAX_LOG_LEN - strlen(rmsrv_log_buf);
+    len = MAX_PRE_LOG_BUF_LEN - strlen(rmsrv_log_buf);
     if (len <= 0) {
         return;
     }
@@ -153,6 +150,12 @@ void rmsrv_log(const int loglevel, const char* functionName, const char* fileNam
     vsnprintf(&rmsrv_log_buf[strlen(rmsrv_log_buf)], len, format, args);
     va_end(args);
 
+    /* logfile reset if going over max_len */
+    fstat(fileno(rmsrv_cfg.logfile_p), &fbuf);
+    if ((fbuf.st_size + strlen(rmsrv_log_buf)) > rmsrv_cfg.logfile_max_len) {
+        freopen(RMSERVER_DAEMON_LOG_FILE_NAME, "w+", rmsrv_cfg.logfile_p);
+    }
+
     fprintf(rmsrv_cfg.logfile_p, "%s", rmsrv_log_buf);
     fflush(rmsrv_cfg.logfile_p);
 }
@@ -354,6 +357,13 @@ static void print_usage(char *appname)
     printf ("Run a resource manager server with the specified [GRL] and [POLICY]\n"
             "[GRL] and [POLICY] must be device tree blob (DTB) files\n"
             "Example: rmserver grl.dtb policy.dtb\n\n"
+            "Configuration:\n"
+            "  -s, --logsize MAXLOGSIZE  MAXLOGSIZE bytes will be written to the\n"
+            "                            log file before the log is reset.  On\n"
+            "                            reset, the log file will be wiped.\n"
+            "\n"
+            "                            The default for MAXLOGSIZE is 8MB if\n"
+            "                            logsize is not specified\n"
             "Optional Input:\n"
             "  -l, --lindtb [LINUX_DTB]  Optionally, provide a Linux DTB file\n"
             "                            that RM will use to reserve resources\n"
@@ -382,17 +392,19 @@ int main(int argc, char *argv[])
     void        *policy;
     void        *lin_dtb = NULL;
     
-
     const struct option longopts[] =
     {
         {"nodaemon", no_argument,       0, 'n'},
         {"kill",        no_argument,       0, 'k'},
         {"help",     no_argument,       0, 'h'},
         {"lindtb",   required_argument, 0, 'l'},
+        {"logsize",  required_argument, 0, 's'},
         {0,          0,                 0,   0},
     };
 
-    while((opt = getopt_long(argc, argv, "nkhl:", longopts, NULL)) != -1) {
+    rmsrv_cfg.logfile_max_len = DEFAULT_LOG_LEN;
+
+    while((opt = getopt_long(argc, argv, "nkhl:s:", longopts, NULL)) != -1) {
         switch (opt) {
             case 'n':
                 daemonize = 0;
@@ -403,6 +415,9 @@ int main(int argc, char *argv[])
             case 'l':
                 lin_dtb_file = optarg;
                 break;
+            case 's':
+                rmsrv_cfg.logfile_max_len = strtol(optarg, NULL, 0);
+                break;
             case 'h':
             default:
                 print_usage(argv[0]);
index 8a4ae07a147132b4b4231c8d0e3d8771ec521d11..e8c16225ddad36a005bc37d307733b1664fbe364 100644 (file)
@@ -44,6 +44,7 @@
 #include <stdarg.h>
 #include <stdlib.h>
 #include <string.h>
+#include <sys/stat.h>
 
 #include "serverlogutil.h"
 
@@ -61,7 +62,7 @@ uint32_t rmFreeCounter   = 0;
  ********************** External Variables ****************************
  **********************************************************************/
 
-extern char rmsrv_log_buf[MAX_LOG_LEN];
+extern char rmsrv_log_buf[MAX_PRE_LOG_BUF_LEN];
 extern rmserver_cfg_t rmsrv_cfg;
 
 /**********************************************************************
@@ -189,12 +190,13 @@ void Osal_rmTaskBlockDelete(void *handle)
  */
 void Osal_rmLog (char *fmt, ... )
 {
-    va_list ap;
-    int     len;
+    va_list     ap;
+    int         len;
+    struct stat fbuf;
 
     rmsrv_log_buf[0] = 0;
 
-    len = MAX_LOG_LEN - strlen(rmsrv_log_buf);
+    len = MAX_PRE_LOG_BUF_LEN - strlen(rmsrv_log_buf);
     if (len <= 0) {
         return;
     }
@@ -203,6 +205,12 @@ void Osal_rmLog (char *fmt, ... )
     vsnprintf(&rmsrv_log_buf[strlen(rmsrv_log_buf)], len, fmt, ap);
     va_end(ap);
 
+    /* logfile reset if going over max_len */
+    fstat(fileno(rmsrv_cfg.logfile_p), &fbuf);
+    if ((fbuf.st_size + strlen(rmsrv_log_buf)) > rmsrv_cfg.logfile_max_len) {
+        freopen(RMSERVER_DAEMON_LOG_FILE_NAME, "w+", rmsrv_cfg.logfile_p);
+    }
+
     fprintf(rmsrv_cfg.logfile_p, "%s", rmsrv_log_buf);
     fflush(rmsrv_cfg.logfile_p);
 }
index d0a10098e9f58ba3177fe16b9ba02b8ff5d6dea0..a0996bcb23f4031f4205aabc8f9b94efa9fe6dc7 100644 (file)
 
 #include <stdio.h>
 
-#define MAX_LOG_LEN (65536)
+#define RMSERVER_DAEMON_LOG_FILE_NAME "/var/log/rmServer.log"
+
+#define MAX_PRE_LOG_BUF_LEN (4096)
+
+/* Default log length before reset is 8MB */
+#define DEFAULT_LOG_LEN     (0x800000)
 
 typedef struct rmserver_cfg_tag {
        FILE *logfile_p;
+    int   logfile_max_len;
 } rmserver_cfg_t;
 
 #endif /* __SERVERLOGUTIL_H__ */
index 5cc094cb540e25360c6d2b13d95fd9991dbf89a0..5624696e678cc24db7f6e554f61781e703005b99 100644 (file)
@@ -18,7 +18,7 @@ For information on how to create new GRLs and Policies please see:
 http://processors.wiki.ti.com/index.php/MCSDK_UG_Chapter_Developing_System_Mgmt#Resource_Manager
 
 To run the Server:
-$ ./rmServer_k2k.out global-resources.dtb server-policy.dtb linux-evm.dtb
+$ ./rmServer_k2k.out global-resources.dtb server-policy.dtb -l linux-evm.dtb
 
 The Server will wait for Client socket connections and service any requests received via those sockets.
 
index 450cdf44d9c79e08d23c035ca67058dda2e985b7..8f17c494410e46fd07a641158c49717bb18ee7fb 100644 (file)
 #include <ti/drv/rm/rm_transport.h>
 
 #define RMSERVER_DAEMON_PID_FILE_NAME "/var/run/rmServer/pid"
-#define RMSERVER_DAEMON_LOG_FILE_NAME "/var/log/rmServer.log"
-
-/* Socket timeout */
-#define SERVER_SOCK_TIMEOUT_USEC     (500)
 
 /* Error checking macro */
 #define ERROR_CHECK(checkVal, resultVal, rmInstName, printMsg)            \
 /* logging debug information */
 #define debug_msg(...) rmsrv_log(LOG_DEBUG, __func__, __FILE__, __LINE__, __VA_ARGS__);
 
-#define LOG_APPEND(x)                              \
-    do {                                           \
-        int len;                                   \
-        len = MAX_LOG_LEN - strlen(rmsrv_log_buf); \
-        if (len > 0) {                             \
-            strncat(rmsrv_log_buf, x, len);        \
-        }                                          \
-        else {                                     \
-            return;                                \
-        }                                          \
+#define LOG_APPEND(x)                                      \
+    do {                                                   \
+        int len;                                           \
+        len = MAX_PRE_LOG_BUF_LEN - strlen(rmsrv_log_buf); \
+        if (len > 0) {                                     \
+            strncat(rmsrv_log_buf, x, len);                \
+        }                                                  \
+        else {                                             \
+            return;                                        \
+        }                                                  \
     } while(0)
 
 /* RM registered transport mapping structure */
@@ -113,7 +109,7 @@ sock_h         server_sock = NULL;
 
 rmserver_cfg_t rmsrv_cfg;
 
-char           rmsrv_log_buf[MAX_LOG_LEN];
+char           rmsrv_log_buf[MAX_PRE_LOG_BUF_LEN];
 
 /**********************************************************************
  ********************** External Variables ****************************
@@ -129,9 +125,10 @@ extern char *optarg;
 /* RM Server logging utility (need to move it to another file) */
 void rmsrv_log(const int loglevel, const char* functionName, const char* fileName, const int lineNo, const char* format, ...)
 {
-    int len;
-    char lineno_a[32];
-    va_list args;
+    int         len;
+    char        lineno_a[32];
+    va_list     args;
+    struct stat fbuf;
 
     sprintf(lineno_a, "%d", lineNo);
 
@@ -144,7 +141,7 @@ void rmsrv_log(const int loglevel, const char* functionName, const char* fileNam
     LOG_APPEND(functionName);
     LOG_APPEND(":");
 
-    len = MAX_LOG_LEN - strlen(rmsrv_log_buf);
+    len = MAX_PRE_LOG_BUF_LEN - strlen(rmsrv_log_buf);
     if (len <= 0) {
         return;
     }
@@ -153,6 +150,12 @@ void rmsrv_log(const int loglevel, const char* functionName, const char* fileNam
     vsnprintf(&rmsrv_log_buf[strlen(rmsrv_log_buf)], len, format, args);
     va_end(args);
 
+    /* logfile reset if going over max_len */
+    fstat(fileno(rmsrv_cfg.logfile_p), &fbuf);
+    if ((fbuf.st_size + strlen(rmsrv_log_buf)) > rmsrv_cfg.logfile_max_len) {
+        freopen(RMSERVER_DAEMON_LOG_FILE_NAME, "w+", rmsrv_cfg.logfile_p);
+    }
+
     fprintf(rmsrv_cfg.logfile_p, "%s", rmsrv_log_buf);
     fflush(rmsrv_cfg.logfile_p);
 }
@@ -354,6 +357,13 @@ static void print_usage(char *appname)
     printf ("Run a resource manager server with the specified [GRL] and [POLICY]\n"
             "[GRL] and [POLICY] must be device tree blob (DTB) files\n"
             "Example: rmserver grl.dtb policy.dtb\n\n"
+            "Configuration:\n"
+            "  -s, --logsize MAXLOGSIZE  MAXLOGSIZE bytes will be written to the\n"
+            "                            log file before the log is reset.  On\n"
+            "                            reset, the log file will be wiped.\n"
+            "\n"
+            "                            The default for MAXLOGSIZE is 8MB if\n"
+            "                            logsize is not specified\n"
             "Optional Input:\n"
             "  -l, --lindtb [LINUX_DTB]  Optionally, provide a Linux DTB file\n"
             "                            that RM will use to reserve resources\n"
@@ -382,17 +392,19 @@ int main(int argc, char *argv[])
     void        *policy;
     void        *lin_dtb = NULL;
     
-
     const struct option longopts[] =
     {
         {"nodaemon", no_argument,       0, 'n'},
         {"kill",        no_argument,       0, 'k'},
         {"help",     no_argument,       0, 'h'},
         {"lindtb",   required_argument, 0, 'l'},
+        {"logsize",  required_argument, 0, 's'},
         {0,          0,                 0,   0},
     };
 
-    while((opt = getopt_long(argc, argv, "nkhl:", longopts, NULL)) != -1) {
+    rmsrv_cfg.logfile_max_len = DEFAULT_LOG_LEN;
+
+    while((opt = getopt_long(argc, argv, "nkhl:s:", longopts, NULL)) != -1) {
         switch (opt) {
             case 'n':
                 daemonize = 0;
@@ -403,6 +415,9 @@ int main(int argc, char *argv[])
             case 'l':
                 lin_dtb_file = optarg;
                 break;
+            case 's':
+                rmsrv_cfg.logfile_max_len = strtol(optarg, NULL, 0);
+                break;
             case 'h':
             default:
                 print_usage(argv[0]);
index 8a4ae07a147132b4b4231c8d0e3d8771ec521d11..e8c16225ddad36a005bc37d307733b1664fbe364 100644 (file)
@@ -44,6 +44,7 @@
 #include <stdarg.h>
 #include <stdlib.h>
 #include <string.h>
+#include <sys/stat.h>
 
 #include "serverlogutil.h"
 
@@ -61,7 +62,7 @@ uint32_t rmFreeCounter   = 0;
  ********************** External Variables ****************************
  **********************************************************************/
 
-extern char rmsrv_log_buf[MAX_LOG_LEN];
+extern char rmsrv_log_buf[MAX_PRE_LOG_BUF_LEN];
 extern rmserver_cfg_t rmsrv_cfg;
 
 /**********************************************************************
@@ -189,12 +190,13 @@ void Osal_rmTaskBlockDelete(void *handle)
  */
 void Osal_rmLog (char *fmt, ... )
 {
-    va_list ap;
-    int     len;
+    va_list     ap;
+    int         len;
+    struct stat fbuf;
 
     rmsrv_log_buf[0] = 0;
 
-    len = MAX_LOG_LEN - strlen(rmsrv_log_buf);
+    len = MAX_PRE_LOG_BUF_LEN - strlen(rmsrv_log_buf);
     if (len <= 0) {
         return;
     }
@@ -203,6 +205,12 @@ void Osal_rmLog (char *fmt, ... )
     vsnprintf(&rmsrv_log_buf[strlen(rmsrv_log_buf)], len, fmt, ap);
     va_end(ap);
 
+    /* logfile reset if going over max_len */
+    fstat(fileno(rmsrv_cfg.logfile_p), &fbuf);
+    if ((fbuf.st_size + strlen(rmsrv_log_buf)) > rmsrv_cfg.logfile_max_len) {
+        freopen(RMSERVER_DAEMON_LOG_FILE_NAME, "w+", rmsrv_cfg.logfile_p);
+    }
+
     fprintf(rmsrv_cfg.logfile_p, "%s", rmsrv_log_buf);
     fflush(rmsrv_cfg.logfile_p);
 }
index d0a10098e9f58ba3177fe16b9ba02b8ff5d6dea0..a0996bcb23f4031f4205aabc8f9b94efa9fe6dc7 100644 (file)
 
 #include <stdio.h>
 
-#define MAX_LOG_LEN (65536)
+#define RMSERVER_DAEMON_LOG_FILE_NAME "/var/log/rmServer.log"
+
+#define MAX_PRE_LOG_BUF_LEN (4096)
+
+/* Default log length before reset is 8MB */
+#define DEFAULT_LOG_LEN     (0x800000)
 
 typedef struct rmserver_cfg_tag {
        FILE *logfile_p;
+    int   logfile_max_len;
 } rmserver_cfg_t;
 
 #endif /* __SERVERLOGUTIL_H__ */