Update heap-monitor
authorSung-jae Park <nicesj.park@samsung.com>
Fri, 23 Aug 2013 08:38:38 +0000 (17:38 +0900)
committerSung-jae Park <nicesj.park@samsung.com>
Fri, 23 Aug 2013 09:36:59 +0000 (18:36 +0900)
[model] Redwood
[binary_type] AP
[customer] Docomo/Orange/Open
[issue#] N/A
[problem]
[cause]
[solution]
[team] HomeTF
[request]
[horizontal_expansion]

Change-Id: Iedf45c461392575fa6340508b1a3b94816fe6095

CMakeLists.txt
include/main.h
org.tizen.data-provider-slave.manifest
packaging/org.tizen.data-provider-slave.spec
src/conf.c
src/lb.c
src/main.c
src/so_handler.c
stub/main.c [new file with mode: 0644]

index ef06077..bcfcdbf 100644 (file)
@@ -17,7 +17,6 @@ pkg_check_modules(pkg REQUIRED
        ecore-x
        ecore
        provider
-       heap-monitor
        livebox-service
        edje
        evas
@@ -30,6 +29,8 @@ pkg_check_modules(pkg REQUIRED
 
 SET(PACKAGE "${PROJECT_NAME}")
 SET(LOCALEDIR "/usr/apps/org.tizen.${PROJECT_NAME}/res/locale")
+SET(ICON_PROVIDER "icon-provider-slave")
+SET(EXE_LOADER "${PROJECT_NAME}")
 
 INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include)
 
@@ -39,7 +40,7 @@ ADD_DEFINITIONS("-DPREFIX=\"${CMAKE_INSTALL_PREFIX}\"")
 ADD_DEFINITIONS("-DPATH_MAX=256")
 ADD_DEFINITIONS("-DPACKAGE=\"${PACKAGE}\"")
 ADD_DEFINITIONS("-DLOCALEDIR=\"${LOCALEDIR}\"")
-ADD_DEFINITIONS("-DEXEC_NAME=\"${PROJECT_NAME}\"")
+ADD_DEFINITIONS("-DEXEC_NAME=\"${PROJECT_NAME}.loader\"")
 
 ADD_DEFINITIONS("-DMASTER_PKGNAME=\"data-provider-master\"")
 ADD_DEFINITIONS("-DSLAVE_PKGNAME=\"org.tizen.data-provider-slave\"")
@@ -56,7 +57,7 @@ ADD_DEFINITIONS(${pkg_CFLAGS})
 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Winline -Werror -g -fno-builtin-malloc")
 #SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pie")
 
-ADD_EXECUTABLE(${PROJECT_NAME}
+ADD_EXECUTABLE("${PROJECT_NAME}.loader"
        src/main.c
        src/so_handler.c
        src/fault.c
@@ -67,22 +68,27 @@ ADD_EXECUTABLE(${PROJECT_NAME}
        src/client.c
        src/critical_log.c
 )
+TARGET_LINK_LIBRARIES("${PROJECT_NAME}.loader" ${pkg_LDFLAGS} "-ldl")
 
-TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkg_LDFLAGS} "-ldl")
-
-ADD_EXECUTABLE(icon-provider-slave
+ADD_EXECUTABLE(${ICON_PROVIDER}
        icon_src/main.c
        icon_src/script_handler.c
        src/util.c
 )
-TARGET_LINK_LIBRARIES("icon-provider-slave" ${pkg_LDFLAGS} "-ldl")
+TARGET_LINK_LIBRARIES(${ICON_PROVIDER} ${pkg_LDFLAGS} "-ldl")
+
+ADD_EXECUTABLE(${EXE_LOADER}
+       stub/main.c
+)
+TARGET_LINK_LIBRARIES(${EXE_LOADER} ${pkg_LDFLAGS} "-ldl")
 
 #INSTALL(FILES ${CMAKE_SOURCE_DIR}/org.tizen.data-provider-slave.desktop DESTINATION /usr/share/applications)
 INSTALL(FILES ${CMAKE_SOURCE_DIR}/org.tizen.data-provider-slave.xml DESTINATION /usr/share/packages)
 INSTALL(FILES ${CMAKE_SOURCE_DIR}/LICENSE DESTINATION /usr/share/license RENAME "org.tizen.${PROJECT_NAME}")
-INSTALL(TARGETS ${PROJECT_NAME} DESTINATION /usr/apps/org.tizen.${PROJECT_NAME}/bin PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
+INSTALL(TARGETS "${PROJECT_NAME}.loader" DESTINATION /usr/apps/org.tizen.${PROJECT_NAME}/bin PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
 INSTALL(FILES ${CMAKE_SOURCE_DIR}/org.tizen.data-provider-slave.rule DESTINATION /etc/smack/accesses.d)
-INSTALL(TARGETS "icon-provider-slave" DESTINATION /usr/apps/org.tizen.${PROJECT_NAME}/bin PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
+INSTALL(TARGETS ${ICON_PROVIDER} DESTINATION /usr/apps/org.tizen.${PROJECT_NAME}/bin PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
+INSTALL(TARGETS ${EXE_LOADER} DESTINATION /usr/apps/org.tizen.${PROJECT_NAME}/bin PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
 
 # INCLUDE FOR BUILD & INSTALL .PO FILES
 ADD_SUBDIRECTORY(res)
index fa64b4e..c2ba761 100644 (file)
@@ -15,5 +15,8 @@
  */
 
 extern int main_heap_monitor_is_enabled(void);
+extern size_t main_heap_monitor_target_usage(const char *name);
+extern int main_heap_monitor_add_target(const char *name);
+extern int main_heap_monitor_del_target(const char *name);
 
 /* End of a file */
index b61942c..16f8754 100644 (file)
@@ -14,6 +14,8 @@
 
                <!-- Executable file -->
                <filesystem path="/usr/apps/org.tizen.data-provider-slave/bin/data-provider-slave" label="org.tizen.data-provider-slave" exec_label="org.tizen.data-provider-slave" />
+               <filesystem path="/usr/apps/org.tizen.data-provider-slave/bin/icon-provider-slave" label="org.tizen.data-provider-slave" exec_label="org.tizen.data-provider-slave" />
+               <filesystem path="/usr/apps/org.tizen.data-provider-slave/bin/data-provider-slave.loader" label="org.tizen.data-provider-slave" exec_label="org.tizen.data-provider-slave" />
 
                <!-- For the package manager -->
                <filesystem path="/usr/share/packages/org.tizen.data-provider-slave.xml" label="_" />
index e09fd99..93a411e 100644 (file)
@@ -2,7 +2,7 @@
 
 Name: org.tizen.data-provider-slave
 Summary: Plugin type livebox service provider.
-Version: 0.12.9
+Version: 0.12.10
 Release: 1
 Group: HomeTF/Livebox
 License: Flora License
index 5948ab7..2d566cf 100644 (file)
@@ -83,7 +83,7 @@ HAPI struct conf g_conf = {
                .input = "/dev/input/event1",
        },
 
-       .ping_time = 240.0f,
+       .ping_time = 120.0f,
        .slave_max_load = 30,
 
        .use_sw_backend = 0,
index c80aff6..cfa127b 100644 (file)
--- a/src/lb.c
+++ b/src/lb.c
@@ -854,7 +854,14 @@ int livebox_request_update_by_id(const char *filename)
 
        if (so_current_op() != LIVEBOX_OP_UNKNOWN) {
                ErrPrint("Current operation: %d\n", so_current_op());
-               return LB_STATUS_ERROR_INVALID;
+               /*!
+                * \note
+                * Some case requires to update the content of other box from livebox_XXX ABI.
+                * In that case this function can be used so we have not to filter it from here.
+                * ex) Setting accessibility.
+                * Press the assistive light, turned on, need to update other instances too.
+                * Then the box will use this function from livebox_clicked function.
+                */
        }
 
        EINA_LIST_FOREACH(s_info.item_list, l, item) {
index ce93d65..3626de2 100644 (file)
@@ -19,6 +19,7 @@
 #include <string.h>
 #include <malloc.h>
 #include <mcheck.h>
+#include <dlfcn.h>
 
 #include <Elementary.h>
 
@@ -35,7 +36,6 @@
 
 #include <dlog.h>
 #include <bundle.h>
-#include <heap-monitor.h>
 #include <livebox-service.h>
 #include <provider.h>
 #include <vconf.h>
 #endif
 
 static struct info {
-       int heap_monitor;
        char *font_name;
        int font_size;
+       int (*heap_monitor_initialized)(void);
+       size_t (*heap_monitor_target_usage)(const char *name);
+       int (*heap_monitor_add_target)(const char *name);
+       int (*heap_monitor_del_target)(const char *name);
+       void *heap_monitor;
 } s_info = {
-       .heap_monitor = 0,
        .font_name = NULL,
        .font_size = DEFAULT_FONT_SIZE,
+       .heap_monitor_initialized = NULL,
+       .heap_monitor_target_usage = NULL,
+       .heap_monitor_add_target = NULL,
+       .heap_monitor_del_target = NULL,
+       .heap_monitor = NULL,
 };
 
 static void update_font_cb(void *data)
@@ -335,13 +343,7 @@ static void app_service(service_h service, void *data)
                return;
        }
 
-       if (!!strcasecmp(secured, "true")) {
-               if (s_info.heap_monitor) {
-                       heap_monitor_start();
-                       /* Add GUARD */
-                       // heap_monitor_add_target("/usr/apps/org.tizen."EXEC_NAME"/bin/"EXEC_NAME);
-               }
-       } else {
+       if (!strcasecmp(secured, "true")) {
                /* Don't use the update timer */
                lb_turn_secured_on();
        }
@@ -356,15 +358,6 @@ static void app_service(service_h service, void *data)
        return;
 }
 
-/* From GNU libc 2.14 this macro is defined, to declare
-   hook variables as volatile. Define it as empty for
-   older glibc versions */
-#ifndef __MALLOC_HOOK_VOLATILE
-     #define __MALLOC_HOOK_VOLATILE
-#endif
-
-void (*__MALLOC_HOOK_VOLATILE __malloc_initialize_hook)(void) = heap_monitor_init;
-
 #if defined(_ENABLE_MCHECK)
 static inline void mcheck_cb(enum mcheck_status status)
 {
@@ -400,6 +393,10 @@ int main(int argc, char *argv[])
        app_event_callback_s event_callback;
        const char *option;
 
+       memset(argv[0], 0, strlen(argv[0]));
+       strcpy(argv[0], "/usr/apps/org.tizen.data-provider-slave/bin/data-provider-slave");
+       DbgPrint("Replace argv[0] with %s\n", argv[0]);
+
 #if defined(_ENABLE_MCHECK)
        mcheck(mcheck_cb);
 #endif
@@ -410,7 +407,13 @@ int main(int argc, char *argv[])
 
        option = getenv("PROVIDER_HEAP_MONITOR_START");
        if (option && !strcasecmp(option, "true")) {
-               s_info.heap_monitor = 1;
+               s_info.heap_monitor = dlopen("/usr/lib/libheap-monitor.so", RTLD_NOW);
+               if (s_info.heap_monitor) {
+                       s_info.heap_monitor_initialized = dlsym(s_info.heap_monitor, "heap_monitor_initialized");
+                       s_info.heap_monitor_target_usage = dlsym(s_info.heap_monitor, "heap_monitor_target_usage");
+                       s_info.heap_monitor_add_target = dlsym(s_info.heap_monitor, "heap_monitor_add_target");
+                       s_info.heap_monitor_del_target = dlsym(s_info.heap_monitor, "heap_monitor_del_target");
+               }
        }
 
        setenv("BUFMGR_LOCK_TYPE", "once", 0);
@@ -429,12 +432,33 @@ int main(int argc, char *argv[])
        event_callback.region_format_changed = app_region_changed;
        ret = app_efl_main(&argc, &argv, &event_callback, NULL);
        critical_log_fini();
+       ErrPrint("Failed to init: %d\n", ret);
+       if (s_info.heap_monitor) {
+               if (dlclose(s_info.heap_monitor) < 0) {
+                       ErrPrint("dlclose: %s\n", strerror(errno));
+               }
+       }
        return ret;
 }
 
 HAPI int main_heap_monitor_is_enabled(void)
 {
-       return s_info.heap_monitor;
+       return s_info.heap_monitor_initialized ? s_info.heap_monitor_initialized() : 0;
+}
+
+HAPI size_t main_heap_monitor_target_usage(const char *name)
+{
+       return s_info.heap_monitor_target_usage ? s_info.heap_monitor_target_usage(name) : 0;
+}
+
+HAPI int main_heap_monitor_add_target(const char *name)
+{
+       return s_info.heap_monitor_add_target ? s_info.heap_monitor_add_target(name) : 0;
+}
+
+HAPI int main_heap_monitor_del_target(const char *name)
+{
+       return s_info.heap_monitor_del_target ? s_info.heap_monitor_del_target(name) : 0;
 }
 
 /* End of a file */
index 53fdd4d..64f4342 100644 (file)
@@ -23,7 +23,6 @@
 #include <dlog.h>
 #include <Eina.h>
 #include <provider.h>
-#include <heap-monitor.h>
 #include <livebox-service.h>
 #include <livebox-errno.h>
 
@@ -125,7 +124,7 @@ static void delete_livebox(struct so_item *item)
                ErrPrint("Package %s, finalize returns %d\n", item->pkgname, ret);
        }
 
-       heap_monitor_del_target(item->so_fname);
+       main_heap_monitor_del_target(item->so_fname);
        if (dlclose(item->handle) != 0) {
                ErrPrint("dlclose: %s\n", dlerror());
        }
@@ -277,7 +276,7 @@ static struct so_item *new_adaptor(const char *pkgname, const char *abi)
                fault_unmark_call(pkgname, "initialize", __func__, USE_ALARM);
                if (ret < 0) {
                        ErrPrint("Failed to initialize package %s\n", pkgname);
-                       heap_monitor_del_target(item->so_fname);
+                       main_heap_monitor_del_target(item->so_fname);
                        delete_livebox(item);
                        return NULL;
                }
@@ -423,7 +422,7 @@ static struct so_item *new_livebox(const char *pkgname)
                ErrPrint("symbol: livebox_is_pinned_up - %s\n", dlerror());
        }
 
-       heap_monitor_add_target(item->so_fname);
+       main_heap_monitor_add_target(item->so_fname);
 
        if (item->livebox.initialize) {
                int ret;
@@ -432,7 +431,7 @@ static struct so_item *new_livebox(const char *pkgname)
                fault_unmark_call(pkgname, "initialize", __func__, USE_ALARM);
                if (ret < 0) {
                        ErrPrint("Failed to initialize package %s\n", pkgname);
-                       heap_monitor_del_target(item->so_fname);
+                       main_heap_monitor_del_target(item->so_fname);
                        delete_livebox(item);
                        return NULL;
                }
@@ -992,7 +991,7 @@ HAPI int so_get_output_info(struct instance *inst, int *w, int *h, double *prior
        }
 
        if (main_heap_monitor_is_enabled()) {
-               DbgPrint("%s allocates %d bytes\n", item->pkgname, heap_monitor_target_usage(item->so_fname));
+               DbgPrint("%s allocates %d bytes\n", item->pkgname, main_heap_monitor_target_usage(item->so_fname));
        }
 
        return ret;
diff --git a/stub/main.c b/stub/main.c
new file mode 100644 (file)
index 0000000..3dd2d57
--- /dev/null
@@ -0,0 +1,73 @@
+#include <stdio.h>
+#include <unistd.h>
+#include <errno.h>
+#include <stdlib.h>
+
+#include <dlog.h>
+#include <livebox-errno.h>
+
+#include "debug.h"
+#if defined(LOG_TAG)
+#undef LOG_TAG
+#define LOG_TAG "DATA_PROVIDER_SLAVE_LOADER"
+#endif
+
+int errno;
+
+/*!
+ * Defined for liblivebox
+ */
+const char *livebox_find_pkgname(const char *filename)
+{
+       return NULL;
+}
+
+int livebox_request_update_by_id(const char *filename)
+{
+       return LB_STATUS_ERROR_NOT_EXIST;
+}
+
+int livebox_trigger_update_monitor(const char *id, int is_pd)
+{
+       return LB_STATUS_ERROR_INVALID;
+}
+
+int main(int argc, char *argv[])
+{
+       int i;
+       char **_argv;
+       const char *option;
+
+       if (argc < 4) {
+               return -EINVAL;
+       }
+
+       _argv = malloc(sizeof(char *) * (argc+2));
+       if (!_argv) {
+               ErrPrint("%s\n", strerror(errno));
+               return -ENOMEM;
+       }
+
+       for (i = 1; i < argc; i++) {
+               _argv[i] = strdup(argv[i]);
+       }
+       _argv[i] = NULL;
+
+       _argv[0] = strdup("/usr/apps/org.tizen.data-provider-slave/bin/data-provider-slave.loader");
+       DbgPrint("Replace argv[0] with %s\n", _argv[0]);
+       for (i = 0; i < argc; i++) {
+               DbgPrint("argv[%d]: %s\n", i, _argv[i]);
+       }
+
+       option = getenv("PROVIDER_HEAP_MONITOR_START");
+       if (option && !strcasecmp(option, "true")) {
+               DbgPrint("Heap monitor is enabled\n");
+               setenv("LD_PRELOAD", "/usr/lib/libheap-monitor.so", 1);
+       }
+
+       execvp(_argv[0], _argv);
+       ErrPrint("%s\n", strerror(errno));
+       return 0;
+}
+
+/* End of a file */