Reduce the duplicated codes.
Change the PATH (use the /opt/usr instead of /opt)
Change-Id: Ib3781819e2e5e83ff8ecd95b26617318e3f50dbb
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
* 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"
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)
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
#include <stdio.h>
#include <stdarg.h>
+#include <stdlib.h>
#include <sys/time.h>
#include <errno.h>
#include <string.h>
#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,
};
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;
}
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;
}
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);
{
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)
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) {
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);
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) {
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);