Update log path
authorSung-jae Park <nicesj.park@samsung.com>
Fri, 13 Dec 2013 12:52:14 +0000 (21:52 +0900)
committerSung-jae Park <nicesj.park@samsung.com>
Fri, 13 Dec 2013 12:52:14 +0000 (21:52 +0900)
Change-Id: Ibe249b56f3d9a8935b67c0179b897d5a28cb38de

data/baltic.conf.ini
data/dump_livebox.sh
data/private.conf.ini
include/util.h
src/main.c
src/server.c
src/util.c

index f556420..644b940 100644 (file)
@@ -18,7 +18,7 @@ max_log_file=3
 sqilte_flush_max=1048576
 db_path=/opt/dbspace/.livebox.db
 share_path=/opt/usr/share/live_magazine/
-log_path=/opt/usr/share/live_magazine/log
+log_path=/tmp/.dbox.service
 always_path=/opt/usr/share/live_magazine/always
 reader_path=/opt/usr/share/live_magazine/reader
 script_port_path=/usr/share/data-provider-master/plugin-script/
index e8e2614..81e06de 100644 (file)
@@ -3,3 +3,4 @@
 LIVEBOX_DEBUG=$1/livebox
 mkdir_function ${LIVEBOX_DEBUG}
 /bin/cp -r /opt/usr/share/live_magazine ${LIVEBOX_DEBUG}
+/bin/cp -r /tmp/.dbox.service ${LIVEBOX_DEBUG}/log
index a25dae6..7f08d10 100644 (file)
@@ -18,7 +18,7 @@ max_log_file=3
 sqilte_flush_max=1048576
 db_path=/opt/dbspace/.livebox.db
 share_path=/opt/usr/share/live_magazine/
-log_path=/opt/usr/share/live_magazine/log
+log_path=/tmp/.dbox.service
 always_path=/opt/usr/share/live_magazine/always
 reader_path=/opt/usr/share/live_magazine/reader
 script_port_path=/usr/share/data-provider-master/plugin-script/
index a43a462..3fe41c5 100644 (file)
@@ -28,6 +28,10 @@ extern const char *util_uri_to_path(const char *uri);
 extern void *util_timer_add(double interval, Eina_Bool (*cb)(void *data), void *data);
 extern void util_timer_interval_set(void *timer, double interval);
 extern double util_time_delay_for_compensation(double period);
+extern void util_setup_log_disk(void);
+extern void util_remove_emergency_disk(void);
+extern void util_prepare_emergency_disk(void);
+extern int util_emergency_disk_is_mounted(void);
 
 #define SCHEMA_FILE    "file://"
 #define SCHEMA_PIXMAP  "pixmap://"
index 9e40ac0..045bc25 100755 (executable)
@@ -21,8 +21,6 @@
 #include <sys/stat.h>
 #include <fcntl.h>
 #include <sys/signalfd.h>
-#include <sys/mount.h>
-#include <sys/smack.h>
 #include <ctype.h>
 
 #include <Ecore.h>
@@ -244,213 +242,6 @@ static Eina_Bool signal_cb(void *data, Ecore_Fd_Handler *handler)
        return ECORE_CALLBACK_RENEW;
 }
 
-static void prepare_emergency_disk(void)
-{
-       char *buf;
-       char *source = NULL;
-       char *type = NULL;
-       char *option = NULL;
-       char *ptr;
-       char *rollback_ptr;
-       int tag_idx;
-       int idx;
-       int len;
-       int ret;
-       static const char *tag[] = {
-               "source",
-               "type",
-               "option",
-               NULL,
-       };
-       enum tag_type {
-               TAG_SOURCE,
-               TAG_TYPE,
-               TAG_OPTION,
-               TAG_ERROR
-       };
-
-       buf = strdup(EMERGENCY_DISK);
-       if (!buf) {
-               ErrPrint("Failed to prepare emergency disk info\n");
-               return;
-       }
-
-       rollback_ptr = ptr = buf;
-       idx = 0;
-       tag_idx = 0;
-       len = strlen(ptr);
-
-       while (tag[tag_idx] != NULL && ptr != (buf + len)) {
-               if (tag[tag_idx][idx] == '\0') {
-                       if (*ptr == '=' || isblank(*ptr)) {
-                               switch (tag_idx) {
-                               case TAG_SOURCE:
-                                       if (source) {
-                                               ErrPrint("source[%s] is overrided\n", source);
-                                       }
-
-                                       while ((*ptr != '\0' && *ptr != ';') && (*ptr == '=' || isblank(*ptr))) {
-                                               ptr++;
-                                       }
-
-                                       source = ptr;
-                                       while (*ptr != '\0' && *ptr != ';') {
-                                               ptr++;
-                                       }
-
-                                       if (*source == '\0') {
-                                               type = NULL;
-                                       }
-
-                                       *ptr = '\0';
-                                       rollback_ptr = ptr + 1;
-                                       idx = 0;
-                                       break;
-                               case TAG_TYPE:
-                                       if (type) {
-                                               ErrPrint("type[%s] is overrided\n", type);
-                                       }
-
-                                       while ((*ptr != '\0' && *ptr != ';') && (*ptr == '=' || isblank(*ptr))) {
-                                               ptr++;
-                                       }
-
-                                       type = ptr;
-                                       while (*ptr != '\0' && *ptr != ';') {
-                                               ptr++;
-                                       }
-
-                                       if (*type == '\0') {
-                                               type = NULL;
-                                       }
-
-                                       *ptr = '\0';
-                                       rollback_ptr = ptr + 1;
-                                       idx = 0;
-                                       break;
-                               case TAG_OPTION:
-                                       if (option) {
-                                               ErrPrint("option[%s] is overrided\n", option);
-                                       }
-
-                                       while ((*ptr != '\0' && *ptr != ';') && (*ptr == '=' || isblank(*ptr))) {
-                                               ptr++;
-                                       }
-
-                                       option = ptr;
-                                       while (*ptr != '\0' && *ptr != ';') {
-                                               ptr++;
-                                       }
-
-                                       if (*option == '\0') {
-                                               option = NULL;
-                                       }
-
-                                       *ptr = '\0';
-                                       rollback_ptr = ptr + 1;
-                                       idx = 0;
-                                       break;
-                               default:
-                                       break;
-                               }
-                       } else {
-                               ptr = rollback_ptr;
-                               tag_idx++;
-                               idx = 0;
-                       }
-               } else if (tag[tag_idx][idx] != *ptr) {
-                       ptr = rollback_ptr;
-                       tag_idx++;
-                       idx = 0;
-               } else {
-                       ptr++;
-                       idx++;
-               } // tag
-       }
-
-       DbgPrint("source[%s] type[%s] option[%s]\n", source, type, option);
-
-       ret = umount(IMAGE_PATH);
-       DbgPrint("Try to unmount[%s] %d\n", IMAGE_PATH, ret);
-       ret = mount(source, IMAGE_PATH, type, MS_NOSUID | MS_NOEXEC, option);
-       DbgFree(buf);
-       if (ret < 0) {
-               ErrPrint("Failed to mount: %s\n", strerror(errno));
-       } else {
-               MINIMUM_SPACE = 0;
-
-               ErrPrint("Disk space is not enough, use the tmpfs. Currently required minimum space is %lu bytes\n", MINIMUM_SPACE);
-               if (chmod(IMAGE_PATH, 0750) < 0) {
-                       ErrPrint("chmod: %s\n", strerror(errno));
-               }
-               if (chown(IMAGE_PATH, 5000, 5000) < 0) {
-                       ErrPrint("chown: %s\n", strerror(errno));
-               }
-
-               ret = smack_setlabel(IMAGE_PATH, DATA_SHARE_LABEL, SMACK_LABEL_ACCESS);
-               if (ret != 0) {
-                       ErrPrint("Failed to set SMACK for %s (%d)\n", IMAGE_PATH, ret);
-               } else {
-                       ret = smack_setlabel(IMAGE_PATH, "1", SMACK_LABEL_TRANSMUTE);
-                       DbgPrint("[%s] is successfully created (t: %d)\n", IMAGE_PATH, ret);
-               }
-
-               if (mkdir(ALWAYS_PATH, 0755) < 0) {
-                       ErrPrint("mkdir: %s\n", strerror(errno));
-               } else {
-                       if (chmod(ALWAYS_PATH, 0750) < 0) {
-                               ErrPrint("chmod: %s\n", strerror(errno));
-                       }
-                       if (chown(ALWAYS_PATH, 5000, 5000) < 0) {
-                               ErrPrint("chown: %s\n", strerror(errno));
-                       }
-                       ret = smack_setlabel(ALWAYS_PATH, DATA_SHARE_LABEL, SMACK_LABEL_ACCESS);
-                       if (ret != 0) {
-                               ErrPrint("Failed to set SMACK for %s (%d)\n", ALWAYS_PATH, ret);
-                       } else {
-                               ret = smack_setlabel(ALWAYS_PATH, "1", SMACK_LABEL_TRANSMUTE);
-                               DbgPrint("[%s] is successfully created (t: %d)\n", ALWAYS_PATH, ret);
-                       }
-               }
-
-               if (mkdir(READER_PATH, 0755) < 0) {
-                       ErrPrint("mkdir: %s\n", strerror(errno));
-               } else {
-                       if (chmod(READER_PATH, 0750) < 0) {
-                               ErrPrint("chmod: %s\n", strerror(errno));
-                       }
-                       if (chown(READER_PATH, 5000, 5000) < 0) {
-                               ErrPrint("chown: %s\n", strerror(errno));
-                       }
-                       ret = smack_setlabel(READER_PATH, DATA_SHARE_LABEL, SMACK_LABEL_ACCESS);
-                       if (ret != 0) {
-                               ErrPrint("Failed to set SMACK for %s (%d)\n", READER_PATH, ret);
-                       } else {
-                               ret = smack_setlabel(READER_PATH, "1", SMACK_LABEL_TRANSMUTE);
-                               DbgPrint("[%s] is successfully created (t: %d)\n", READER_PATH, ret);
-                       }
-               }
-
-               if (mkdir(SLAVE_LOG_PATH, 0755) < 0) {
-                       ErrPrint("mkdir: %s\n", strerror(errno));
-               } else {
-                       if (chmod(SLAVE_LOG_PATH, 0750) < 0) {
-                               ErrPrint("chmod: %s\n", strerror(errno));
-                       }
-                       if (chown(SLAVE_LOG_PATH, 5000, 5000) < 0) {
-                               ErrPrint("chown: %s\n", strerror(errno));
-                       }
-                       ret = smack_setlabel(SLAVE_LOG_PATH, DATA_SHARE_LABEL, SMACK_LABEL_ACCESS);
-                       if (ret != 0) {
-                               ErrPrint("Failed to set SMACK for %s (%d)\n", SLAVE_LOG_PATH, ret);
-                       } else {
-                               ret = smack_setlabel(SLAVE_LOG_PATH, "1", SMACK_LABEL_TRANSMUTE);
-                               DbgPrint("[%s] is successfully created (t: %d)\n", SLAVE_LOG_PATH, ret);
-                       }
-               }
-       }
-}
-
 int main(int argc, char *argv[])
 {
        int ret;
@@ -471,9 +262,12 @@ int main(int argc, char *argv[])
        (void)util_unlink_files(SLAVE_LOG_PATH);
 
        if (util_free_space(IMAGE_PATH) < MINIMUM_SPACE) {
-               prepare_emergency_disk();
+               util_remove_emergency_disk();
+               util_prepare_emergency_disk();
        }
 
+       util_setup_log_disk();
+
        /*!
         * How could we care this return values?
         * Is there any way to print something on the screen?
index 9c92be3..e9a4bf9 100644 (file)
@@ -5991,9 +5991,8 @@ static inline int update_pkg_cb(struct category *category, const char *pkgname,
                if (!inst) {
                        ErrPrint("Failed to create a new instance\n");
                }
-       } else {
-               ErrPrint("Not enough space\n");
        }
+
        return EXIT_SUCCESS;
 }
 
index 214862a..5b89a28 100644 (file)
@@ -25,7 +25,9 @@
 #include <dirent.h>
 #include <ctype.h>
 #include <sys/statvfs.h>
+#include <sys/mount.h>
 
+#include <sys/smack.h>
 #include <dlog.h>
 #include <Eina.h>
 #include <Ecore.h>
 #include "debug.h"
 #include "conf.h"
 
+static struct info {
+       int emergency_mounted;
+} s_info = {
+       .emergency_mounted = 0,
+};
+
 int errno;
 
 HAPI unsigned long util_string_hash(const char *str)
@@ -467,4 +475,247 @@ HAPI int util_unlink_files(const char *folder)
        return LB_STATUS_SUCCESS;
 }
 
+HAPI void util_remove_emergency_disk(void)
+{
+       int ret;
+       ret = umount(IMAGE_PATH);
+       if (ret < 0) {
+               ErrPrint("umount: %s\n", strerror(errno));
+       }
+
+       DbgPrint("Try to unmount[%s] %d\n", IMAGE_PATH, ret);
+       s_info.emergency_mounted = 0;
+}
+
+HAPI void util_prepare_emergency_disk(void)
+{
+       char *buf;
+       char *source = NULL;
+       char *type = NULL;
+       char *option = NULL;
+       char *ptr;
+       char *rollback_ptr;
+       int tag_idx;
+       int idx;
+       int len;
+       int ret;
+       static const char *tag[] = {
+               "source",
+               "type",
+               "option",
+               NULL,
+       };
+       enum tag_type {
+               TAG_SOURCE,
+               TAG_TYPE,
+               TAG_OPTION,
+               TAG_ERROR
+       };
+
+       buf = strdup(EMERGENCY_DISK);
+       if (!buf) {
+               ErrPrint("Failed to prepare emergency disk info\n");
+               return;
+       }
+
+       rollback_ptr = ptr = buf;
+       idx = 0;
+       tag_idx = 0;
+       len = strlen(ptr);
+
+       while (tag[tag_idx] != NULL && ptr != (buf + len)) {
+               if (tag[tag_idx][idx] == '\0') {
+                       if (*ptr == '=' || isblank(*ptr)) {
+                               switch (tag_idx) {
+                               case TAG_SOURCE:
+                                       if (source) {
+                                               ErrPrint("source[%s] is overrided\n", source);
+                                       }
+
+                                       while ((*ptr != '\0' && *ptr != ';') && (*ptr == '=' || isblank(*ptr))) {
+                                               ptr++;
+                                       }
+
+                                       source = ptr;
+                                       while (*ptr != '\0' && *ptr != ';') {
+                                               ptr++;
+                                       }
+
+                                       if (*source == '\0') {
+                                               type = NULL;
+                                       }
+
+                                       *ptr = '\0';
+                                       rollback_ptr = ptr + 1;
+                                       idx = 0;
+                                       break;
+                               case TAG_TYPE:
+                                       if (type) {
+                                               ErrPrint("type[%s] is overrided\n", type);
+                                       }
+
+                                       while ((*ptr != '\0' && *ptr != ';') && (*ptr == '=' || isblank(*ptr))) {
+                                               ptr++;
+                                       }
+
+                                       type = ptr;
+                                       while (*ptr != '\0' && *ptr != ';') {
+                                               ptr++;
+                                       }
+
+                                       if (*type == '\0') {
+                                               type = NULL;
+                                       }
+
+                                       *ptr = '\0';
+                                       rollback_ptr = ptr + 1;
+                                       idx = 0;
+                                       break;
+                               case TAG_OPTION:
+                                       if (option) {
+                                               ErrPrint("option[%s] is overrided\n", option);
+                                       }
+
+                                       while ((*ptr != '\0' && *ptr != ';') && (*ptr == '=' || isblank(*ptr))) {
+                                               ptr++;
+                                       }
+
+                                       option = ptr;
+                                       while (*ptr != '\0' && *ptr != ';') {
+                                               ptr++;
+                                       }
+
+                                       if (*option == '\0') {
+                                               option = NULL;
+                                       }
+
+                                       *ptr = '\0';
+                                       rollback_ptr = ptr + 1;
+                                       idx = 0;
+                                       break;
+                               default:
+                                       break;
+                               }
+                       } else {
+                               ptr = rollback_ptr;
+                               tag_idx++;
+                               idx = 0;
+                       }
+               } else if (tag[tag_idx][idx] != *ptr) {
+                       ptr = rollback_ptr;
+                       tag_idx++;
+                       idx = 0;
+               } else {
+                       ptr++;
+                       idx++;
+               } // tag
+       }
+
+       DbgPrint("source[%s] type[%s] option[%s]\n", source, type, option);
+
+       ret = mount(source, IMAGE_PATH, type, MS_NOSUID | MS_NOEXEC, option);
+       DbgFree(buf);
+       if (ret < 0) {
+               ErrPrint("Failed to mount: %s\n", strerror(errno));
+               return;
+       }
+
+       MINIMUM_SPACE = 0;
+
+       ErrPrint("Disk space is not enough, use the tmpfs. Currently required minimum space is %lu bytes\n", MINIMUM_SPACE);
+       if (chmod(IMAGE_PATH, 0750) < 0) {
+               ErrPrint("chmod: %s\n", strerror(errno));
+       }
+
+       if (chown(IMAGE_PATH, 5000, 5000) < 0) {
+               ErrPrint("chown: %s\n", strerror(errno));
+       }
+
+       ret = smack_setlabel(IMAGE_PATH, DATA_SHARE_LABEL, SMACK_LABEL_ACCESS);
+       if (ret != 0) {
+               ErrPrint("Failed to set SMACK for %s (%d)\n", IMAGE_PATH, ret);
+       } else {
+               ret = smack_setlabel(IMAGE_PATH, "1", SMACK_LABEL_TRANSMUTE);
+               DbgPrint("[%s] is successfully created (t: %d)\n", IMAGE_PATH, ret);
+       }
+
+       if (mkdir(ALWAYS_PATH, 0755) < 0) {
+               ErrPrint("mkdir: (%s) %s\n", ALWAYS_PATH, strerror(errno));
+       } else {
+               if (chmod(ALWAYS_PATH, 0750) < 0) {
+                       ErrPrint("chmod: %s\n", strerror(errno));
+               }
+
+               if (chown(ALWAYS_PATH, 5000, 5000) < 0) {
+                       ErrPrint("chown: %s\n", strerror(errno));
+               }
+
+               ret = smack_setlabel(ALWAYS_PATH, DATA_SHARE_LABEL, SMACK_LABEL_ACCESS);
+               if (ret != 0) {
+                       ErrPrint("Failed to set SMACK for %s (%d)\n", ALWAYS_PATH, ret);
+               } else {
+                       ret = smack_setlabel(ALWAYS_PATH, "1", SMACK_LABEL_TRANSMUTE);
+                       DbgPrint("[%s] is successfully created (t: %d)\n", ALWAYS_PATH, ret);
+               }
+       }
+
+       if (mkdir(READER_PATH, 0755) < 0) {
+               ErrPrint("mkdir: (%s) %s\n", READER_PATH, strerror(errno));
+       } else {
+               if (chmod(READER_PATH, 0750) < 0) {
+                       ErrPrint("chmod: %s\n", strerror(errno));
+               }
+
+               if (chown(READER_PATH, 5000, 5000) < 0) {
+                       ErrPrint("chown: %s\n", strerror(errno));
+               }
+
+               ret = smack_setlabel(READER_PATH, DATA_SHARE_LABEL, SMACK_LABEL_ACCESS);
+               if (ret != 0) {
+                       ErrPrint("Failed to set SMACK for %s (%d)\n", READER_PATH, ret);
+               } else {
+                       ret = smack_setlabel(READER_PATH, "1", SMACK_LABEL_TRANSMUTE);
+                       DbgPrint("[%s] is successfully created (t: %d)\n", READER_PATH, ret);
+               }
+       }
+
+       s_info.emergency_mounted = 1;
+}
+
+HAPI int util_emergency_disk_is_mounted(void)
+{
+       return s_info.emergency_mounted;
+}
+
+HAPI void util_setup_log_disk(void)
+{
+       int ret;
+
+       if (access(SLAVE_LOG_PATH, R_OK | W_OK | X_OK) == 0) {
+               DbgPrint("[%s] is already accessible\n", SLAVE_LOG_PATH);
+               return;
+       }
+
+       DbgPrint("Initiate the critical log folder [%s]\n", SLAVE_LOG_PATH);
+       if (mkdir(SLAVE_LOG_PATH, 0755) < 0) {
+               ErrPrint("mkdir: %s\n", strerror(errno));
+       } else {
+               if (chmod(SLAVE_LOG_PATH, 0750) < 0) {
+                       ErrPrint("chmod: %s\n", strerror(errno));
+               }
+
+               if (chown(SLAVE_LOG_PATH, 5000, 5000) < 0) {
+                       ErrPrint("chown: %s\n", strerror(errno));
+               }
+
+               ret = smack_setlabel(SLAVE_LOG_PATH, DATA_SHARE_LABEL, SMACK_LABEL_ACCESS);
+               if (ret != 0) {
+                       ErrPrint("Failed to set SMACK for %s (%d)\n", SLAVE_LOG_PATH, ret);
+               } else {
+                       ret = smack_setlabel(SLAVE_LOG_PATH, "1", SMACK_LABEL_TRANSMUTE);
+                       DbgPrint("[%s] is successfully created (t: %d)\n", SLAVE_LOG_PATH, ret);
+               }
+       }
+}
+
 /* End of a file */