From: Karel Zak Date: Tue, 29 Mar 2011 08:45:57 +0000 (+0200) Subject: partx: add fallback for openat() to be usable on old systems X-Git-Tag: v2.20-rc1~422 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=741a5b1085c6e47c8076b9960fa59cd5dd204b96;p=thirdparty%2Futil-linux.git partx: add fallback for openat() to be usable on old systems Reported-by: "Gabor Z. Papp" Signed-off-by: Karel Zak --- diff --git a/partx/Makefile.am b/partx/Makefile.am index 67ba7c53e1..46fc641724 100644 --- a/partx/Makefile.am +++ b/partx/Makefile.am @@ -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 diff --git a/partx/partx.c b/partx/partx.c index 62a8f872d6..f4741d86da 100644 --- a/partx/partx.c +++ b/partx/partx.c @@ -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: