forked from enlightenment/efl
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.
This commit is contained in:
parent
42309042c6
commit
16c8ab3b18
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue