import portage
-import emergehelp,xpak,string,re,commands,time,shutil,traceback,atexit,signal,socket,types
+import emergehelp,xpak,string,re,commands,time,shutil,traceback,signal,socket,types
from stat import *
from output import *
emergelog(" *** terminating.")
if "notitles" not in portage.features:
xtermTitleReset()
-atexit.register(emergeexit)
+portage.atexit_register(emergeexit)
def emergeexitsig(signum, frame):
signal.signal(signal.SIGINT, signal.SIG_IGN)
if len(mymergelist) > mergecount:
emergelog(" *** RESTARTING emerge via exec() after change of portage version.")
del portage.mtimedb["resume"]["mergelist"][0]
- portage.portageexit()
+ portage.run_exitfuncs()
mynewargv=[sys.argv[0],"--resume"]
badlongopts = ("--ask","--tree","--changelog","--skipfirst","--resume")
for arg in myopts:
raise SystemExit, 127
try:
- import os,string,types,atexit,signal,fcntl
+ import os,string,types,signal,fcntl
import time,cPickle,traceback,copy
import re,pwd,grp,commands
import shlex,shutil
import portage_gpg
import portage_locks
import portage_exec
+ from portage_exec import atexit_register, run_exitfuncs
from portage_locks import unlockfile,unlockdir,lockfile,lockdir
import portage_checksum
from portage_checksum import perform_md5,perform_checksum,prelink_capable
close_portdbapi_caches()
commit_mtimedb()
-atexit.register(portageexit)
+atexit_register(portageexit)
if (secpass==2) and (not os.environ.has_key("SANDBOX_ACTIVE")):
if settings["PORTAGE_CALLER"] in ["emerge","fixpackages"]:
import os, atexit, signal, sys
import portage_data
+from portage_util import dump_traceback
from portage_const import BASH_BINARY, SANDBOX_BINARY
args.append(mycommand)
return spawn(args, opt_name=opt_name, **keywords)
+_exithandlers = []
+def atexit_register(func, *args, **kargs):
+ """Wrapper around atexit.register that is needed in order to track
+ what is registered. For example, when portage restarts itself via
+ os.execv, the atexit module does not work so we have to do it
+ manually by calling the run_exitfuncs() function in this module."""
+ _exithandlers.append((func, args, kargs))
+
+def run_exitfuncs():
+ """This should behave identically to the routine performed by
+ the atexit module at exit time. It's only necessary to call this
+ function when atexit will not work (because of os.execv, for
+ example)."""
+
+ # This function is a copy of the private atexit._run_exitfuncs()
+ # from the python 2.4.2 sources. The only difference from the
+ # original function is in the output to stderr.
+ exc_info = None
+ while _exithandlers:
+ func, targs, kargs = _exithandlers.pop()
+ try:
+ func(*targs, **kargs)
+ except SystemExit:
+ exc_info = sys.exc_info()
+ except:
+ dump_traceback("Error in portage_exec.run_exitfuncs", noiselevel=0)
+ exc_info = sys.exc_info()
+
+ if exc_info is not None:
+ raise exc_info[0], exc_info[1], exc_info[2]
+
+atexit.register(run_exitfuncs)
+
# We need to make sure that any processes spawned are killed off when
# we exit. spawn() takes care of adding and removing pids to this list
# as it creates and cleans up processes.
# of spawn().
pass
-atexit.register(cleanup)
+atexit_register(cleanup)
def spawn(mycommand, env={}, opt_name=None, fd_pipes=None, returnpid=False,
uid=None, gid=None, groups=None, umask=None, logfile=None,
# $Id: /var/cvsroot/gentoo-src/portage/pym/portage_locks.py,v 1.18.2.2 2005/01/16 02:35:33 carpaski Exp $
-import atexit
import errno
import os
import stat
import portage_file
import portage_util
import portage_data
+from portage_exec import atexit_register
from portage_localization import _
HARDLINK_FD = -2
if os.path.isdir(mypath):
hardlock_path_list = mypath[:]
-atexit.register(clean_my_hardlocks)
+atexit_register(clean_my_hardlocks)
def lockdir(mydir):
return lockfile(mydir,wantnewlockfile=1)