Commit 49266dee authored by Alexandre Duret-Lutz's avatar Alexandre Duret-Lutz

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.
parent a0956d25
......@@ -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:
......
// -*- 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.
......
......@@ -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;
}
}
}
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