aboutsummaryrefslogtreecommitdiffstats
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
parentba863894480ad1a8f14c6992e154b1aaa85dc7e5 (diff)
downloadefl-762163bb45e819f7a8668e51b6fbb7977896874f.tar.gz
efl-762163bb45e819f7a8668e51b6fbb7977896874f.tar.xz
efl-762163bb45e819f7a8668e51b6fbb7977896874f.zip
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.
-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 2f44326da..a44fbeff9 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 */
typedef void (*Ecore_Pipe_Cb)(void *data, void *buffer, unsigned int nbyte);
EAPI Ecore_Pipe *ecore_pipe_add(Ecore_Pipe_Cb handler, const void *data);
+EAPI Ecore_Pipe *ecore_pipe_full_add(Ecore_Pipe_Cb handler,
+ const void *data,
+ int fd_read, int fd_write,
+ Eina_Bool read_survive_fork,
+ Eina_Bool write_survive_fork);
EAPI void *ecore_pipe_del(Ecore_Pipe *p);
EAPI Eina_Bool ecore_pipe_write(Ecore_Pipe *p, const void *buffer, unsigned int nbytes);
EAPI void ecore_pipe_write_close(Ecore_Pipe *p);
EAPI void ecore_pipe_read_close(Ecore_Pipe *p);
+EAPI int ecore_pipe_read_fd(Ecore_Pipe *p);
+EAPI int ecore_pipe_write_fd(Ecore_Pipe *p);
EAPI void ecore_pipe_thaw(Ecore_Pipe *p);
EAPI void ecore_pipe_freeze(Ecore_Pipe *p);
EAPI 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 1159e82d8..09b18daed 100644
--- a/src/lib/ecore/ecore_pipe.c
+++ b/src/lib/ecore/ecore_pipe.c
@@ -179,6 +179,13 @@ out:
_ecore_unlock();
}
+EAPI int
+ecore_pipe_read_fd(Ecore_Pipe *p)
+{
+ EINA_MAIN_LOOP_CHECK_RETURN_VAL(PIPE_FD_INVALID);
+ return p->fd_read;
+}
+
/**
* Stop monitoring if necessary the pipe for reading. See ecore_pipe_thaw()
* for monitoring it again.
@@ -281,6 +288,13 @@ out:
_ecore_unlock();
}
+EAPI int
+ecore_pipe_write_fd(Ecore_Pipe *p)
+{
+ EINA_MAIN_LOOP_CHECK_RETURN_VAL(PIPE_FD_INVALID);
+ return p->fd_write;
+}
+
/**
* Write on the file descriptor the data passed as parameter.
*
@@ -386,14 +400,13 @@ out:
return ok;
}
-/**
- * @}
- */
-
-/* Private functions */
-Ecore_Pipe *
-_ecore_pipe_add(Ecore_Pipe_Cb handler,
- const void *data)
+EAPI Ecore_Pipe *
+ecore_pipe_full_add(Ecore_Pipe_Cb handler,
+ const void *data,
+ int fd_read,
+ int fd_write,
+ Eina_Bool read_survive_fork,
+ Eina_Bool write_survive_fork)
{
Ecore_Pipe *p = NULL;
int fds[2];
@@ -404,20 +417,33 @@ _ecore_pipe_add(Ecore_Pipe_Cb handler,
p = ecore_pipe_calloc(1);
if (!p) return NULL;
- if (pipe(fds))
+ if (fd_read == -1 &&
+ fd_write == -1)
{
- ecore_pipe_mp_free(p);
- return NULL;
+ if (pipe(fds))
+ {
+ ecore_pipe_mp_free(p);
+ return NULL;
+ }
+ fd_read = fds[0];
+ fd_write = fds[1];
+ }
+ else
+ {
+ fd_read = fd_read == -1 ? PIPE_FD_INVALID : fd_read;
+ fd_write = fd_write == -1 ? PIPE_FD_INVALID : fd_write;
}
ECORE_MAGIC_SET(p, ECORE_MAGIC_PIPE);
- p->fd_read = fds[0];
- p->fd_write = fds[1];
+ p->fd_read = fd_read;
+ p->fd_write = fd_write;
p->handler = handler;
p->data = data;
- _ecore_fd_close_on_exec(fds[0]);
- _ecore_fd_close_on_exec(fds[1]);
+ if (!read_survive_fork)
+ _ecore_fd_close_on_exec(fd_read);
+ if (!write_survive_fork)
+ _ecore_fd_close_on_exec(fd_write);
fcntl(p->fd_read, F_SETFL, O_NONBLOCK);
p->fd_handler = ecore_main_fd_handler_add(p->fd_read,
@@ -426,7 +452,21 @@ _ecore_pipe_add(Ecore_Pipe_Cb handler,
p,
NULL, NULL);
- return p;
+ return p;
+}
+
+/**
+ * @}
+ */
+
+/* Private functions */
+Ecore_Pipe *
+_ecore_pipe_add(Ecore_Pipe_Cb handler,
+ const void *data)
+{
+ return ecore_pipe_full_add(handler, data,
+ -1, -1,
+ EINA_FALSE, EINA_FALSE);
}
void *