//
// Automated Testing Framework (atf)
//
// Copyright (c) 2007 The NetBSD Foundation, Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
//
// THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
// CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
// IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
// IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
// IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
#if defined(HAVE_CONFIG_H)
#include "bconfig.h"
#endif
extern "C" {
#include <unistd.h>
}
#include <cerrno>
#include <cstdlib>
#include <cstring>
#include "atf-c++/detail/auto_array.hpp"
#include "atf-c++/detail/process.hpp"
#include "atf-c++/detail/sanity.hpp"
#include "fs.hpp"
#include "user.hpp"
// ------------------------------------------------------------------------
// Auxiliary functions.
// ------------------------------------------------------------------------
bool);
// The cleanup routines below are tricky: they are executed immediately after
// a test case's death, and after we have forcibly killed any stale processes.
// However, even if the processes are dead, this does not mean that the file
// system we are scanning is stable. In particular, if the test case has
// does not mean that the file system is truly unmounted.
//
// The code below attempts to cope with this by catching errors and either
// before giving up.
// The erase parameter in this routine is to control nested mount points.
// We want to descend into a mount point to unmount anything that is
// mounted under it, but we do not want to delete any files while doing
// this traversal. In other words, we erase files until we cross the
// first mount point, and after that point we only scan and unmount.
static
void
{
try {
do_unmount(p);
if (erase) {
else
}
} catch (const atf::system_error& e) {
throw e;
}
}
static
void
bool erase)
{
if (retries > 0) {
retries--;
goto retry_chmod;
} else {
errno);
}
}
}
{
bool ok = false;
while (!ok) {
try {
ok = true;
} catch (const atf::system_error& e) {
retries--;
if (retries == 0)
throw e;
}
}
}
}
}
static
void
{
// At least, FreeBSD's unmount(2) requires the path to be absolute.
// Let's make it absolute in all cases just to be safe that this does
// not affect other systems.
#if defined(HAVE_UNMOUNT)
retries--;
goto retry_unmount;
} else {
}
}
#else
// We could use umount(2) instead if it was available... but
// trying to do so under, e.g. Linux, is a nightmare because we
// satf::fser to just leave the system-specific umount(8) tool deal
// with it, at least for now.
#endif
}
// ------------------------------------------------------------------------
// The "temp_dir" class.
// ------------------------------------------------------------------------
{
errno);
}
{
}
const
{
return *m_path;
}
// ------------------------------------------------------------------------
// Free functions.
// ------------------------------------------------------------------------
{
"chdir(2) failed", errno);
}
return olddir;
}
void
{
}
{
#if defined(HAVE_GETCWD_DYN)
#else
#endif
"getcwd() failed", errno);
}