summaryrefslogtreecommitdiff
path: root/src/module.c
diff options
context:
space:
mode:
authorSemun Lee <sm79.lee@samsung.com>2014-02-25 20:06:26 +0900
committerSemun Lee <sm79.lee@samsung.com>2014-02-25 20:06:26 +0900
commit92210284ef62357b7a08fbd973d291ee1afe04ec (patch)
treee219cc5a2c18ba8914b427df1f0660cfc264f36e /src/module.c
parentf0e0a08562a88cac22640384e1f8cadbec9f4ce1 (diff)
parentc7bb89ae628988e1555a950c8b478c9de85ef2c6 (diff)
downloadui-gadget-1-92210284ef62357b7a08fbd973d291ee1afe04ec.tar.gz
ui-gadget-1-92210284ef62357b7a08fbd973d291ee1afe04ec.tar.bz2
ui-gadget-1-92210284ef62357b7a08fbd973d291ee1afe04ec.zip
Merge branches 'HEAD' and 'tizen_2.2' into tizen
Conflicts: CMakeLists.txt client/CMakeLists.txt client/ug-client.c include/ui-gadget.h packaging/ui-gadget-1.spec src/manager.c ui-gadget-1.manifest
Diffstat (limited to 'src/module.c')
-rw-r--r--src/module.c73
1 files changed, 73 insertions, 0 deletions
diff --git a/src/module.c b/src/module.c
index 8307325..e07291e 100644
--- a/src/module.c
+++ b/src/module.c
@@ -38,6 +38,9 @@
#define UG_MODULE_INIT_SYM "UG_MODULE_INIT"
#define UG_MODULE_EXIT_SYM "UG_MODULE_EXIT"
+#define MEM_ADDR_LEN 8
+#define MEM_ADDR_TOT_LEN 17
+
static int file_exist(const char *filename)
{
FILE *file;
@@ -49,6 +52,66 @@ static int file_exist(const char *filename)
return 0;
}
+static char *__ug_module_get_addr(const char *ug_so)
+{
+ FILE *file;
+ int ret;
+ char buf[PATH_MAX] = {0,};
+ char mem[PATH_MAX] = {0,};
+
+ char *token_param = NULL;
+ char *saveptr = NULL;
+ int cnt = 0;
+
+ if(ug_so == NULL)
+ goto func_out;
+
+ snprintf(buf, sizeof(buf), "/proc/%d/maps", getpid());
+
+ file = fopen(buf, "r");
+ if (file == NULL) {
+ _WRN("proc open fail(%d)", errno);
+ goto func_out;
+ }
+
+ memset(buf, 0x00, PATH_MAX);
+
+ while(fgets(buf, PATH_MAX, file) != NULL)
+ {
+ if(strstr(buf, ug_so)) {
+ token_param = strtok_r(buf," ", &saveptr);
+ if((token_param == NULL) || (strlen(token_param) > MEM_ADDR_TOT_LEN)) {
+ _ERR("proc token param(%s) error", token_param);
+ goto close_out;
+ }
+
+ if(cnt > 0) {
+ memcpy((void *)(mem+MEM_ADDR_LEN+1),
+ (const void *)(token_param+MEM_ADDR_LEN+1), MEM_ADDR_LEN);
+ } else {
+ memcpy((void *)mem, (const void *)token_param, strlen(token_param));
+ cnt++;
+ }
+ } else {
+ if(cnt > 0)
+ goto close_out;
+ }
+
+ memset(buf, 0x00, PATH_MAX);
+ saveptr = NULL;
+ }
+
+close_out:
+ fclose(file);
+ file = NULL;
+
+func_out:
+ if(strlen(mem) > 0)
+ return strdup(mem);
+ else
+ return NULL;
+}
+
struct ug_module *ug_module_load(const char *name)
{
void *handle;
@@ -78,6 +141,9 @@ struct ug_module *ug_module_load(const char *name)
snprintf(ug_file, PATH_MAX, "/usr/ug/lib/libug-%s.so", name);
if (file_exist(ug_file))
break;
+ snprintf(ug_file, PATH_MAX, "/opt/ug/lib/libug-%s.so", name);
+ if (file_exist(ug_file))
+ break;
snprintf(ug_file, PATH_MAX, "/opt/usr/ug/lib/libug-%s.so", name);
if (file_exist(ug_file))
break;
@@ -105,6 +171,9 @@ struct ug_module *ug_module_load(const char *name)
module->handle = handle;
module->module_name = strdup(name);
+
+ module->addr = __ug_module_get_addr(ug_file);
+
return module;
module_dlclose:
@@ -131,6 +200,7 @@ int ug_module_unload(struct ug_module *module)
else
_ERR("dlsym failed: %s", dlerror());
+ _DBG("dlclose(%s)", module->module_name);
dlclose(module->handle);
module->handle = NULL;
}
@@ -138,6 +208,9 @@ int ug_module_unload(struct ug_module *module)
if(module->module_name)
free(module->module_name);
+ if(module->addr)
+ free(module->addr);
+
free(module);
return 0;
}