diff options
-rw-r--r-- | config.h.in | 3 | ||||
-rw-r--r-- | configure.in | 6 | ||||
-rw-r--r-- | lib/fs.c | 47 | ||||
-rw-r--r-- | misc/getmntent.c | 2 | ||||
-rw-r--r-- | misc/miscfn.h | 5 |
5 files changed, 46 insertions, 17 deletions
diff --git a/config.h.in b/config.h.in index 270266801..07b32bf5c 100644 --- a/config.h.in +++ b/config.h.in @@ -93,4 +93,7 @@ /* Define as one if you have "struct mnttab" (only sco?) */ #define HAVE_STRUCT_MNTTAB 0 +/* Define as one if you have getmntinfo_r() (only osf?) */ +#define HAVE_GETMNTINFO_R 0 + #endif diff --git a/configure.in b/configure.in index 6393251a5..2a92e2e92 100644 --- a/configure.in +++ b/configure.in @@ -277,8 +277,10 @@ fi dnl Checks for library functions. AC_CHECK_FUNC(inet_aton, AC_DEFINE(HAVE_INET_ATON), MISCOBJS="$MISCOBJS inet_aton.o") AC_CHECK_FUNC(realpath, AC_DEFINE(HAVE_REALPATH), MISCOBJS="$MISCOBJS realpath.o") -AC_CHECK_FUNC(getmntent, AC_DEFINE(HAVE_GETMNTENT), MISCOBJS="$MISCOBJS getmntent.o") -AC_CHECK_FUNC(mntctl, AC_DEFINE(HAVE_MNTCTL)) +AC_CHECK_FUNC(getmntent, AC_DEFINE(HAVE_GETMNTENT), [ + AC_CHECK_FUNC(mntctl, AC_DEFINE(HAVE_MNTCTL),[ + AC_CHECK_FUNC(getmntinfo_r, AC_DEFINE(HAVE_GETMNTINFO_R), + MISCOBJS="$MISCOBJS getmntent.o") ])]) AC_CHECK_FUNC(strerror, [], MISCOBJS="$MISCOBJS strerror.o") AC_CHECK_FUNC(strtol, [], MISCOBJS="$MISCOBJS strtol.o") AC_CHECK_FUNC(strtoul, [], MISCOBJS="$MISCOBJS strtoul.o") @@ -108,19 +108,30 @@ static int getFilesystemList(void) { } #else static int getFilesystemList(void) { - our_mntent item, * itemptr; - FILE * mtab; int numAlloced = 10; int num = 0; struct stat sb; int i; - - mtab = fopen(MOUNTED, "r"); - if (!mtab) { - rpmError(RPMERR_MTAB, _("failed to open %s: %s"), MOUNTED, - strerror(errno)); - return 1; - } + char * mntdir; + #if GETMNTENT_ONE || GETMNTENT_TWO + our_mntent item, * itemptr; + FILE * mtab; + #elif HAVE_GETMNTINFO_R + struct statfs * mounts = NULL; + int mntCount = 0, bufSize = 0, flags = MNT_NOWAIT; + int nextMount = 0; + #endif + + #if GETMNTENT_ONE || GETMNTENT_TWO + mtab = fopen(MOUNTED, "r"); + if (!mtab) { + rpmError(RPMERR_MTAB, _("failed to open %s: %s"), MOUNTED, + strerror(errno)); + return 1; + } + #elif HAVE_GETMNTINFO_R + getmntinfo_r(&mounts, flags, &mntCount, &bufSize); + #endif filesystems = malloc(sizeof(*filesystems) * (numAlloced + 1)); @@ -130,13 +141,18 @@ static int getFilesystemList(void) { itemptr = getmntent(mtab); if (!itemptr) break; item = *itemptr; + mntdir = item.our_mntdir; #elif GETMNTENT_TWO /* Solaris, maybe others */ if (getmntent(mtab, &item)) break; + mntdir = item.our_mntdir; + #elif HAVE_GETMNTINFO_R + if (nextMount == mntCount) break; + mntdir = mounts[nextMount++].f_mntonname; #endif - if (stat(item.our_mntdir, &sb)) { - rpmError(RPMERR_STAT, "failed to stat %s: %s", item.our_mntdir, + if (stat(mntdir, &sb)) { + rpmError(RPMERR_STAT, "failed to stat %s: %s", mntdir, strerror(errno)); for (i = 0; i < num; i++) @@ -153,10 +169,15 @@ static int getFilesystemList(void) { } filesystems[num].dev = sb.st_dev; - filesystems[num++].mntPoint = strdup(item.our_mntdir); + filesystems[num++].mntPoint = strdup(mntdir); } - fclose(mtab); + #if GETMNTENT_ONE || GETMNTENT_TWO + fclose(mtab); + #elif HAVE_GETMNTINFO_R + free(mounts); + #endif + filesystems[num].mntPoint = NULL; fsnames = malloc(sizeof(*fsnames) * (num + 1)); diff --git a/misc/getmntent.c b/misc/getmntent.c index ebce8ab34..d2455a266 100644 --- a/misc/getmntent.c +++ b/misc/getmntent.c @@ -11,7 +11,7 @@ #define COMMENTCHAR '#' #endif -#if HAVE_STRUCT_MNTTAB { +#if HAVE_STRUCT_MNTTAB our_mntent * getmntent(FILE *filep) { static struct mnttab entry; static our_mntent item = { entry.mt_filsys }; diff --git a/misc/miscfn.h b/misc/miscfn.h index 0ca0ef397..80a519480 100644 --- a/misc/miscfn.h +++ b/misc/miscfn.h @@ -62,7 +62,10 @@ extern void *myrealloc(void *, size_t); #define lchown chown #endif -#if HAVE_MNTENT_H || !(HAVE_GETMNTENT) || HAVE_STRUCT_MNTTAB +#if HAVE_GETMNTINFO_R || HAVE_MNTCTL +# define GETMNTENT_ONE 0 +# define GETMNTENT_TWO 0 +#elif HAVE_MNTENT_H || !(HAVE_GETMNTENT) || HAVE_STRUCT_MNTTAB # if HAVE_MNTENT_H || HAVE_STRUCT_MNTTAB # include <mntent.h> # define our_mntent struct mntent |