Skip to content
This repository has been archived by the owner on Feb 7, 2024. It is now read-only.

Commit

Permalink
Fix container cleanup
Browse files Browse the repository at this point in the history
Signed-off-by: Michal Fabik <[email protected]>
  • Loading branch information
michalfabik authored and mkutlak committed Jan 29, 2020
1 parent 921759f commit f6deee5
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 32 deletions.
36 changes: 15 additions & 21 deletions src/retrace/retrace.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ def parse_http_gettext(lang, charset):
return result


def run_gdb(savedir, plugin, repopath, fafrepo=None):
def run_gdb(savedir, plugin, repopath, fafrepo=None, taskid=None):
# exception is caught on the higher level
exec_file = open(os.path.join(savedir, "crash", "executable"), "r")
executable = exec_file.read(ALLOWED_FILES["executable"])
Expand Down Expand Up @@ -422,19 +422,14 @@ def run_gdb(savedir, plugin, repopath, fafrepo=None):
if build_image:
raise Exception("Unable to build podman container")

container_id = str(taskid)

if CONFIG["UseFafPackages"]:
child = Popen(["/usr/bin/podman",
"run",
"-it",
"--detach",
"--volume=%s:%s:ro" % (repopath, repopath),
"--volume=%s:/var/spool/abrt/faf-packages" % fafrepo,
"retrace-image"],
stdout=PIPE, stderr=PIPE, encoding='utf-8')
container_id = child.communicate()[0]
container_id = container_id.rstrip()

log_debug("Retrace container id: %s" % container_id)
run(["/usr/bin/podman", "run", "-it", "--detach",
"--volume=%s:%s:ro" % (repopath, repopath),
"--volume=%s:/var/spool/abrt/faf-packages" % fafrepo,
"retrace-image"],
stdout=DEVNULL, stderr=DEVNULL, encoding='utf-8')

child = Popen("/usr/bin/podman exec -it %s bash -c "
"'for PKG in /var/spool/abrt/faf-packages/*; "
Expand All @@ -445,21 +440,20 @@ def run_gdb(savedir, plugin, repopath, fafrepo=None):
child = Popen(["/usr/bin/podman", "exec", container_id,
"/var/spool/abrt/gdb.sh"], stdout=PIPE, stderr=PIPE, encoding='utf-8')
else:
child = Popen(["/usr/bin/podman", "run", "-it", "--volume=%s:%s:ro" % (repopath, repopath),
"retrace-image"], stdout=PIPE, stderr=PIPE, encoding='utf-8')
child = run(["/usr/bin/podman", "run", "-it", "--volume=%s:%s:ro" % (repopath, repopath),
"--name=%s" % container_id, "retrace-image"], stdout=PIPE, encoding='utf-8')
else:
raise Exception("RetraceEnvironment set to invalid value")

backtrace = child.communicate()[0].strip()
if child.wait():
raise Exception("Running GDB failed")

if container_id:
log_debug("Stopping container %s" % container_id)
err = call(["/usr/bin/podman", "stop", container_id], stdout=DEVNULL, stderr=DEVNULL)
if err:
log_warn("Couldn't stop container %s" % container_id)
log_debug("Removing container %s" % container_id)
if CONFIG["RetraceEnvironment"] == "podman":
if CONFIG["UseFafPackages"]:
err = call(["/usr/bin/podman", "stop", container_id], stdout=DEVNULL, stderr=DEVNULL)
if err:
log_warn("Couldn't stop container %s" % container_id)
err = call(["/usr/bin/podman", "rm", container_id], stdout=DEVNULL, stderr=DEVNULL)
if err:
log_warn("Couldn't remove container %s" % container_id)
Expand Down
21 changes: 10 additions & 11 deletions src/retrace/retrace_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ def start_retrace(self, custom_arch=None):
self.hook.run("pre_retrace")

try:
backtrace, exploitable = run_gdb(task.get_savedir(), self.plugin, repopath, self.fafrepo)
backtrace, exploitable = run_gdb(task.get_savedir(), self.plugin, repopath, self.fafrepo, task.get_taskid())
except Exception as ex:
log_error(str(ex))
self._fail()
Expand Down Expand Up @@ -810,16 +810,15 @@ def start_vmcore(self, custom_kernelver=None):
raise Exception("Unable to build podman container")

vmlinux = vmcore.prepare_debuginfo(task, kernelver=kernelver)
child = Popen(["/usr/bin/podman",
"run",
"--detach",
"-it",
"retrace-image"],
stdout=PIPE, stderr=PIPE, encoding='utf-8')
(container_id, err) = child.communicate()
container_id = container_id.rstrip()
if err:
log_error(str(err))
child = run(["/usr/bin/podman",
"run",
"--detach",
"-it",
"retrace-image"],
stdout=PIPE, encoding='utf-8')
container_id = str(task.get_taskid())
if child.err:
log_error(child.err)
raise Exception("Unable to run podman container")

crash_normal = ["/usr/bin/podman", "exec", container_id,
Expand Down

0 comments on commit f6deee5

Please sign in to comment.