diff --git a/legacy/ethumb/src/bin/Makefile.am b/legacy/ethumb/src/bin/Makefile.am index c733455371..e1b5c809a5 100644 --- a/legacy/ethumb/src/bin/Makefile.am +++ b/legacy/ethumb/src/bin/Makefile.am @@ -19,16 +19,24 @@ ethumb_DEPENDENCIES = $(top_builddir)/config.h if USE_MODULE_ETHUMBD -AM_CPPFLAGS += @EDBUS_CFLAGS@ +AM_CPPFLAGS += @EDBUS_CFLAGS@ \ + -DETHUMB_LIBEXEC_DIR=\"$(libexecdir)\" bin_PROGRAMS += ethumbd ethumbd_client noinst_HEADERS += ethumbd_private.h -ethumbd_SOURCES = ethumbd.c ethumbd_child.c +libexec_PROGRAMS = ethumbd_slave + +ethumbd_SOURCES = ethumbd.c ethumbd_LDADD = \ @EINA_LIBS@ @ECORE_LIBS@ @EDBUS_LIBS@ \ $(top_builddir)/src/lib/libethumb.la ethumbd_DEPENDENCIES = $(top_builddir)/config.h +ethumbd_slave_SOURCES = ethumbd_child.c +ethumbd_slave_LDADD = \ + @EINA_LIBS@ @ECORE_LIBS@ @EDBUS_LIBS@ \ + $(top_builddir)/src/lib/libethumb.la + ethumbd_client_SOURCES = ethumbd_client.c ethumbd_client_LDADD = \ @EINA_LIBS@ @ECORE_LIBS@ \ diff --git a/legacy/ethumb/src/bin/ethumbd.c b/legacy/ethumb/src/bin/ethumbd.c index 5da7e2e89e..0401d7902c 100644 --- a/legacy/ethumb/src/bin/ethumbd.c +++ b/legacy/ethumb/src/bin/ethumbd.c @@ -130,6 +130,16 @@ struct _Ethumb_Queue int *list; }; +struct _Ethumb_Slave +{ + Ecore_Exe *exe; + Ecore_Event_Handler *data_cb; + Ecore_Event_Handler *del_cb; + char *bufcmd; // buffer to read commands from slave + int scmd; // size of command to read + int pcmd; // position in the command buffer +}; + struct _Ethumbd { E_DBus_Connection *conn; @@ -139,11 +149,9 @@ struct _Ethumbd Ecore_Idler *idler; struct _Ethumb_Request *processing; struct _Ethumb_Queue queue; - int pipeout; - int pipein; - Ecore_Fd_Handler *fd_handler; double timeout; Ecore_Timer *timeout_timer; + struct _Ethumb_Slave slave; }; struct _Ethumb_Object_Data @@ -189,6 +197,7 @@ const Ecore_Getopt optdesc = { }; static void _ethumb_dbus_generated_signal(struct _Ethumbd *ed, int *id, const char *thumb_path, const char *thumb_key, Eina_Bool success); +static int _ethumbd_slave_spawn(struct _Ethumbd *ed); static int _ethumbd_timeout_cb(void *data) @@ -270,75 +279,16 @@ _ethumb_dbus_inc_min_id(struct _Ethumb_Object *eobject) } int -_ethumbd_read_safe(int fd, void *buf, ssize_t size) +_ethumbd_write_safe(struct _Ethumbd *ed, const void *buf, ssize_t size) { - ssize_t todo; - char *p; - todo = size; - p = buf; - - while (todo > 0) + if (!ed->slave.exe) { - ssize_t r; - - r = read(fd, p, todo); - if (r > 0) - { - todo -= r; - p += r; - } - else if (r == 0) - return 0; - else - { - if (errno == EINTR || errno == EAGAIN) - continue; - else - { - ERR("could not read from fd %d: %s", - fd, strerror(errno)); - return 0; - } - } - } - - return 1; -} - -int -_ethumbd_write_safe(int fd, const void *buf, ssize_t size) -{ - ssize_t todo; - const char *p; - - todo = size; - p = buf; - - while (todo > 0) - { - ssize_t r; - - r = write(fd, p, todo); - if (r > 0) - { - todo -= r; - p += r; - } - else if (r == 0) - return 0; - else - { - if (errno == EINTR || errno == EAGAIN) - continue; - else - { - ERR("could not write to fd %d: %s", fd, strerror(errno)); - return 0; - } - } + ERR("slave process isn't running.\n"); + return 0; } + ecore_exe_send(ed->slave.exe, buf, size); return 1; } @@ -346,20 +296,20 @@ static void _ethumbd_child_write_op_new(struct _Ethumbd *ed, int index) { int id = ETHUMBD_OP_NEW; - _ethumbd_write_safe(ed->pipeout, &id, sizeof(id)); - _ethumbd_write_safe(ed->pipeout, &index, sizeof(index)); + _ethumbd_write_safe(ed, &id, sizeof(id)); + _ethumbd_write_safe(ed, &index, sizeof(index)); } static void _ethumbd_child_write_op_del(struct _Ethumbd *ed, int index) { int id = ETHUMBD_OP_DEL; - _ethumbd_write_safe(ed->pipeout, &id, sizeof(id)); - _ethumbd_write_safe(ed->pipeout, &index, sizeof(index)); + _ethumbd_write_safe(ed, &id, sizeof(id)); + _ethumbd_write_safe(ed, &index, sizeof(index)); } static void -_ethumbd_pipe_str_write(int fd, const char *str) +_ethumbd_pipe_str_write(struct _Ethumbd *ed, const char *str) { int len; @@ -368,39 +318,8 @@ _ethumbd_pipe_str_write(int fd, const char *str) else len = 0; - _ethumbd_write_safe(fd, &len, sizeof(len)); - _ethumbd_write_safe(fd, str, len); -} - -static int -_ethumbd_pipe_str_read(int fd, char **str) -{ - int size; - int r; - char buf[PATH_MAX]; - - r = _ethumbd_read_safe(fd, &size, sizeof(size)); - if (!r) - { - *str = NULL; - return 0; - } - - if (!size) - { - *str = NULL; - return 1; - } - - r = _ethumbd_read_safe(fd, buf, size); - if (!r) - { - *str = NULL; - return 0; - } - - *str = strdup(buf); - return 1; + _ethumbd_write_safe(ed, &len, sizeof(len)); + _ethumbd_write_safe(ed, str, len); } static void @@ -408,13 +327,13 @@ _ethumbd_child_write_op_generate(struct _Ethumbd *ed, int index, const char *pat { int id = ETHUMBD_OP_GENERATE; - _ethumbd_write_safe(ed->pipeout, &id, sizeof(id)); - _ethumbd_write_safe(ed->pipeout, &index, sizeof(index)); + _ethumbd_write_safe(ed, &id, sizeof(id)); + _ethumbd_write_safe(ed, &index, sizeof(index)); - _ethumbd_pipe_str_write(ed->pipeout, path); - _ethumbd_pipe_str_write(ed->pipeout, key); - _ethumbd_pipe_str_write(ed->pipeout, thumb_path); - _ethumbd_pipe_str_write(ed->pipeout, thumb_key); + _ethumbd_pipe_str_write(ed, path); + _ethumbd_pipe_str_write(ed, key); + _ethumbd_pipe_str_write(ed, thumb_path); + _ethumbd_pipe_str_write(ed, thumb_key); } static void @@ -435,47 +354,153 @@ _generated_cb(struct _Ethumbd *ed, Eina_Bool success, const char *thumb_path, co ed->processing = NULL; } +static void +_ethumbd_slave_cmd_ready(struct _Ethumbd *ed) +{ + char *bufcmd = ed->slave.bufcmd; + Eina_Bool *success; + char *thumb_path, *thumb_key; + int *size_path, *size_key; + + + success = (Eina_Bool *)bufcmd; + bufcmd += sizeof(*success); + + size_path = (int *)bufcmd; + bufcmd += sizeof(*size_path); + + write(STDERR_FILENO, bufcmd, ed->slave.scmd); + + thumb_path = bufcmd; + bufcmd += *size_path; + + size_key = (int *)bufcmd; + bufcmd += sizeof(*size_key); + + thumb_key = bufcmd; + + _generated_cb(ed, *success, thumb_path, thumb_key); + + free(ed->slave.bufcmd); + ed->slave.bufcmd = NULL; + ed->slave.scmd = 0; +} + static int -_ethumbd_fd_handler(void *data, Ecore_Fd_Handler *fd_handler) +_ethumbd_slave_alloc_cmd(struct _Ethumbd *ed, int ssize, char *sdata) +{ + int *scmd; + + if (ed->slave.bufcmd) + return 0; + + scmd = (int *)sdata; + if (ssize < sizeof(*scmd)) { + ERR("could not read size of command.\n"); + return 0; + } + ed->slave.bufcmd = malloc(*scmd); + ed->slave.scmd = *scmd; + ed->slave.pcmd = 0; + + return sizeof(*scmd); +} + +static int +_ethumbd_slave_data_read_cb(void *data, int type, void *event) { struct _Ethumbd *ed = data; - Eina_Bool success; - int r; - char *thumb_path, *thumb_key; + Ecore_Exe_Event_Data *ev = event; + int ssize; + char *sdata; - if (ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_ERROR)) + if (ev->exe != ed->slave.exe) { - ERR("error on pipein! child exiting...\n"); - ed->fd_handler = NULL; - ecore_main_loop_quit(); + ERR("PARENT ERROR: slave != ev->exe\n"); return 0; } - r = _ethumbd_read_safe(ed->pipein, &success, sizeof(success)); - if (!r) + ssize = ev->size; + sdata = ev->data; + + write(STDERR_FILENO, sdata, ssize); + + while (ssize > 0) { - ERR("ethumbd child exited!\n"); - ed->fd_handler = NULL; - return 0; + if (!ed->slave.bufcmd) + { + int n; + n = _ethumbd_slave_alloc_cmd(ed, ssize, sdata); + ssize -= n; + sdata += n; + } + else + { + char *bdata; + int nbytes; + bdata = ed->slave.bufcmd + ed->slave.pcmd; + nbytes = ed->slave.scmd - ed->slave.pcmd; + nbytes = ssize < nbytes ? ssize : nbytes; + memcpy(bdata, sdata, nbytes); + sdata += nbytes; + ssize -= nbytes; + ed->slave.pcmd += nbytes; + + if (ed->slave.pcmd == ed->slave.scmd) + _ethumbd_slave_cmd_ready(ed); + } } - r = _ethumbd_pipe_str_read(ed->pipein, &thumb_path); - r = _ethumbd_pipe_str_read(ed->pipein, &thumb_key); - _generated_cb(ed, success, thumb_path, thumb_key); - - free(thumb_path); - free(thumb_key); - return 1; } +static int +_ethumbd_slave_del_cb(void *data, int type, void *event) +{ + struct _Ethumbd *ed = data; + Ecore_Exe_Event_Del *ev = event; + int i; + + if (ev->exe != ed->slave.exe) + return 1; + + if (ev->exited) + ERR("slave exited with code: %d\n", ev->exit_code); + else if (ev->signalled) + ERR("slave exited by signal: %d\n", ev->exit_signal); + + if (!ed->processing) + goto end; + + i = ed->queue.current; + ERR("failed to generate thumbnail for: \"%s:%s\"\n", + ed->processing->file, ed->processing->key); + + if (ed->queue.table[i].used) + _ethumb_dbus_generated_signal + (ed, &ed->processing->id, NULL, NULL, EINA_FALSE); + eina_stringshare_del(ed->processing->file); + eina_stringshare_del(ed->processing->key); + eina_stringshare_del(ed->processing->thumb); + eina_stringshare_del(ed->processing->thumb_key); + free(ed->processing); + ed->processing = NULL; + +end: + ed->slave.exe = NULL; + if (ed->slave.bufcmd) + free(ed->slave.bufcmd); + + return _ethumbd_slave_spawn(ed); +} + static void -_ethumbd_pipe_write_setup(int fd, int type, const void *data) +_ethumbd_pipe_write_setup(struct _Ethumbd *ed, int type, const void *data) { const int *i_value; const float *f_value; - _ethumbd_write_safe(fd, &type, sizeof(type)); + _ethumbd_write_safe(ed, &type, sizeof(type)); switch (type) { @@ -490,7 +515,7 @@ _ethumbd_pipe_write_setup(int fd, int type, const void *data) case ETHUMBD_VIDEO_NTIMES: case ETHUMBD_VIDEO_FPS: i_value = data; - _ethumbd_write_safe(fd, i_value, sizeof(*i_value)); + _ethumbd_write_safe(ed, i_value, sizeof(*i_value)); break; case ETHUMBD_CROP_X: case ETHUMBD_CROP_Y: @@ -498,14 +523,14 @@ _ethumbd_pipe_write_setup(int fd, int type, const void *data) case ETHUMBD_VIDEO_START: case ETHUMBD_VIDEO_INTERVAL: f_value = data; - _ethumbd_write_safe(fd, f_value, sizeof(*f_value)); + _ethumbd_write_safe(ed, f_value, sizeof(*f_value)); break; case ETHUMBD_DIRECTORY: case ETHUMBD_CATEGORY: case ETHUMBD_FRAME_FILE: case ETHUMBD_FRAME_GROUP: case ETHUMBD_FRAME_SWALLOW: - _ethumbd_pipe_str_write(fd, data); + _ethumbd_pipe_str_write(ed, data); break; case ETHUMBD_SETUP_FINISHED: break; @@ -519,58 +544,57 @@ _process_setup(struct _Ethumbd *ed) { int op_id = ETHUMBD_OP_SETUP; int index = ed->queue.current; - int fd = ed->pipeout; struct _Ethumb_Setup *setup = &ed->processing->setup; - _ethumbd_write_safe(ed->pipeout, &op_id, sizeof(op_id)); - _ethumbd_write_safe(ed->pipeout, &index, sizeof(index)); + _ethumbd_write_safe(ed, &op_id, sizeof(op_id)); + _ethumbd_write_safe(ed, &index, sizeof(index)); if (setup->flags.fdo) - _ethumbd_pipe_write_setup(fd, ETHUMBD_FDO, &setup->fdo); + _ethumbd_pipe_write_setup(ed, ETHUMBD_FDO, &setup->fdo); if (setup->flags.size) { - _ethumbd_pipe_write_setup(fd, ETHUMBD_SIZE_W, &setup->tw); - _ethumbd_pipe_write_setup(fd, ETHUMBD_SIZE_H, &setup->th); + _ethumbd_pipe_write_setup(ed, ETHUMBD_SIZE_W, &setup->tw); + _ethumbd_pipe_write_setup(ed, ETHUMBD_SIZE_H, &setup->th); } if (setup->flags.format) - _ethumbd_pipe_write_setup(fd, ETHUMBD_FORMAT, &setup->format); + _ethumbd_pipe_write_setup(ed, ETHUMBD_FORMAT, &setup->format); if (setup->flags.aspect) - _ethumbd_pipe_write_setup(fd, ETHUMBD_ASPECT, &setup->aspect); + _ethumbd_pipe_write_setup(ed, ETHUMBD_ASPECT, &setup->aspect); if (setup->flags.crop) { - _ethumbd_pipe_write_setup(fd, ETHUMBD_CROP_X, &setup->cx); - _ethumbd_pipe_write_setup(fd, ETHUMBD_CROP_Y, &setup->cy); + _ethumbd_pipe_write_setup(ed, ETHUMBD_CROP_X, &setup->cx); + _ethumbd_pipe_write_setup(ed, ETHUMBD_CROP_Y, &setup->cy); } if (setup->flags.quality) - _ethumbd_pipe_write_setup(fd, ETHUMBD_QUALITY, &setup->quality); + _ethumbd_pipe_write_setup(ed, ETHUMBD_QUALITY, &setup->quality); if (setup->flags.compress) - _ethumbd_pipe_write_setup(fd, ETHUMBD_COMPRESS, &setup->compress); + _ethumbd_pipe_write_setup(ed, ETHUMBD_COMPRESS, &setup->compress); if (setup->flags.directory) - _ethumbd_pipe_write_setup(fd, ETHUMBD_DIRECTORY, setup->directory); + _ethumbd_pipe_write_setup(ed, ETHUMBD_DIRECTORY, setup->directory); if (setup->flags.category) - _ethumbd_pipe_write_setup(fd, ETHUMBD_CATEGORY, setup->category); + _ethumbd_pipe_write_setup(ed, ETHUMBD_CATEGORY, setup->category); if (setup->flags.frame) { - _ethumbd_pipe_write_setup(fd, ETHUMBD_FRAME_FILE, setup->theme_file); - _ethumbd_pipe_write_setup(fd, ETHUMBD_FRAME_GROUP, setup->group); - _ethumbd_pipe_write_setup(fd, ETHUMBD_FRAME_SWALLOW, setup->swallow); + _ethumbd_pipe_write_setup(ed, ETHUMBD_FRAME_FILE, setup->theme_file); + _ethumbd_pipe_write_setup(ed, ETHUMBD_FRAME_GROUP, setup->group); + _ethumbd_pipe_write_setup(ed, ETHUMBD_FRAME_SWALLOW, setup->swallow); } if (setup->flags.video_time) - _ethumbd_pipe_write_setup(fd, ETHUMBD_VIDEO_TIME, &setup->video_time); + _ethumbd_pipe_write_setup(ed, ETHUMBD_VIDEO_TIME, &setup->video_time); if (setup->flags.video_start) - _ethumbd_pipe_write_setup(fd, ETHUMBD_VIDEO_START, &setup->video_start); + _ethumbd_pipe_write_setup(ed, ETHUMBD_VIDEO_START, &setup->video_start); if (setup->flags.video_interval) - _ethumbd_pipe_write_setup(fd, ETHUMBD_VIDEO_INTERVAL, + _ethumbd_pipe_write_setup(ed, ETHUMBD_VIDEO_INTERVAL, &setup->video_interval); if (setup->flags.video_ntimes) - _ethumbd_pipe_write_setup(fd, ETHUMBD_VIDEO_NTIMES, &setup->video_ntimes); + _ethumbd_pipe_write_setup(ed, ETHUMBD_VIDEO_NTIMES, &setup->video_ntimes); if (setup->flags.video_fps) - _ethumbd_pipe_write_setup(fd, ETHUMBD_VIDEO_FPS, &setup->video_fps); + _ethumbd_pipe_write_setup(ed, ETHUMBD_VIDEO_FPS, &setup->video_fps); if (setup->flags.document_page) - _ethumbd_pipe_write_setup(fd, ETHUMBD_DOCUMENT_PAGE, + _ethumbd_pipe_write_setup(ed, ETHUMBD_DOCUMENT_PAGE, &setup->document_page); - _ethumbd_pipe_write_setup(fd, ETHUMBD_SETUP_FINISHED, NULL); + _ethumbd_pipe_write_setup(ed, ETHUMBD_SETUP_FINISHED, NULL); if (setup->directory) eina_stringshare_del(setup->directory); @@ -1706,49 +1730,26 @@ _ethumb_dbus_finish(struct _Ethumbd *ed) } static int -_ethumbd_spawn(struct _Ethumbd *ed) +_ethumbd_slave_spawn(struct _Ethumbd *ed) { - int pparent[2]; // parent writes here - int pchild[2]; // child writes here - int pid; + ed->slave.data_cb = ecore_event_handler_add( + ECORE_EXE_EVENT_DATA, _ethumbd_slave_data_read_cb, ed); + ed->slave.del_cb = ecore_event_handler_add( + ECORE_EXE_EVENT_DEL, _ethumbd_slave_del_cb, ed); - if (pipe(pparent) == -1) + ed->slave.bufcmd = NULL; + ed->slave.scmd = 0; + + ed->slave.exe = ecore_exe_pipe_run( + ETHUMB_LIBEXEC_DIR"/ethumbd_slave", + ECORE_EXE_PIPE_READ | ECORE_EXE_PIPE_WRITE, ed); + if (!ed->slave.exe) { - ERR("could not create parent pipe.\n"); + ERR("could not create slave.\n"); return 0; } - if (pipe(pchild) == -1) - { - ERR("could not create child pipe.\n"); - return 0; - } - - pid = fork(); - if (pid == -1) - { - ERR("fork error.\n"); - return 0; - } - - if (pid == 0) - { - close(pparent[1]); - close(pchild[0]); - ethumbd_child_start(pparent[0], pchild[1]); - return 2; - } - else - { - close(pparent[0]); - close(pchild[1]); - ed->pipeout = pparent[1]; - ed->pipein = pchild[0]; - ed->fd_handler = ecore_main_fd_handler_add - (ed->pipein, ECORE_FD_READ | ECORE_FD_ERROR, - _ethumbd_fd_handler, ed, NULL, NULL); - return 1; - } + return 1; } int @@ -1767,7 +1768,7 @@ main(int argc, char *argv[]) ethumb_init(); - child = _ethumbd_spawn(&ed); + child = _ethumbd_slave_spawn(&ed); if (!child) { exit_value = -6; @@ -1831,6 +1832,8 @@ main(int argc, char *argv[]) finish_edbus: e_dbus_shutdown(); finish: + if (ed.slave.exe) + ecore_exe_quit(ed.slave.exe); ethumb_shutdown(); eina_init(); ecore_shutdown(); diff --git a/legacy/ethumb/src/bin/ethumbd_child.c b/legacy/ethumb/src/bin/ethumbd_child.c index c45c06b60b..252450bf5f 100644 --- a/legacy/ethumb/src/bin/ethumbd_child.c +++ b/legacy/ethumb/src/bin/ethumbd_child.c @@ -47,7 +47,6 @@ struct _Ethumbd_Child { Ecore_Fd_Handler *fd_handler; Ethumb *ethumbt[NETHUMBS]; - int pipein, pipeout; }; @@ -131,7 +130,7 @@ _ec_pipe_str_read(struct _Ethumbd_Child *ec, char **str) int r; char buf[PATH_MAX]; - r = _ec_read_safe(ec->pipein, &size, sizeof(size)); + r = _ec_read_safe(STDIN_FILENO, &size, sizeof(size)); if (!r) { *str = NULL; @@ -144,7 +143,7 @@ _ec_pipe_str_read(struct _Ethumbd_Child *ec, char **str) return 1; } - r = _ec_read_safe(ec->pipein, buf, size); + r = _ec_read_safe(STDIN_FILENO, buf, size); if (!r) { *str = NULL; @@ -155,28 +154,11 @@ _ec_pipe_str_read(struct _Ethumbd_Child *ec, char **str) return 1; } -static void -_ec_pipe_str_write(struct _Ethumbd_Child *ec, const char *str) -{ - int size; - - if (!str) - size = 0; - else - size = strlen(str) + 1; - - _ec_write_safe(ec->pipeout, &size, sizeof(size)); - _ec_write_safe(ec->pipeout, str, size); -} - static struct _Ethumbd_Child * -_ec_new(int pipein, int pipeout) +_ec_new(void) { struct _Ethumbd_Child *ec = calloc(1, sizeof(*ec)); - ec->pipein = pipein; - ec->pipeout = pipeout; - return ec; } @@ -203,7 +185,7 @@ _ec_op_new(struct _Ethumbd_Child *ec) int r; int index; - r = _ec_read_safe(ec->pipein, &index, sizeof(index)); + r = _ec_read_safe(STDIN_FILENO, &index, sizeof(index)); if (!r) return 0; @@ -219,7 +201,7 @@ _ec_op_del(struct _Ethumbd_Child *ec) int r; int index; - r = _ec_read_safe(ec->pipein, &index, sizeof(index)); + r = _ec_read_safe(STDIN_FILENO, &index, sizeof(index)); if (!r) return 0; @@ -233,15 +215,34 @@ _ec_op_del(struct _Ethumbd_Child *ec) static void _ec_op_generated_cb(void *data, Ethumb *e, Eina_Bool success) { - struct _Ethumbd_Child *ec = data; const char *thumb_path, *thumb_key; + int size_path, size_key, size_cmd; + fprintf(stderr, "thumbnail generated!\n"); DBG("thumb generated!\n"); ethumb_thumb_path_get(e, &thumb_path, &thumb_key); - _ec_write_safe(ec->pipeout, &success, sizeof(success)); - _ec_pipe_str_write(ec, thumb_path); - _ec_pipe_str_write(ec, thumb_key); + if (!thumb_path) + size_path = 0; + else + size_path = strlen(thumb_path) + 1; + + if (!thumb_key) + size_key = 0; + else + size_key = strlen(thumb_key) + 1; + + size_cmd = sizeof(success) + sizeof(size_path) + size_path + + sizeof(size_key) + size_key; + + _ec_write_safe(STDOUT_FILENO, &size_cmd, sizeof(size_cmd)); + _ec_write_safe(STDOUT_FILENO, &success, sizeof(success)); + + _ec_write_safe(STDOUT_FILENO, &size_path, sizeof(size_path)); + _ec_write_safe(STDOUT_FILENO, thumb_path, size_path); + + _ec_write_safe(STDOUT_FILENO, &size_key, sizeof(size_key)); + _ec_write_safe(STDOUT_FILENO, thumb_key, size_key); } static int @@ -251,7 +252,7 @@ _ec_op_generate(struct _Ethumbd_Child *ec) char *path, *key, *thumb_path, *thumb_key; int r; - r = _ec_read_safe(ec->pipein, &index, sizeof(index)); + r = _ec_read_safe(STDIN_FILENO, &index, sizeof(index)); if (!r) return 0; @@ -286,7 +287,7 @@ _ec_fdo_set(struct _Ethumbd_Child *ec, Ethumb *e) int r; int value; - r = _ec_read_safe(ec->pipein, &value, sizeof(value)); + r = _ec_read_safe(STDIN_FILENO, &value, sizeof(value)); if (!r) return 0; ethumb_thumb_fdo_set(e, value); @@ -302,13 +303,13 @@ _ec_size_set(struct _Ethumbd_Child *ec, Ethumb *e) int w, h; int type; - r = _ec_read_safe(ec->pipein, &w, sizeof(w)); + r = _ec_read_safe(STDIN_FILENO, &w, sizeof(w)); if (!r) return 0; - r = _ec_read_safe(ec->pipein, &type, sizeof(type)); + r = _ec_read_safe(STDIN_FILENO, &type, sizeof(type)); if (!r) return 0; - r = _ec_read_safe(ec->pipein, &h, sizeof(h)); + r = _ec_read_safe(STDIN_FILENO, &h, sizeof(h)); if (!r) return 0; ethumb_thumb_size_set(e, w, h); @@ -323,7 +324,7 @@ _ec_format_set(struct _Ethumbd_Child *ec, Ethumb *e) int r; int value; - r = _ec_read_safe(ec->pipein, &value, sizeof(value)); + r = _ec_read_safe(STDIN_FILENO, &value, sizeof(value)); if (!r) return 0; ethumb_thumb_format_set(e, value); @@ -338,7 +339,7 @@ _ec_aspect_set(struct _Ethumbd_Child *ec, Ethumb *e) int r; int value; - r = _ec_read_safe(ec->pipein, &value, sizeof(value)); + r = _ec_read_safe(STDIN_FILENO, &value, sizeof(value)); if (!r) return 0; ethumb_thumb_aspect_set(e, value); @@ -354,13 +355,13 @@ _ec_crop_set(struct _Ethumbd_Child *ec, Ethumb *e) float x, y; int type; - r = _ec_read_safe(ec->pipein, &x, sizeof(x)); + r = _ec_read_safe(STDIN_FILENO, &x, sizeof(x)); if (!r) return 0; - r = _ec_read_safe(ec->pipein, &type, sizeof(type)); + r = _ec_read_safe(STDIN_FILENO, &type, sizeof(type)); if (!r) return 0; - r = _ec_read_safe(ec->pipein, &y, sizeof(y)); + r = _ec_read_safe(STDIN_FILENO, &y, sizeof(y)); if (!r) return 0; ethumb_thumb_crop_align_set(e, x, y); @@ -375,7 +376,7 @@ _ec_quality_set(struct _Ethumbd_Child *ec, Ethumb *e) int r; int value; - r = _ec_read_safe(ec->pipein, &value, sizeof(value)); + r = _ec_read_safe(STDIN_FILENO, &value, sizeof(value)); if (!r) return 0; ethumb_thumb_quality_set(e, value); @@ -390,7 +391,7 @@ _ec_compress_set(struct _Ethumbd_Child *ec, Ethumb *e) int r; int value; - r = _ec_read_safe(ec->pipein, &value, sizeof(value)); + r = _ec_read_safe(STDIN_FILENO, &value, sizeof(value)); if (!r) return 0; ethumb_thumb_compress_set(e, value); @@ -409,13 +410,13 @@ _ec_frame_set(struct _Ethumbd_Child *ec, Ethumb *e) r = _ec_pipe_str_read(ec, &theme_file); if (!r) return 0; - r = _ec_read_safe(ec->pipein, &type, sizeof(type)); + r = _ec_read_safe(STDIN_FILENO, &type, sizeof(type)); if (!r) return 0; r = _ec_pipe_str_read(ec, &group); if (!r) return 0; - r = _ec_read_safe(ec->pipein, &type, sizeof(type)); + r = _ec_read_safe(STDIN_FILENO, &type, sizeof(type)); if (!r) return 0; r = _ec_pipe_str_read(ec, &swallow); @@ -468,7 +469,7 @@ _ec_video_time_set(struct _Ethumbd_Child *ec, Ethumb *e) int r; float value; - r = _ec_read_safe(ec->pipein, &value, sizeof(value)); + r = _ec_read_safe(STDIN_FILENO, &value, sizeof(value)); if (!r) return 0; ethumb_video_time_set(e, value); @@ -483,7 +484,7 @@ _ec_video_start_set(struct _Ethumbd_Child *ec, Ethumb *e) int r; float value; - r = _ec_read_safe(ec->pipein, &value, sizeof(value)); + r = _ec_read_safe(STDIN_FILENO, &value, sizeof(value)); if (!r) return 0; ethumb_video_start_set(e, value); @@ -498,7 +499,7 @@ _ec_video_interval_set(struct _Ethumbd_Child *ec, Ethumb *e) int r; float value; - r = _ec_read_safe(ec->pipein, &value, sizeof(value)); + r = _ec_read_safe(STDIN_FILENO, &value, sizeof(value)); if (!r) return 0; ethumb_video_interval_set(e, value); @@ -513,7 +514,7 @@ _ec_video_ntimes_set(struct _Ethumbd_Child *ec, Ethumb *e) int r; int value; - r = _ec_read_safe(ec->pipein, &value, sizeof(value)); + r = _ec_read_safe(STDIN_FILENO, &value, sizeof(value)); if (!r) return 0; ethumb_video_ntimes_set(e, value); @@ -528,7 +529,7 @@ _ec_video_fps_set(struct _Ethumbd_Child *ec, Ethumb *e) int r; int value; - r = _ec_read_safe(ec->pipein, &value, sizeof(value)); + r = _ec_read_safe(STDIN_FILENO, &value, sizeof(value)); if (!r) return 0; ethumb_video_fps_set(e, value); @@ -543,7 +544,7 @@ _ec_document_page_set(struct _Ethumbd_Child *ec, Ethumb *e) int r; int value; - r = _ec_read_safe(ec->pipein, &value, sizeof(value)); + r = _ec_read_safe(STDIN_FILENO, &value, sizeof(value)); if (!r) return 0; ethumb_document_page_set(e, value); @@ -621,17 +622,17 @@ _ec_op_setup(struct _Ethumbd_Child *ec) int index; int type; - r = _ec_read_safe(ec->pipein, &index, sizeof(index)); + r = _ec_read_safe(STDIN_FILENO, &index, sizeof(index)); if (!r) return 0; - r = _ec_read_safe(ec->pipein, &type, sizeof(type)); + r = _ec_read_safe(STDIN_FILENO, &type, sizeof(type)); if (!r) return 0; while (type != ETHUMBD_SETUP_FINISHED) { _ec_setup_process(ec, index, type); - r = _ec_read_safe(ec->pipein, &type, sizeof(type)); + r = _ec_read_safe(STDIN_FILENO, &type, sizeof(type)); if (!r) return 0; } @@ -654,7 +655,7 @@ _ec_fd_handler(void *data, Ecore_Fd_Handler *fd_handler) return 0; } - r = _ec_read_safe(ec->pipein, &op_id, sizeof(op_id)); + r = _ec_read_safe(STDIN_FILENO, &op_id, sizeof(op_id)); if (!r) { DBG("ethumbd exited! child exiting...\n"); @@ -699,18 +700,18 @@ static void _ec_setup(struct _Ethumbd_Child *ec) { ec->fd_handler = ecore_main_fd_handler_add( - ec->pipein, ECORE_FD_READ | ECORE_FD_ERROR, + STDIN_FILENO, ECORE_FD_READ | ECORE_FD_ERROR, _ec_fd_handler, ec, NULL, NULL); } -void -ethumbd_child_start(int pipein, int pipeout) +int +main(int argc, const char *argv[]) { struct _Ethumbd_Child *ec; ethumb_init(); - ec = _ec_new(pipein, pipeout); + ec = _ec_new(); _ec_setup(ec); @@ -721,4 +722,6 @@ ethumbd_child_start(int pipein, int pipeout) _ec_free(ec); ethumb_shutdown(); + + return 0; }