Commit a30a4721 authored by Rob Latham's avatar Rob Latham
Browse files

use PATH_MAX instead of magic number



User on OpenMPI list wanted to create a 259 character file.  shared file
pointer name construction used the magic '256' value to construct a full
path to the hidden shared file pointer file.  PATH_MAX already exists
for this purpose, so use it.

While there, found a few spots checking/setting PATH_MAX, so do that in
one place

Closes #2212
Signed-off-by: Kenneth Raffenetti's avatarKen Raffenetti <raffenet@mcs.anl.gov>
parent ed39c901
......@@ -137,10 +137,6 @@ Output Parameters:
*/
#ifdef ROMIO_NEEDS_ADIOPARENTDIR
#ifndef PATH_MAX
#define PATH_MAX 65535
#endif
/* In a strict ANSI environment, S_ISLNK may not be defined. Fix that
here. We assume that S_ISLNK is *always* defined as a macro. If
that is not universally true, then add a test to the romio
......
......@@ -21,8 +21,11 @@
store the shared file pointer. The shared-file-pointer file is a
hidden file in the same directory as the real file being accessed.
If the real file is /tmp/thakur/testfile, the shared-file-pointer
file will be /tmp/thakur/.testfile.shfp.xxxx, where xxxx is
a random number. This file is created only if the shared
file will be /tmp/thakur/.testfile.shfp.yyy.xxxx, where yyy
is rank 0's process id and xxxx is a random number. If the
underlying file system supports shared file pointers
(PVFS does not, for example), the file name is always
constructed. This file is created only if the shared
file pointer functions are used and is deleted when the real
file is closed. */
......@@ -33,14 +36,14 @@ void ADIOI_Shfp_fname(ADIO_File fd, int rank, int *error_code)
char *slash, *ptr, tmp[128];
int pid = 0;
fd->shared_fp_fname = (char *) ADIOI_Malloc(256);
fd->shared_fp_fname = (char *) ADIOI_Malloc(PATH_MAX);
if (!rank) {
srand(time(NULL));
i = rand();
pid = (int)getpid();
if (ADIOI_Strncpy(fd->shared_fp_fname, fd->filename, 256)) {
if (ADIOI_Strncpy(fd->shared_fp_fname, fd->filename, PATH_MAX)) {
*error_code = ADIOI_Err_create_code("ADIOI_Shfp_fname",
fd->filename, ENAMETOOLONG);
return;
......@@ -57,7 +60,7 @@ void ADIOI_Shfp_fname(ADIO_File fd, int rank, int *error_code)
fd->filename, ENAMETOOLONG);
return;
}
if (ADIOI_Strncpy(fd->shared_fp_fname + 1, fd->filename, 255)) {
if (ADIOI_Strncpy(fd->shared_fp_fname + 1, fd->filename, PATH_MAX-1)) {
*error_code = ADIOI_Err_create_code("ADIOI_Shfp_fname",
fd->filename, ENAMETOOLONG);
return;
......@@ -76,7 +79,7 @@ void ADIOI_Shfp_fname(ADIO_File fd, int rank, int *error_code)
return;
}
/* ok to cast: file names bounded by PATH_MAX and NAME_MAX */
len = (int) (256 - (slash+2 - fd->shared_fp_fname));
len = (int) (PATH_MAX - (slash+2 - fd->shared_fp_fname));
if (ADIOI_Strncpy(slash + 2, ptr + 1, len)) {
*error_code = ADIOI_Err_create_code("ADIOI_Shfp_fname",
ptr + 1, ENAMETOOLONG);
......@@ -86,7 +89,7 @@ void ADIOI_Shfp_fname(ADIO_File fd, int rank, int *error_code)
ADIOI_Snprintf(tmp, 128, ".shfp.%d.%d", pid, i);
/* ADIOI_Strnapp will return non-zero if truncated. That's ok */
ADIOI_Strnapp(fd->shared_fp_fname, tmp, 256);
ADIOI_Strnapp(fd->shared_fp_fname, tmp, PATH_MAX);
len = (int)strlen(fd->shared_fp_fname);
MPI_Bcast(&len, 1, MPI_INT, 0, fd->comm);
......
......@@ -28,10 +28,6 @@
#include <io.h>
#endif
#ifndef PATH_MAX
#define PATH_MAX 65535
#endif
/*#define SYSHINT_DEBUG 1 */
#define ROMIO_HINT_DEFAULT_CFG "/etc/romio-hints"
......
......@@ -1034,7 +1034,13 @@ typedef struct wcThreadFuncData {
void *ADIOI_IO_Thread_Func(void *vptr_args);
#ifdef HAVE_LIMITS_H
#include <limits.h>
#endif
#ifndef PATH_MAX
#define PATH_MAX 65535
#endif
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment