From 807834ec41e1163f17c27891a8213898cdb37b32 Mon Sep 17 00:00:00 2001 From: Alexandre Duret-Lutz Date: Fri, 14 Sep 2012 09:45:40 +0200 Subject: [PATCH] Detect fail conditions on std::cout in user's tools. * src/bin/common_cout.cc, src/bin/common_cout.hh: New files. * src/bin/Makefile.am: Add them. * src/bin/ltl2tgba.cc, src/bin/ltlfilt.cc, src/bin/common_output.cc: Report error when writing to std::cout failed. This is mainly motivated by ltlfilt not being killed by SIGPIPE on lip6's OSX buildfarm (SIGPIPE is probably ignored when the build is started), but it could detect other errors such as a disk full. --- src/bin/Makefile.am | 2 ++ src/bin/common_cout.cc | 39 +++++++++++++++++++++++++++++++++++++++ src/bin/common_cout.hh | 28 ++++++++++++++++++++++++++++ src/bin/common_output.cc | 6 +++++- src/bin/ltl2tgba.cc | 3 ++- src/bin/ltlfilt.cc | 11 ++++++----- 6 files changed, 82 insertions(+), 7 deletions(-) create mode 100644 src/bin/common_cout.cc create mode 100644 src/bin/common_cout.hh diff --git a/src/bin/Makefile.am b/src/bin/Makefile.am index 188ce9090..471dc1fb1 100644 --- a/src/bin/Makefile.am +++ b/src/bin/Makefile.am @@ -28,6 +28,8 @@ LDADD = libcommon.a $(top_builddir)/lib/libgnu.a ../libspot.la noinst_LIBRARIES = libcommon.a libcommon_a_SOURCES = \ + common_cout.hh \ + common_cout.cc \ common_output.cc \ common_output.hh \ common_range.cc \ diff --git a/src/bin/common_cout.cc b/src/bin/common_cout.cc new file mode 100644 index 000000000..71cbd5ad2 --- /dev/null +++ b/src/bin/common_cout.cc @@ -0,0 +1,39 @@ +// -*- coding: utf-8 -*- +// Copyright (C) 2012 Laboratoire de Recherche et Développement de +// l'Epita (LRDE). +// +// This file is part of Spot, a model checking library. +// +// Spot is free software; you can redistribute it and/or modify it +// under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// Spot is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public +// License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Spot; see the file COPYING. If not, write to the Free +// Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA +// 02111-1307, USA. + +#include "common_sys.hh" +#include "common_cout.hh" +#include +#include "error.h" + +void check_cout() +{ + // Make sure we abort if we can't write to std::cout anymore + // (like disk full or broken pipe with SIGPIPE ignored). + if (!std::cout) + error(2, 0, "error writing to standard output"); +} + +void flush_cout() +{ + std::cout.flush(); + check_cout(); +} diff --git a/src/bin/common_cout.hh b/src/bin/common_cout.hh new file mode 100644 index 000000000..0403f001a --- /dev/null +++ b/src/bin/common_cout.hh @@ -0,0 +1,28 @@ +// -*- coding: utf-8 -*- +// Copyright (C) 2012 Laboratoire de Recherche et Développement de +// l'Epita (LRDE). +// +// This file is part of Spot, a model checking library. +// +// Spot is free software; you can redistribute it and/or modify it +// under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// Spot is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public +// License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Spot; see the file COPYING. If not, write to the Free +// Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA +// 02111-1307, USA. + +#ifndef SPOT_BIN_COMMON_COUT_HH +#define SPOT_BIN_COMMON_COUT_HH + +void check_cout(); +void flush_cout(); + +#endif // SPOT_BIN_COMMON_COUT_HH diff --git a/src/bin/common_output.cc b/src/bin/common_output.cc index 91ed7c127..6dbff7b31 100644 --- a/src/bin/common_output.cc +++ b/src/bin/common_output.cc @@ -22,6 +22,7 @@ #include "common_output.hh" #include #include "ltlvisit/tostring.hh" +#include "common_cout.hh" #define OPT_SPOT 1 @@ -79,5 +80,8 @@ output_formula(const spot::ltl::formula* f) spot::ltl::to_utf8_string(f, std::cout, full_parenth); break; } - std::cout << "\n"; + // Make sure we abort if we can't write to std::cout anymore + // (like disk full or broken pipe with SIGPIPE ignored). + std::cout << std::endl; + check_cout(); } diff --git a/src/bin/ltl2tgba.cc b/src/bin/ltl2tgba.cc index 4d08c3478..08668a28f 100644 --- a/src/bin/ltl2tgba.cc +++ b/src/bin/ltl2tgba.cc @@ -31,6 +31,7 @@ #include "error.h" #include "common_r.hh" +#include "common_cout.hh" #include "misc/_config.h" #include "ltlparse/public.hh" @@ -246,8 +247,8 @@ namespace spot::never_claim_reachable(std::cout, aut, f); break; } - delete aut; + flush_cout(); return 0; } diff --git a/src/bin/ltlfilt.cc b/src/bin/ltlfilt.cc index 7cd6e88e2..ac8ec8387 100644 --- a/src/bin/ltlfilt.cc +++ b/src/bin/ltlfilt.cc @@ -31,6 +31,7 @@ #include "error.h" #include "common_output.hh" +#include "common_cout.hh" #include "common_r.hh" #include "misc/_config.h" @@ -384,6 +385,7 @@ namespace std::cout << input << std::endl; else assert(error_style == drop_errors); + check_cout(); return !quiet; } @@ -474,7 +476,6 @@ namespace one_match = true; output_formula(f); } - f->destroy(); return 0; } @@ -512,16 +513,16 @@ run_jobs() spot::ltl::ltl_simplifier simpl(simplifier_options()); ltl_processor processor(simpl); - int error = 0; + int nerror = 0; jobs_t::const_iterator i; for (i = jobs.begin(); i != jobs.end(); ++i) { if (!i->file_p) - error |= processor.process_formula(i->str); + nerror |= processor.process_formula(i->str); else - error |= processor.process_file(i->str); + nerror |= processor.process_file(i->str); } - if (error) + if (nerror) return 2; return one_match ? 0 : 1; }