aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-07-26 23:38:10 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-07-26 23:38:10 +0000
commit82b61b1bed051ae9e98ba1fe68b5b77ff5fc98fb (patch)
tree0c1e4c5da19cba01922492f263ff78fa28bbdef3
parenta07eef61025a2614bb8a535dac98a75947a32be5 (diff)
downloadpaludis-82b61b1bed051ae9e98ba1fe68b5b77ff5fc98fb.tar.gz
paludis-82b61b1bed051ae9e98ba1fe68b5b77ff5fc98fb.tar.xz
Sync in a fork()ed pid. No locking or refreshing done currently, so, uh, things can break in very weird ways...
-rw-r--r--src/gtkpaludis/browse_tree.cc64
-rw-r--r--src/gtkpaludis/browse_tree.hh1
2 files changed, 58 insertions, 7 deletions
diff --git a/src/gtkpaludis/browse_tree.cc b/src/gtkpaludis/browse_tree.cc
index 6355b05..d57c8ba 100644
--- a/src/gtkpaludis/browse_tree.cc
+++ b/src/gtkpaludis/browse_tree.cc
@@ -25,8 +25,12 @@
#include <gtkmm/messagedialog.h>
#include <paludis/default_environment.hh>
+#include <paludis/util/log.hh>
#include <paludis/syncer.hh>
+#include <sys/types.h>
+#include <sys/wait.h>
+
using namespace paludis;
namespace
@@ -308,8 +312,11 @@ namespace paludis
Gtk::Menu popup_menu;
+ pid_t paludis_child;
+
Implementation(InformationTree * const i) :
- information_tree(i)
+ information_tree(i),
+ paludis_child(-1)
{
}
@@ -376,16 +383,31 @@ BrowseTree::on_menu_sync()
{
Gtk::TreeModel::iterator i(selection->get_selected());
if (i)
- try
+ {
+ pid_t child(fork());
+ if (0 == child)
{
- BrowseTreeDisplayData::Pointer((*i)[_imp->columns.col_data])->sync();
+ try
+ {
+ BrowseTreeDisplayData::Pointer((*i)[_imp->columns.col_data])->sync();
+ _exit(0);
+ }
+ catch (const SyncFailedError & e)
+ {
+ _exit(1);
+ }
}
- catch (const SyncFailedError & e)
+ else if (-1 == child)
+ throw InternalError(PALUDIS_HERE, "fork failed");
+ else
{
- Gtk::MessageDialog dialog("Sync failed", false, Gtk::MESSAGE_ERROR);
- dialog.set_secondary_text(e.message());
- dialog.run();
+ Log::get_instance()->message(ll_debug, lc_no_context,
+ "Forked child process " + stringify(child));
+ _imp->paludis_child = child;
+ Glib::signal_timeout().connect(sigc::mem_fun(*this,
+ &BrowseTree::on_child_process_timer), 50);
}
+ }
}
}
@@ -400,3 +422,31 @@ BrowseTree::on_button_press_event(GdkEventButton * event)
return result;
}
+bool
+BrowseTree::on_child_process_timer()
+{
+ if (-1 == _imp->paludis_child)
+ return false;
+
+ int status(-1);
+ switch (waitpid(_imp->paludis_child, &status, WNOHANG))
+ {
+ case 0:
+ return true;
+
+ case -1:
+ throw InternalError(PALUDIS_HERE, "bad value -1 from waitpid");
+
+ default:
+ if (0 == status)
+ Log::get_instance()->message(ll_debug, lc_no_context, "child " + stringify(_imp->paludis_child)
+ + " exited with success");
+ else
+ Log::get_instance()->message(ll_debug, lc_no_context, "child " + stringify(_imp->paludis_child)
+ + " exited with failure code " + stringify(status));
+
+ _imp->paludis_child = -1;
+ return false;
+ }
+}
+
diff --git a/src/gtkpaludis/browse_tree.hh b/src/gtkpaludis/browse_tree.hh
index 91f4892..51f4de5 100644
--- a/src/gtkpaludis/browse_tree.hh
+++ b/src/gtkpaludis/browse_tree.hh
@@ -39,6 +39,7 @@ namespace paludis
virtual void on_menu_sync();
virtual bool on_button_press_event(GdkEventButton *);
+ virtual bool on_child_process_timer();
};
}