Commit d2ba5545 authored by Alexandre Duret-Lutz's avatar Alexandre Duret-Lutz

tmpfile: improve error message

* spot/misc/tmpfile.cc: Display strerror(errno) plus some suggestions
that depend on the error.  Based on a report from Shengping Shaw.
* THANKS: Add reporter.
* tests/core/ltlcross5.test: New file.
* tests/Makefile.am: Add it.
parent a06e5474
Pipeline #15311 failed with stages
in 354 minutes and 14 seconds
......@@ -42,6 +42,7 @@ Reuben Rowe
Rüdiger Ehlers
Silien Hong
Simon Jantsch
Shengping Shaw
Shufang Zhu
Sonali Dutta
Tereza Šťastná
......
// -*- coding: utf-8 -*-
// Copyright (C) 2013, 2015, 2017, 2018 Laboratoire de Recherche et
// Copyright (C) 2013, 2015, 2017-2019 Laboratoire de Recherche et
// Développement de l'Epita (LRDE).
//
// This file is part of Spot, a model checking library.
......@@ -75,7 +75,29 @@ namespace spot
fd = mkstemp(*name);
}
if (fd < 0)
throw std::runtime_error("failed to create "s + *name);
{
std::string err = ("failed to create temporary file "s + *name
+ ": " + strerror(errno));
if (errno == EACCES)
{
if (tmpdir)
err += ("\nConsider setting the SPOT_TMPDIR environment "
"variable to a writable directory.");
else
err += ("\nConsider executing this from a writable "
"directory, or setting\nthe SPOT_TMPDIR environment "
"variable to such a directory.");
}
else if (tmpdir)
{
const char* dir =
secure_getenv("SPOT_TMPDIR") ? "SPOT_TMPDIR" : "TMPDIR";
err += ("\nNote that the directory comes from the "s
+ dir
+ " environment variable.");
}
throw std::runtime_error(err);
}
return fd;
}
}
......
......@@ -214,6 +214,7 @@ TESTS_twa = \
core/bdddict.test \
core/alternating.test \
core/ltlcross3.test \
core/ltlcross5.test \
core/taatgba.test \
core/renault.test \
core/nondet.test \
......
#!/bin/sh
# -*- coding: utf-8 -*-
# Copyright (C) 2019 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 3 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 this program. If not, see <http://www.gnu.org/licenses/>.
. ./defs
set -e
unset TMPDIR
unset SPOT_TMPDIR
mkdir foo
chmod a-w foo
cd foo
err=0
if touch bar; then
# We are likely running as root, so we cannot detect permission
# issues.
cd ..
rm -rf foo
exit 77
fi
ltlcross ltl2tgba -f GFa 2>../err && err=1
cd ..
cat err
grep 'failed to create temporary file' err || err=1
grep 'executing this from a writable' err || err=1
grep 'SPOT_TMPDIR' err || err=1
SPOT_TMPDIR=foo ltlcross ltl2tgba -f GFa 2>err && err=2
cat err
grep 'failed to create temporary file' err || err=2
grep 'executing this from a writable' err && err=2
grep 'SPOT_TMPDIR' err
chmod a+w foo
rmdir foo
SPOT_TMPDIR=bar ltlcross ltl2tgba -f GFa 2>err && err=3
cat err
grep 'failed to create temporary file' err
grep 'Note that the directory.*SPOT_TMPDIR ' err
TMPDIR=bar ltlcross ltl2tgba -f GFa 2>err && err=4
cat err
grep 'failed to create temporary file' err
grep 'Note that the directory.* TMPDIR ' err
exit $err
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