Mercurial > pidgin
comparison finch/libgnt/gntmain.c @ 18526:09db6fec9dce
Allow having a callback after the child process terminates. Use the callback
to remove the temporary file used by the pager.
author | Sadrul Habib Chowdhury <imadil@gmail.com> |
---|---|
date | Fri, 13 Jul 2007 16:50:03 +0000 |
parents | ec80e921818c |
children | 0873698f8cce 9f7587b86b0d |
comparison
equal
deleted
inserted
replaced
18525:59c361c2f25b | 18526:09db6fec9dce |
---|---|
304 | 304 |
305 g_io_channel_unref(channel); /* Apparently this caused crashes for some people. | 305 g_io_channel_unref(channel); /* Apparently this caused crashes for some people. |
306 But irssi does this, so I am going to assume the | 306 But irssi does this, so I am going to assume the |
307 crashes were caused by some other stuff. */ | 307 crashes were caused by some other stuff. */ |
308 | 308 |
309 g_printerr("gntmain: setting up IO\n"); | 309 g_printerr("gntmain: setting up IO (%d)\n", channel_read_callback); |
310 } | 310 } |
311 | 311 |
312 static gboolean | 312 static gboolean |
313 refresh_screen() | 313 refresh_screen() |
314 { | 314 { |
641 { | 641 { |
642 return gnt_clipboard_get_string(clipboard); | 642 return gnt_clipboard_get_string(clipboard); |
643 } | 643 } |
644 | 644 |
645 #if GLIB_CHECK_VERSION(2,4,0) | 645 #if GLIB_CHECK_VERSION(2,4,0) |
646 typedef struct | |
647 { | |
648 void (*callback)(int status, gpointer data); | |
649 gpointer data; | |
650 } ChildProcess; | |
651 | |
646 static void | 652 static void |
647 reap_child(GPid pid, gint status, gpointer data) | 653 reap_child(GPid pid, gint status, gpointer data) |
648 { | 654 { |
655 ChildProcess *cp = data; | |
656 if (cp->callback) { | |
657 cp->callback(status, cp->data); | |
658 } | |
659 g_free(cp); | |
660 clean_pid(); | |
649 wm->mode = GNT_KP_MODE_NORMAL; | 661 wm->mode = GNT_KP_MODE_NORMAL; |
650 clear(); | 662 clear(); |
651 setup_io(); | 663 setup_io(); |
652 refresh_screen(); | 664 refresh_screen(); |
653 } | 665 } |
654 #endif | 666 #endif |
655 | 667 |
656 gboolean gnt_giveup_console(const char *wd, char **argv, char **envp, | 668 gboolean gnt_giveup_console(const char *wd, char **argv, char **envp, |
657 gint *stin, gint *stout, gint *sterr) | 669 gint *stin, gint *stout, gint *sterr, |
670 void (*callback)(int status, gpointer data), gpointer data) | |
658 { | 671 { |
659 #if GLIB_CHECK_VERSION(2,4,0) | 672 #if GLIB_CHECK_VERSION(2,4,0) |
660 GPid pid = 0; | 673 GPid pid = 0; |
674 ChildProcess *cp = NULL; | |
661 | 675 |
662 if (!g_spawn_async_with_pipes(wd, argv, envp, | 676 if (!g_spawn_async_with_pipes(wd, argv, envp, |
663 G_SPAWN_SEARCH_PATH | G_SPAWN_DO_NOT_REAP_CHILD, | 677 G_SPAWN_SEARCH_PATH | G_SPAWN_DO_NOT_REAP_CHILD, |
664 (GSpawnChildSetupFunc)endwin, NULL, | 678 (GSpawnChildSetupFunc)endwin, NULL, |
665 &pid, stin, stout, sterr, NULL)) | 679 &pid, stin, stout, sterr, NULL)) |
666 return FALSE; | 680 return FALSE; |
667 | 681 |
682 cp = g_new0(ChildProcess, 1); | |
683 cp->callback = callback; | |
684 cp->data = data; | |
668 g_source_remove(channel_read_callback); | 685 g_source_remove(channel_read_callback); |
669 wm->mode = GNT_KP_MODE_WAIT_ON_CHILD; | 686 wm->mode = GNT_KP_MODE_WAIT_ON_CHILD; |
670 g_child_watch_add(pid, reap_child, NULL); | 687 g_child_watch_add(pid, reap_child, cp); |
671 | 688 |
672 return TRUE; | 689 return TRUE; |
673 #else | 690 #else |
674 return FALSE; | 691 return FALSE; |
675 #endif | 692 #endif |