summaryrefslogtreecommitdiffstats
path: root/partx/partx.c
diff options
context:
space:
mode:
authorKarel Zak2011-03-29 10:45:57 +0200
committerKarel Zak2011-03-29 10:45:57 +0200
commit741a5b1085c6e47c8076b9960fa59cd5dd204b96 (patch)
treed84b52cb38c137aee1b8ac1426e39d096b0ff411 /partx/partx.c
parentinclude: [c.h] add definition wrappers for old libc versions (diff)
downloadkernel-qcow2-util-linux-741a5b1085c6e47c8076b9960fa59cd5dd204b96.tar.gz
kernel-qcow2-util-linux-741a5b1085c6e47c8076b9960fa59cd5dd204b96.tar.xz
kernel-qcow2-util-linux-741a5b1085c6e47c8076b9960fa59cd5dd204b96.zip
partx: add fallback for openat() to be usable on old systems
Reported-by: "Gabor Z. Papp" <gzp@papp.hu> Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'partx/partx.c')
-rw-r--r--partx/partx.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/partx/partx.c b/partx/partx.c
index 62a8f872d..f4741d86d 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: