]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
partx: add fallback for openat() to be usable on old systems
authorKarel Zak <kzak@redhat.com>
Tue, 29 Mar 2011 08:45:57 +0000 (10:45 +0200)
committerKarel Zak <kzak@redhat.com>
Tue, 29 Mar 2011 08:45:57 +0000 (10:45 +0200)
Reported-by: "Gabor Z. Papp" <gzp@papp.hu>
Signed-off-by: Karel Zak <kzak@redhat.com>
partx/Makefile.am
partx/partx.c

index 67ba7c53e17da590b5847acb3c1c175531e42990..46fc641724440f5818394536f49ee1d347be0841 100644 (file)
@@ -7,6 +7,7 @@ usrsbin_exec_PROGRAMS += partx
 partx_SOURCES = partx.c partx.h \
                $(top_srcdir)/lib/blkdev.c \
                $(top_srcdir)/lib/tt.c \
+               $(top_srcdir)/lib/at.c \
                $(top_srcdir)/lib/mbsalign.c \
                $(top_srcdir)/lib/strutils.c \
                $(top_srcdir)/lib/linux_version.c
index 62a8f872d69f34aaf47e153b5365c5b43b701ce3..f4741d86daba16ed5ee2da1dea49af67f4348e44 100644 (file)
@@ -36,6 +36,7 @@
 #include "strutils.h"
 #include "xalloc.h"
 #include "partx.h"
+#include "at.h"
 
 /* this is the default upper limit, could be modified by --nr */
 #define SLICES_MAX     256
@@ -178,7 +179,7 @@ err:
 
 static int get_max_partno(const char *disk, dev_t devno)
 {
-       char path[PATH_MAX], *parent;
+       char path[PATH_MAX], *parent, *dirname = NULL;
        struct stat st;
        DIR *dir;
        struct dirent *d;
@@ -200,7 +201,9 @@ static int get_max_partno(const char *disk, dev_t devno)
        if (!dir)
                goto dflt;
 
-        while ((d = readdir(dir))) {
+       dirname = xstrdup(path);
+
+       while ((d = readdir(dir))) {
                int fd;
 
                if (!strcmp(d->d_name, ".") ||
@@ -214,7 +217,7 @@ static int get_max_partno(const char *disk, dev_t devno)
                        continue;
                snprintf(path, sizeof(path), "%s/partition", d->d_name);
 
-               fd = openat(dirfd(dir), path, O_RDONLY);
+               fd = open_at(dirfd(dir), dirname, path, O_RDONLY);
                if (fd) {
                        int x = 0;
                        FILE *f = fdopen(fd, "r");
@@ -226,6 +229,7 @@ static int get_max_partno(const char *disk, dev_t devno)
                }
        }
 
+       free(dirname);
        closedir(dir);
        return partno;
 dflt: