Skip to content

test: use mntent in util/opal_path_nfs #4177

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 35 additions & 9 deletions test/util/opal_path_nfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
* Copyright (c) 2010 IBM Corporation. All rights reserved.
* Copyright (c) 2014 Los Alamos National Security, LLC. All rights
* reserved.
* Copyright (c) 2017 Research Organization for Information Science
* and Technology (RIST). All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
Expand All @@ -38,6 +40,9 @@
#ifdef HAVE_SYS_VFS_H
#include <sys/vfs.h>
#endif
#ifdef HAVE_MNTENT_H
#include <mntent.h>
#endif

#include "support.h"
#include "opal/util/path.h"
Expand Down Expand Up @@ -134,39 +139,58 @@ void get_mounts (int * num_dirs, char ** dirs[], bool * nfs[])
{
#define MAX_DIR 256
#define SIZE 1024
char * cmd = "mount | cut -f3,5 -d' ' > opal_path_nfs.out";
int rc;
int i;
FILE * file;
char ** dirs_tmp;
bool * nfs_tmp;
char buffer[SIZE];
struct statfs mystatfs;
#ifdef HAVE_MNTENT_H
struct mntent * ent;
#else
char * cmd = "mount | cut -f3,5 -d' ' > opal_path_nfs.out";
char buffer[SIZE];
int rc;
#endif

dirs_tmp = (char**) calloc (MAX_DIR, sizeof(char*));
nfs_tmp = (bool*) malloc (MAX_DIR * sizeof(bool));

#ifdef HAVE_MNTENT_H
file = setmntent("/proc/mounts", "r");
#else
rc = system (cmd);

if (-1 == rc) {
*num_dirs = 0;
**dirs = NULL;
*nfs = NULL;
}
dirs_tmp = (char**) calloc (MAX_DIR, sizeof(char**));
nfs_tmp = (bool*) malloc (MAX_DIR * sizeof(bool));

rc = 4711;
file = fopen("opal_path_nfs.out", "r");
#endif
i = 0;
rc = 4711;
while (NULL != fgets (buffer, SIZE, file)) {
while (NULL !=
#ifdef HAVE_MNTENT_H
(ent = getmntent(file))
#else
fgets (buffer, SIZE, file)
#endif
) {
int mount_known;
char fs[MAXNAMLEN];

#ifdef HAVE_MNTENT_H
char *fs = ent->mnt_type;
dirs_tmp[i] = strdup(ent->mnt_dir);
#else
char fs[MAXNAMLEN];
if (!dirs_tmp[i]) {
dirs_tmp[i] = malloc (MAXNAMLEN);
}

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

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

}
#ifndef HAVE_MNTENT_H
out:
#endif
*num_dirs = i;
*dirs = dirs_tmp;
*nfs = nfs_tmp;
Expand Down