12
12
* All rights reserved.
13
13
* Copyright (c) 2010 Oak Ridge National Laboratory.
14
14
* All rights reserved.
15
- * Copyright (c) 2010-2014 Cisco Systems, Inc. All rights reserved.
15
+ * Copyright (c) 2010-2017 Cisco Systems, Inc. All rights reserved
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.
@@ -132,7 +132,6 @@ void test(char* file, bool expect)
132
132
133
133
void get_mounts (int * num_dirs , char * * dirs [], bool * nfs [])
134
134
{
135
- #define MAX_DIR 256
136
135
#define SIZE 1024
137
136
char * cmd = "mount | cut -f3,5 -d' ' > opal_path_nfs.out" ;
138
137
int rc ;
@@ -150,13 +149,31 @@ void get_mounts (int * num_dirs, char ** dirs[], bool * nfs[])
150
149
* * dirs = NULL ;
151
150
* nfs = NULL ;
152
151
}
153
- dirs_tmp = (char * * ) calloc (MAX_DIR , sizeof (char * * ));
154
- nfs_tmp = (bool * ) malloc (MAX_DIR * sizeof (bool ));
155
152
153
+ /* First, count how many mount points there are. Previous
154
+ versions of this test tried to have a (large) constant-sized
155
+ array for the mount points, but periodically it would break
156
+ because we would run this test on a system with a larger number
157
+ of mount points than the array. So just count and make sure to
158
+ have an array large enough. */
156
159
file = fopen ("opal_path_nfs.out" , "r" );
160
+ int count = 0 ;
161
+ while (NULL != fgets (buffer , SIZE , file )) {
162
+ ++ count ;
163
+ }
164
+ printf ("Found %d mounts\n" , count );
165
+
166
+ // Add one more so we can have a NULL entry at the end
167
+ ++ count ;
168
+
169
+ dirs_tmp = (char * * ) calloc (count , sizeof (char * ));
170
+ nfs_tmp = (bool * ) calloc (count , sizeof (bool ));
171
+
157
172
i = 0 ;
158
173
rc = 4711 ;
159
- while (NULL != fgets (buffer , SIZE , file )) {
174
+ rewind (file );
175
+ // i should never be more than count, but be safe anyway.
176
+ while (i < count && NULL != fgets (buffer , SIZE , file )) {
160
177
int mount_known ;
161
178
char fs [MAXNAMLEN ];
162
179
0 commit comments