summaryrefslogtreecommitdiff
path: root/legacy/ethumb
diff options
context:
space:
mode:
authorRafael Antognolli <antognolli@gmail.com>2009-12-01 13:34:09 +0000
committerRafael Antognolli <antognolli@gmail.com>2009-12-01 13:34:09 +0000
commit6cbcfd262fcfa7e3d787ca28ff224af0b9ee68f4 (patch)
treeb5cf2303f629de4067bf1e042d329e2b9ca7f3e1 /legacy/ethumb
parent22e44c2b3b9dbd697fd674be953c419b8ce6144f (diff)
ethumb: now using ecore_exe to start the slave.
SVN revision: 44092
Diffstat (limited to 'legacy/ethumb')
-rw-r--r--legacy/ethumb/src/bin/Makefile.am12
-rw-r--r--legacy/ethumb/src/bin/ethumbd.c395
-rw-r--r--legacy/ethumb/src/bin/ethumbd_child.c113
3 files changed, 267 insertions, 253 deletions
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
19 19
20if USE_MODULE_ETHUMBD 20if USE_MODULE_ETHUMBD
21 21
22AM_CPPFLAGS += @EDBUS_CFLAGS@ 22AM_CPPFLAGS += @EDBUS_CFLAGS@ \
23 -DETHUMB_LIBEXEC_DIR=\"$(libexecdir)\"
23bin_PROGRAMS += ethumbd ethumbd_client 24bin_PROGRAMS += ethumbd ethumbd_client
24noinst_HEADERS += ethumbd_private.h 25noinst_HEADERS += ethumbd_private.h
25 26
26ethumbd_SOURCES = ethumbd.c ethumbd_child.c 27libexec_PROGRAMS = ethumbd_slave
28
29ethumbd_SOURCES = ethumbd.c
27ethumbd_LDADD = \ 30ethumbd_LDADD = \
28 @EINA_LIBS@ @ECORE_LIBS@ @EDBUS_LIBS@ \ 31 @EINA_LIBS@ @ECORE_LIBS@ @EDBUS_LIBS@ \
29 $(top_builddir)/src/lib/libethumb.la 32 $(top_builddir)/src/lib/libethumb.la
30ethumbd_DEPENDENCIES = $(top_builddir)/config.h 33ethumbd_DEPENDENCIES = $(top_builddir)/config.h
31 34
35ethumbd_slave_SOURCES = ethumbd_child.c
36ethumbd_slave_LDADD = \
37 @EINA_LIBS@ @ECORE_LIBS@ @EDBUS_LIBS@ \
38 $(top_builddir)/src/lib/libethumb.la
39
32ethumbd_client_SOURCES = ethumbd_client.c 40ethumbd_client_SOURCES = ethumbd_client.c
33ethumbd_client_LDADD = \ 41ethumbd_client_LDADD = \
34 @EINA_LIBS@ @ECORE_LIBS@ \ 42 @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
130 int *list; 130 int *list;
131}; 131};
132 132
133struct _Ethumb_Slave
134{
135 Ecore_Exe *exe;
136 Ecore_Event_Handler *data_cb;
137 Ecore_Event_Handler *del_cb;
138 char *bufcmd; // buffer to read commands from slave
139 int scmd; // size of command to read
140 int pcmd; // position in the command buffer
141};
142
133struct _Ethumbd 143struct _Ethumbd
134{ 144{
135 E_DBus_Connection *conn; 145 E_DBus_Connection *conn;
@@ -139,11 +149,9 @@ struct _Ethumbd
139 Ecore_Idler *idler; 149 Ecore_Idler *idler;
140 struct _Ethumb_Request *processing; 150 struct _Ethumb_Request *processing;
141 struct _Ethumb_Queue queue; 151 struct _Ethumb_Queue queue;
142 int pipeout;
143 int pipein;
144 Ecore_Fd_Handler *fd_handler;
145 double timeout; 152 double timeout;
146 Ecore_Timer *timeout_timer; 153 Ecore_Timer *timeout_timer;
154 struct _Ethumb_Slave slave;
147}; 155};
148 156
149struct _Ethumb_Object_Data 157struct _Ethumb_Object_Data
@@ -189,6 +197,7 @@ const Ecore_Getopt optdesc = {
189}; 197};
190 198
191static void _ethumb_dbus_generated_signal(struct _Ethumbd *ed, int *id, const char *thumb_path, const char *thumb_key, Eina_Bool success); 199static void _ethumb_dbus_generated_signal(struct _Ethumbd *ed, int *id, const char *thumb_path, const char *thumb_key, Eina_Bool success);
200static int _ethumbd_slave_spawn(struct _Ethumbd *ed);
192 201
193static int 202static int
194_ethumbd_timeout_cb(void *data) 203_ethumbd_timeout_cb(void *data)
@@ -270,75 +279,16 @@ _ethumb_dbus_inc_min_id(struct _Ethumb_Object *eobject)
270} 279}
271 280
272int 281int
273_ethumbd_read_safe(int fd, void *buf, ssize_t size) 282_ethumbd_write_safe(struct _Ethumbd *ed, const void *buf, ssize_t size)
274{ 283{
275 ssize_t todo;
276 char *p;
277 284
278 todo = size; 285 if (!ed->slave.exe)
279 p = buf;
280
281 while (todo > 0)
282 { 286 {
283 ssize_t r; 287 ERR("slave process isn't running.\n");
284 288 return 0;
285 r = read(fd, p, todo);
286 if (r > 0)
287 {
288 todo -= r;
289 p += r;
290 }
291 else if (r == 0)
292 return 0;
293 else
294 {
295 if (errno == EINTR || errno == EAGAIN)
296 continue;
297 else
298 {
299 ERR("could not read from fd %d: %s",
300 fd, strerror(errno));
301 return 0;
302 }
303 }
304 }
305
306 return 1;
307}
308
309int
310_ethumbd_write_safe(int fd, const void *buf, ssize_t size)
311{
312 ssize_t todo;
313 const char *p;
314
315 todo = size;
316 p = buf;
317
318 while (todo > 0)
319 {
320 ssize_t r;
321
322 r = write(fd, p, todo);
323 if (r > 0)
324 {
325 todo -= r;
326 p += r;
327 }
328 else if (r == 0)
329 return 0;
330 else
331 {
332 if (errno == EINTR || errno == EAGAIN)
333 continue;
334 else
335 {
336 ERR("could not write to fd %d: %s", fd, strerror(errno));
337 return 0;
338 }
339 }
340 } 289 }
341 290
291 ecore_exe_send(ed->slave.exe, buf, size);
342 return 1; 292 return 1;
343} 293}
344 294
@@ -346,20 +296,20 @@ static void
346_ethumbd_child_write_op_new(struct _Ethumbd *ed, int index) 296_ethumbd_child_write_op_new(struct _Ethumbd *ed, int index)
347{ 297{
348 int id = ETHUMBD_OP_NEW; 298 int id = ETHUMBD_OP_NEW;
349 _ethumbd_write_safe(ed->pipeout, &id, sizeof(id)); 299 _ethumbd_write_safe(ed, &id, sizeof(id));
350 _ethumbd_write_safe(ed->pipeout, &index, sizeof(index)); 300 _ethumbd_write_safe(ed, &index, sizeof(index));
351} 301}
352 302
353static void 303static void
354_ethumbd_child_write_op_del(struct _Ethumbd *ed, int index) 304_ethumbd_child_write_op_del(struct _Ethumbd *ed, int index)
355{ 305{
356 int id = ETHUMBD_OP_DEL; 306 int id = ETHUMBD_OP_DEL;
357 _ethumbd_write_safe(ed->pipeout, &id, sizeof(id)); 307 _ethumbd_write_safe(ed, &id, sizeof(id));
358 _ethumbd_write_safe(ed->pipeout, &index, sizeof(index)); 308 _ethumbd_write_safe(ed, &index, sizeof(index));
359} 309}
360 310
361static void 311static void
362_ethumbd_pipe_str_write(int fd, const char *str) 312_ethumbd_pipe_str_write(struct _Ethumbd *ed, const char *str)
363{ 313{
364 int len; 314 int len;
365 315
@@ -368,39 +318,8 @@ _ethumbd_pipe_str_write(int fd, const char *str)
368 else 318 else
369 len = 0; 319 len = 0;
370 320
371 _ethumbd_write_safe(fd, &len, sizeof(len)); 321 _ethumbd_write_safe(ed, &len, sizeof(len));
372 _ethumbd_write_safe(fd, str, len); 322 _ethumbd_write_safe(ed, str, len);
373}
374
375static int
376_ethumbd_pipe_str_read(int fd, char **str)
377{
378 int size;
379 int r;
380 char buf[PATH_MAX];
381
382 r = _ethumbd_read_safe(fd, &size, sizeof(size));
383 if (!r)
384 {
385 *str = NULL;
386 return 0;
387 }
388
389 if (!size)
390 {
391 *str = NULL;
392 return 1;
393 }
394
395 r = _ethumbd_read_safe(fd, buf, size);
396 if (!r)
397 {
398 *str = NULL;
399 return 0;
400 }
401
402 *str = strdup(buf);
403 return 1;
404} 323}
405 324
406static void 325static void
@@ -408,13 +327,13 @@ _ethumbd_child_write_op_generate(struct _Ethumbd *ed, int index, const char *pat
408{ 327{
409 int id = ETHUMBD_OP_GENERATE; 328 int id = ETHUMBD_OP_GENERATE;
410 329
411 _ethumbd_write_safe(ed->pipeout, &id, sizeof(id)); 330 _ethumbd_write_safe(ed, &id, sizeof(id));
412 _ethumbd_write_safe(ed->pipeout, &index, sizeof(index)); 331 _ethumbd_write_safe(ed, &index, sizeof(index));
413 332
414 _ethumbd_pipe_str_write(ed->pipeout, path); 333 _ethumbd_pipe_str_write(ed, path);
415 _ethumbd_pipe_str_write(ed->pipeout, key); 334 _ethumbd_pipe_str_write(ed, key);
416 _ethumbd_pipe_str_write(ed->pipeout, thumb_path); 335 _ethumbd_pipe_str_write(ed, thumb_path);
417 _ethumbd_pipe_str_write(ed->pipeout, thumb_key); 336 _ethumbd_pipe_str_write(ed, thumb_key);
418} 337}
419 338
420static void 339static void
@@ -435,47 +354,153 @@ _generated_cb(struct _Ethumbd *ed, Eina_Bool success, const char *thumb_path, co
435 ed->processing = NULL; 354 ed->processing = NULL;
436} 355}
437 356
357static void
358_ethumbd_slave_cmd_ready(struct _Ethumbd *ed)
359{
360 char *bufcmd = ed->slave.bufcmd;
361 Eina_Bool *success;
362 char *thumb_path, *thumb_key;
363 int *size_path, *size_key;
364
365
366 success = (Eina_Bool *)bufcmd;
367 bufcmd += sizeof(*success);
368
369 size_path = (int *)bufcmd;
370 bufcmd += sizeof(*size_path);
371
372 write(STDERR_FILENO, bufcmd, ed->slave.scmd);
373
374 thumb_path = bufcmd;
375 bufcmd += *size_path;
376
377 size_key = (int *)bufcmd;
378 bufcmd += sizeof(*size_key);
379
380 thumb_key = bufcmd;
381
382 _generated_cb(ed, *success, thumb_path, thumb_key);
383
384 free(ed->slave.bufcmd);
385 ed->slave.bufcmd = NULL;
386 ed->slave.scmd = 0;
387}
388
438static int 389static int
439_ethumbd_fd_handler(void *data, Ecore_Fd_Handler *fd_handler) 390_ethumbd_slave_alloc_cmd(struct _Ethumbd *ed, int ssize, char *sdata)
391{
392 int *scmd;
393
394 if (ed->slave.bufcmd)
395 return 0;
396
397 scmd = (int *)sdata;
398 if (ssize < sizeof(*scmd)) {
399 ERR("could not read size of command.\n");
400 return 0;
401 }
402 ed->slave.bufcmd = malloc(*scmd);
403 ed->slave.scmd = *scmd;
404 ed->slave.pcmd = 0;
405
406 return sizeof(*scmd);
407}
408
409static int
410_ethumbd_slave_data_read_cb(void *data, int type, void *event)
440{ 411{
441 struct _Ethumbd *ed = data; 412 struct _Ethumbd *ed = data;
442 Eina_Bool success; 413 Ecore_Exe_Event_Data *ev = event;
443 int r; 414 int ssize;
444 char *thumb_path, *thumb_key; 415 char *sdata;
445 416
446 if (ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_ERROR)) 417 if (ev->exe != ed->slave.exe)
447 { 418 {
448 ERR("error on pipein! child exiting...\n"); 419 ERR("PARENT ERROR: slave != ev->exe\n");
449 ed->fd_handler = NULL;
450 ecore_main_loop_quit();
451 return 0; 420 return 0;
452 } 421 }
453 422
454 r = _ethumbd_read_safe(ed->pipein, &success, sizeof(success)); 423 ssize = ev->size;
455 if (!r) 424 sdata = ev->data;
425
426 write(STDERR_FILENO, sdata, ssize);
427
428 while (ssize > 0)
456 { 429 {
457 ERR("ethumbd child exited!\n"); 430 if (!ed->slave.bufcmd)
458 ed->fd_handler = NULL; 431 {
459 return 0; 432 int n;
433 n = _ethumbd_slave_alloc_cmd(ed, ssize, sdata);
434 ssize -= n;
435 sdata += n;
436 }
437 else
438 {
439 char *bdata;
440 int nbytes;
441 bdata = ed->slave.bufcmd + ed->slave.pcmd;
442 nbytes = ed->slave.scmd - ed->slave.pcmd;
443 nbytes = ssize < nbytes ? ssize : nbytes;
444 memcpy(bdata, sdata, nbytes);
445 sdata += nbytes;
446 ssize -= nbytes;
447 ed->slave.pcmd += nbytes;
448
449 if (ed->slave.pcmd == ed->slave.scmd)
450 _ethumbd_slave_cmd_ready(ed);
451 }
460 } 452 }
461 453
462 r = _ethumbd_pipe_str_read(ed->pipein, &thumb_path); 454 return 1;
463 r = _ethumbd_pipe_str_read(ed->pipein, &thumb_key); 455}
464 _generated_cb(ed, success, thumb_path, thumb_key);
465 456
466 free(thumb_path); 457static int
467 free(thumb_key); 458_ethumbd_slave_del_cb(void *data, int type, void *event)
459{
460 struct _Ethumbd *ed = data;
461 Ecore_Exe_Event_Del *ev = event;
462 int i;
468 463
469 return 1; 464 if (ev->exe != ed->slave.exe)
465 return 1;
466
467 if (ev->exited)
468 ERR("slave exited with code: %d\n", ev->exit_code);
469 else if (ev->signalled)
470 ERR("slave exited by signal: %d\n", ev->exit_signal);
471
472 if (!ed->processing)
473 goto end;
474
475 i = ed->queue.current;
476 ERR("failed to generate thumbnail for: \"%s:%s\"\n",
477 ed->processing->file, ed->processing->key);
478
479 if (ed->queue.table[i].used)
480 _ethumb_dbus_generated_signal
481 (ed, &ed->processing->id, NULL, NULL, EINA_FALSE);
482 eina_stringshare_del(ed->processing->file);
483 eina_stringshare_del(ed->processing->key);
484 eina_stringshare_del(ed->processing->thumb);
485 eina_stringshare_del(ed->processing->thumb_key);
486 free(ed->processing);
487 ed->processing = NULL;
488
489end:
490 ed->slave.exe = NULL;
491 if (ed->slave.bufcmd)
492 free(ed->slave.bufcmd);
493
494 return _ethumbd_slave_spawn(ed);
470} 495}
471 496
472static void 497static void
473_ethumbd_pipe_write_setup(int fd, int type, const void *data) 498_ethumbd_pipe_write_setup(struct _Ethumbd *ed, int type, const void *data)
474{ 499{
475 const int *i_value; 500 const int *i_value;
476 const float *f_value; 501 const float *f_value;
477 502
478 _ethumbd_write_safe(fd, &type, sizeof(type)); 503 _ethumbd_write_safe(ed, &type, sizeof(type));
479 504
480 switch (type) 505 switch (type)
481 { 506 {
@@ -490,7 +515,7 @@ _ethumbd_pipe_write_setup(int fd, int type, const void *data)
490 case ETHUMBD_VIDEO_NTIMES: 515 case ETHUMBD_VIDEO_NTIMES:
491 case ETHUMBD_VIDEO_FPS: 516 case ETHUMBD_VIDEO_FPS:
492 i_value = data; 517 i_value = data;
493 _ethumbd_write_safe(fd, i_value, sizeof(*i_value)); 518 _ethumbd_write_safe(ed, i_value, sizeof(*i_value));
494 break; 519 break;
495 case ETHUMBD_CROP_X: 520 case ETHUMBD_CROP_X:
496 case ETHUMBD_CROP_Y: 521 case ETHUMBD_CROP_Y:
@@ -498,14 +523,14 @@ _ethumbd_pipe_write_setup(int fd, int type, const void *data)
498 case ETHUMBD_VIDEO_START: 523 case ETHUMBD_VIDEO_START:
499 case ETHUMBD_VIDEO_INTERVAL: 524 case ETHUMBD_VIDEO_INTERVAL:
500 f_value = data; 525 f_value = data;
501 _ethumbd_write_safe(fd, f_value, sizeof(*f_value)); 526 _ethumbd_write_safe(ed, f_value, sizeof(*f_value));
502 break; 527 break;
503 case ETHUMBD_DIRECTORY: 528 case ETHUMBD_DIRECTORY:
504 case ETHUMBD_CATEGORY: 529 case ETHUMBD_CATEGORY:
505 case ETHUMBD_FRAME_FILE: 530 case ETHUMBD_FRAME_FILE:
506 case ETHUMBD_FRAME_GROUP: 531 case ETHUMBD_FRAME_GROUP:
507 case ETHUMBD_FRAME_SWALLOW: 532 case ETHUMBD_FRAME_SWALLOW:
508 _ethumbd_pipe_str_write(fd, data); 533 _ethumbd_pipe_str_write(ed, data);
509 break; 534 break;
510 case ETHUMBD_SETUP_FINISHED: 535 case ETHUMBD_SETUP_FINISHED:
511 break; 536 break;
@@ -519,58 +544,57 @@ _process_setup(struct _Ethumbd *ed)
519{ 544{
520 int op_id = ETHUMBD_OP_SETUP; 545 int op_id = ETHUMBD_OP_SETUP;
521 int index = ed->queue.current; 546 int index = ed->queue.current;
522 int fd = ed->pipeout;
523 547
524 struct _Ethumb_Setup *setup = &ed->processing->setup; 548 struct _Ethumb_Setup *setup = &ed->processing->setup;
525 549
526 _ethumbd_write_safe(ed->pipeout, &op_id, sizeof(op_id)); 550 _ethumbd_write_safe(ed, &op_id, sizeof(op_id));
527 _ethumbd_write_safe(ed->pipeout, &index, sizeof(index)); 551 _ethumbd_write_safe(ed, &index, sizeof(index));
528 552
529 if (setup->flags.fdo) 553 if (setup->flags.fdo)
530 _ethumbd_pipe_write_setup(fd, ETHUMBD_FDO, &setup->fdo); 554 _ethumbd_pipe_write_setup(ed, ETHUMBD_FDO, &setup->fdo);
531 if (setup->flags.size) 555 if (setup->flags.size)
532 { 556 {
533 _ethumbd_pipe_write_setup(fd, ETHUMBD_SIZE_W, &setup->tw); 557 _ethumbd_pipe_write_setup(ed, ETHUMBD_SIZE_W, &setup->tw);
534 _ethumbd_pipe_write_setup(fd, ETHUMBD_SIZE_H, &setup->th); 558 _ethumbd_pipe_write_setup(ed, ETHUMBD_SIZE_H, &setup->th);
535 } 559 }
536 if (setup->flags.format) 560 if (setup->flags.format)
537 _ethumbd_pipe_write_setup(fd, ETHUMBD_FORMAT, &setup->format); 561 _ethumbd_pipe_write_setup(ed, ETHUMBD_FORMAT, &setup->format);
538 if (setup->flags.aspect) 562 if (setup->flags.aspect)
539 _ethumbd_pipe_write_setup(fd, ETHUMBD_ASPECT, &setup->aspect); 563 _ethumbd_pipe_write_setup(ed, ETHUMBD_ASPECT, &setup->aspect);
540 if (setup->flags.crop) 564 if (setup->flags.crop)
541 { 565 {
542 _ethumbd_pipe_write_setup(fd, ETHUMBD_CROP_X, &setup->cx); 566 _ethumbd_pipe_write_setup(ed, ETHUMBD_CROP_X, &setup->cx);
543 _ethumbd_pipe_write_setup(fd, ETHUMBD_CROP_Y, &setup->cy); 567 _ethumbd_pipe_write_setup(ed, ETHUMBD_CROP_Y, &setup->cy);
544 } 568 }
545 if (setup->flags.quality) 569 if (setup->flags.quality)
546 _ethumbd_pipe_write_setup(fd, ETHUMBD_QUALITY, &setup->quality); 570 _ethumbd_pipe_write_setup(ed, ETHUMBD_QUALITY, &setup->quality);
547 if (setup->flags.compress) 571 if (setup->flags.compress)
548 _ethumbd_pipe_write_setup(fd, ETHUMBD_COMPRESS, &setup->compress); 572 _ethumbd_pipe_write_setup(ed, ETHUMBD_COMPRESS, &setup->compress);
549 if (setup->flags.directory) 573 if (setup->flags.directory)
550 _ethumbd_pipe_write_setup(fd, ETHUMBD_DIRECTORY, setup->directory); 574 _ethumbd_pipe_write_setup(ed, ETHUMBD_DIRECTORY, setup->directory);
551 if (setup->flags.category) 575 if (setup->flags.category)
552 _ethumbd_pipe_write_setup(fd, ETHUMBD_CATEGORY, setup->category); 576 _ethumbd_pipe_write_setup(ed, ETHUMBD_CATEGORY, setup->category);
553 if (setup->flags.frame) 577 if (setup->flags.frame)
554 { 578 {
555 _ethumbd_pipe_write_setup(fd, ETHUMBD_FRAME_FILE, setup->theme_file); 579 _ethumbd_pipe_write_setup(ed, ETHUMBD_FRAME_FILE, setup->theme_file);
556 _ethumbd_pipe_write_setup(fd, ETHUMBD_FRAME_GROUP, setup->group); 580 _ethumbd_pipe_write_setup(ed, ETHUMBD_FRAME_GROUP, setup->group);
557 _ethumbd_pipe_write_setup(fd, ETHUMBD_FRAME_SWALLOW, setup->swallow); 581 _ethumbd_pipe_write_setup(ed, ETHUMBD_FRAME_SWALLOW, setup->swallow);
558 } 582 }
559 if (setup->flags.video_time) 583 if (setup->flags.video_time)
560 _ethumbd_pipe_write_setup(fd, ETHUMBD_VIDEO_TIME, &setup->video_time); 584 _ethumbd_pipe_write_setup(ed, ETHUMBD_VIDEO_TIME, &setup->video_time);
561 if (setup->flags.video_start) 585 if (setup->flags.video_start)
562 _ethumbd_pipe_write_setup(fd, ETHUMBD_VIDEO_START, &setup->video_start); 586 _ethumbd_pipe_write_setup(ed, ETHUMBD_VIDEO_START, &setup->video_start);
563 if (setup->flags.video_interval) 587 if (setup->flags.video_interval)
564 _ethumbd_pipe_write_setup(fd, ETHUMBD_VIDEO_INTERVAL, 588 _ethumbd_pipe_write_setup(ed, ETHUMBD_VIDEO_INTERVAL,
565 &setup->video_interval); 589 &setup->video_interval);
566 if (setup->flags.video_ntimes) 590 if (setup->flags.video_ntimes)
567 _ethumbd_pipe_write_setup(fd, ETHUMBD_VIDEO_NTIMES, &setup->video_ntimes); 591 _ethumbd_pipe_write_setup(ed, ETHUMBD_VIDEO_NTIMES, &setup->video_ntimes);
568 if (setup->flags.video_fps) 592 if (setup->flags.video_fps)
569 _ethumbd_pipe_write_setup(fd, ETHUMBD_VIDEO_FPS, &setup->video_fps); 593 _ethumbd_pipe_write_setup(ed, ETHUMBD_VIDEO_FPS, &setup->video_fps);
570 if (setup->flags.document_page) 594 if (setup->flags.document_page)
571 _ethumbd_pipe_write_setup(fd, ETHUMBD_DOCUMENT_PAGE, 595 _ethumbd_pipe_write_setup(ed, ETHUMBD_DOCUMENT_PAGE,
572 &setup->document_page); 596 &setup->document_page);
573 _ethumbd_pipe_write_setup(fd, ETHUMBD_SETUP_FINISHED, NULL); 597 _ethumbd_pipe_write_setup(ed, ETHUMBD_SETUP_FINISHED, NULL);
574 598
575 599
576 if (setup->directory) eina_stringshare_del(setup->directory); 600 if (setup->directory) eina_stringshare_del(setup->directory);
@@ -1706,49 +1730,26 @@ _ethumb_dbus_finish(struct _Ethumbd *ed)
1706} 1730}
1707 1731
1708static int 1732static int
1709_ethumbd_spawn(struct _Ethumbd *ed) 1733_ethumbd_slave_spawn(struct _Ethumbd *ed)
1710{ 1734{
1711 int pparent[2]; // parent writes here 1735 ed->slave.data_cb = ecore_event_handler_add(
1712 int pchild[2]; // child writes here 1736 ECORE_EXE_EVENT_DATA, _ethumbd_slave_data_read_cb, ed);
1713 int pid; 1737 ed->slave.del_cb = ecore_event_handler_add(
1738 ECORE_EXE_EVENT_DEL, _ethumbd_slave_del_cb, ed);
1714 1739
1715 if (pipe(pparent) == -1) 1740 ed->slave.bufcmd = NULL;
1716 { 1741 ed->slave.scmd = 0;
1717 ERR("could not create parent pipe.\n");
1718 return 0;
1719 }
1720
1721 if (pipe(pchild) == -1)
1722 {
1723 ERR("could not create child pipe.\n");
1724 return 0;
1725 }
1726 1742
1727 pid = fork(); 1743 ed->slave.exe = ecore_exe_pipe_run(
1728 if (pid == -1) 1744 ETHUMB_LIBEXEC_DIR"/ethumbd_slave",
1745 ECORE_EXE_PIPE_READ | ECORE_EXE_PIPE_WRITE, ed);
1746 if (!ed->slave.exe)
1729 { 1747 {
1730 ERR("fork error.\n"); 1748 ERR("could not create slave.\n");
1731 return 0; 1749 return 0;
1732 } 1750 }
1733 1751
1734 if (pid == 0) 1752 return 1;
1735 {
1736 close(pparent[1]);
1737 close(pchild[0]);
1738 ethumbd_child_start(pparent[0], pchild[1]);
1739 return 2;
1740 }
1741 else
1742 {
1743 close(pparent[0]);
1744 close(pchild[1]);
1745 ed->pipeout = pparent[1];
1746 ed->pipein = pchild[0];
1747 ed->fd_handler = ecore_main_fd_handler_add
1748 (ed->pipein, ECORE_FD_READ | ECORE_FD_ERROR,
1749 _ethumbd_fd_handler, ed, NULL, NULL);
1750 return 1;
1751 }
1752} 1753}
1753 1754
1754int 1755int
@@ -1767,7 +1768,7 @@ main(int argc, char *argv[])
1767 1768
1768 ethumb_init(); 1769 ethumb_init();
1769 1770
1770 child = _ethumbd_spawn(&ed); 1771 child = _ethumbd_slave_spawn(&ed);
1771 if (!child) 1772 if (!child)
1772 { 1773 {
1773 exit_value = -6; 1774 exit_value = -6;
@@ -1831,6 +1832,8 @@ main(int argc, char *argv[])
1831 finish_edbus: 1832 finish_edbus:
1832 e_dbus_shutdown(); 1833 e_dbus_shutdown();
1833 finish: 1834 finish:
1835 if (ed.slave.exe)
1836 ecore_exe_quit(ed.slave.exe);
1834 ethumb_shutdown(); 1837 ethumb_shutdown();
1835 eina_init(); 1838 eina_init();
1836 ecore_shutdown(); 1839 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
47{ 47{
48 Ecore_Fd_Handler *fd_handler; 48 Ecore_Fd_Handler *fd_handler;
49 Ethumb *ethumbt[NETHUMBS]; 49 Ethumb *ethumbt[NETHUMBS];
50 int pipein, pipeout;
51}; 50};
52 51
53 52
@@ -131,7 +130,7 @@ _ec_pipe_str_read(struct _Ethumbd_Child *ec, char **str)
131 int r; 130 int r;
132 char buf[PATH_MAX]; 131 char buf[PATH_MAX];
133 132
134 r = _ec_read_safe(ec->pipein, &size, sizeof(size)); 133 r = _ec_read_safe(STDIN_FILENO, &size, sizeof(size));
135 if (!r) 134 if (!r)
136 { 135 {
137 *str = NULL; 136 *str = NULL;
@@ -144,7 +143,7 @@ _ec_pipe_str_read(struct _Ethumbd_Child *ec, char **str)
144 return 1; 143 return 1;
145 } 144 }
146 145
147 r = _ec_read_safe(ec->pipein, buf, size); 146 r = _ec_read_safe(STDIN_FILENO, buf, size);
148 if (!r) 147 if (!r)
149 { 148 {
150 *str = NULL; 149 *str = NULL;
@@ -155,28 +154,11 @@ _ec_pipe_str_read(struct _Ethumbd_Child *ec, char **str)
155 return 1; 154 return 1;
156} 155}
157 156
158static void
159_ec_pipe_str_write(struct _Ethumbd_Child *ec, const char *str)
160{
161 int size;
162
163 if (!str)
164 size = 0;
165 else
166 size = strlen(str) + 1;
167
168 _ec_write_safe(ec->pipeout, &size, sizeof(size));
169 _ec_write_safe(ec->pipeout, str, size);
170}
171
172static struct _Ethumbd_Child * 157static struct _Ethumbd_Child *
173_ec_new(int pipein, int pipeout) 158_ec_new(void)
174{ 159{
175 struct _Ethumbd_Child *ec = calloc(1, sizeof(*ec)); 160 struct _Ethumbd_Child *ec = calloc(1, sizeof(*ec));
176 161
177 ec->pipein = pipein;
178 ec->pipeout = pipeout;
179
180 return ec; 162 return ec;
181} 163}
182 164
@@ -203,7 +185,7 @@ _ec_op_new(struct _Ethumbd_Child *ec)
203 int r; 185 int r;
204 int index; 186 int index;
205 187
206 r = _ec_read_safe(ec->pipein, &index, sizeof(index)); 188 r = _ec_read_safe(STDIN_FILENO, &index, sizeof(index));
207 if (!r) 189 if (!r)
208 return 0; 190 return 0;
209 191
@@ -219,7 +201,7 @@ _ec_op_del(struct _Ethumbd_Child *ec)
219 int r; 201 int r;
220 int index; 202 int index;
221 203
222 r = _ec_read_safe(ec->pipein, &index, sizeof(index)); 204 r = _ec_read_safe(STDIN_FILENO, &index, sizeof(index));
223 if (!r) 205 if (!r)
224 return 0; 206 return 0;
225 207
@@ -233,15 +215,34 @@ _ec_op_del(struct _Ethumbd_Child *ec)
233static void 215static void
234_ec_op_generated_cb(void *data, Ethumb *e, Eina_Bool success) 216_ec_op_generated_cb(void *data, Ethumb *e, Eina_Bool success)
235{ 217{
236 struct _Ethumbd_Child *ec = data;
237 const char *thumb_path, *thumb_key; 218 const char *thumb_path, *thumb_key;
219 int size_path, size_key, size_cmd;
238 220
221 fprintf(stderr, "thumbnail generated!\n");
239 DBG("thumb generated!\n"); 222 DBG("thumb generated!\n");
240 ethumb_thumb_path_get(e, &thumb_path, &thumb_key); 223 ethumb_thumb_path_get(e, &thumb_path, &thumb_key);
241 _ec_write_safe(ec->pipeout, &success, sizeof(success));
242 224
243 _ec_pipe_str_write(ec, thumb_path); 225 if (!thumb_path)
244 _ec_pipe_str_write(ec, thumb_key); 226 size_path = 0;
227 else
228 size_path = strlen(thumb_path) + 1;
229
230 if (!thumb_key)
231 size_key = 0;
232 else
233 size_key = strlen(thumb_key) + 1;
234
235 size_cmd = sizeof(success) + sizeof(size_path) + size_path +
236 sizeof(size_key) + size_key;
237
238 _ec_write_safe(STDOUT_FILENO, &size_cmd, sizeof(size_cmd));
239 _ec_write_safe(STDOUT_FILENO, &success, sizeof(success));
240
241 _ec_write_safe(STDOUT_FILENO, &size_path, sizeof(size_path));
242 _ec_write_safe(STDOUT_FILENO, thumb_path, size_path);
243
244 _ec_write_safe(STDOUT_FILENO, &size_key, sizeof(size_key));
245 _ec_write_safe(STDOUT_FILENO, thumb_key, size_key);
245} 246}
246 247
247static int 248static int
@@ -251,7 +252,7 @@ _ec_op_generate(struct _Ethumbd_Child *ec)
251 char *path, *key, *thumb_path, *thumb_key; 252 char *path, *key, *thumb_path, *thumb_key;
252 int r; 253 int r;
253 254
254 r = _ec_read_safe(ec->pipein, &index, sizeof(index)); 255 r = _ec_read_safe(STDIN_FILENO, &index, sizeof(index));
255 if (!r) 256 if (!r)
256 return 0; 257 return 0;
257 258
@@ -286,7 +287,7 @@ _ec_fdo_set(struct _Ethumbd_Child *ec, Ethumb *e)
286 int r; 287 int r;
287 int value; 288 int value;
288 289
289 r = _ec_read_safe(ec->pipein, &value, sizeof(value)); 290 r = _ec_read_safe(STDIN_FILENO, &value, sizeof(value));
290 if (!r) 291 if (!r)
291 return 0; 292 return 0;
292 ethumb_thumb_fdo_set(e, value); 293 ethumb_thumb_fdo_set(e, value);
@@ -302,13 +303,13 @@ _ec_size_set(struct _Ethumbd_Child *ec, Ethumb *e)
302 int w, h; 303 int w, h;
303 int type; 304 int type;
304 305
305 r = _ec_read_safe(ec->pipein, &w, sizeof(w)); 306 r = _ec_read_safe(STDIN_FILENO, &w, sizeof(w));
306 if (!r) 307 if (!r)
307 return 0; 308 return 0;
308 r = _ec_read_safe(ec->pipein, &type, sizeof(type)); 309 r = _ec_read_safe(STDIN_FILENO, &type, sizeof(type));
309 if (!r) 310 if (!r)
310 return 0; 311 return 0;
311 r = _ec_read_safe(ec->pipein, &h, sizeof(h)); 312 r = _ec_read_safe(STDIN_FILENO, &h, sizeof(h));
312 if (!r) 313 if (!r)
313 return 0; 314 return 0;
314 ethumb_thumb_size_set(e, w, h); 315 ethumb_thumb_size_set(e, w, h);
@@ -323,7 +324,7 @@ _ec_format_set(struct _Ethumbd_Child *ec, Ethumb *e)
323 int r; 324 int r;
324 int value; 325 int value;
325 326
326 r = _ec_read_safe(ec->pipein, &value, sizeof(value)); 327 r = _ec_read_safe(STDIN_FILENO, &value, sizeof(value));
327 if (!r) 328 if (!r)
328 return 0; 329 return 0;
329 ethumb_thumb_format_set(e, value); 330 ethumb_thumb_format_set(e, value);
@@ -338,7 +339,7 @@ _ec_aspect_set(struct _Ethumbd_Child *ec, Ethumb *e)
338 int r; 339 int r;
339 int value; 340 int value;
340 341
341 r = _ec_read_safe(ec->pipein, &value, sizeof(value)); 342 r = _ec_read_safe(STDIN_FILENO, &value, sizeof(value));
342 if (!r) 343 if (!r)
343 return 0; 344 return 0;
344 ethumb_thumb_aspect_set(e, value); 345 ethumb_thumb_aspect_set(e, value);
@@ -354,13 +355,13 @@ _ec_crop_set(struct _Ethumbd_Child *ec, Ethumb *e)
354 float x, y; 355 float x, y;
355 int type; 356 int type;
356 357
357 r = _ec_read_safe(ec->pipein, &x, sizeof(x)); 358 r = _ec_read_safe(STDIN_FILENO, &x, sizeof(x));
358 if (!r) 359 if (!r)
359 return 0; 360 return 0;
360 r = _ec_read_safe(ec->pipein, &type, sizeof(type)); 361 r = _ec_read_safe(STDIN_FILENO, &type, sizeof(type));
361 if (!r) 362 if (!r)
362 return 0; 363 return 0;
363 r = _ec_read_safe(ec->pipein, &y, sizeof(y)); 364 r = _ec_read_safe(STDIN_FILENO, &y, sizeof(y));
364 if (!r) 365 if (!r)
365 return 0; 366 return 0;
366 ethumb_thumb_crop_align_set(e, x, y); 367 ethumb_thumb_crop_align_set(e, x, y);
@@ -375,7 +376,7 @@ _ec_quality_set(struct _Ethumbd_Child *ec, Ethumb *e)
375 int r; 376 int r;
376 int value; 377 int value;
377 378
378 r = _ec_read_safe(ec->pipein, &value, sizeof(value)); 379 r = _ec_read_safe(STDIN_FILENO, &value, sizeof(value));
379 if (!r) 380 if (!r)
380 return 0; 381 return 0;
381 ethumb_thumb_quality_set(e, value); 382 ethumb_thumb_quality_set(e, value);
@@ -390,7 +391,7 @@ _ec_compress_set(struct _Ethumbd_Child *ec, Ethumb *e)
390 int r; 391 int r;
391 int value; 392 int value;
392 393
393 r = _ec_read_safe(ec->pipein, &value, sizeof(value)); 394 r = _ec_read_safe(STDIN_FILENO, &value, sizeof(value));
394 if (!r) 395 if (!r)
395 return 0; 396 return 0;
396 ethumb_thumb_compress_set(e, value); 397 ethumb_thumb_compress_set(e, value);
@@ -409,13 +410,13 @@ _ec_frame_set(struct _Ethumbd_Child *ec, Ethumb *e)
409 r = _ec_pipe_str_read(ec, &theme_file); 410 r = _ec_pipe_str_read(ec, &theme_file);
410 if (!r) 411 if (!r)
411 return 0; 412 return 0;
412 r = _ec_read_safe(ec->pipein, &type, sizeof(type)); 413 r = _ec_read_safe(STDIN_FILENO, &type, sizeof(type));
413 if (!r) 414 if (!r)
414 return 0; 415 return 0;
415 r = _ec_pipe_str_read(ec, &group); 416 r = _ec_pipe_str_read(ec, &group);
416 if (!r) 417 if (!r)
417 return 0; 418 return 0;
418 r = _ec_read_safe(ec->pipein, &type, sizeof(type)); 419 r = _ec_read_safe(STDIN_FILENO, &type, sizeof(type));
419 if (!r) 420 if (!r)
420 return 0; 421 return 0;
421 r = _ec_pipe_str_read(ec, &swallow); 422 r = _ec_pipe_str_read(ec, &swallow);
@@ -468,7 +469,7 @@ _ec_video_time_set(struct _Ethumbd_Child *ec, Ethumb *e)
468 int r; 469 int r;
469 float value; 470 float value;
470 471
471 r = _ec_read_safe(ec->pipein, &value, sizeof(value)); 472 r = _ec_read_safe(STDIN_FILENO, &value, sizeof(value));
472 if (!r) 473 if (!r)
473 return 0; 474 return 0;
474 ethumb_video_time_set(e, value); 475 ethumb_video_time_set(e, value);
@@ -483,7 +484,7 @@ _ec_video_start_set(struct _Ethumbd_Child *ec, Ethumb *e)
483 int r; 484 int r;
484 float value; 485 float value;
485 486
486 r = _ec_read_safe(ec->pipein, &value, sizeof(value)); 487 r = _ec_read_safe(STDIN_FILENO, &value, sizeof(value));
487 if (!r) 488 if (!r)
488 return 0; 489 return 0;
489 ethumb_video_start_set(e, value); 490 ethumb_video_start_set(e, value);
@@ -498,7 +499,7 @@ _ec_video_interval_set(struct _Ethumbd_Child *ec, Ethumb *e)
498 int r; 499 int r;
499 float value; 500 float value;
500 501
501 r = _ec_read_safe(ec->pipein, &value, sizeof(value)); 502 r = _ec_read_safe(STDIN_FILENO, &value, sizeof(value));
502 if (!r) 503 if (!r)
503 return 0; 504 return 0;
504 ethumb_video_interval_set(e, value); 505 ethumb_video_interval_set(e, value);
@@ -513,7 +514,7 @@ _ec_video_ntimes_set(struct _Ethumbd_Child *ec, Ethumb *e)
513 int r; 514 int r;
514 int value; 515 int value;
515 516
516 r = _ec_read_safe(ec->pipein, &value, sizeof(value)); 517 r = _ec_read_safe(STDIN_FILENO, &value, sizeof(value));
517 if (!r) 518 if (!r)
518 return 0; 519 return 0;
519 ethumb_video_ntimes_set(e, value); 520 ethumb_video_ntimes_set(e, value);
@@ -528,7 +529,7 @@ _ec_video_fps_set(struct _Ethumbd_Child *ec, Ethumb *e)
528 int r; 529 int r;
529 int value; 530 int value;
530 531
531 r = _ec_read_safe(ec->pipein, &value, sizeof(value)); 532 r = _ec_read_safe(STDIN_FILENO, &value, sizeof(value));
532 if (!r) 533 if (!r)
533 return 0; 534 return 0;
534 ethumb_video_fps_set(e, value); 535 ethumb_video_fps_set(e, value);
@@ -543,7 +544,7 @@ _ec_document_page_set(struct _Ethumbd_Child *ec, Ethumb *e)
543 int r; 544 int r;
544 int value; 545 int value;
545 546
546 r = _ec_read_safe(ec->pipein, &value, sizeof(value)); 547 r = _ec_read_safe(STDIN_FILENO, &value, sizeof(value));
547 if (!r) 548 if (!r)
548 return 0; 549 return 0;
549 ethumb_document_page_set(e, value); 550 ethumb_document_page_set(e, value);
@@ -621,17 +622,17 @@ _ec_op_setup(struct _Ethumbd_Child *ec)
621 int index; 622 int index;
622 int type; 623 int type;
623 624
624 r = _ec_read_safe(ec->pipein, &index, sizeof(index)); 625 r = _ec_read_safe(STDIN_FILENO, &index, sizeof(index));
625 if (!r) 626 if (!r)
626 return 0; 627 return 0;
627 628
628 r = _ec_read_safe(ec->pipein, &type, sizeof(type)); 629 r = _ec_read_safe(STDIN_FILENO, &type, sizeof(type));
629 if (!r) 630 if (!r)
630 return 0; 631 return 0;
631 while (type != ETHUMBD_SETUP_FINISHED) 632 while (type != ETHUMBD_SETUP_FINISHED)
632 { 633 {
633 _ec_setup_process(ec, index, type); 634 _ec_setup_process(ec, index, type);
634 r = _ec_read_safe(ec->pipein, &type, sizeof(type)); 635 r = _ec_read_safe(STDIN_FILENO, &type, sizeof(type));
635 if (!r) 636 if (!r)
636 return 0; 637 return 0;
637 } 638 }
@@ -654,7 +655,7 @@ _ec_fd_handler(void *data, Ecore_Fd_Handler *fd_handler)
654 return 0; 655 return 0;
655 } 656 }
656 657
657 r = _ec_read_safe(ec->pipein, &op_id, sizeof(op_id)); 658 r = _ec_read_safe(STDIN_FILENO, &op_id, sizeof(op_id));
658 if (!r) 659 if (!r)
659 { 660 {
660 DBG("ethumbd exited! child exiting...\n"); 661 DBG("ethumbd exited! child exiting...\n");
@@ -699,18 +700,18 @@ static void
699_ec_setup(struct _Ethumbd_Child *ec) 700_ec_setup(struct _Ethumbd_Child *ec)
700{ 701{
701 ec->fd_handler = ecore_main_fd_handler_add( 702 ec->fd_handler = ecore_main_fd_handler_add(
702 ec->pipein, ECORE_FD_READ | ECORE_FD_ERROR, 703 STDIN_FILENO, ECORE_FD_READ | ECORE_FD_ERROR,
703 _ec_fd_handler, ec, NULL, NULL); 704 _ec_fd_handler, ec, NULL, NULL);
704} 705}
705 706
706void 707int
707ethumbd_child_start(int pipein, int pipeout) 708main(int argc, const char *argv[])
708{ 709{
709 struct _Ethumbd_Child *ec; 710 struct _Ethumbd_Child *ec;
710 711
711 ethumb_init(); 712 ethumb_init();
712 713
713 ec = _ec_new(pipein, pipeout); 714 ec = _ec_new();
714 715
715 _ec_setup(ec); 716 _ec_setup(ec);
716 717
@@ -721,4 +722,6 @@ ethumbd_child_start(int pipein, int pipeout)
721 _ec_free(ec); 722 _ec_free(ec);
722 723
723 ethumb_shutdown(); 724 ethumb_shutdown();
725
726 return 0;
724} 727}