|
16 | 16 | * Copyright (c) 2010 IBM Corporation. All rights reserved.
|
17 | 17 | * Copyright (c) 2014 Los Alamos National Security, LLC. All rights
|
18 | 18 | * reserved.
|
| 19 | + * Copyright (c) 2017 Research Organization for Information Science |
| 20 | + * and Technology (RIST). All rights reserved. |
19 | 21 | * $COPYRIGHT$
|
20 | 22 | *
|
21 | 23 | * Additional copyrights may follow
|
|
38 | 40 | #ifdef HAVE_SYS_VFS_H
|
39 | 41 | #include <sys/vfs.h>
|
40 | 42 | #endif
|
| 43 | +#ifdef HAVE_MNTENT_H |
| 44 | +#include <mntent.h> |
| 45 | +#endif |
41 | 46 |
|
42 | 47 | #include "support.h"
|
43 | 48 | #include "opal/util/path.h"
|
@@ -134,39 +139,58 @@ void get_mounts (int * num_dirs, char ** dirs[], bool * nfs[])
|
134 | 139 | {
|
135 | 140 | #define MAX_DIR 256
|
136 | 141 | #define SIZE 1024
|
137 |
| - char * cmd = "mount | cut -f3,5 -d' ' > opal_path_nfs.out"; |
138 |
| - int rc; |
139 | 142 | int i;
|
140 | 143 | FILE * file;
|
141 | 144 | char ** dirs_tmp;
|
142 | 145 | bool * nfs_tmp;
|
143 |
| - char buffer[SIZE]; |
144 | 146 | 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)); |
145 | 157 |
|
| 158 | +#ifdef HAVE_MNTENT_H |
| 159 | + file = setmntent("/proc/mounts", "r"); |
| 160 | +#else |
146 | 161 | rc = system (cmd);
|
147 | 162 |
|
148 | 163 | if (-1 == rc) {
|
149 | 164 | *num_dirs = 0;
|
150 | 165 | **dirs = NULL;
|
151 | 166 | *nfs = NULL;
|
152 | 167 | }
|
153 |
| - dirs_tmp = (char**) calloc (MAX_DIR, sizeof(char**)); |
154 |
| - nfs_tmp = (bool*) malloc (MAX_DIR * sizeof(bool)); |
155 |
| - |
| 168 | + rc = 4711; |
156 | 169 | file = fopen("opal_path_nfs.out", "r");
|
| 170 | +#endif |
157 | 171 | 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 | + ) { |
160 | 179 | int mount_known;
|
161 |
| - char fs[MAXNAMLEN]; |
162 | 180 |
|
| 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]; |
163 | 186 | if (!dirs_tmp[i]) {
|
164 | 187 | dirs_tmp[i] = malloc (MAXNAMLEN);
|
165 | 188 | }
|
166 | 189 |
|
167 | 190 | if (2 != (rc = sscanf (buffer, "%s %s\n", dirs_tmp[i], fs))) {
|
168 | 191 | goto out;
|
169 | 192 | }
|
| 193 | +#endif |
170 | 194 |
|
171 | 195 | /*
|
172 | 196 | * 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[])
|
226 | 250 | i++;
|
227 | 251 |
|
228 | 252 | }
|
| 253 | +#ifndef HAVE_MNTENT_H |
229 | 254 | out:
|
| 255 | +#endif |
230 | 256 | *num_dirs = i;
|
231 | 257 | *dirs = dirs_tmp;
|
232 | 258 | *nfs = nfs_tmp;
|
|
0 commit comments