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.
This commit is contained in:
Alexandre Duret-Lutz 2019-12-15 16:10:05 +01:00
parent a06e547473
commit d2ba554507
4 changed files with 91 additions and 2 deletions

View file

@ -1,5 +1,5 @@
// -*- 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;
}
}