7 #ifndef CVMFS_UTIL_PLATFORM_LINUX_H_
8 #define CVMFS_UTIL_PLATFORM_LINUX_H_
10 #include <sys/types.h>
12 #include <sys/xattr.h>
23 #include <sys/mount.h>
24 #include <sys/prctl.h>
25 #include <sys/select.h>
27 #include <sys/utsname.h>
40 #ifdef CVMFS_NAMESPACE_GUARD
41 namespace CVMFS_NAMESPACE_GUARD {
44 #define platform_sighandler_t sighandler_t
47 std::vector<std::string> result;
48 FILE *fmnt = setmntent(
"/proc/mounts",
"r");
49 struct mntent *mntbuf;
50 while ((mntbuf = getmntent(fmnt)) != NULL) {
51 result.push_back(mntbuf->mnt_dir);
59 #define MNT_DETACH 0x00000002
62 struct stat64 mtab_info;
63 int retval = lstat64(_PATH_MOUNTED, &mtab_info);
65 if ((retval == 0) && S_ISREG(mtab_info.st_mode)) {
68 std::string lockfile = std::string(_PATH_MOUNTED) +
".cvmfslock";
69 const int fd_lockfile = open(lockfile.c_str(), O_RDONLY | O_CREAT, 0600);
73 while ((flock(fd_lockfile, LOCK_EX | LOCK_NB) != 0) && (timeout > 0)) {
74 if (errno != EWOULDBLOCK) {
78 struct timeval wait_for;
81 select(0, NULL, NULL, NULL, &wait_for);
90 std::string mntnew = std::string(_PATH_MOUNTED) +
".cvmfstmp";
91 FILE *fmntold = setmntent(_PATH_MOUNTED,
"r");
93 flock(fd_lockfile, LOCK_UN);
97 FILE *fmntnew = setmntent(mntnew.c_str(),
"w+");
98 if (!fmntnew && (chmod(mntnew.c_str(), mtab_info.st_mode) != 0)
99 && (chown(mntnew.c_str(), mtab_info.st_uid, mtab_info.st_gid) != 0)) {
101 flock(fd_lockfile, LOCK_UN);
105 struct mntent *mntbuf;
106 while ((mntbuf = getmntent(fmntold)) != NULL) {
107 if (strcmp(mntbuf->mnt_dir, mountpoint) != 0) {
108 retval = addmntent(fmntnew, mntbuf);
112 unlink(mntnew.c_str());
113 flock(fd_lockfile, LOCK_UN);
121 retval = rename(mntnew.c_str(), _PATH_MOUNTED);
122 flock(fd_lockfile, LOCK_UN);
127 retval = chmod(_PATH_MOUNTED, mtab_info.st_mode);
129 retval = chown(_PATH_MOUNTED, mtab_info.st_uid, mtab_info.st_gid);
135 retval = umount2(mountpoint, flags);
150 return pthread_spin_init(lock, pshared);
154 return pthread_spin_destroy(lock);
158 return pthread_spin_trylock(lock);
162 pthread_spin_unlock(lock);
172 int retval = sigemptyset(&sigset);
174 retval = sigaddset(&sigset, signum);
176 retval = sigwaitinfo(&sigset, NULL);
188 #ifdef PR_SET_PTRACER
192 const int retval =
prctl(PR_SET_PTRACER, pid, 0, 0, 0);
196 return (retval == 0) || (errno == EINVAL);
209 return readdir64(dirp);
215 return stat64(path, buf);
219 return lstat64(path, buf);
223 return fstat64(filedes, buf);
228 std::string *value) {
232 retval = getxattr(path.c_str(), name.c_str(), buffer,
size);
235 buffer = smalloc(size);
236 retval = getxattr(path.c_str(), name.c_str(), buffer,
size);
238 if ((retval < 0) || (retval >
size)) {
243 value->assign(static_cast<const char *>(buffer), size);
253 const std::string &value) {
254 int retval = setxattr(path.c_str(), name.c_str(), value.c_str(), value.size(),
260 const std::string &value) {
261 int retval = lsetxattr(path.c_str(), name.c_str(), value.c_str(),
267 void *value,
size_t size) {
268 return lgetxattr(path, name, value, size);
272 return llistxattr(path, list, size);
276 (void)posix_fadvise(filedes, 0, 0, POSIX_FADV_RANDOM | POSIX_FADV_NOREUSE);
280 return readahead(filedes, 0, static_cast<size_t>(-1));
307 const off_t length) {
308 return posix_fadvise(fd, offset, length, POSIX_FADV_DONTNEED);
312 return "lib" + base_name +
".so";
316 char buf[PATH_MAX + 1];
317 ssize_t ret = readlink(
"/proc/self/exe", buf, PATH_MAX);
320 return std::string(buf);
327 int retval = clock_gettime(clock, &tp);
333 #ifdef CLOCK_MONOTONIC_COARSE
338 return tp.tv_sec + (tp.tv_nsec >= 500000000);
343 return static_cast<uint64_t
>(
static_cast<double>(tp.tv_sec) * 1e9
344 + static_cast<double>(tp.tv_nsec));
349 return static_cast<uint64_t
>(
static_cast<double>(tp.tv_sec) * 1e9
350 + static_cast<double>(tp.tv_nsec));
354 return static_cast<uint64_t
>(sysconf(_SC_PHYS_PAGES))
355 * static_cast<uint64_t>(sysconf(_SC_PAGE_SIZE));
358 #ifdef CVMFS_NAMESPACE_GUARD
362 #endif // CVMFS_UTIL_PLATFORM_LINUX_H_
assert((mem||(size==0))&&"Out Of Memory")