From 04640af135144c735e6086fa8d96abf7d8aaf861 Mon Sep 17 00:00:00 2001 From: Alexandre Duret-Lutz Date: Thu, 4 May 2017 14:40:32 +0200 Subject: [PATCH] bin: remove temporary files even on errors Fixes #259. * bin/common_setup.cc: Register a cleanup_tmpfiles() via atexit. * tests/core/ltldo.test: Add a test case. * NEWS: Mention the bug. --- NEWS | 3 +++ bin/common_setup.cc | 9 +++++++++ tests/core/ltldo.test | 15 +++++++++++++-- 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/NEWS b/NEWS index 53daf5ec5..d7de6b731 100644 --- a/NEWS +++ b/NEWS @@ -8,6 +8,9 @@ New in spot 2.3.3.dev (not yet released) - the --help output of randaut and ltl2tgba was showing an unsupported %b stat. + - ltldo and ltlcross could leave temporary files behind when + aborting on error. + New in spot 2.3.3 (2017-04-11) Tools: diff --git a/bin/common_setup.cc b/bin/common_setup.cc index fd90a2719..4d7c518e8 100644 --- a/bin/common_setup.cc +++ b/bin/common_setup.cc @@ -43,8 +43,16 @@ This is free software: you are free to change and redistribute it.\n\ There is NO WARRANTY, to the extent permitted by law.\n", stream); } +// This is called on normal exit (i.e., when leaving +// main or calling exit(), even via error()). +static void atexit_cleanup() +{ + spot::cleanup_tmpfiles(); +} #ifdef HAVE_SIGACTION +// This is called on abnormal exit, i.e. when the process is killed by +// some signal. static void sig_handler(int sig) { spot::cleanup_tmpfiles(); @@ -92,6 +100,7 @@ setup(char** argv) setup_default_output_format(); setup_sig_handler(); + atexit(atexit_cleanup); } diff --git a/tests/core/ltldo.test b/tests/core/ltldo.test index 5dab1e4a3..c02465881 100755 --- a/tests/core/ltldo.test +++ b/tests/core/ltldo.test @@ -1,7 +1,7 @@ #!/bin/sh # -*- coding: utf-8 -*- -# Copyright (C) 2015, 2016 Laboratoire de Recherche et -# Développement de l'Epita (LRDE). +# Copyright (C) 2015-2017 Laboratoire de Recherche et Développement de +# l'Epita (LRDE). # # This file is part of Spot, a model checking library. # @@ -152,3 +152,14 @@ genltl --rv-counter=9 | ltldo ltl2tgba --stats=' print("%[up]R + %[uc]R + %[sp]R + %[sc]R - %R\n"); die if abs(%[up]R + %[uc]R + %[sp]R + %[sc]R - %R) > 0.02;' > code.pl perl code.pl + +# ltldo should not leave temporary files behind itself on errors +ltldo -f a 'ltl2dstar --ltl2nba=spin:ltl2tgba@-DS' && exit 2 +for i in lcr-*; do + case $i in + 'lcr-*');; + *) + echo $i should not be here; + exit 2;; + esac +done