Commit 807834ec authored by Alexandre Duret-Lutz's avatar Alexandre Duret-Lutz
Browse files

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.
parent 70f51b27
......@@ -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 \
......
// -*- 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 <iostream>
#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();
}
// -*- 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
......@@ -22,6 +22,7 @@
#include "common_output.hh"
#include <iostream>
#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();
}
......@@ -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;
}
......
......@@ -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;
}
......
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