summaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2007-03-01 20:42:52 +0000
committerZac Medico <zmedico@gentoo.org>2007-03-01 20:42:52 +0000
commit0a9293061ecf4dc54ad6ce17028bd0c9e8d0dde4 (patch)
treeb4e1a574a4be67836c96d5df6ff04acb83f0ac47 /bin
parent0341c0957ee66888e2d44ac65e53895d1dd281c8 (diff)
downloadportage-0a9293061ecf4dc54ad6ce17028bd0c9e8d0dde4.tar.gz
portage-0a9293061ecf4dc54ad6ce17028bd0c9e8d0dde4.tar.bz2
portage-0a9293061ecf4dc54ad6ce17028bd0c9e8d0dde4.zip
Use an alarm signal to implement a timeout when rsync is fetching the server timestamp file, since rsync's --timeout option doesn't apply to the initial connection attempt. (trunk r6108:6109)
svn path=/main/branches/2.1.2/; revision=6110
Diffstat (limited to 'bin')
-rwxr-xr-xbin/emerge52
1 files changed, 40 insertions, 12 deletions
diff --git a/bin/emerge b/bin/emerge
index 3133ae29e..95169c14b 100755
--- a/bin/emerge
+++ b/bin/emerge
@@ -3929,23 +3929,51 @@ def action_sync(settings, trees, mtimedb, myopts, myaction):
"/metadata/timestamp.chk")
mycommand.append(tmpservertimestampfile)
import portage_exec
+ content = None
+ mypids = []
try:
- exitcode = portage_exec.spawn(
- mycommand, env=settings.environ())
- content = portage.grabfile(tmpservertimestampfile)
- if content:
+ def timeout_handler(signum, frame):
+ raise portage_exception.PortageException("timed out")
+ signal.signal(signal.SIGALRM, timeout_handler)
+ # Timeout here in case the server is unresponsive. The
+ # --timeout rsync option doesn't apply to the initial
+ # connection attempt.
+ signal.alarm(15)
+ try:
+ mypids.extend(portage_exec.spawn(
+ mycommand, env=settings.environ(), returnpid=True))
+ exitcode = os.waitpid(mypids[0], 0)[1]
+ content = portage.grabfile(tmpservertimestampfile)
+ finally:
+ signal.alarm(0)
try:
- servertimestamp = time.mktime(time.strptime(
- content[0], "%a, %d %b %Y %H:%M:%S +0000"))
- except OverflowError, ValueError:
+ os.unlink(tmpservertimestampfile)
+ except OSError:
pass
- del content
- finally:
+ except portage_exception.PortageException, e:
+ # timed out
+ print e
+ del e
+ if mypids and os.waitpid(mypids[0], os.WNOHANG) == (0,0):
+ os.kill(mypids[0], signal.SIGTERM)
+ os.waitpid(mypids[0], 0)
+ # This is the same code rsync uses for timeout.
+ exitcode = 30
+ else:
+ if mypids:
+ portage_exec.spawned_pids.remove(mypids[0])
+ if exitcode != os.EX_OK:
+ if exitcode & 0xff:
+ exitcode = (exitcode & 0xff) << 8
+ else:
+ exitcode >> 8
+ if content:
try:
- os.unlink(tmpservertimestampfile)
- except OSError:
+ servertimestamp = time.mktime(time.strptime(
+ content[0], "%a, %d %b %Y %H:%M:%S +0000"))
+ except OverflowError, ValueError:
pass
- del mycommand
+ del mycommand, mypids, content
if exitcode == os.EX_OK:
if (servertimestamp != 0) and (servertimestamp == mytimestamp):
emergelog(xterm_titles,