aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJean-Philippe Andre <jp.andre@samsung.com>2013-06-12 15:04:01 +0900
committerCedric Bail <cedric.bail@samsung.com>2013-06-14 17:09:03 +0900
commit16c8ab3b18a6e2ae5fd0065a5ee4c82bd0aced3b (patch)
tree2e9088a0918868bab6dfc2b437a9cce57381dc1b
parentevas/cserve2: fix crash when shutting down cserve2 (diff)
downloadefl-16c8ab3b18a6e2ae5fd0065a5ee4c82bd0aced3b.tar.gz
evas/cserve2: remove garbage shm files during server init
If server crashes or is forcefully killed, it will not properly cleanup its shm files. So, some memory will be leaked pretty badly.
-rw-r--r--src/bin/evas/evas_cserve2.h2
-rw-r--r--src/bin/evas/evas_cserve2_main.c4
-rw-r--r--src/bin/evas/evas_cserve2_shm.c38
3 files changed, 44 insertions, 0 deletions
diff --git a/src/bin/evas/evas_cserve2.h b/src/bin/evas/evas_cserve2.h
index 277968b7c8..5b4c408438 100644
--- a/src/bin/evas/evas_cserve2.h
+++ b/src/bin/evas/evas_cserve2.h
@@ -266,6 +266,8 @@ void cserve2_slave_kill(Slave *s);
void cserve2_message_handler(int fd, Fd_Flags flags, void *data);
+void cserve2_shm_init();
+void cserve2_shm_shutdown();
Shm_Handle *cserve2_shm_request(size_t size);
void cserve2_shm_unref(Shm_Handle *shm);
const char *cserve2_shm_name_get(const Shm_Handle *shm);
diff --git a/src/bin/evas/evas_cserve2_main.c b/src/bin/evas/evas_cserve2_main.c
index 4c2910689e..0c900443cc 100644
--- a/src/bin/evas/evas_cserve2_main.c
+++ b/src/bin/evas/evas_cserve2_main.c
@@ -358,6 +358,8 @@ main(int argc EINA_UNUSED, const char *argv[])
cserve2_cache_init();
+ cserve2_shm_init();
+
_clients_setup();
cserve2_main_loop_run();
@@ -376,6 +378,8 @@ main(int argc EINA_UNUSED, const char *argv[])
cserve2_main_loop_finish();
+ cserve2_shm_shutdown();
+
eina_prefix_free(_evas_cserve2_pfx);
eina_log_domain_unregister(_evas_cserve2_bin_log_dom);
diff --git a/src/bin/evas/evas_cserve2_shm.c b/src/bin/evas/evas_cserve2_shm.c
index 99b7f25066..0c31e17e34 100644
--- a/src/bin/evas/evas_cserve2_shm.c
+++ b/src/bin/evas/evas_cserve2_shm.c
@@ -193,3 +193,41 @@ cserve2_shm_unmap(Shm_Handle *shm)
munmap(shm->data, shm->image_size);
shm->data = NULL;
}
+
+static void
+_cserve2_shm_cleanup()
+{
+ Eina_Iterator *iter;
+ const Eina_File_Direct_Info *f_info;
+ char pattern[NAME_MAX];
+
+ sprintf(pattern, "evas-shm-img-%x-", (int) getuid());
+ iter = eina_file_direct_ls("/dev/shm");
+ EINA_ITERATOR_FOREACH(iter, f_info)
+ {
+ if (strstr(f_info->path, pattern))
+ {
+ const char *shmname = strrchr(f_info->path, '/');
+ if (!shmname) continue;
+
+ if (shm_unlink(shmname) == -1)
+ ERR("Failed to remove shm entry at %s: %d %s", shmname, errno, strerror(errno));
+ else
+ DBG("cserve2 cleanup: removed %s", shmname);
+ }
+ else
+ DBG("cserve2 cleanup: ignoring %s", f_info->path);
+ }
+}
+
+void
+cserve2_shm_init()
+{
+ _cserve2_shm_cleanup();
+}
+
+void
+cserve2_shm_shutdown()
+{
+ _cserve2_shm_cleanup();
+}