Changeset 6754
- Timestamp:
- Mar 31, 2006, 5:00:23 PM (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/rel10_ifa/psModules/src/config/pmConfig.c
r6734 r6754 3 3 * @author PAP, IfA 4 4 * 5 * @version $Revision: 1.7.4. 7$ $Name: not supported by cvs2svn $6 * @date $Date: 2006-0 3-30 20:08:30$5 * @version $Revision: 1.7.4.8 $ $Name: not supported by cvs2svn $ 6 * @date $Date: 2006-04-01 03:00:23 $ 7 7 * 8 8 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 13 13 #include <unistd.h> 14 14 #include <assert.h> 15 #include <sys/types.h> 16 #include <sys/stat.h> 15 17 #include "pslib.h" 16 18 #include "pmConfig.h" 17 19 18 #define PS_SITE "PS_SITE" // Name of the environment variable containing the site config file 19 #define PS_DEFAULT_SITE "ipprc.config" // Default site config file 20 #define PS_SITE "PS_SITE" // Name of the environment variable containing the site config file 21 #define PS_DEFAULT_SITE ".ipprc" // Default site config file 22 23 static psArray *configPath = NULL; 20 24 21 25 static void configFree(pmConfig *config) … … 57 61 const char *description) // Description of file 58 62 { 63 char *realName = NULL; 59 64 unsigned int numBadLines = 0; 65 struct stat filestat; 60 66 61 67 psLogMsg(__func__, PS_LOG_INFO, "Loading %s configuration from file %s\n", 62 68 description, name); 63 *config = psMetadataConfigParse(NULL, &numBadLines, name, true); 69 70 uid_t uid = getuid(); 71 gid_t gid = getgid(); 72 73 // we try: name, path[0]/name, path[1]/name, ... 74 // find the first existing entry in the path (starting with the bare name) 75 realName = psStringCopy (name); 76 psTrace (__func__, 5, "trying %s\n", realName); 77 78 int status = stat (realName, &filestat); 79 if (status == 0) { 80 if ((uid == filestat.st_uid) && (filestat.st_mode & S_IRUSR)) 81 goto found; 82 if ((gid == filestat.st_gid) && (filestat.st_mode & S_IRGRP)) 83 goto found; 84 if (filestat.st_mode & S_IROTH) 85 goto found; 86 } 87 psFree (realName); 88 89 if (configPath == NULL) { 90 psError(PS_ERR_IO, false, "Cannot find %s configuration file in path\n", description); 91 return false; 92 } 93 94 for (int i = 0; i < configPath->n; i++) { 95 realName = psStringCopy (configPath->data[i]); 96 psStringAppend (&realName, "/%s", name); 97 psTrace (__func__, 5, "trying %s\n", realName); 98 99 status = stat (realName, &filestat); 100 if (status == 0) { 101 if ((uid == filestat.st_uid) && (filestat.st_mode & S_IRUSR)) 102 goto found; 103 if ((gid == filestat.st_gid) && (filestat.st_mode & S_IRGRP)) 104 goto found; 105 if (filestat.st_mode & S_IROTH) 106 goto found; 107 } 108 psFree (realName); 109 } 110 111 psError(PS_ERR_IO, false, "Cannot find %s configuration file in path\n", description); 112 return false; 113 114 found: 115 *config = psMetadataConfigParse(NULL, &numBadLines, realName, true); 64 116 if (numBadLines > 0) { 65 117 psLogMsg(__func__, PS_LOG_WARN, "%d bad lines in %s configuration file (%s)\n", 66 description, name);118 description, realName); 67 119 } 68 120 if (!*config) { 69 121 psError(PS_ERR_IO, false, "Unable to read %s configuration from %s\n", 70 description, name); 122 description, realName); 123 psFree (realName); 71 124 return false; 72 125 } 73 126 127 psFree (realName); 74 128 return true; 75 129 } … … 115 169 "-site command-line switch provided without the required filename --- ignored.\n"); 116 170 } else { 117 siteName = argv[argNum];171 siteName = psStringCopy(argv[argNum]); 118 172 psArgumentRemove(argNum, argc, argv); 119 173 } … … 124 178 if (!siteName) { 125 179 siteName = getenv(PS_SITE); 180 if (siteName) { 181 siteName = psStringCopy (siteName); 182 } 126 183 } 127 184 … … 129 186 // Last chance is ~/.ipprc 130 187 // 131 bool cleanupSiteName = false; // Do I have to psFree siteName?132 188 if (!siteName) { 133 siteName = psStringCopy(PS_DEFAULT_SITE); 134 cleanupSiteName = true; 135 } 136 137 // 138 // We have the connfiguration filename; now we read and parse the config 189 char *home = getenv("HOME"); 190 siteName = psStringCopy(home); 191 psStringAppend(&siteName, "/%s", PS_DEFAULT_SITE); 192 } 193 194 195 // We have the configuration filename; now we read and parse the config 139 196 // file and store in psMetadata struct site. 140 197 // … … 144 201 return NULL; 145 202 } 146 if (cleanupSiteName) { 147 psFree(siteName); 148 } 149 150 151 // 203 psFree(siteName); 204 205 // define the config-file search path (configPath) 206 if (configPath) { 207 psFree (configPath); 208 configPath = NULL; 209 } 210 char *path = psMetadataLookupStr(NULL, config->site, "PATH"); 211 if (path) { 212 psList *list = psStringSplit(path, ":"); 213 configPath = psListToArray(list); 214 psFree (list); 215 } 216 152 217 // Next, we do a similar thing for the camera configuration file. The 153 218 // file is read and parsed into psMetadata struct "camera". … … 350 415 ) 351 416 { 417 psMetadata *testFormat; 418 352 419 assert(format); 353 420 assert(camera); … … 374 441 } 375 442 psTrace(__func__, 5, "Reading camera format for %s...\n", formatsItem->name); 376 unsigned int badLines = 0; // Number of bad lines in reading camera configuration443 // unsigned int badLines = 0; // Number of bad lines in reading camera configuration 377 444 // Format to test against what we've got 378 psMetadata *testFormat = psMetadataConfigParse(NULL, &badLines, formatsItem->data.V, true); 445 446 if (!readConfig(&testFormat, formatsItem->data.V, formatsItem->name)) { 447 psLogMsg(__func__, PS_LOG_WARN, "trouble reading reading camera format %s\n", formatsItem->name); 448 psFree(testFormat); 449 continue; 450 } 451 452 # if (0) 453 psMetadata *testFormat = psMetadataConfigParse(NULL, &badLines, formatsItem->data.V, true); 379 454 if (badLines > 0) { 380 455 psLogMsg(__func__, PS_LOG_WARN, "%d bad lines encountered while reading camera" 381 456 "format %s\n", badLines, formatsItem->name); 382 457 } 458 # endif 459 383 460 if (pmConfigValidateCameraFormat(testFormat, header)) { 384 461 if (!*format) { … … 408 485 psMetadata *format = NULL; // The winning format 409 486 bool mdok = false; // Metadata lookup status 487 psMetadata *testCamera = NULL; 410 488 411 489 // If we don't know what sort of camera we have, we try all that we know … … 430 508 431 509 psTrace(__func__, 5, "Reading camera configuration for %s...\n", camerasItem->name); 432 unsigned int badLines = 0; // Number of bad lines in reading camera configuration510 // unsigned int badLines = 0; // Number of bad lines in reading camera configuration 433 511 // Camera to test against what we've got: 434 psMetadata *testCamera = psMetadataConfigParse(NULL, &badLines, camerasItem->data.V, true); 512 513 if (!readConfig(&testCamera, camerasItem->data.V, camerasItem->name)) { 514 psLogMsg(__func__, PS_LOG_WARN, "trouble reading reading camera configuration %s\n", camerasItem->name); 515 psFree(testCamera); 516 continue; 517 } 518 519 # if (0) 520 psMetadata *testCamera = psMetadataConfigParse(NULL, &badLines, camerasItem->data.V, true); 435 521 if (badLines > 0) { 436 522 psLogMsg(__func__, PS_LOG_WARN, "%d bad lines encountered while reading camera" 437 523 "configuration %s\n", badLines, camerasItem->name); 438 524 } 525 # endif 526 439 527 if (! testCamera) { 440 528 psLogMsg(__func__, PS_LOG_WARN, "Unable to interpret camera configuration for %s (%s) --- "
Note:
See TracChangeset
for help on using the changeset viewer.
