summaryrefslogtreecommitdiff
path: root/src/modules/emotion/generic/emotion_generic.c
diff options
context:
space:
mode:
authorGustavo Sverzut Barbieri <barbieri@profusion.mobi>2013-12-21 17:03:38 -0200
committerGustavo Sverzut Barbieri <barbieri@profusion.mobi>2013-12-21 17:08:35 -0200
commit91a27112258a3d29be802146d67ae1f493218e28 (patch)
treefc51d54b925107c505327983cec458eb127a781d /src/modules/emotion/generic/emotion_generic.c
parent376ca3f09b25b5b9b8f5ac43d9367fb3ef21aea1 (diff)
emotion_generic: fix permissions, resource leaks and error handling.
- create permissions as 0700, this should be private to the running user. - do shm_unlink() on error, prevents resource leaks; - apply close() on error, prevents resource leaks; - handle strerror() properly. - shm name uses process id, object name and ecore's time, should be cleaner and avoid possible clashes - ecore_exe do not need to read from slave stdout/err, this removing the flags allows messages to come visible at terminal.
Diffstat (limited to '')
-rw-r--r--src/modules/emotion/generic/emotion_generic.c27
1 files changed, 13 insertions, 14 deletions
diff --git a/src/modules/emotion/generic/emotion_generic.c b/src/modules/emotion/generic/emotion_generic.c
index 02de70732e..9b4303a07a 100644
--- a/src/modules/emotion/generic/emotion_generic.c
+++ b/src/modules/emotion/generic/emotion_generic.c
@@ -121,11 +121,10 @@ _create_shm_data(Emotion_Generic_Video *ev, const char *shmname)
121 size_t size; 121 size_t size;
122 Emotion_Generic_Video_Shared *vs; 122 Emotion_Generic_Video_Shared *vs;
123 123
124 shmfd = shm_open(shmname, O_CREAT | O_RDWR | O_TRUNC, 0777); 124 shmfd = shm_open(shmname, O_CREAT | O_RDWR | O_TRUNC, 0700);
125 if (shmfd == -1) 125 if (shmfd == -1)
126 { 126 {
127 ERR("player: could not open shm: %s", shmname); 127 ERR("player: could not create shm %s: %s", shmname, strerror(errno));
128 ERR("player: %s", strerror(errno));
129 return 0; 128 return 0;
130 } 129 }
131 size = 3 * (ev->w * ev->h * DEFAULTPITCH) + sizeof(*vs); 130 size = 3 * (ev->w * ev->h * DEFAULTPITCH) + sizeof(*vs);
@@ -137,15 +136,19 @@ _create_shm_data(Emotion_Generic_Video *ev, const char *shmname)
137 { 136 {
138 ERR("error when allocating shared memory (size = %zd): " 137 ERR("error when allocating shared memory (size = %zd): "
139 "%s", size, strerror(errno)); 138 "%s", size, strerror(errno));
139 close(shmfd);
140 shm_unlink(shmname); 140 shm_unlink(shmname);
141 return EINA_FALSE; 141 return EINA_FALSE;
142 } 142 }
143 vs = mmap(NULL, size, PROT_READ|PROT_WRITE, MAP_SHARED, shmfd, 0); 143 vs = mmap(NULL, size, PROT_READ|PROT_WRITE, MAP_SHARED, shmfd, 0);
144 if (vs == MAP_FAILED) 144 if (vs == MAP_FAILED)
145 { 145 {
146 ERR("error when mapping shared memory"); 146 ERR("error when mapping shared memory: %s", strerror(errno));
147 close(shmfd);
148 shm_unlink(shmname);
147 return EINA_FALSE; 149 return EINA_FALSE;
148 } 150 }
151 close(shmfd);
149 152
150 vs->size = size; 153 vs->size = size;
151 vs->width = ev->w; 154 vs->width = ev->w;
@@ -159,6 +162,8 @@ _create_shm_data(Emotion_Generic_Video *ev, const char *shmname)
159 if (!eina_semaphore_new(&vs->lock, 1)) 162 if (!eina_semaphore_new(&vs->lock, 1))
160 { 163 {
161 ERR("can not create semaphore"); 164 ERR("can not create semaphore");
165 munmap(vs, size);
166 shm_unlink(shmname);
162 return EINA_FALSE; 167 return EINA_FALSE;
163 } 168 }
164 ev->frame.frames[0] = (unsigned char *)vs + sizeof(*vs); 169 ev->frame.frames[0] = (unsigned char *)vs + sizeof(*vs);
@@ -896,16 +901,12 @@ _player_exec(Emotion_Generic_Video *ev)
896 return EINA_FALSE; 901 return EINA_FALSE;
897 } 902 }
898 903
899 snprintf(buf, sizeof(buf), "%s %d %d\n", ev->engine->path, 904 snprintf(buf, sizeof(buf), "%s %d %d", ev->engine->path,
900 ecore_pipe_read_fd(out), 905 ecore_pipe_read_fd(out),
901 ecore_pipe_write_fd(in)); 906 ecore_pipe_write_fd(in));
902 907
903 ev->player.exe = ecore_exe_pipe_run( 908 ev->player.exe = ecore_exe_pipe_run(
904 buf, 909 buf, ECORE_EXE_NOT_LEADER | ECORE_EXE_TERM_WITH_PARENT, ev);
905 ECORE_EXE_PIPE_READ | ECORE_EXE_PIPE_WRITE |
906 ECORE_EXE_PIPE_READ_LINE_BUFFERED | ECORE_EXE_NOT_LEADER |
907 ECORE_EXE_TERM_WITH_PARENT,
908 ev);
909 910
910 INF("created pipe emotion -> player: %d -> %d", 911 INF("created pipe emotion -> player: %d -> %d",
911 ecore_pipe_write_fd(out), ecore_pipe_read_fd(out)); 912 ecore_pipe_write_fd(out), ecore_pipe_read_fd(out));
@@ -932,11 +933,9 @@ static Eina_Bool
932_fork_and_exec(Emotion_Generic_Video *ev) 933_fork_and_exec(Emotion_Generic_Video *ev)
933{ 934{
934 char shmname[256]; 935 char shmname[256];
935 struct timeval tv;
936 936
937 gettimeofday(&tv, NULL); 937 snprintf(shmname, sizeof(shmname), "/em-generic-shm_%d_%p_%f",
938 snprintf(shmname, sizeof(shmname), "/em-generic-shm_%d_%d", 938 getpid(), ev->obj, ecore_time_get());
939 (int)tv.tv_sec, (int)tv.tv_usec);
940 939
941 ev->shmname = eina_stringshare_add(shmname); 940 ev->shmname = eina_stringshare_add(shmname);
942 941