5 #ifndef CVMFS_UTIL_POSIX_H_
6 #define CVMFS_UTIL_POSIX_H_
10 #include <sys/types.h>
25 #ifdef CVMFS_NAMESPACE_GUARD
26 namespace CVMFS_NAMESPACE_GUARD {
33 S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH;
72 std::string *filename);
82 void CreateFile(
const std::string &path,
const int mode,
83 const bool ignore_failure =
false);
84 int MakeSocket(
const std::string &path,
const int mode);
89 void WritePipe(
int fd,
const void *buf,
size_t nbyte);
90 void ReadPipe(
int fd,
void *buf,
size_t nbyte);
93 bool DiffTree(
const std::string &path_a,
const std::string &path_b);
102 const bool temporarily);
108 bool SymlinkForced(
const std::string &src,
const std::string &dest);
109 bool MkdirDeep(
const std::string &path,
const mode_t mode,
110 bool verify_writable =
true);
112 FILE *
CreateTempFile(
const std::string &path_prefix,
const int mode,
113 const char *open_flags, std::string *final_path);
114 std::string
CreateTempPath(
const std::string &path_prefix,
const int mode);
118 int LockFile(
const std::string &path);
123 const std::string &suffix);
125 const std::string &prefix);
126 std::vector<std::string>
FindDirectories(
const std::string &parent_dir);
129 std::vector<std::string> *names,
130 std::vector<mode_t> *modes);
135 bool GetUidOf(
const std::string &username, uid_t *uid, gid_t *main_gid);
136 bool GetGidOf(
const std::string &groupname, gid_t *gid);
148 std::vector<LsofEntry>
Lsof(
const std::string &path);
154 const std::vector<int> &sig_ok = std::vector<int>());
156 bool Shell(
int *pipe_stdin,
int *pipe_stdout,
int *pipe_stderr);
160 const std::string &binary_path,
161 const std::vector<std::string> &argv,
162 const bool double_fork =
true,
163 pid_t *child_pid = NULL);
164 bool ManagedExec(
const std::vector<std::string> &command_line,
165 const std::set<int> &preserve_fildes,
166 const std::map<int, int> &map_fildes,
167 const bool drop_credentials,
168 const bool clear_env =
false,
169 const bool double_fork =
true,
170 pid_t *child_pid = NULL);
175 ssize_t
SafeRead(
int fd,
void *buf,
size_t nbyte);
176 bool SafeWrite(
int fd,
const void *buf,
size_t nbyte);
177 bool SafeWriteV(
int fd,
struct iovec *iov,
unsigned iovcnt);
182 const std::string &path,
int mode);
188 read_end = pipe_fd[0];
189 write_end = pipe_fd[1];
192 Pipe(
const int fd_read,
const int fd_write) :
193 read_end(fd_read), write_end(fd_write) {}
203 const int num_bytes = write(write_end, &data,
sizeof(T));
204 return (num_bytes >= 0) && (
static_cast<size_t>(num_bytes) ==
sizeof(T));
210 int num_bytes = read(read_end, data,
sizeof(T));
211 return (num_bytes >= 0) && (
static_cast<size_t>(num_bytes) ==
sizeof(T));
214 bool Write(
const void *buf,
size_t nbyte) {
219 bool Read(
void *buf,
size_t nbyte) {
229 #ifdef CVMFS_NAMESPACE_GUARD
233 #endif // CVMFS_UTIL_POSIX_H_
bool MakeCacheDirectories(const std::string &path, const mode_t mode)
int MakeSocket(const std::string &path, const int mode)
bool SymlinkForced(const std::string &src, const std::string &dest)
bool Write(const void *buf, size_t nbyte)
std::string GetFileName(const std::string &path)
const int kPrivateDirMode
int MakeTcpEndpoint(const std::string &ipv4_address, int portno)
std::string GetUserName()
const int kDefaultFileMode
void CreateFile(const std::string &path, const int mode, const bool ignore_failure)
bool GetUserNameOf(uid_t uid, std::string *username)
FILE * CreateTempFile(const std::string &path_prefix, const int mode, const char *open_flags, std::string *final_path)
Pipe(const int fd_read, const int fd_write)
int ConnectTcpEndpoint(const std::string &ipv4_address, int portno)
bool Shell(int *fd_stdin, int *fd_stdout, int *fd_stderr)
bool IsHttpUrl(const std::string &path)
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)
std::string CreateTempPath(const std::string &path_prefix, const int mode)
bool SafeWrite(int fd, const void *buf, size_t nbyte)
void SendMsg2Socket(const int fd, const std::string &msg)
assert((mem||(size==0))&&"Out Of Memory")
bool SafeWriteToFile(const std::string &content, const std::string &path, int mode)
std::string FindExecutable(const std::string &exe)
bool SendFd2Socket(int socket_fd, int passing_fd)
int WaitForChild(pid_t pid, const std::vector< int > &sig_ok)
std::string GetParentPath(const std::string &path)
bool Write(const T &data)
bool AddGroup2Persona(const gid_t gid)
void MakePipe(int pipe_fd[2])
std::vector< std::string > FindDirectories(const std::string &parent_dir)
int SetLimitNoFile(unsigned limit_nofile)
bool SymlinkExists(const std::string &path)
bool FileExists(const std::string &path)
const int kPrivateFileMode
std::string GetAbsolutePath(const std::string &path)
void SplitPath(const std::string &path, std::string *dirname, std::string *filename)
void GetLimitNoFile(unsigned *soft_limit, unsigned *hard_limit)
void ReadHalfPipe(int fd, void *buf, size_t nbyte)
ssize_t SafeRead(int fd, void *buf, size_t nbyte)
const int kDefaultDirMode
FileSystemInfo GetFileSystemInfo(const std::string &path)
void Nonblock2Block(int filedes)
bool Read(void *buf, size_t nbyte)
int TryLockFile(const std::string &path)
bool MkdirDeep(const std::string &path, const mode_t mode, bool verify_writable)
int LockFile(const std::string &path)
string ResolvePath(const std::string &path)
std::string GetHomeDirectory()
void WaitForSignal(int signum)
bool GetGidOf(const std::string &groupname, gid_t *gid)
std::string CreateTempDir(const std::string &path_prefix)
bool DirectoryExists(const std::string &path)
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, pid_t *child_pid)
bool RemoveTree(const std::string &path)
bool SafeReadToString(int fd, std::string *final_result)
int WritePidFile(const std::string &path)
int ConnectSocket(const std::string &path)
bool GetUidOf(const std::string &username, uid_t *uid, gid_t *main_gid)
std::vector< std::string > FindFilesByPrefix(const std::string &dir, const std::string &prefix)
bool SwitchCredentials(const uid_t uid, const gid_t gid, const bool temporarily)
std::string ReadSymlink(const std::string &path)
std::vector< LsofEntry > Lsof(const std::string &path)
bool ListDirectory(const std::string &directory, std::vector< std::string > *names, std::vector< mode_t > *modes)
int64_t GetFileSize(const std::string &path)
void SafeSleepMs(const unsigned ms)
bool DiffTree(const std::string &path_a, const std::string &path_b)
void Block2Nonblock(int filedes)
bool IsAbsolutePath(const std::string &path)
bool ProcessExists(pid_t pid)
std::string MakeCanonicalPath(const std::string &path)
void WritePipe(int fd, const void *buf, size_t nbyte)
std::string GetCurrentWorkingDirectory()
void ReadPipe(int fd, void *buf, size_t nbyte)
std::vector< std::string > FindFilesBySuffix(const std::string &dir, const std::string &suffix)
void ClosePipe(int pipe_fd[2])
bool IsMountPoint(const std::string &path)
int RecvFdFromSocket(int msg_fd)
const size_t kMaxPathLength
bool SafeWriteV(int fd, struct iovec *iov, unsigned iovcnt)
void UnlockFile(const int filedes)
void BlockSignal(int signum)