summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorRuediger Meier2016-02-29 12:38:58 +0100
committerKarel Zak2016-03-07 15:33:56 +0100
commit2208b3ccb298be2675cf005b761b1668f8cd576f (patch)
tree2321d7e68e87a87be24220824a47453f67a3881a /lib
parenttaskset: fix description of `-c` option in the man page (diff)
downloadkernel-qcow2-util-linux-2208b3ccb298be2675cf005b761b1668f8cd576f.tar.gz
kernel-qcow2-util-linux-2208b3ccb298be2675cf005b761b1668f8cd576f.tar.xz
kernel-qcow2-util-linux-2208b3ccb298be2675cf005b761b1668f8cd576f.zip
lib: remove openat fallback functions (include/at.h)
I have validated that we are still compatible at least back to - openSUSE 11.4 - SLE 11 - RHEL/CentOS 6 - OSX 10.10.x, (Xcode 6.3) - FreeBSD 10.2 Confirmed incompatibility: - OSX 10.9.x, (Xcode 6.2) Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
Diffstat (limited to 'lib')
-rw-r--r--lib/Makemodule.am4
-rw-r--r--lib/at.c124
-rw-r--r--lib/loopdev.c3
-rw-r--r--lib/procutils.c6
-rw-r--r--lib/sysfs.c15
5 files changed, 14 insertions, 138 deletions
diff --git a/lib/Makemodule.am b/lib/Makemodule.am
index 94e845349..25e1ba04e 100644
--- a/lib/Makemodule.am
+++ b/lib/Makemodule.am
@@ -52,7 +52,6 @@ dist_man_MANS += lib/terminal-colors.d.5
check_PROGRAMS += \
- test_at \
test_blkdev \
test_canonicalize \
test_colors \
@@ -91,9 +90,6 @@ test_ismounted_LDADD = $(LDADD) libcommon.la
test_mangle_SOURCES = lib/mangle.c
test_mangle_CFLAGS = $(AM_CFLAGS) -DTEST_PROGRAM
-test_at_SOURCES = lib/at.c
-test_at_CFLAGS = $(AM_CFLAGS) -DTEST_PROGRAM_AT
-
test_strutils_SOURCES = lib/strutils.c
test_strutils_CFLAGS = $(AM_CFLAGS) -DTEST_PROGRAM
diff --git a/lib/at.c b/lib/at.c
index 4086a2541..e32a8f5d3 100644
--- a/lib/at.c
+++ b/lib/at.c
@@ -7,138 +7,18 @@
* Written by Karel Zak <kzak@redhat.com>
*/
#include <stdio.h>
-#include <stdlib.h>
#include <fcntl.h>
-#include <sys/stat.h>
#include "at.h"
#include "c.h"
-#ifdef HAVE_FSTATAT
-int fstat_at(int dir, const char *dirname __attribute__ ((__unused__)),
- const char *filename, struct stat *st, int nofollow)
-{
- return fstatat(dir, filename, st,
- nofollow ? AT_SYMLINK_NOFOLLOW : 0);
-}
-#else
-int fstat_at(int dir __attribute__ ((__unused__)), const char *dirname,
- const char *filename, struct stat *st, int nofollow)
-{
-
- if (*filename != '/') {
- char path[PATH_MAX];
- int len;
-
- len = snprintf(path, sizeof(path), "%s/%s", dirname, filename);
- if (len < 0 || (size_t)len >= sizeof(path))
- return -1;
-
- return nofollow ? lstat(path, st) : stat(path, st);
- }
-
- return nofollow ? lstat(filename, st) : stat(filename, st);
-}
-#endif
-
-#ifdef HAVE_FSTATAT
-int open_at(int dir, const char *dirname __attribute__ ((__unused__)),
- const char *filename, int flags)
-{
- return openat(dir, filename, flags);
-}
-#else
-int open_at(int dir __attribute__((__unused__)), const char *dirname,
- const char *filename, int flags)
-{
- if (*filename != '/') {
- char path[PATH_MAX];
- int len;
-
- len = snprintf(path, sizeof(path), "%s/%s", dirname, filename);
- if (len < 0 || (size_t)len >= sizeof(path))
- return -1;
-
- return open(path, flags);
- }
- return open(filename, flags);
-}
-#endif
-
-FILE *fopen_at(int dir, const char *dirname, const char *filename, int flags,
+FILE *fopen_at(int dir, const char *filename, int flags,
const char *mode)
{
- int fd = open_at(dir, dirname, filename, flags);
+ int fd = openat(dir, filename, flags);
if (fd < 0)
return NULL;
return fdopen(fd, mode);
}
-
-#ifdef HAVE_FSTATAT
-ssize_t readlink_at(int dir, const char *dirname __attribute__ ((__unused__)),
- const char *pathname, char *buf, size_t bufsiz)
-{
- return readlinkat(dir, pathname, buf, bufsiz);
-}
-#else
-ssize_t readlink_at(int dir __attribute__((__unused__)), const char *dirname,
- const char *pathname, char *buf, size_t bufsiz)
-{
- if (*pathname != '/') {
- char path[PATH_MAX];
- int len;
-
- len = snprintf(path, sizeof(path), "%s/%s", dirname, pathname);
- if (len < 0 || (size_t)len >= sizeof(path))
- return -1;
-
- return readlink(path, buf, bufsiz);
- }
- return readlink(pathname, buf, bufsiz);
-}
-#endif
-
-#ifdef TEST_PROGRAM_AT
-#include <errno.h>
-#include <sys/types.h>
-#include <dirent.h>
-#include <string.h>
-
-int main(int argc, char *argv[])
-{
- DIR *dir;
- struct dirent *d;
- char *dirname;
-
- if (argc != 2) {
- fprintf(stderr, "usage: %s <directory>\n", argv[0]);
- exit(EXIT_FAILURE);
- }
- dirname = argv[1];
-
- dir = opendir(dirname);
- if (!dir)
- err(EXIT_FAILURE, "cannot open %s", dirname);
-
- while ((d = readdir(dir))) {
- struct stat st;
- FILE *f;
-
- printf("%32s ", d->d_name);
-
- if (fstat_at(dirfd(dir), dirname, d->d_name, &st, 0) == 0)
- printf("%16zd bytes ", st.st_size);
- else
- printf("%16s bytes ", "???");
-
- f = fopen_at(dirfd(dir), dirname, d->d_name, O_RDONLY, "r");
- printf(" %s\n", f ? "OK" : strerror(errno));
- if (f)
- fclose(f);
- }
- closedir(dir);
- return EXIT_SUCCESS;
-}
-#endif
diff --git a/lib/loopdev.c b/lib/loopdev.c
index 5f3c3a246..b2c8b987b 100644
--- a/lib/loopdev.c
+++ b/lib/loopdev.c
@@ -40,7 +40,6 @@
#include "pathnames.h"
#include "loopdev.h"
#include "canonicalize.h"
-#include "at.h"
#include "blkdev.h"
#include "debug.h"
@@ -546,7 +545,7 @@ static int loopcxt_next_from_sysfs(struct loopdev_cxt *lc)
continue;
snprintf(name, sizeof(name), "%s/loop/backing_file", d->d_name);
- if (fstat_at(fd, _PATH_SYS_BLOCK, name, &st, 0) != 0)
+ if (fstatat(fd, name, &st, 0) != 0)
continue;
if (loopiter_set_device(lc, d->d_name) == 0)
diff --git a/lib/procutils.c b/lib/procutils.c
index 2e9a0537a..6f016345a 100644
--- a/lib/procutils.c
+++ b/lib/procutils.c
@@ -18,6 +18,7 @@
#include <stdlib.h>
#include <string.h>
#include <errno.h>
+#include <sys/stat.h>
#include <sys/types.h>
#include <dirent.h>
#include <ctype.h>
@@ -199,7 +200,7 @@ int proc_next_pid(struct proc_processes *ps, pid_t *pid)
if (ps->has_fltr_uid) {
struct stat st;
- if (fstat_at(dirfd(ps->dir), "/proc", d->d_name, &st, 0))
+ if (fstatat(dirfd(ps->dir), d->d_name, &st, 0))
continue;
if (ps->fltr_uid != st.st_uid)
continue;
@@ -211,8 +212,7 @@ int proc_next_pid(struct proc_processes *ps, pid_t *pid)
FILE *f;
snprintf(buf, sizeof(buf), "%s/stat", d->d_name);
- f = fopen_at(dirfd(ps->dir), "/proc", buf,
- O_CLOEXEC|O_RDONLY, "r");
+ f = fopen_at(dirfd(ps->dir), buf, O_CLOEXEC|O_RDONLY, "r");
if (!f)
continue;
diff --git a/lib/sysfs.c b/lib/sysfs.c
index b6e0b7230..9e973a4f7 100644
--- a/lib/sysfs.c
+++ b/lib/sysfs.c
@@ -6,9 +6,11 @@
*/
#include <ctype.h>
#include <libgen.h>
+#include <fcntl.h>
+#include <sys/stat.h>
+#include <unistd.h>
#include "c.h"
-#include "at.h"
#include "pathnames.h"
#include "sysfs.h"
#include "fileutils.h"
@@ -203,7 +205,7 @@ void sysfs_deinit(struct sysfs_cxt *cxt)
int sysfs_stat(struct sysfs_cxt *cxt, const char *attr, struct stat *st)
{
- int rc = fstat_at(cxt->dir_fd, cxt->dir_path, attr, st, 0);
+ int rc = fstatat(cxt->dir_fd, attr, st, 0);
if (rc != 0 && errno == ENOENT &&
strncmp(attr, "queue/", 6) == 0 && cxt->parent) {
@@ -211,8 +213,7 @@ int sysfs_stat(struct sysfs_cxt *cxt, const char *attr, struct stat *st)
/* Exception for "queue/<attr>". These attributes are available
* for parental devices only
*/
- return fstat_at(cxt->parent->dir_fd,
- cxt->parent->dir_path, attr, st, 0);
+ return fstatat(cxt->parent->dir_fd, attr, st, 0);
}
return rc;
}
@@ -226,7 +227,7 @@ int sysfs_has_attribute(struct sysfs_cxt *cxt, const char *attr)
static int sysfs_open(struct sysfs_cxt *cxt, const char *attr, int flags)
{
- int fd = open_at(cxt->dir_fd, cxt->dir_path, attr, flags);
+ int fd = openat(cxt->dir_fd, attr, flags);
if (fd == -1 && errno == ENOENT &&
strncmp(attr, "queue/", 6) == 0 && cxt->parent) {
@@ -234,7 +235,7 @@ static int sysfs_open(struct sysfs_cxt *cxt, const char *attr, int flags)
/* Exception for "queue/<attr>". These attributes are available
* for parental devices only
*/
- fd = open_at(cxt->parent->dir_fd, cxt->dir_path, attr, flags);
+ fd = openat(cxt->parent->dir_fd, attr, flags);
}
return fd;
}
@@ -246,7 +247,7 @@ ssize_t sysfs_readlink(struct sysfs_cxt *cxt, const char *attr,
return -1;
if (attr)
- return readlink_at(cxt->dir_fd, cxt->dir_path, attr, buf, bufsiz);
+ return readlinkat(cxt->dir_fd, attr, buf, bufsiz);
/* read /sys/dev/block/<maj:min> link */
return readlink(cxt->dir_path, buf, bufsiz);