parseaut: do not close fd or stdin

* spot/parseaut/public.hh, spot/parseaut/scanaut.ll: When parsing
automata read from some given FD, do not close the file descriptor, as
the caller is likely to already close it, and closing FDs twice is very
bad.  This seems to have be the root of some issue we had with recent
jupyter versions, were 0MQ would crash with "Bad file descriptor"
messages.  Also do not close stdin while we are at it.
* NEWS: Mention the bug.
This commit is contained in:
Alexandre Duret-Lutz 2016-11-11 12:24:15 +01:00
parent a0956d25b6
commit 49266dee7f
3 changed files with 16 additions and 7 deletions

4
NEWS
View file

@ -59,6 +59,10 @@ New in spot 2.1.2.dev (not yet released)
when run with use_simulation (the default) on non-simplified
automata.
* When the automaton_stream_parser reads an automaton from an
already opened file descriptor, it will not close the file
anymore.
New in spot 2.1.2 (2016-10-14)
Command-line tools:

View file

@ -1,6 +1,6 @@
// -*- coding: utf-8 -*-
// Copyright (C) 2013, 2014, 2015 Laboratoire de Recherche et Développement
// de l'Epita (LRDE).
// Copyright (C) 2013, 2014, 2015, 2016 Laboratoire de Recherche et
// Développement de l'Epita (LRDE).
//
// This file is part of Spot, a model checking library.
//
@ -123,7 +123,7 @@ namespace spot
std::string filename_;
automaton_parser_options opts_;
public:
/// \brief Parse from a file opened file descriptor.
/// \brief Parse from a file.
///
/// \param filename The file to read from.
/// \param opts Parser options.
@ -132,6 +132,8 @@ namespace spot
/// \brief Parse from an already opened file descriptor.
///
/// The file descriptor will not be closed.
///
/// \param fd The file descriptor to read from.
/// \param filename What to display in error messages.
/// \param opts Parser options.

View file

@ -38,6 +38,7 @@ static int orig_cond = 0;
static bool lbtt_s = false;
static bool lbtt_t = false;
static unsigned lbtt_states = 0;
static bool yyin_close = true;
%}
@ -410,15 +411,15 @@ namespace spot
if (S_ISFIFO(s.st_mode))
want_interactive = true;
// Only set yyin once we know we will use
// it, so that we do not close it otherwise.
yyin = stdin;
yyin_close = false;
}
else
{
yyin = fopen(name.c_str(), "r");
if (!yyin)
return 1;
yyin_close = true;
}
// Reset the lexer in case a previous parse
// ended badly.
@ -441,6 +442,7 @@ namespace spot
hoayyopen(int fd)
{
bool want_interactive = false;
yyin_close = false;
yyin = fdopen(fd, "r");
@ -470,8 +472,9 @@ namespace spot
{
if (yyin)
{
fclose(yyin);
yyin = NULL;
if (yyin_close)
fclose(yyin);
yyin = NULL;
}
}
}