summaryrefslogtreecommitdiff
path: root/src/module.c
diff options
context:
space:
mode:
authorHyungdeuk Kim <hd3.kim@samsung.com>2013-06-25 21:15:18 +0900
committerHyungdeuk Kim <hd3.kim@samsung.com>2013-06-25 21:15:18 +0900
commit48f8ff983274cc286f23b406681daf77d11e57a8 (patch)
treeb161a415dd534be97e9cce7b62223f19a8d7c082 /src/module.c
parent7b502e38e0e6536cea4f72d7ba7d0331b6fa3760 (diff)
downloadui-gadget-1-48f8ff983274cc286f23b406681daf77d11e57a8.tar.gz
ui-gadget-1-48f8ff983274cc286f23b406681daf77d11e57a8.tar.bz2
ui-gadget-1-48f8ff983274cc286f23b406681daf77d11e57a8.zip
merge latest code
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 bd2fedc..ddc34bd 100644
--- a/src/module.c
+++ b/src/module.c
@@ -36,6 +36,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;
@@ -47,6 +50,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;
@@ -76,6 +139,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;
@@ -103,6 +169,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:
@@ -129,6 +198,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;
}
@@ -136,6 +206,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;
}