![]() |
CernVM-FS
2.11.0
|
#include <pthread.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/uio.h>
#include <unistd.h>
#include <cassert>
#include <cerrno>
#include <cstddef>
#include <map>
#include <set>
#include <string>
#include <vector>
#include "util/export.h"
#include "util/pointer.h"
#include "util/single_copy.h"
Go to the source code of this file.
Classes | |
struct | FileSystemInfo |
struct | LsofEntry |
Enumerations | |
enum | EFileSystemTypes { kFsTypeUnknown = 0, kFsTypeAutofs = 0x0187, kFsTypeNFS = 0x6969, kFsTypeProc = 0x9fa0, kFsTypeBeeGFS = 0x19830326, kFsTypeTmpfs = 0x01021994 } |
Functions | |
CVMFS_EXPORT std::string | MakeCanonicalPath (const std::string &path) |
CVMFS_EXPORT std::string | GetParentPath (const std::string &path) |
CVMFS_EXPORT std::string | GetFileName (const std::string &path) |
CVMFS_EXPORT void | SplitPath (const std::string &path, std::string *dirname, std::string *filename) |
CVMFS_EXPORT bool | IsAbsolutePath (const std::string &path) |
CVMFS_EXPORT std::string | GetAbsolutePath (const std::string &path) |
CVMFS_EXPORT bool | IsHttpUrl (const std::string &path) |
CVMFS_EXPORT std::string | ReadSymlink (const std::string &path) |
CVMFS_EXPORT std::string | ResolvePath (const std::string &path) |
CVMFS_EXPORT bool | IsMountPoint (const std::string &path) |
CVMFS_EXPORT FileSystemInfo | GetFileSystemInfo (const std::string &path) |
CVMFS_EXPORT void | CreateFile (const std::string &path, const int mode, const bool ignore_failure=false) |
CVMFS_EXPORT int | MakeSocket (const std::string &path, const int mode) |
CVMFS_EXPORT int | MakeTcpEndpoint (const std::string &ipv4_address, int portno) |
CVMFS_EXPORT int | ConnectSocket (const std::string &path) |
CVMFS_EXPORT int | ConnectTcpEndpoint (const std::string &ipv4_address, int portno) |
CVMFS_EXPORT void | MakePipe (int pipe_fd[2]) |
CVMFS_EXPORT void | WritePipe (int fd, const void *buf, size_t nbyte) |
CVMFS_EXPORT void | ReadPipe (int fd, void *buf, size_t nbyte) |
CVMFS_EXPORT void | ReadHalfPipe (int fd, void *buf, size_t nbyte) |
CVMFS_EXPORT void | ClosePipe (int pipe_fd[2]) |
CVMFS_EXPORT bool | DiffTree (const std::string &path_a, const std::string &path_b) |
CVMFS_EXPORT void | Nonblock2Block (int filedes) |
CVMFS_EXPORT void | Block2Nonblock (int filedes) |
CVMFS_EXPORT void | SendMsg2Socket (const int fd, const std::string &msg) |
CVMFS_EXPORT bool | SendFd2Socket (int socket_fd, int passing_fd) |
CVMFS_EXPORT int | RecvFdFromSocket (int msg_fd) |
CVMFS_EXPORT std::string | GetHostname () |
CVMFS_EXPORT bool | SwitchCredentials (const uid_t uid, const gid_t gid, const bool temporarily) |
CVMFS_EXPORT bool | FileExists (const std::string &path) |
CVMFS_EXPORT int64_t | GetFileSize (const std::string &path) |
CVMFS_EXPORT bool | DirectoryExists (const std::string &path) |
CVMFS_EXPORT bool | SymlinkExists (const std::string &path) |
CVMFS_EXPORT bool | SymlinkForced (const std::string &src, const std::string &dest) |
CVMFS_EXPORT bool | MkdirDeep (const std::string &path, const mode_t mode, bool verify_writable=true) |
CVMFS_EXPORT bool | MakeCacheDirectories (const std::string &path, const mode_t mode) |
CVMFS_EXPORT FILE * | CreateTempFile (const std::string &path_prefix, const int mode, const char *open_flags, std::string *final_path) |
CVMFS_EXPORT std::string | CreateTempPath (const std::string &path_prefix, const int mode) |
CVMFS_EXPORT std::string | CreateTempDir (const std::string &path_prefix) |
CVMFS_EXPORT std::string | GetCurrentWorkingDirectory () |
CVMFS_EXPORT int | TryLockFile (const std::string &path) |
CVMFS_EXPORT int | LockFile (const std::string &path) |
CVMFS_EXPORT int | WritePidFile (const std::string &path) |
CVMFS_EXPORT void | UnlockFile (const int filedes) |
CVMFS_EXPORT bool | RemoveTree (const std::string &path) |
CVMFS_EXPORT std::vector < std::string > | FindFilesBySuffix (const std::string &dir, const std::string &suffix) |
CVMFS_EXPORT std::vector < std::string > | FindFilesByPrefix (const std::string &dir, const std::string &prefix) |
CVMFS_EXPORT std::vector < std::string > | FindDirectories (const std::string &parent_dir) |
CVMFS_EXPORT std::string | FindExecutable (const std::string &exe) |
CVMFS_EXPORT bool | ListDirectory (const std::string &directory, std::vector< std::string > *names, std::vector< mode_t > *modes) |
CVMFS_EXPORT std::string | GetUserName () |
CVMFS_EXPORT std::string | GetShell () |
CVMFS_EXPORT bool | GetUserNameOf (uid_t uid, std::string *username) |
CVMFS_EXPORT bool | GetUidOf (const std::string &username, uid_t *uid, gid_t *main_gid) |
CVMFS_EXPORT bool | GetGidOf (const std::string &groupname, gid_t *gid) |
CVMFS_EXPORT mode_t | GetUmask () |
CVMFS_EXPORT bool | AddGroup2Persona (const gid_t gid) |
CVMFS_EXPORT std::string | GetHomeDirectory () |
CVMFS_EXPORT std::string | GetArch () |
CVMFS_EXPORT int | SetLimitNoFile (unsigned limit_nofile) |
CVMFS_EXPORT void | GetLimitNoFile (unsigned *soft_limit, unsigned *hard_limit) |
CVMFS_EXPORT std::vector < LsofEntry > | Lsof (const std::string &path) |
CVMFS_EXPORT bool | ProcessExists (pid_t pid) |
CVMFS_EXPORT void | BlockSignal (int signum) |
CVMFS_EXPORT void | WaitForSignal (int signum) |
CVMFS_EXPORT int | WaitForChild (pid_t pid, const std::vector< int > &sig_ok=std::vector< int >()) |
CVMFS_EXPORT void | Daemonize () |
CVMFS_EXPORT bool | Shell (int *pipe_stdin, int *pipe_stdout, int *pipe_stderr) |
CVMFS_EXPORT bool | ExecuteBinary (int *fd_stdin, int *fd_stdout, int *fd_stderr, const std::string &binary_path, const std::vector< std::string > &argv, const bool double_fork=true, pid_t *child_pid=NULL) |
CVMFS_EXPORT bool | ManagedExec (const std::vector< std::string > &command_line, const std::set< int > &preserve_fildes, const std::map< int, int > &map_fildes, const bool drop_credentials, const bool clear_env=false, const bool double_fork=true, pid_t *child_pid=NULL) |
CVMFS_EXPORT bool | CloseAllFildes (const std::set< int > &preserve_fildes) |
CVMFS_EXPORT void | SafeSleepMs (const unsigned ms) |
CVMFS_EXPORT ssize_t | SafeRead (int fd, void *buf, size_t nbyte) |
CVMFS_EXPORT bool | SafeWrite (int fd, const void *buf, size_t nbyte) |
CVMFS_EXPORT bool | SafeWriteV (int fd, struct iovec *iov, unsigned iovcnt) |
CVMFS_EXPORT bool | SafeReadToString (int fd, std::string *final_result) |
CVMFS_EXPORT bool | SafeWriteToFile (const std::string &content, const std::string &path, int mode) |
Variables | |
const unsigned | kPageSize = 4096 |
const size_t | kMaxPathLength = 256 |
const int | kDefaultFileMode = S_IWUSR | S_IRUSR | S_IRGRP | S_IROTH |
const int | kDefaultDirMode |
const int | kPrivateFileMode = S_IWUSR | S_IRUSR |
const int | kPrivateDirMode = S_IXUSR | S_IWUSR | S_IRUSR |
enum EFileSystemTypes |
The magic numbers that identify a file system in statfs() Adjust GetFileSystemInfo() when new file systems are added
Enumerator | |
---|---|
kFsTypeUnknown | |
kFsTypeAutofs | |
kFsTypeNFS | |
kFsTypeProc | |
kFsTypeBeeGFS | |
kFsTypeTmpfs |
CVMFS_EXPORT bool AddGroup2Persona | ( | const gid_t | gid | ) |
CVMFS_EXPORT void Block2Nonblock | ( | int | filedes | ) |
Changes a blocking file descriptor to a non-blocking one.
Definition at line 647 of file posix.cc.
Referenced by Watchdog::GenerateStackTrace(), and PosixQuotaManager::MainCommandServer().
CVMFS_EXPORT void BlockSignal | ( | int | signum | ) |
Blocks a signal for the calling thread.
Definition at line 1573 of file posix.cc.
Referenced by FuseMain().
CVMFS_EXPORT bool CloseAllFildes | ( | const std::set< int > & | preserve_fildes | ) |
Closes all file descriptors except the ones in preserve_fildes. To be used after fork but before exec.
Definition at line 1810 of file posix.cc.
Referenced by PosixQuotaManager::DoCleanup(), Watchdog::Fork(), and ManagedExec().
CVMFS_EXPORT void ClosePipe | ( | int | pipe_fd[2] | ) |
Closes both ends of a pipe
Definition at line 551 of file posix.cc.
Referenced by publish::CallServerHook(), cvmfs::Fetcher::CleanupTls(), PosixQuotaManager::CloseReturnPipe(), PosixQuotaManager::CreateShared(), ExecuteBinary(), swissknife::CommandPull::Main(), ExternalCacheManager::SpawnPlugin(), file_watcher::FileWatcher::Stop(), shrinkwrap::SyncInit(), PosixQuotaManager::UnregisterBackChannel(), ExternalQuotaManager::UnregisterBackChannel(), quota::UnregisterListener(), upload::S3Uploader::RequestCtrl::WaitFor(), CachePlugin::~CachePlugin(), glue::DentryTracker::~DentryTracker(), FuseInvalidator::~FuseInvalidator(), FuseRemounter::~FuseRemounter(), PosixQuotaManager::~PosixQuotaManager(), s3fanout::S3FanoutManager::~S3FanoutManager(), and perf::TelemetryAggregator::~TelemetryAggregator().
CVMFS_EXPORT int ConnectSocket | ( | const std::string & | path | ) |
Connects to a named socket.
Definition at line 427 of file posix.cc.
Referenced by CheckConcurrentMount(), ExternalCacheManager::ConnectLocator(), GetExistingFuseFd(), loader::loader_talk::MainReload(), SendCommand(), cvmfs::SendFuseFd(), and publish::SendTalkCommand().
CVMFS_EXPORT int ConnectTcpEndpoint | ( | const std::string & | ipv4_address, |
int | portno | ||
) |
Connects to a (remote) TCP server
Definition at line 461 of file posix.cc.
Referenced by ExternalCacheManager::ConnectLocator().
CVMFS_EXPORT void CreateFile | ( | const std::string & | path, |
const int | mode, | ||
const bool | ignore_failure | ||
) |
By default PANIC(NULL) on failure
Definition at line 280 of file posix.cc.
Referenced by publish::CmdEnter::CreateUnderlay(), FuseMain(), loader::Reload(), FileSystem::SetupNfsMaps(), and FileSystem::SetupPosixCacheMgr().
CVMFS_EXPORT std::string CreateTempDir | ( | const std::string & | path_prefix | ) |
Create a directory with a unique name.
Definition at line 1047 of file posix.cc.
Referenced by publish::ClearScratch(), GetExistingFuseFd(), publish::CmdEnter::Main(), and MakeShortSocketLink().
CVMFS_EXPORT FILE* CreateTempFile | ( | const std::string & | path_prefix, |
const int | mode, | ||
const char * | open_flags, | ||
std::string * | final_path | ||
) |
Wrapper around mkstemp.
Definition at line 1005 of file posix.cc.
Referenced by cvmfs::Uuid::Create(), CreateTempPath(), upload::LocalUploader::DoUpload(), HttpObjectFetcher< CatalogT, HistoryT, ReflogT >::Download(), publish::DownloadRootObjects(), manifest::Breadcrumb::Export(), LocalObjectFetcher< CatalogT, HistoryT, ReflogT >::Fetch(), swissknife::CommandCheck::FetchPath(), catalog::SimpleCatalogManager::LoadCatalog(), swissknife::MainWorker(), swissknife::CommandPull::Pull(), FileBackedBuffer::SaveToFile(), swissknife::Store(), and swissknife::StoreBuffer().
CVMFS_EXPORT std::string CreateTempPath | ( | const std::string & | path_prefix, |
const int | mode | ||
) |
Create the file but don't open. Use only in non-public tmp directories.
Definition at line 1034 of file posix.cc.
Referenced by swissknife::CommandEditTag::AddNewTag(), publish::SyncMediator::Commit(), upload::AbstractUploader::CreateAndOpenTemporaryChunkFile(), ServerTool::CreateEmptyReflog(), catalog::WritableCatalogManager::CreateNestedCatalog(), swissknife::CommandMigrate::MigrationWorker_20x::CreateNewEmptyCatalog(), receiver::CatalogMergeTool< RwCatalogMgr, RoCatalogMgr >::CreateNewManifest(), publish::CreateRootObjects(), swissknife::CommandMigrate::GenerateNestedCatalogMarkerChunk(), swissknife::Assistant::GetCatalog(), swissknife::Assistant::GetHistory(), swissknife::CommandTag::InitializeEnvironment(), and swissknife::CommandRollbackTag::Main().
CVMFS_EXPORT void Daemonize | ( | ) |
Makes a daemon. The daemon() call is deprecated on OS X
Definition at line 1628 of file posix.cc.
Referenced by Watchdog::Fork(), FuseMain(), and PosixQuotaManager::MainCacheManager().
CVMFS_EXPORT bool DiffTree | ( | const std::string & | path_a, |
const std::string & | path_b | ||
) |
Compares two directory trees on the meta-data level. Returns true iff the trees have identical content.
Definition at line 561 of file posix.cc.
Referenced by DiffTree().
CVMFS_EXPORT bool DirectoryExists | ( | const std::string & | path | ) |
Checks if the directory (not symlink) path exists.
Definition at line 813 of file posix.cc.
Referenced by swissknife::CommandSync::CheckParams(), publish::CmdEnter::CreateUnderlay(), publish::SettingsTransaction::DetectUnionFsType(), swissknife::CommandApplyDirtab::FilterCandidatesFromGlobResult(), FuseMain(), publish::InitSpoolArea(), publish::SyncUnionOverlayfs::IsOpaqueDirectory(), swissknife::CommandGc::Main(), swissknife::CommandListReflog::Main(), swissknife::CommandListCatalogs::Main(), swissknife::CommandPull::Main(), swissknife::CommandCheck::Main(), swissknife::CommandFileStats::Main(), BashOptionsManager::ParsePath(), posix_archive_provenance(), posix_cleanup_path(), posix_initialize(), PosixCheckDirStructure(), SigningTool::Run(), and WaitForReload().
CVMFS_EXPORT bool ExecuteBinary | ( | int * | fd_stdin, |
int * | fd_stdout, | ||
int * | fd_stderr, | ||
const std::string & | binary_path, | ||
const std::vector< std::string > & | argv, | ||
const bool | double_fork = true , |
||
pid_t * | child_pid = NULL |
||
) |
Definition at line 1659 of file posix.cc.
Referenced by Watchdog::GenerateStackTrace(), main(), and Shell().
CVMFS_EXPORT bool FileExists | ( | const std::string & | path | ) |
Checks if the regular file path exists.
Definition at line 791 of file posix.cc.
Referenced by publish::CallServerHook(), MountPoint::CheckBlacklists(), swissknife::CommandApplyDirtab::CreateCatalogMarkers(), publish::CheckoutMarker::CreateFrom(), publish::SettingsBuilder::CreateSettingsPublisher(), PosixQuotaManager::CreateShared(), swissknife::CommandInfo::Exists(), swissknife::CommandCheck::Exists(), LocalObjectFetcher< CatalogT, HistoryT, ReflogT >::Fetch(), LocalObjectFetcher< CatalogT, HistoryT, ReflogT >::FetchManifest(), swissknife::CommandApplyDirtab::FilterCandidatesFromGlobResult(), AuthzExternalFetcher::FindHelper(), GetCvmfsBinary(), publish::SettingsKeychain::HasDanglingMasterKeys(), publish::SettingsKeychain::HasDanglingRepositoryKeys(), publish::SettingsKeychain::HasGatewayKey(), publish::SettingsKeychain::HasMasterKeys(), publish::SettingsKeychain::HasRepositoryKeys(), PosixCacheManager::InitCacheDirectory(), swissknife::CommandTag::InitializeEnvironment(), InitializeGarbageCollection(), download::Interrupted(), publish::SyncUnionAufs::IsOpaqueDirectory(), publish::ServerFlagFile::IsSet(), publish::CmdEnter::Main(), swissknife::CommandApplyDirtab::Main(), PosixQuotaManager::MainCacheManager(), PosixQuotaManager::MainCommandServer(), SpecTree::Open(), catalog::Dirtab::Open(), StatisticsDatabase::OpenStandardDB(), upload::S3Uploader::ParseSpoolerDefinition(), upload::LocalUploader::Peek(), swissknife::Peek(), posix_cleanup_path(), posix_do_link(), posix_has_file(), publish::Publisher(), MountPoint::ReloadBlacklists(), FileSystem::SetupNfsMaps(), SslCertificateStore::UseSystemCertificatePath(), and WaitForReload().
CVMFS_EXPORT std::vector<std::string> FindDirectories | ( | const std::string & | parent_dir | ) |
Finds all direct subdirectories under parent_dir (except ., ..). Used, for instance, to parse /etc/cvmfs/repositories.d/<reponoame>
Definition at line 1179 of file posix.cc.
Referenced by publish::SettingsBuilder::GetSingleAlias().
CVMFS_EXPORT std::string FindExecutable | ( | const std::string & | exe | ) |
Looks whether exe is an executable file. If exe is not an absolute path, searches the PATH environment.
Definition at line 1244 of file posix.cc.
Referenced by publish::CmdEnter::MountCvmfs(), and publish::CmdEnter::MountOverlayfs().
CVMFS_EXPORT std::vector<std::string> FindFilesByPrefix | ( | const std::string & | dir, |
const std::string & | prefix | ||
) |
CVMFS_EXPORT std::vector<std::string> FindFilesBySuffix | ( | const std::string & | dir, |
const std::string & | suffix | ||
) |
Returns ls $dir/GLOB$suffix
Definition at line 1124 of file posix.cc.
Referenced by MountPoint::CreateSignatureManager(), anonymous_namespace{cmd_sub.cc}::SwissknifeSubscriber::Init(), swissknife::CommandGc::Main(), swissknife::CommandListReflog::Main(), swissknife::CommandListCatalogs::Main(), swissknife::CommandPull::Main(), swissknife::CommandCheck::Main(), swissknife::CommandFileStats::Main(), OptionsManager::ParseDefault(), and publish::Repository().
CVMFS_EXPORT std::string GetAbsolutePath | ( | const std::string & | path | ) |
Definition at line 160 of file posix.cc.
Referenced by publish::SyncUnionTarball::Initialize(), and swissknife::CommandFileStats::Run().
CVMFS_EXPORT std::string GetArch | ( | ) |
Returns the output of uname -m
Definition at line 1446 of file posix.cc.
Referenced by FileSystem::SetupGlobalEnvironmentParams().
CVMFS_EXPORT std::string GetCurrentWorkingDirectory | ( | ) |
Get the current working directory of the running process
Definition at line 1060 of file posix.cc.
Referenced by CreateMountNamespace(), GetAbsolutePath(), publish::CmdAbort::Main(), publish::CmdEnter::Main(), and Spawn().
CVMFS_EXPORT std::string GetFileName | ( | const std::string & | path | ) |
CVMFS_EXPORT int64_t GetFileSize | ( | const std::string & | path | ) |
Returns -1 on failure.
Definition at line 801 of file posix.cc.
Referenced by swissknife::CommandEditTag::AddNewTag(), catalog::WritableCatalogManager::CatalogUploadCallback(), catalog::WritableCatalogManager::CreateRepository(), upload::LocalUploader::DoGetObjectSize(), swissknife::CommandCheck::FetchCatalog(), upload::LocalUploader::FinalizeStreamedUpload(), catalog::VirtualCatalog::InsertSnapshot(), swissknife::CommandMigrate::MigrationCallback(), swissknife::CatalogTraversalBase< ObjectFetcherT >::PrepareCatalog(), swissknife::CommandFileStats::ProcessCatalog(), catalog::WritableCatalogManager::SnapshotCatalogsSerialized(), and swissknife::CommandTag::UploadCatalogAndUpdateManifest().
CVMFS_EXPORT FileSystemInfo GetFileSystemInfo | ( | const std::string & | path | ) |
Definition at line 180 of file posix.cc.
Referenced by PosixCacheManager::InitCacheDirectory(), publish::CmdCommit::Main(), and publish::CmdTransaction::Main().
CVMFS_EXPORT bool GetGidOf | ( | const std::string & | groupname, |
gid_t * | gid | ||
) |
CVMFS_EXPORT std::string GetHomeDirectory | ( | ) |
Definition at line 1424 of file posix.cc.
Referenced by publish::CmdEnter::Main().
CVMFS_EXPORT std::string GetHostname | ( | ) |
Definition at line 750 of file posix.cc.
Referenced by MakeAcquireRequest(), and anonymous_namespace{repository_session.cc}::MakeAcquireRequest().
CVMFS_EXPORT void GetLimitNoFile | ( | unsigned * | soft_limit, |
unsigned * | hard_limit | ||
) |
Get the file descriptor limits
Definition at line 1480 of file posix.cc.
Referenced by CheckMaxOpenFiles(), MountPoint::CreateCatalogManager(), and FuseMain().
CVMFS_EXPORT std::string GetParentPath | ( | const std::string & | path | ) |
CVMFS_EXPORT std::string GetShell | ( | ) |
Definition at line 1300 of file posix.cc.
Referenced by publish::CmdEnter::Main().
CVMFS_EXPORT bool GetUidOf | ( | const std::string & | username, |
uid_t * | uid, | ||
gid_t * | main_gid | ||
) |
Name -> UID from passwd database
Definition at line 1344 of file posix.cc.
Referenced by main(), publish::SettingsPublisher::SetOwner(), and MountPoint::SetupBehavior().
CVMFS_EXPORT mode_t GetUmask | ( | ) |
CVMFS_EXPORT std::string GetUserName | ( | ) |
Definition at line 1282 of file posix.cc.
Referenced by publish::CmdMkfs::Main().
CVMFS_EXPORT bool GetUserNameOf | ( | uid_t | uid, |
std::string * | username | ||
) |
UID -> Name from passwd database
Definition at line 1321 of file posix.cc.
Referenced by publish::CmdAbort::Main().
CVMFS_EXPORT bool IsAbsolutePath | ( | const std::string & | path | ) |
Definition at line 155 of file posix.cc.
Referenced by GetAbsolutePath().
CVMFS_EXPORT bool IsHttpUrl | ( | const std::string & | path | ) |
Definition at line 168 of file posix.cc.
Referenced by notify::DoPublish(), s3fanout::S3FanoutManager::InitializeDnsSettings(), swissknife::CommandListReflog::Main(), swissknife::CommandListCatalogs::Main(), swissknife::CommandCheck::Main(), swissknife::CommandFileStats::Main(), and swissknife::CommandMigrate::Main().
CVMFS_EXPORT bool IsMountPoint | ( | const std::string & | path | ) |
CVMFS_EXPORT bool ListDirectory | ( | const std::string & | directory, |
std::vector< std::string > * | names, | ||
std::vector< mode_t > * | modes | ||
) |
Finds all files and direct subdirectories under directory (except ., ..).
Definition at line 1208 of file posix.cc.
Referenced by publish::ClearScratch(), publish::CmdEnter::CreateUnderlay(), and Lsof().
CVMFS_EXPORT int LockFile | ( | const std::string & | path | ) |
Locks file path, blocks if file is already locked. Creates path if required.
Definition at line 971 of file posix.cc.
Referenced by PosixQuotaManager::CreateShared(), PosixQuotaManager::InitDatabase(), FileSystem::LockWorkspace(), and PosixQuotaManager::MainCacheManager().
CVMFS_EXPORT std::vector<LsofEntry> Lsof | ( | const std::string & | path | ) |
Searches for open file descriptors on the subtree starting at path. For the time being works only on Linux, not on macOS.
Definition at line 1499 of file posix.cc.
Referenced by publish::CmdLsof::Main(), and publish::CmdAbort::Main().
CVMFS_EXPORT bool MakeCacheDirectories | ( | const std::string & | path, |
const mode_t | mode | ||
) |
Creates the "hash cache" directory structure in path.
Definition at line 882 of file posix.cc.
Referenced by upload::LocalUploader::Create(), FuseMain(), PosixCacheManager::InitCacheDirectory(), and main().
CVMFS_EXPORT std::string MakeCanonicalPath | ( | const std::string & | path | ) |
Removes a trailing "/" from a path.
Definition at line 98 of file posix.cc.
Referenced by FileSystem::DeterminePosixCacheSettings(), notify::DoPublish(), manifest::Breadcrumb::Export(), FuseMain(), GetCacheDir(), publish::GetFqrnFromUrl(), anonymous_namespace{cvmfs_cache_posix.cc}::GetSettings(), GetWorkspace(), swissknife::CommandTag::InitializeEnvironment(), swissknife::CommandInfo::Main(), swissknife::CommandScrub::Main(), swissknife::Ingest::Main(), publish::CmdTransaction::Main(), swissknife::CommandCheck::Main(), swissknife::CommandApplyDirtab::Main(), main(), swissknife::CommandSync::Main(), MakeCacheDirectories(), publish::SyncUnionTarball::ProcessArchiveEntry(), and FileSystem::SetupWorkspace().
CVMFS_EXPORT void MakePipe | ( | int | pipe_fd[2] | ) |
Creating a pipe should always succeed.
Definition at line 492 of file posix.cc.
Referenced by CachePlugin::CachePlugin(), publish::CallServerHook(), PosixQuotaManager::Create(), upload::S3Uploader::Create(), CreatePidNamespace(), PosixQuotaManager::CreateShared(), upload::S3Uploader::DoUpload(), AuthzExternalFetcher::ExecHelper(), ExecuteBinary(), FuseInvalidator::FuseInvalidator(), cvmfs::Fetcher::GetTls(), swissknife::CommandPull::Main(), PosixQuotaManager::MakeReturnPipe(), BashOptionsManager::ParsePath(), upload::S3Uploader::Peek(), Pipe< kPipeWatchdog >::Pipe(), PosixQuotaManager::RegisterBackChannel(), ExternalQuotaManager::RegisterBackChannel(), quota::RegisterUnpinListener(), quota::RegisterWatchdogListener(), s3fanout::S3FanoutManager::S3FanoutManager(), FuseRemounter::Spawn(), perf::TelemetryAggregator::Spawn(), file_watcher::FileWatcher::Spawn(), glue::DentryTracker::SpawnCleaner(), ExternalCacheManager::SpawnPlugin(), and shrinkwrap::SyncInit().
CVMFS_EXPORT int MakeSocket | ( | const std::string & | path, |
const int | mode | ||
) |
Creates and binds to a named socket.
Definition at line 331 of file posix.cc.
Referenced by TalkManager::Create(), GetExistingFuseFd(), loader::loader_talk::Init(), and CachePlugin::Listen().
CVMFS_EXPORT int MakeTcpEndpoint | ( | const std::string & | ipv4_address, |
int | portno | ||
) |
Creates and binds a TCP/IPv4 socket. An empty address binds to the "any" address.
Definition at line 389 of file posix.cc.
Referenced by CachePlugin::Listen().
CVMFS_EXPORT bool ManagedExec | ( | const std::vector< std::string > & | command_line, |
const std::set< int > & | preserve_fildes, | ||
const std::map< int, int > & | map_fildes, | ||
const bool | drop_credentials, | ||
const bool | clear_env, | ||
const bool | double_fork, | ||
pid_t * | child_pid | ||
) |
Execve to the given command line, preserving the given file descriptors. If stdin, stdout, stderr should be preserved, add 0, 1, 2. File descriptors from the parent process can also be mapped to the new process (dup2) using map_fildes. Can be useful for stdout/in/err redirection. NOTE: The destination fildes have to be preserved! Does a double fork to detach child. The command_line parameter contains the binary at index 0 and the arguments in the rest of the vector. Using the optional parameter *pid it is possible to retrieve the process ID of the spawned process.
Definition at line 1843 of file posix.cc.
Referenced by publish::CallServerHook(), PosixQuotaManager::CreateShared(), ExecuteBinary(), publish::CmdEnter::Main(), publish::CmdEnter::MountCvmfs(), publish::CmdEnter::MountOverlayfs(), publish::RunSuidHelper(), and ExternalCacheManager::SpawnPlugin().
CVMFS_EXPORT bool MkdirDeep | ( | const std::string & | path, |
const mode_t | mode, | ||
bool | verify_writable | ||
) |
The mkdir -p command. Additionally checks if the directory is writable if it exists.
Definition at line 846 of file posix.cc.
Referenced by upload::LocalUploader::Create(), publish::CreateDirectoryAsOwner(), swissknife::CommandGraft::DirCallback(), publish::SettingsSpoolArea::EnsureDirectories(), anonymous_namespace{cmd_enter.cc}::EnsureDirectory(), FuseMain(), StatisticsDatabase::GetDBParams(), receiver::PayloadProcessor::Initialize(), publish::CmdEnter::Main(), main(), MakeCacheDirectories(), upload::LocalUploader::Mkdir(), MkdirDeep(), posix_archive_provenance(), posix_initialize(), PosixCheckDirStructure(), receiver::CommitProcessor::Process(), swissknife::CommandFileStats::Run(), FileSystem::SetupNfsMaps(), and FileSystem::SetupWorkspace().
CVMFS_EXPORT void Nonblock2Block | ( | int | filedes | ) |
Changes a non-blocking file descriptor to a blocking one.
Definition at line 636 of file posix.cc.
Referenced by PosixQuotaManager::BindReturnPipe(), PosixQuotaManager::CreateShared(), PosixQuotaManager::MainCacheManager(), and PosixQuotaManager::MakeReturnPipe().
CVMFS_EXPORT bool ProcessExists | ( | pid_t | pid | ) |
Definition at line 1561 of file posix.cc.
Referenced by publish::CmdEnter::CleanupSession().
CVMFS_EXPORT void ReadHalfPipe | ( | int | fd, |
void * | buf, | ||
size_t | nbyte | ||
) |
Reads from a pipe where writer's end is not yet necessarily connected
Definition at line 525 of file posix.cc.
Referenced by PosixQuotaManager::Cleanup(), PosixQuotaManager::DoList(), PosixQuotaManager::GetCleanupRate(), PosixQuotaManager::GetLimits(), PosixQuotaManager::GetPid(), PosixQuotaManager::GetProtocolRevision(), PosixQuotaManager::GetSharedStatus(), PosixQuotaManager::Pin(), PosixQuotaManager::RegisterBackChannel(), PosixQuotaManager::Remove(), and file_watcher::FileWatcher::Spawn().
CVMFS_EXPORT void ReadPipe | ( | int | fd, |
void * | buf, | ||
size_t | nbyte | ||
) |
Reads from a pipe should always succeed.
Definition at line 513 of file posix.cc.
Referenced by PosixQuotaManager::DoList(), cvmfs::Fetcher::Fetch(), PosixQuotaManager::GetLimits(), PosixQuotaManager::GetSharedStatus(), PosixQuotaManager::MainCacheManager(), glue::DentryTracker::MainCleaner(), PosixQuotaManager::MainCommandServer(), FuseInvalidator::MainInvalidator(), CachePlugin::MainProcessRequests(), FuseRemounter::MainRemountTrigger(), perf::TelemetryAggregator::MainTelemetry(), quota::MainUnpinListener(), s3fanout::S3FanoutManager::MainUpload(), quota::MainWatchdogListener(), swissknife::MainWorker(), shrinkwrap::MainWorker(), BashOptionsManager::ParsePath(), s3fanout::S3FanoutManager::PopCompletedJob(), Pipe< kPipeWatchdog >::Read(), file_watcher::FileWatcherInotify::RunEventLoop(), file_watcher::FileWatcherKqueue::RunEventLoop(), and upload::S3Uploader::RequestCtrl::WaitFor().
CVMFS_EXPORT std::string ReadSymlink | ( | const std::string & | path | ) |
CVMFS_EXPORT int RecvFdFromSocket | ( | int | msg_fd | ) |
Returns the file descriptor that has been sent with SendFd2Socket. The msg_fd file descriptor needs to come from a call to accept() on the socket where the passing file descriptor has been sent to. Returns -errno on error.
Definition at line 708 of file posix.cc.
Referenced by GetExistingFuseFd().
CVMFS_EXPORT bool RemoveTree | ( | const std::string & | path | ) |
Does rm -rf on path.
Definition at line 1095 of file posix.cc.
Referenced by publish::CmdEnter::CleanupSession(), NfsMapsLeveldb::Create(), and RaiiTempDir::~RaiiTempDir().
CVMFS_EXPORT std::string ResolvePath | ( | const std::string & | path | ) |
Follow all symlinks if possible. Equivalent to readlink --canonicalize-missing
Definition at line 68 of file cvmfs_suid_util.cc.
Referenced by IsMountPoint(), Mount(), and ResolvePath().
CVMFS_EXPORT ssize_t SafeRead | ( | int | fd, |
void * | buf, | ||
size_t | nbyte | ||
) |
Deal with EINTR and partial reads.
Definition at line 2042 of file posix.cc.
Referenced by CheckNamespaceFeatures(), anonymous_namespace{cmd_enter.cc}::EnterRootContainer(), FileIngestionSource::Read(), receiver::Reactor::ReadReply(), receiver::Reactor::ReadRequest(), AuthzExternalFetcher::Recv(), CacheTransport::RecvFrame(), CacheTransport::RecvHeader(), and SafeReadToString().
CVMFS_EXPORT bool SafeReadToString | ( | int | fd, |
std::string * | final_result | ||
) |
Pull file contents into a string
Definition at line 2065 of file posix.cc.
Referenced by publish::SyncMediator::Add(), notify::DoPublish(), publish::ExitShell(), signature::SignatureManager::LoadBlacklist(), swissknife::Ingest::Main(), publish::CmdEnter::Main(), swissknife::CommandSync::Main(), gateway::ReadKeys(), and download::ResolveProxyDescription().
CVMFS_EXPORT void SafeSleepMs | ( | const unsigned | ms | ) |
Sleeps using select. This is without signals and doesn't interfere with other uses of the ALRM signal.
Definition at line 1972 of file posix.cc.
Referenced by download::DownloadManager::Backoff(), s3fanout::S3FanoutManager::Backoff(), NfsMapsSqlite::BusyHandler(), ExternalCacheManager::CreatePlugin(), Fence::Drain(), anonymous_namespace{cache_posix.cc}::CallGuard::Drainout(), Fence::Enter(), Watchdog::GenerateStackTrace(), FuseInvalidator::MainInvalidator(), swissknife::CommandPull::Pull(), ReadHalfPipe(), Watchdog::SendTrace(), NfsMapsLeveldb::ForkAwareEnv::SleepForMicroseconds(), shrinkwrap::SyncInit(), PosixCacheManager::TearDown2ReadOnly(), BackoffThrottle::Throttle(), auto_umount::UmountOnCrash(), FuseInvalidator::Handle::WaitFor(), NfsMapsLeveldb::ForkAwareEnv::WaitForBGThreads(), and WaitForReload().
CVMFS_EXPORT bool SafeWrite | ( | int | fd, |
const void * | buf, | ||
size_t | nbyte | ||
) |
Deal with EINTR and partial writes.
Definition at line 1983 of file posix.cc.
Referenced by CreatePidNamespace(), FuseMain(), LogCustom(), swissknife::CommandGraft::Publish(), SafeWriteToFile(), AuthzExternalFetcher::Send(), publish::SetInConfig(), manifest::Reflog::WriteChecksum(), WritePidFile(), receiver::Reactor::WriteReply(), and receiver::Reactor::WriteRequest().
CVMFS_EXPORT bool SafeWriteToFile | ( | const std::string & | content, |
const std::string & | path, | ||
int | mode | ||
) |
Definition at line 2081 of file posix.cc.
Referenced by publish::ExportKeychain(), swissknife::CommandLease::Main(), publish::CmdAbort::Main(), publish::CmdCommit::Main(), publish::CmdEnter::Main(), download::ResolveProxyDescription(), SigningTool::Run(), publish::CheckoutMarker::SaveAs(), and publish::CmdEnter::WriteCvmfsConfig().
CVMFS_EXPORT bool SafeWriteV | ( | int | fd, |
struct iovec * | iov, | ||
unsigned | iovcnt | ||
) |
The contents of the iov vector might be modified by the function.
Definition at line 2001 of file posix.cc.
Referenced by CacheTransport::SendData().
CVMFS_EXPORT bool SendFd2Socket | ( | int | socket_fd, |
int | passing_fd | ||
) |
Sends the file descriptor passing_fd to the socket socket_fd. Can be used to transfer an open file descriptor from one process to another. Use ConnectSocket() to get the socket_fd.
Definition at line 668 of file posix.cc.
Referenced by cvmfs::SendFuseFd().
CVMFS_EXPORT void SendMsg2Socket | ( | const int | fd, |
const std::string & | msg | ||
) |
Drops the characters of string to a socket. It doesn't matter if the other side has hung up.
Definition at line 659 of file posix.cc.
Referenced by CheckConcurrentMount(), FreeSavedState(), CacheManager::FreeState(), GetExistingFuseFd(), loader::loader_talk::MainTalk(), MaintenanceMode(), loader::Reload(), CacheManager::RestoreState(), RestoreState(), CacheManager::SaveState(), and SaveState().
CVMFS_EXPORT int SetLimitNoFile | ( | unsigned | limit_nofile | ) |
Sets soft and hard limit for maximum number of open file descriptors. Returns 0 on success, -1 on failure, -2 if running under valgrind.
Definition at line 1458 of file posix.cc.
Referenced by FuseMain(), and LibGlobals::Initialize().
CVMFS_EXPORT bool Shell | ( | int * | fd_stdin, |
int * | fd_stdout, | ||
int * | fd_stderr | ||
) |
Opens /bin/sh and provides file descriptors to write into stdin and read from stdout. Quit shell simply by closing stderr, stdout, and stdin.
Definition at line 1715 of file posix.cc.
Referenced by BashOptionsManager::ParsePath().
CVMFS_EXPORT void SplitPath | ( | const std::string & | path, |
std::string * | dirname, | ||
std::string * | filename | ||
) |
Return both the file and directory name for a given path.
NOTE: If only a filename is given, the directory is returned as "."
Definition at line 113 of file posix.cc.
Referenced by catalog::WritableCatalogManager::Clone(), publish::SyncUnionTarball::CreateDirectories(), publish::SyncUnionTarball::ProcessArchiveEntry(), swissknife::CommandGraft::Publish(), and publish::SyncUnionTarball::Traverse().
CVMFS_EXPORT bool SwitchCredentials | ( | const uid_t | uid, |
const gid_t | gid, | ||
const bool | temporarily | ||
) |
set(e){g/u}id wrapper.
Definition at line 761 of file posix.cc.
Referenced by FuseMain(), Watchdog::GenerateStackTrace(), publish::CmdAbort::Main(), publish::CmdCommit::Main(), publish::CmdTransaction::Main(), ManagedExec(), SwitchCredentials(), and auto_umount::UmountOnCrash().
CVMFS_EXPORT bool SymlinkExists | ( | const std::string & | path | ) |
Checks if the symlink file path exists.
Definition at line 823 of file posix.cc.
Referenced by CheckNamespaceFeatures(), swissknife::CommandCheck::Exists(), GetCvmfsBinary(), posix_cleanup_path(), ResolvePath(), and SslCertificateStore::UseSystemCertificatePath().
CVMFS_EXPORT bool SymlinkForced | ( | const std::string & | src, |
const std::string & | dest | ||
) |
Equivalent of ln -sf $src $dest
Definition at line 833 of file posix.cc.
Referenced by publish::CmdEnter::CreateUnderlay(), publish::CmdEnter::Main(), and upload::LocalUploader::PlaceBootstrappingShortcut().
CVMFS_EXPORT int TryLockFile | ( | const std::string & | path | ) |
Tries to locks file path, return an error if file is already locked. Creates path if required.
Definition at line 913 of file posix.cc.
Referenced by CachePlugin::Listen(), FileSystem::LockWorkspace(), and publish::ServerLockFile::TryLock().
CVMFS_EXPORT void UnlockFile | ( | const int | filedes | ) |
Definition at line 995 of file posix.cc.
Referenced by PosixQuotaManager::CloseDatabase(), PosixQuotaManager::CreateShared(), PosixQuotaManager::InitDatabase(), swissknife::CommandPull::Main(), PosixQuotaManager::MainCacheManager(), WritePidFile(), CachePlugin::~CachePlugin(), and FileSystem::~FileSystem().
CVMFS_EXPORT int WaitForChild | ( | pid_t | pid, |
const std::vector< int > & | sig_ok | ||
) |
Returns -1 if the child crashed or the exit code otherwise.
pid | Process identifier. |
sig_ok | List of signals that are still considered a successful termination. |
Definition at line 1602 of file posix.cc.
Referenced by publish::CallServerHook(), publish::CmdEnter::Main(), publish::CmdEnter::MountCvmfs(), publish::CmdEnter::MountOverlayfs(), and publish::RunSuidHelper().
CVMFS_EXPORT void WaitForSignal | ( | int | signum | ) |
Waits for a signal. The signal should be blocked before for all threads. Threads inherit their parent's signal mask.
Definition at line 1588 of file posix.cc.
Referenced by loader::Reload().
CVMFS_EXPORT int WritePidFile | ( | const std::string & | path | ) |
CVMFS_EXPORT void WritePipe | ( | int | fd, |
const void * | buf, | ||
size_t | nbyte | ||
) |
Writes to a pipe should always succeed.
Definition at line 501 of file posix.cc.
Referenced by CachePlugin::AskToDetach(), publish::CallServerHook(), PosixQuotaManager::Cleanup(), PosixQuotaManager::DoInsert(), PosixQuotaManager::DoList(), PosixQuotaManager::GetCleanupRate(), PosixQuotaManager::GetLimits(), PosixQuotaManager::GetPid(), PosixQuotaManager::GetProtocolRevision(), PosixQuotaManager::GetSharedStatus(), shrinkwrap::handle_file(), FuseInvalidator::InvalidateDentry(), FuseInvalidator::InvalidateInodes(), swissknife::CommandPull::Main(), PosixQuotaManager::MainCacheManager(), PosixQuotaManager::MainCommandServer(), loader::loader_talk::MainReload(), CachePlugin::NotifySupervisor(), upload::S3Uploader::OnReqComplete(), BashOptionsManager::ParsePath(), PosixQuotaManager::Pin(), swissknife::CommandPull::Pull(), s3fanout::S3FanoutManager::PushCompletedJob(), s3fanout::S3FanoutManager::PushNewJob(), PosixQuotaManager::RegisterBackChannel(), PosixQuotaManager::Remove(), file_watcher::FileWatcherKqueue::RunEventLoop(), file_watcher::FileWatcherInotify::RunEventLoop(), SendCommand(), publish::SendTalkCommand(), FuseRemounter::SetAlarm(), cvmfs::Fetcher::SignalWaitingThreads(), file_watcher::FileWatcher::Stop(), shrinkwrap::SyncInit(), CachePlugin::Terminate(), PosixQuotaManager::Touch(), PosixQuotaManager::Unpin(), PosixQuotaManager::UnregisterBackChannel(), quota::UnregisterListener(), Pipe< kPipeWatchdog >::Write(), glue::DentryTracker::~DentryTracker(), FuseInvalidator::~FuseInvalidator(), FuseRemounter::~FuseRemounter(), PosixQuotaManager::~PosixQuotaManager(), s3fanout::S3FanoutManager::~S3FanoutManager(), and perf::TelemetryAggregator::~TelemetryAggregator().
const int kDefaultDirMode |
Definition at line 33 of file posix.h.
Referenced by publish::ExportKeychain().
const int kDefaultFileMode = S_IWUSR | S_IRUSR | S_IRGRP | S_IROTH |
Definition at line 32 of file posix.h.
Referenced by CopyMem2Path(), swissknife::CommandApplyDirtab::CreateCatalogMarkers(), swissknife::CommandCheck::FetchPath(), publish::CheckoutMarker::SaveAs(), publish::SetInConfig(), and manifest::Reflog::WriteChecksum().
const unsigned kPageSize = 4096 |
This file is part of the CernVM File System.
Definition at line 30 of file posix.h.
Referenced by upload::LocalUploader::DoUpload(), upload::S3Uploader::DoUpload(), AuthzExternalFetcher::Recv(), and RamCacheManager::StartTxn().
const int kPrivateDirMode = S_IXUSR | S_IWUSR | S_IRUSR |
Definition at line 36 of file posix.h.
Referenced by publish::ClearScratch(), publish::CreateDirectoryAsOwner(), publish::InitSpoolArea(), and publish::Publisher().
const int kPrivateFileMode = S_IWUSR | S_IRUSR |
Definition at line 35 of file posix.h.
Referenced by publish::DownloadRootObjects(), publish::CmdEnter::Main(), publish::CmdEnter::MountCvmfs(), publish::CmdEnter::MountOverlayfs(), and publish::CmdEnter::WriteCvmfsConfig().