Commit 9a5824ad authored by Nicolas Wavrant's avatar Nicolas Wavrant

SlapObject: when destroying a partition, no processes should be remaining

parent aaa098a5
......@@ -30,6 +30,7 @@
import os
import pkg_resources
import psutil
import pwd
import shutil
import stat
......@@ -673,11 +674,12 @@ class Partition(object):
if not self.checkRetentionIsAuthorized():
return False
uid, gid = self.getUserGroupId()
# Launches "destroy" binary if exists
destroy_executable_location = os.path.join(self.instance_path, 'sbin',
'destroy')
if os.path.exists(destroy_executable_location):
uid, gid = self.getUserGroupId()
self.logger.debug('Invoking %r' % destroy_executable_location)
process_handler = SlapPopen([destroy_executable_location],
preexec_fn=lambda: dropPrivileges(uid, gid, logger=self.logger),
......@@ -726,6 +728,19 @@ class Partition(object):
except IOError as exc:
raise IOError("I/O error while freeing partition (%s): %s" % (self.instance_path, exc))
# Kill remaining processes
try:
current_pid = os.getpid()
[x.terminate() for x in psutil.process_iter() if uid in x.uids()
and x.pid != current_pid]
except (psutil.NoSuchProcess, psutil.AccessDenied) as e:
self.logger.info("Process finished before being "
"killed when freeing partition %s" % self.instance_path)
except psutil.TimeoutExpired as e:
self.logger.error("Couldn't kill process %s of destroyed partition %s"
% self.instance_path)
return True
def cleanupFolder(self, folder_path):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment