diff options
author | goodale <goodale@17b73243-c579-4c4c-a9d2-2d5706c11dac> | 2005-10-03 14:52:19 +0000 |
---|---|---|
committer | goodale <goodale@17b73243-c579-4c4c-a9d2-2d5706c11dac> | 2005-10-03 14:52:19 +0000 |
commit | 552823c907827feb4176a31bbde87b4ab9e7e2c6 (patch) | |
tree | 01744dbfb6be3a0015d0cebaa275be4866b661ae /src | |
parent | 564462e4f7658a5d82487511ffaaa41bfb9f16b6 (diff) |
Do sanity checking on parameter file name and give a reason why it
can't be opened if at all possible.
Fixes PR 1864.
git-svn-id: http://svn.cactuscode.org/flesh/trunk@4159 17b73243-c579-4c4c-a9d2-2d5706c11dac
Diffstat (limited to 'src')
-rw-r--r-- | src/main/ProcessParameterDatabase.c | 72 |
1 files changed, 70 insertions, 2 deletions
diff --git a/src/main/ProcessParameterDatabase.c b/src/main/ProcessParameterDatabase.c index 0f57cc1f..b4e82ea5 100644 --- a/src/main/ProcessParameterDatabase.c +++ b/src/main/ProcessParameterDatabase.c @@ -8,8 +8,11 @@ @version $Id$ @@*/ +#include <errno.h> #include <stdio.h> #include <string.h> +#include <sys/types.h> +#include <sys/stat.h> #include "cctk_Flesh.h" #include "cctk_Parameter.h" @@ -22,6 +25,15 @@ static const char *rcsid = "$Header$"; CCTK_FILEVERSION(main_ProcessParameterDatabase_c); /******************************************************************** + ********************* Macro Definitions ************************** + ********************************************************************/ + +/* some systems (eg. Windows NT) don't define this macro */ +#ifndef S_ISDIR +#define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR) +#endif + +/******************************************************************** ********************* Other Routine Prototypes ********************* ********************************************************************/ int ParseFile (FILE *ifp, @@ -62,6 +74,7 @@ int CCTKi_ProcessParameterDatabase (tFleshConfig *ConfigData) int parse_errors; int major, minor; FILE *parameter_file; + struct stat statbuf; CCTKi_SetParameterSetMask (PARAMETER_RECOVERY_PRE); @@ -70,11 +83,66 @@ int CCTKi_ProcessParameterDatabase (tFleshConfig *ConfigData) { parameter_file = stdin; } - else + else if (!stat(ConfigData->parameter_file_name, &statbuf)) { - parameter_file = fopen (ConfigData->parameter_file_name, "r"); + if(S_ISDIR(statbuf.st_mode)) + { + parameter_file = NULL; + CCTK_VWarn (0, __LINE__, __FILE__, "Cactus", + "Cannot open parameter file '%s': it is a directory", + ConfigData->parameter_file_name); + } + else + { + parameter_file = fopen (ConfigData->parameter_file_name, "r"); + } } + else + { + /* Stat failed */ + parameter_file = NULL; + switch(errno) + { + case ENOENT: + CCTK_VWarn (0, __LINE__, __FILE__, "Cactus", + "Cannot open parameter file '%s': file doesn't exist", + ConfigData->parameter_file_name); + break; + case ENOTDIR: + CCTK_VWarn (0, __LINE__, __FILE__, "Cactus", + "Cannot open parameter file '%s': the path is invalid", + ConfigData->parameter_file_name); + break; +#ifdef ELOOP + case ELOOP: + CCTK_VWarn (0, __LINE__, __FILE__, "Cactus", + "Cannot open parameter file '%s': too many symbolic links", + ConfigData->parameter_file_name); + break; +#endif /* ELOOP */ + case EACCES: + CCTK_VWarn (0, __LINE__, __FILE__, "Cactus", + "Cannot open parameter file '%s': permission denied", + ConfigData->parameter_file_name); + break; + case ENAMETOOLONG: + CCTK_VWarn (0, __LINE__, __FILE__, "Cactus", + "Cannot open parameter file '%s': filename too long", + ConfigData->parameter_file_name); + break; + case ENOMEM: + CCTK_VWarn (0, __LINE__, __FILE__, "Cactus", + "Cannot open parameter file '%s': out of system memory", + ConfigData->parameter_file_name); + break; + default: + CCTK_VWarn (0, __LINE__, __FILE__, "Cactus", + "Cannot open parameter file '%s'", + ConfigData->parameter_file_name); + } + } + if (parameter_file == NULL) { CCTK_VWarn (0, __LINE__, __FILE__, "Cactus", |