1
=== modified file 'aptdaemon/debconf.py'
2
--- aptdaemon/debconf.py 2009-10-02 11:27:03 +0000
3
+++ aptdaemon/debconf.py 2010-03-15 02:05:34 +0000
13
self._listener_id = None
14
self._active_conn = None
16
+ self._socket_lock = threading.Lock()
17
+ self._socket_closed = False
19
def _get_debconf_env(self):
20
"""Returns a dictonary of the environment variables required by
23
"""Stop listening on the socket."""
24
logging.debug("debconf.stop()")
26
- # ensure outstanding gio messages are processed
27
- context = glib.main_context_default()
28
- while context.pending():
30
- gobject.source_remove(self._listener_id)
31
- self._listener_id = None
32
+ self._socket_lock.acquire()
35
+ self._socket_closed = True
36
+ # ensure outstanding gio messages are processed
37
+ context = glib.main_context_default()
38
+ while context.pending():
40
+ gobject.source_remove(self._listener_id)
41
+ self._listener_id = None
43
+ self._socket_lock.release()
45
def _accept_connection(self, source, condition):
46
"""Callback for new connections of the passthrough frontend."""
47
log.debug("New passthrough connection")
48
- # ensure outstanding gio messages are processed (to ensure
49
- # that _hangup was run on the previous connection, see LP: #432607)
50
- context = glib.main_context_default()
51
- while context.pending():
53
- if self._active_conn:
54
- raise IOError, "Multiple debconf connections not supported"
55
- conn, addr = source.accept()
56
- self._active_conn = conn
57
- self.helper = subprocess.Popen(["debconf-communicate"],
58
- stdin=subprocess.PIPE,
59
- stdout=subprocess.PIPE,
60
- env=self._get_debconf_env())
61
- w = gobject.io_add_watch(conn, gobject.IO_IN|gobject.IO_HUP|gobject.IO_ERR,
62
- self._copy_conn, self.helper.stdin)
63
- self._watch_ids.append(w)
64
- w= gobject.io_add_watch(self.helper.stdout, gobject.IO_IN,
65
- self._copy_stdout, conn)
66
- self._watch_ids.append(w)
67
- w = gobject.io_add_watch(self.helper.stdout, gobject.IO_HUP|gobject.IO_ERR,
69
- self._watch_ids.append(w)
71
+ self._socket_lock.acquire()
73
+ # ensure outstanding gio messages are processed (to ensure
74
+ # that _hangup was run on the previous connection, see LP: #432607)
75
+ context = glib.main_context_default()
76
+ while context.pending():
78
+ if self._socket_closed:
80
+ if self._active_conn:
81
+ raise IOError, "Multiple debconf connections not supported"
82
+ conn, addr = source.accept()
83
+ self._active_conn = conn
84
+ self.helper = subprocess.Popen(["debconf-communicate"],
85
+ stdin=subprocess.PIPE,
86
+ stdout=subprocess.PIPE,
87
+ env=self._get_debconf_env())
88
+ w = gobject.io_add_watch(conn, gobject.IO_IN|gobject.IO_HUP|gobject.IO_ERR,
89
+ self._copy_conn, self.helper.stdin)
90
+ self._watch_ids.append(w)
91
+ w= gobject.io_add_watch(self.helper.stdout, gobject.IO_IN,
92
+ self._copy_stdout, conn)
93
+ self._watch_ids.append(w)
94
+ w = gobject.io_add_watch(self.helper.stdout, gobject.IO_HUP|gobject.IO_ERR,
96
+ self._watch_ids.append(w)
99
+ self._socket_lock.release()
101
def _hangup(self, source, condition):
102
"""Callback when the debconf-communicate program exists