Skip to content

Commit aff49e2

Browse files
committed
test: use mntent in util/opal_path_nfs
Refs #4167 Signed-off-by: Gilles Gouaillardet <gilles@rist.or.jp>
1 parent dc538e9 commit aff49e2

File tree

1 file changed

+35
-9
lines changed

1 file changed

+35
-9
lines changed

test/util/opal_path_nfs.c

+35-9
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
* Copyright (c) 2010 IBM Corporation. All rights reserved.
1717
* Copyright (c) 2014 Los Alamos National Security, LLC. All rights
1818
* reserved.
19+
* Copyright (c) 2017 Research Organization for Information Science
20+
* and Technology (RIST). All rights reserved.
1921
* $COPYRIGHT$
2022
*
2123
* Additional copyrights may follow
@@ -38,6 +40,9 @@
3840
#ifdef HAVE_SYS_VFS_H
3941
#include <sys/vfs.h>
4042
#endif
43+
#ifdef HAVE_MNTENT_H
44+
#include <mntent.h>
45+
#endif
4146

4247
#include "support.h"
4348
#include "opal/util/path.h"
@@ -134,39 +139,58 @@ void get_mounts (int * num_dirs, char ** dirs[], bool * nfs[])
134139
{
135140
#define MAX_DIR 256
136141
#define SIZE 1024
137-
char * cmd = "mount | cut -f3,5 -d' ' > opal_path_nfs.out";
138-
int rc;
139142
int i;
140143
FILE * file;
141144
char ** dirs_tmp;
142145
bool * nfs_tmp;
143-
char buffer[SIZE];
144146
struct statfs mystatfs;
147+
#ifdef HAVE_MNTENT_H
148+
struct mntent * ent;
149+
#else
150+
char * cmd = "mount | cut -f3,5 -d' ' > opal_path_nfs.out";
151+
char buffer[SIZE];
152+
int rc;
153+
#endif
154+
155+
dirs_tmp = (char**) calloc (MAX_DIR, sizeof(char*));
156+
nfs_tmp = (bool*) malloc (MAX_DIR * sizeof(bool));
145157

158+
#ifdef HAVE_MNTENT_H
159+
file = setmntent("/proc/mounts", "r");
160+
#else
146161
rc = system (cmd);
147162

148163
if (-1 == rc) {
149164
*num_dirs = 0;
150165
**dirs = NULL;
151166
*nfs = NULL;
152167
}
153-
dirs_tmp = (char**) calloc (MAX_DIR, sizeof(char**));
154-
nfs_tmp = (bool*) malloc (MAX_DIR * sizeof(bool));
155-
168+
rc = 4711;
156169
file = fopen("opal_path_nfs.out", "r");
170+
#endif
157171
i = 0;
158-
rc = 4711;
159-
while (NULL != fgets (buffer, SIZE, file)) {
172+
while (NULL !=
173+
#ifdef HAVE_MNTENT_H
174+
(ent = getmntent(file))
175+
#else
176+
fgets (buffer, SIZE, file)
177+
#endif
178+
) {
160179
int mount_known;
161-
char fs[MAXNAMLEN];
162180

181+
#ifdef HAVE_MNTENT_H
182+
char *fs = ent->mnt_type;
183+
dirs_tmp[i] = strdup(ent->mnt_dir);
184+
#else
185+
char fs[MAXNAMLEN];
163186
if (!dirs_tmp[i]) {
164187
dirs_tmp[i] = malloc (MAXNAMLEN);
165188
}
166189

167190
if (2 != (rc = sscanf (buffer, "%s %s\n", dirs_tmp[i], fs))) {
168191
goto out;
169192
}
193+
#endif
170194

171195
/*
172196
* rpc_pipefs is a FS mounted on /var/lib/nfs/rpc_pipefs for NFS4
@@ -226,7 +250,9 @@ void get_mounts (int * num_dirs, char ** dirs[], bool * nfs[])
226250
i++;
227251

228252
}
253+
#ifndef HAVE_MNTENT_H
229254
out:
255+
#endif
230256
*num_dirs = i;
231257
*dirs = dirs_tmp;
232258
*nfs = nfs_tmp;

0 commit comments

Comments
 (0)