summaryrefslogtreecommitdiff
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
parent42309042c6e63944cda26e9f7f89cf56d6af3643 (diff)
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);
266 266
267void cserve2_message_handler(int fd, Fd_Flags flags, void *data); 267void cserve2_message_handler(int fd, Fd_Flags flags, void *data);
268 268
269void cserve2_shm_init();
270void cserve2_shm_shutdown();
269Shm_Handle *cserve2_shm_request(size_t size); 271Shm_Handle *cserve2_shm_request(size_t size);
270void cserve2_shm_unref(Shm_Handle *shm); 272void cserve2_shm_unref(Shm_Handle *shm);
271const char *cserve2_shm_name_get(const Shm_Handle *shm); 273const 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[])
358 358
359 cserve2_cache_init(); 359 cserve2_cache_init();
360 360
361 cserve2_shm_init();
362
361 _clients_setup(); 363 _clients_setup();
362 364
363 cserve2_main_loop_run(); 365 cserve2_main_loop_run();
@@ -376,6 +378,8 @@ main(int argc EINA_UNUSED, const char *argv[])
376 378
377 cserve2_main_loop_finish(); 379 cserve2_main_loop_finish();
378 380
381 cserve2_shm_shutdown();
382
379 eina_prefix_free(_evas_cserve2_pfx); 383 eina_prefix_free(_evas_cserve2_pfx);
380 384
381 eina_log_domain_unregister(_evas_cserve2_bin_log_dom); 385 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)
193 munmap(shm->data, shm->image_size); 193 munmap(shm->data, shm->image_size);
194 shm->data = NULL; 194 shm->data = NULL;
195} 195}
196
197static void
198_cserve2_shm_cleanup()
199{
200 Eina_Iterator *iter;
201 const Eina_File_Direct_Info *f_info;
202 char pattern[NAME_MAX];
203
204 sprintf(pattern, "evas-shm-img-%x-", (int) getuid());
205 iter = eina_file_direct_ls("/dev/shm");
206 EINA_ITERATOR_FOREACH(iter, f_info)
207 {
208 if (strstr(f_info->path, pattern))
209 {
210 const char *shmname = strrchr(f_info->path, '/');
211 if (!shmname) continue;
212
213 if (shm_unlink(shmname) == -1)
214 ERR("Failed to remove shm entry at %s: %d %s", shmname, errno, strerror(errno));
215 else
216 DBG("cserve2 cleanup: removed %s", shmname);
217 }
218 else
219 DBG("cserve2 cleanup: ignoring %s", f_info->path);
220 }
221}
222
223void
224cserve2_shm_init()
225{
226 _cserve2_shm_cleanup();
227}
228
229void
230cserve2_shm_shutdown()
231{
232 _cserve2_shm_cleanup();
233}