summaryrefslogtreecommitdiffstats
path: root/pym/_emerge/EbuildIpcDaemon.py
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2010-08-12 20:46:53 -0700
committerZac Medico <zmedico@gentoo.org>2010-08-12 20:46:53 -0700
commit6451c6cbde1fa91cf15fa03f79bfbd421329ba2c (patch)
tree0f2d9fb780ebe31595847af773bcfe8cf9325ccb /pym/_emerge/EbuildIpcDaemon.py
parentffe0e3fb6998c776b08f725c53dfe6c632ce7d02 (diff)
downloadportage-6451c6cbde1fa91cf15fa03f79bfbd421329ba2c.tar.gz
portage-6451c6cbde1fa91cf15fa03f79bfbd421329ba2c.tar.bz2
portage-6451c6cbde1fa91cf15fa03f79bfbd421329ba2c.zip
Split out an EbuildIpcDaemon class from FifoIpcDaemon.
Diffstat (limited to 'pym/_emerge/EbuildIpcDaemon.py')
-rw-r--r--pym/_emerge/EbuildIpcDaemon.py52
1 files changed, 52 insertions, 0 deletions
diff --git a/pym/_emerge/EbuildIpcDaemon.py b/pym/_emerge/EbuildIpcDaemon.py
new file mode 100644
index 000000000..48f58224b
--- /dev/null
+++ b/pym/_emerge/EbuildIpcDaemon.py
@@ -0,0 +1,52 @@
+# Copyright 2010 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+import array
+import pickle
+from portage import os
+from _emerge.FifoIpcDaemon import FifoIpcDaemon
+from _emerge.PollConstants import PollConstants
+
+class EbuildIpcDaemon(FifoIpcDaemon):
+ """
+ This class serves as an IPC daemon, which ebuild processes can use
+ to communicate with portage's main python process.
+
+ Here are a few possible uses:
+
+ 1) Robust subshell/subprocess die support. This allows the ebuild
+ environment to reliably die without having to rely on signal IPC.
+
+ 2) Delegation of portageq calls to the main python process, eliminating
+ performance and userpriv permission issues.
+
+ 3) Reliable ebuild termination in cases when the ebuild has accidentally
+ left orphan processes running in the backgraound (as in bug 278895).
+ """
+
+ __slots__ = ()
+
+ def _input_handler(self, fd, event):
+
+ if event & PollConstants.POLLIN:
+
+ buf = array.array('B')
+ try:
+ buf.fromfile(self._files.pipe_in, self._bufsize)
+ except (EOFError, IOError):
+ pass
+
+ if buf:
+ obj = pickle.loads(buf.tostring())
+ if isinstance(obj, list) and \
+ obj and \
+ obj[0] == 'exit':
+ output_fd = os.open(self.output_fifo, os.O_WRONLY|os.O_NONBLOCK)
+ output_file = os.fdopen(output_fd, 'wb')
+ pickle.dump('OK', output_file)
+ output_file.close()
+ self._unregister()
+ self.wait()
+
+ self._unregister_if_appropriate(event)
+ return self._registered