Reduce the duplicated implementations. Change the path
authorSung-jae Park <nicesj.park@samsung.com>
Mon, 22 Oct 2012 11:15:37 +0000 (20:15 +0900)
committerSung-jae Park <nicesj.park@samsung.com>
Mon, 22 Oct 2012 13:38:22 +0000 (22:38 +0900)
Change-Id: Idd8e1ecacf37785ca9014c07459421031f0bd0ba

CMakeLists.txt
include/conf.h
include/critical_log.h
packaging/liblivebox-viewer.spec
src/critical_log.c
src/livebox.c
src/util.c

index 49a516c..7294b81 100644 (file)
@@ -37,11 +37,10 @@ SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
 
 ADD_DEFINITIONS("-DPREFIX=\"${PREFIX}\"")
 ADD_DEFINITIONS("-DLOG_TAG=\"${PROJECT_NAME}\"")
-ADD_DEFINITIONS("-DLIVE_IMAGE_FOLDER=\"/opt/share/live_magazine/\"")
 ADD_DEFINITIONS("-DNDEBUG")
 #ADD_DEFINITIONS("-DFLOG")
 ADD_DEFINITIONS("-DMASTER_PKGNAME=\"com.samsung.data-provider-master\"")
-ADD_DEFINITIONS("-DSOCKET_FILE=\"/opt/share/live_magazine/.live.socket\"")
+ADD_DEFINITIONS("-DSOCKET_FILE=\"/opt/usr/share/live_magazine/.live.socket\"")
 ADD_LIBRARY(${PROJECT_NAME} SHARED
        src/dlist.c
        src/livebox.c
index 313a111..4021ded 100644 (file)
@@ -3,3 +3,6 @@
  * milli seconds
  */
 #define RECONNECT_PERIOD       1000
+#define MAX_LOG_FILE   3
+#define MAX_LOG_LINE   1000
+#define SLAVE_LOG_PATH "/opt/usr/share/live_magazine/log"
index 4f1ebea..8348223 100644 (file)
@@ -1,5 +1,5 @@
 extern int critical_log(const char *func, int line, const char *fmt, ...);
-extern int critical_log_init(void);
+extern int critical_log_init(const char *tag);
 extern int critical_log_fini(void);
 
 #define CRITICAL_LOG(args...) critical_log(__func__, __LINE__, args)
index 135b9e4..aadfaf3 100644 (file)
@@ -1,6 +1,6 @@
 Name: liblivebox-viewer
 Summary: Library for the development of a livebox viewer
-Version: 0.6.8
+Version: 0.6.9
 Release: 1
 Group: main/app
 License: Samsung Proprietary License
index 850d9ae..a432ad9 100644 (file)
@@ -1,5 +1,6 @@
 #include <stdio.h>
 #include <stdarg.h>
+#include <stdlib.h>
 #include <sys/time.h>
 #include <errno.h>
 #include <string.h>
@@ -7,12 +8,23 @@
 #include <sys/types.h>
 #include <unistd.h>
 
+#include <dlog.h>
+
+#include "conf.h"
+#include "debug.h"
+#include "util.h"
 #include "critical_log.h"
 
 static struct {
        FILE *fp;
+       int file_id;
+       int nr_of_lines;
+       char *filename;
 } s_info = {
        .fp = NULL,
+       .file_id = 0,
+       .nr_of_lines = 0,
+       .filename = NULL,
 };
 
 
@@ -27,27 +39,77 @@ int critical_log(const char *func, int line, const char *fmt, ...)
                return -EIO;
 
        gettimeofday(&tv, NULL);
-       fprintf(s_info.fp, "%d %lu.%lu [%s:%d] ", getpid(), tv.tv_sec, tv.tv_usec, basename((char *)func), line);
+       fprintf(s_info.fp, "%d %lu.%lu [%s:%d] ", getpid(), tv.tv_sec, tv.tv_usec, util_basename((char *)func), line);
 
        va_start(ap, fmt);
        ret = vfprintf(s_info.fp, fmt, ap);
        va_end(ap);
+
+       s_info.nr_of_lines++;
+       if (s_info.nr_of_lines == MAX_LOG_LINE) {
+               char *filename;
+               int namelen;
+
+               s_info.file_id = (s_info.file_id + 1) % MAX_LOG_FILE;
+
+               namelen = strlen(s_info.filename) + strlen(SLAVE_LOG_PATH) + 20;
+               filename = malloc(namelen);
+               if (filename) {
+                       snprintf(filename, namelen, "%s/%d_%s", SLAVE_LOG_PATH, s_info.file_id, s_info.filename);
+
+                       if (s_info.fp)
+                               fclose(s_info.fp);
+
+                       s_info.fp = fopen(filename, "w+");
+                       if (!s_info.fp)
+                               ErrPrint("Failed to open a file: %s\n", filename);
+
+                       free(filename);
+               }
+
+               s_info.nr_of_lines = 0;
+       }
        return ret;
 }
 
 
 
-int critical_log_init(void)
+int critical_log_init(const char *name)
 {
+       int namelen;
+       char *filename;
+
        if (s_info.fp)
                return 0;
 
-       s_info.fp = fopen("/opt/var/log/livebox-viewer.log", "a+");
+       s_info.filename = strdup(name);
+       if (!s_info.filename) {
+               ErrPrint("Failed to create a log file\n");
+               return -ENOMEM;
+       }
+
+       namelen = strlen(name) + strlen(SLAVE_LOG_PATH) + 20;
+
+       filename = malloc(namelen);
+       if (!filename) {
+               ErrPrint("Failed to create a log file\n");
+               free(s_info.filename);
+               s_info.filename = NULL;
+               return -ENOMEM;
+       }
+
+       snprintf(filename, namelen, "%s/%d_%s", SLAVE_LOG_PATH, s_info.file_id, name);
+
+       s_info.fp = fopen(filename, "w+");
        if (!s_info.fp) {
-               fprintf(stderr, "Failed to open log: %s\n", strerror(errno));
+               ErrPrint("Failed to open log: %s\n", strerror(errno));
+               free(s_info.filename);
+               s_info.filename = NULL;
+               free(filename);
                return -EIO;
        }
 
+       free(filename);
        return 0;
 }
 
@@ -55,10 +117,16 @@ int critical_log_init(void)
 
 int critical_log_fini(void)
 {
-       if (s_info.fp)
+       if (s_info.filename) {
+               free(s_info.filename);
+               s_info.filename = NULL;
+       }
+
+       if (s_info.fp) {
                fclose(s_info.fp);
+               s_info.fp = NULL;
+       }
 
-       s_info.fp = NULL;
        return 0;
 }
 
index 8c8a57c..fe882cb 100644 (file)
@@ -524,7 +524,7 @@ EAPI int livebox_init(void *disp)
        if (!__file_log_fp)
                __file_log_fp = fdopen(1, "w+t");
 #endif
-       critical_log_init();
+       critical_log_init("viewer");
        livebox_service_init();
        fb_init(disp);
 
@@ -1851,12 +1851,13 @@ EAPI int livebox_is_exists(const char *pkgname)
 {
        char *lb;
 
-       lb = livebox_service_pkgname(pkgname);
-       if (!lb)
-               return util_validate_livebox_package(pkgname) == 0;
+       lb = lb_pkgname(pkgname);
+       if (lb) {
+               free(lb);
+               return 1;
+       }
 
-       free(lb);
-       return 1;
+       return 0;
 }
 
 EAPI const char *livebox_content(struct livebox *handler)
index 385343d..b50d293 100644 (file)
@@ -75,7 +75,7 @@ static inline int check_native_livebox(const char *pkgname)
        char *path;
 
        len = strlen(pkgname) * 2;
-       len += strlen("/opt/live/%s/libexec/liblive-%s.so");
+       len += strlen("/opt/usr/live/%s/libexec/liblive-%s.so");
 
        path = malloc(len + 1);
        if (!path) {
@@ -83,7 +83,7 @@ static inline int check_native_livebox(const char *pkgname)
                return -ENOMEM;
        }
 
-       snprintf(path, len, "/opt/live/%s/libexec/liblive-%s.so", pkgname, pkgname);
+       snprintf(path, len, "/opt/usr/live/%s/libexec/liblive-%s.so", pkgname, pkgname);
        if (access(path, F_OK | R_OK) != 0) {
                ErrPrint("%s is not a valid package\n", pkgname);
                free(path);
@@ -100,7 +100,7 @@ static inline int check_web_livebox(const char *pkgname)
        char *path;
 
        len = strlen(pkgname) * 2;
-       len += strlen("/opts/apps/%s/res/wgt/livebox/index.html");
+       len += strlen("/opt/usr/apps/%s/res/wgt/livebox/index.html");
 
        path = malloc(len + 1);
        if (!path) {
@@ -108,7 +108,7 @@ static inline int check_web_livebox(const char *pkgname)
                return -ENOMEM;
        }
 
-       snprintf(path, len, "/opt/apps/%s/res/wgt/livebox/index.html", pkgname);
+       snprintf(path, len, "/opt/usr/apps/%s/res/wgt/livebox/index.html", pkgname);
        if (access(path, F_OK | R_OK) != 0) {
                ErrPrint("%s is not a valid package\n", pkgname);
                free(path);