summaryrefslogtreecommitdiff
path: root/src/lib/ecore
diff options
context:
space:
mode:
authorCedric BAIL <cedric.bail@samsung.com>2013-02-25 09:32:27 +0900
committerCedric BAIL <cedric.bail@samsung.com>2013-02-27 21:10:28 +0900
commit762163bb45e819f7a8668e51b6fbb7977896874f (patch)
treeb6c05e228941357da80a1968a7a9de7ad787dca9 /src/lib/ecore
parentba863894480ad1a8f14c6992e154b1aaa85dc7e5 (diff)
ecore: extend Ecore_Pipe API to make it more useful.
This make it possible to take over a pipe that was open in another process and also prevent its destruction partially during exec.
Diffstat (limited to 'src/lib/ecore')
-rw-r--r--src/lib/ecore/Ecore.h7
-rw-r--r--src/lib/ecore/ecore_pipe.c72
2 files changed, 63 insertions, 16 deletions
diff --git a/src/lib/ecore/Ecore.h b/src/lib/ecore/Ecore.h
index 2f44326dad..a44fbeff9c 100644
--- a/src/lib/ecore/Ecore.h
+++ b/src/lib/ecore/Ecore.h
@@ -2830,10 +2830,17 @@ typedef struct _Ecore_Pipe Ecore_Pipe; /**< A handle for pipes */
2830typedef void (*Ecore_Pipe_Cb)(void *data, void *buffer, unsigned int nbyte); 2830typedef void (*Ecore_Pipe_Cb)(void *data, void *buffer, unsigned int nbyte);
2831 2831
2832EAPI Ecore_Pipe *ecore_pipe_add(Ecore_Pipe_Cb handler, const void *data); 2832EAPI Ecore_Pipe *ecore_pipe_add(Ecore_Pipe_Cb handler, const void *data);
2833EAPI Ecore_Pipe *ecore_pipe_full_add(Ecore_Pipe_Cb handler,
2834 const void *data,
2835 int fd_read, int fd_write,
2836 Eina_Bool read_survive_fork,
2837 Eina_Bool write_survive_fork);
2833EAPI void *ecore_pipe_del(Ecore_Pipe *p); 2838EAPI void *ecore_pipe_del(Ecore_Pipe *p);
2834EAPI Eina_Bool ecore_pipe_write(Ecore_Pipe *p, const void *buffer, unsigned int nbytes); 2839EAPI Eina_Bool ecore_pipe_write(Ecore_Pipe *p, const void *buffer, unsigned int nbytes);
2835EAPI void ecore_pipe_write_close(Ecore_Pipe *p); 2840EAPI void ecore_pipe_write_close(Ecore_Pipe *p);
2836EAPI void ecore_pipe_read_close(Ecore_Pipe *p); 2841EAPI void ecore_pipe_read_close(Ecore_Pipe *p);
2842EAPI int ecore_pipe_read_fd(Ecore_Pipe *p);
2843EAPI int ecore_pipe_write_fd(Ecore_Pipe *p);
2837EAPI void ecore_pipe_thaw(Ecore_Pipe *p); 2844EAPI void ecore_pipe_thaw(Ecore_Pipe *p);
2838EAPI void ecore_pipe_freeze(Ecore_Pipe *p); 2845EAPI void ecore_pipe_freeze(Ecore_Pipe *p);
2839EAPI int ecore_pipe_wait(Ecore_Pipe *p, int message_count, double wait); 2846EAPI int ecore_pipe_wait(Ecore_Pipe *p, int message_count, double wait);
diff --git a/src/lib/ecore/ecore_pipe.c b/src/lib/ecore/ecore_pipe.c
index 1159e82d8d..09b18daeda 100644
--- a/src/lib/ecore/ecore_pipe.c
+++ b/src/lib/ecore/ecore_pipe.c
@@ -179,6 +179,13 @@ out:
179 _ecore_unlock(); 179 _ecore_unlock();
180} 180}
181 181
182EAPI int
183ecore_pipe_read_fd(Ecore_Pipe *p)
184{
185 EINA_MAIN_LOOP_CHECK_RETURN_VAL(PIPE_FD_INVALID);
186 return p->fd_read;
187}
188
182/** 189/**
183 * Stop monitoring if necessary the pipe for reading. See ecore_pipe_thaw() 190 * Stop monitoring if necessary the pipe for reading. See ecore_pipe_thaw()
184 * for monitoring it again. 191 * for monitoring it again.
@@ -281,6 +288,13 @@ out:
281 _ecore_unlock(); 288 _ecore_unlock();
282} 289}
283 290
291EAPI int
292ecore_pipe_write_fd(Ecore_Pipe *p)
293{
294 EINA_MAIN_LOOP_CHECK_RETURN_VAL(PIPE_FD_INVALID);
295 return p->fd_write;
296}
297
284/** 298/**
285 * Write on the file descriptor the data passed as parameter. 299 * Write on the file descriptor the data passed as parameter.
286 * 300 *
@@ -386,14 +400,13 @@ out:
386 return ok; 400 return ok;
387} 401}
388 402
389/** 403EAPI Ecore_Pipe *
390 * @} 404ecore_pipe_full_add(Ecore_Pipe_Cb handler,
391 */ 405 const void *data,
392 406 int fd_read,
393/* Private functions */ 407 int fd_write,
394Ecore_Pipe * 408 Eina_Bool read_survive_fork,
395_ecore_pipe_add(Ecore_Pipe_Cb handler, 409 Eina_Bool write_survive_fork)
396 const void *data)
397{ 410{
398 Ecore_Pipe *p = NULL; 411 Ecore_Pipe *p = NULL;
399 int fds[2]; 412 int fds[2];
@@ -404,20 +417,33 @@ _ecore_pipe_add(Ecore_Pipe_Cb handler,
404 p = ecore_pipe_calloc(1); 417 p = ecore_pipe_calloc(1);
405 if (!p) return NULL; 418 if (!p) return NULL;
406 419
407 if (pipe(fds)) 420 if (fd_read == -1 &&
421 fd_write == -1)
408 { 422 {
409 ecore_pipe_mp_free(p); 423 if (pipe(fds))
410 return NULL; 424 {
425 ecore_pipe_mp_free(p);
426 return NULL;
427 }
428 fd_read = fds[0];
429 fd_write = fds[1];
430 }
431 else
432 {
433 fd_read = fd_read == -1 ? PIPE_FD_INVALID : fd_read;
434 fd_write = fd_write == -1 ? PIPE_FD_INVALID : fd_write;
411 } 435 }
412 436
413 ECORE_MAGIC_SET(p, ECORE_MAGIC_PIPE); 437 ECORE_MAGIC_SET(p, ECORE_MAGIC_PIPE);
414 p->fd_read = fds[0]; 438 p->fd_read = fd_read;
415 p->fd_write = fds[1]; 439 p->fd_write = fd_write;
416 p->handler = handler; 440 p->handler = handler;
417 p->data = data; 441 p->data = data;
418 442
419 _ecore_fd_close_on_exec(fds[0]); 443 if (!read_survive_fork)
420 _ecore_fd_close_on_exec(fds[1]); 444 _ecore_fd_close_on_exec(fd_read);
445 if (!write_survive_fork)
446 _ecore_fd_close_on_exec(fd_write);
421 447
422 fcntl(p->fd_read, F_SETFL, O_NONBLOCK); 448 fcntl(p->fd_read, F_SETFL, O_NONBLOCK);
423 p->fd_handler = ecore_main_fd_handler_add(p->fd_read, 449 p->fd_handler = ecore_main_fd_handler_add(p->fd_read,
@@ -426,7 +452,21 @@ _ecore_pipe_add(Ecore_Pipe_Cb handler,
426 p, 452 p,
427 NULL, NULL); 453 NULL, NULL);
428 454
429 return p; 455 return p;
456}
457
458/**
459 * @}
460 */
461
462/* Private functions */
463Ecore_Pipe *
464_ecore_pipe_add(Ecore_Pipe_Cb handler,
465 const void *data)
466{
467 return ecore_pipe_full_add(handler, data,
468 -1, -1,
469 EINA_FALSE, EINA_FALSE);
430} 470}
431 471
432void * 472void *