mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-07-29 10:25:12 +00:00
Support: Don't remove special files on signals.
- Similar to Path::eraseFromDisk(), we don't want LLVM to remove things like /dev/null, even if it has the permission. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@166105 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -121,17 +121,29 @@ static void UnregisterHandlers() {
|
|||||||
/// NB: This must be an async signal safe function. It cannot allocate or free
|
/// NB: This must be an async signal safe function. It cannot allocate or free
|
||||||
/// memory, even in debug builds.
|
/// memory, even in debug builds.
|
||||||
static void RemoveFilesToRemove() {
|
static void RemoveFilesToRemove() {
|
||||||
// Note: avoid iterators in case of debug iterators that allocate or release
|
// We avoid iterators in case of debug iterators that allocate or release
|
||||||
// memory.
|
// memory.
|
||||||
for (unsigned i = 0, e = FilesToRemove.size(); i != e; ++i) {
|
for (unsigned i = 0, e = FilesToRemove.size(); i != e; ++i) {
|
||||||
// Note that we don't want to use any external code here, and we don't care
|
// We rely on a std::string implementation for which repeated calls to
|
||||||
// about errors. We're going to try as hard as we can as often as we need
|
// 'c_str()' don't allocate memory. We pre-call 'c_str()' on all of these
|
||||||
// to to make these files go away. If these aren't files, too bad.
|
// strings to try to ensure this is safe.
|
||||||
//
|
const char *path = FilesToRemove[i].c_str();
|
||||||
// We do however rely on a std::string implementation for which repeated
|
|
||||||
// calls to 'c_str()' don't allocate memory. We pre-call 'c_str()' on all
|
// Get the status so we can determine if it's a file or directory. If we
|
||||||
// of these strings to try to ensure this is safe.
|
// can't stat the file, ignore it.
|
||||||
unlink(FilesToRemove[i].c_str());
|
struct stat buf;
|
||||||
|
if (stat(path, &buf) != 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
// If this is not a regular file, ignore it. We want to prevent removal of
|
||||||
|
// special files like /dev/null, even if the compiler is being run with the
|
||||||
|
// super-user permissions.
|
||||||
|
if (!S_ISREG(buf.st_mode))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
// Otherwise, remove the file. We ignore any errors here as there is nothing
|
||||||
|
// else we can do.
|
||||||
|
unlink(path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user