Make certain that server.utils.__clean_tmp_dirs is called; currently
it relies on atexit.register to handle this, but subprocesses that
exit with os._exit don't trigger this. We can add in another
join hook to subcommand that will handle that case.
Risk: Medium
Visibility: There should be a lot less garbage /tmp directories left
lying around.
Signed-off-by: John Admanski <jadmanski@google.com>
git-svn-id: http://test.kernel.org/svn/autotest/trunk@2562 592f7852-d20e-0410-864c-8624ca9c26a4
diff --git a/server/utils.py b/server/utils.py
index 9a4b655..3e80430 100644
--- a/server/utils.py
+++ b/server/utils.py
@@ -15,6 +15,7 @@
import atexit, os, re, shutil, textwrap, sys, tempfile, types
from autotest_lib.client.common_lib import utils
+from autotest_lib.server import subcommand
# A dictionary of pid and a list of tmpdirs for that pid
@@ -170,9 +171,7 @@
The directory and its content will be deleted automatically
at the end of the program execution if they are still present.
"""
- global __tmp_dirs
-
- dir_name= tempfile.mkdtemp(prefix="autoserv-")
+ dir_name = tempfile.mkdtemp(prefix="autoserv-")
pid = os.getpid()
if not pid in __tmp_dirs:
__tmp_dirs[pid] = []
@@ -180,13 +179,10 @@
return dir_name
-@atexit.register
def __clean_tmp_dirs():
"""Erase temporary directories that were created by the get_tmp_dir()
function and that are still present.
"""
- global __tmp_dirs
-
pid = os.getpid()
if pid not in __tmp_dirs:
return
@@ -197,6 +193,8 @@
if e.errno == 2:
pass
__tmp_dirs[pid] = []
+atexit.register(__clean_tmp_dirs)
+subcommand.subcommand.register_join_hook(lambda _: __clean_tmp_dirs())
def unarchive(host, source_material):