Changeset 16611 for trunk/psModules/src/config/pmConfig.c
- Timestamp:
- Feb 22, 2008, 10:21:52 AM (18 years ago)
- File:
-
- 1 edited
-
trunk/psModules/src/config/pmConfig.c (modified) (33 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/src/config/pmConfig.c
r16415 r16611 34 34 #endif // ifdef HAVE_NEBCLIENT 35 35 36 #define PS_SITE "PS_SITE" // Name of the environment variable containing the siteconfig file37 #define PS_DEFAULT_SITE ".ipprc" // Default siteconfig file36 #define IPPRC_ENV "IPPRC" // Name of the environment variable containing the top-level config file 37 #define IPPRC_FILE ".ipprc" // Default top-level config file 38 38 39 39 #define DEFAULT_LOG STDERR_FILENO // Default file descriptor for log messages … … 52 52 static void configFree(pmConfig *config) 53 53 { 54 psFree(config->user); 54 55 psFree(config->site); 56 psFree(config->system); 57 psFree(config->complete); 55 58 psFree(config->files); 56 59 psFree(config->camera); … … 80 83 81 84 // Initialise 85 config->user = NULL; 82 86 config->site = NULL; 87 config->system = NULL; 88 config->complete = NULL; 83 89 config->camera = NULL; 84 90 config->cameraName = NULL; … … 145 151 PS_ASSERT_STRING_NON_EMPTY(path,); 146 152 147 pmConfigDone(); 153 assert (configPath == NULL); 154 // XXX why was this being called? pmConfigSet should only be called once... 155 // pmConfigDone(); 148 156 149 157 psList *list = psStringSplit(path, ":", false); … … 159 167 void pmConfigDone(void) 160 168 { 161 psFree(configPath); 169 if (configPath) { 170 psFree(configPath); 171 } 162 172 configPath = NULL; 163 173 … … 380 390 config->defaultRecipe = defaultRecipe; 381 391 382 // 383 // The following section of code attempts to determine which file is 384 // the configuration file. At the end of this code block, the siteName 392 // The following section of code attempts to determine which file to use as the 393 // top-level the configuration file. At the end of this code block, the configFile 385 394 // variable will contain the name of the configuration file. 386 // 387 char * siteName = NULL;395 396 char *configFile = NULL; 388 397 // 389 398 // First, try command line 390 399 // 391 psS32 argNum = psArgumentGet(*argc, argv, "- site");400 psS32 argNum = psArgumentGet(*argc, argv, "-ipprc"); 392 401 if (argNum != 0) { 393 // 394 // We remove the "-site" argument from argv. Then 395 // we look for the next argument, which should be the filename, and 396 // remove it as well. 397 // 402 // remove the "-ipprc" argument from argv, check and remove filename 398 403 psArgumentRemove(argNum, argc, argv); 399 404 if (argNum >= *argc) { 400 psWarning("- sitecommand-line switch provided without the required filename --- ignored.\n");405 psWarning("-ipprc command-line switch provided without the required filename --- ignored.\n"); 401 406 } else { 402 siteName = psStringCopy(argv[argNum]);407 configFile = psStringCopy(argv[argNum]); 403 408 psArgumentRemove(argNum, argc, argv); 404 409 } … … 407 412 // Next, try environment variable 408 413 // 409 if (! siteName) {410 siteName = getenv(PS_SITE);411 if ( siteName) {412 siteName = psStringCopy (siteName);414 if (!configFile) { 415 configFile = getenv(IPPRC_ENV); 416 if (configFile) { 417 configFile = psStringCopy (configFile); 413 418 } 414 419 } … … 417 422 // Last chance is ~/.ipprc 418 423 // 419 if (! siteName) {424 if (!configFile) { 420 425 char *home = getenv("HOME"); 421 siteName = psStringCopy(home); 422 psStringAppend(&siteName, "/%s", PS_DEFAULT_SITE); 423 } 424 426 configFile = psStringCopy(home); 427 psStringAppend(&configFile, "/%s", IPPRC_FILE); 428 } 425 429 426 430 // We have the configuration filename; now we read and parse the config 427 // file and store in psMetadata struct site.428 // 429 430 if (!pmConfigFileRead(&config-> site, siteName, "site")) {431 // file and store in psMetadata struct user. 432 // XXX move this section to pmConfigReadUser.c ? 433 434 if (!pmConfigFileRead(&config->user, configFile, "user")) { 431 435 psFree(config); 432 436 return NULL; 433 437 } 434 438 435 // Set options based on the site configuration. 439 // XXX why was this being called here? Is someone calling pmConfigRead multiple times? 440 // pmConfigDone(); 441 assert (configPath == NULL); 442 443 // define the config-file search path (configPath). 444 psString path = psMetadataLookupStr(NULL, config->user, "PATH"); 445 pmConfigSet (path); 446 447 // read the SITE file 448 psString siteFile = psMetadataLookupStr(NULL, config->user, "SITE"); 449 if (!pmConfigFileRead(&config->site, siteFile, "site")) { 450 psFree(config); 451 return NULL; 452 } 453 454 // load the SYSTEM file 455 psString systemFile = psMetadataLookupStr(NULL, config->user, "SYSTEM"); 456 if (!pmConfigFileRead(&config->system, systemFile, "system")) { 457 psFree(config); 458 return NULL; 459 } 460 461 // interpolate USER, SITE and SYSTEM into the config->complete metadata 462 config->complete = psMetadataCopy (NULL, config->user); 463 config->complete = psMetadataCopy (config->complete, config->site); 464 config->complete = psMetadataCopy (config->complete, config->system); 465 466 // Set LOG and TRACE options based on the user configuration. These must be set AFTER 467 // the SITE and SYSTEM config files are read so path:// entries here can be resolved. 436 468 { 437 469 bool mdok = true; // Status of MD lookup result 438 470 439 // Initialise the psLib time handling440 psString timeName = psMetadataLookupStr(&mdok, config->site, "TIME");441 if (mdok && timeName)442 {443 psTrace("psModules.config", 7, "Initialising psTime with file %s\n", timeName);444 psTimeInit(timeName);445 }446 447 448 471 // Set logging level 449 int logLevel = psMetadataLookupS32(&mdok, config-> site, "LOGLEVEL");472 int logLevel = psMetadataLookupS32(&mdok, config->user, "LOGLEVEL"); 450 473 if (mdok && logLevel >= 0) 451 474 { … … 456 479 457 480 // Set logging format 458 psString logFormat = psMetadataLookupStr(&mdok, config-> site, "LOGFORMAT");481 psString logFormat = psMetadataLookupStr(&mdok, config->user, "LOGFORMAT"); 459 482 if (mdok && logFormat) 460 483 { … … 463 486 } 464 487 465 // Set logging destination first from command line, second from siteconfiguration488 // Set logging destination first from command line, second from user configuration 466 489 psString logDest = NULL; // Logging destination 467 490 argNum = psArgumentGet(*argc, argv, "-log"); … … 477 500 } 478 501 if (!logDest) { 479 logDest = psMemIncrRefCounter(psMetadataLookupStr(&mdok, config-> site, "LOGDEST"));502 logDest = psMemIncrRefCounter(psMetadataLookupStr(&mdok, config->user, "LOGDEST")); 480 503 } 481 504 if (logDest) { … … 497 520 498 521 // Set trace levels 499 psMetadata *trace = psMetadataLookupMetadata(&mdok, config-> site, "TRACE");522 psMetadata *trace = psMetadataLookupMetadata(&mdok, config->user, "TRACE"); 500 523 if (mdok && trace) { 501 524 psMetadataIterator *traceIter = psMetadataIteratorAlloc(trace, PS_LIST_HEAD, NULL); // Iterator … … 515 538 516 539 // Set trace formats 517 psString traceFormat = psMetadataLookupStr(&mdok, config-> site, "TRACEFORMAT");540 psString traceFormat = psMetadataLookupStr(&mdok, config->user, "TRACEFORMAT"); 518 541 if (mdok && traceFormat) { 519 542 psTrace("psModules.config", 7, "Setting trace format to %s\n", traceFormat); … … 535 558 } 536 559 if (!traceDest) { 537 traceDest = psMemIncrRefCounter(psMetadataLookupStr(&mdok, config-> site, "TRACEDEST"));560 traceDest = psMemIncrRefCounter(psMetadataLookupStr(&mdok, config->user, "TRACEDEST")); 538 561 } 539 562 if (traceDest) { … … 563 586 } 564 587 565 // define the config-file search path (configPath). Ensure that 566 // it contains the directory where we found the config file in 567 // the first place 568 if (configPath) { 569 pmConfigDone(); 570 } 571 572 psString siteNameDir = psStringCopy(dirname(siteName)); 573 psFree(siteName); 574 575 psString path = psMetadataLookupStr(NULL, config->site, "PATH"); 576 psString newPath = NULL; // New path 577 // The following gymnastics with 'newPath' are required to avoid changing the pointer out from under the 578 // psMetadataItem on which 'path' sits (leading to memory corruption because it no longer points to valid 579 // memory). 580 if (path) { 581 psStringAppend(&newPath, "%s:%s", path, siteNameDir); 582 } else { 583 newPath = psMemIncrRefCounter(siteNameDir); 584 } 585 psFree(siteNameDir); 586 pmConfigSet(newPath); 587 psFree(newPath); 588 // XXX read TIME from SITE (or system?) 589 { 590 bool mdok = true; 591 592 // Initialise the psLib time handling 593 // XXX is this still needed / desired? 594 psString timeName = psMetadataLookupStr(&mdok, config->complete, "TIME"); 595 if (mdok && timeName) 596 { 597 psTrace("psModules.config", 7, "Initialising psTime with file %s\n", timeName); 598 psTimeInit(timeName); 599 } 600 } 588 601 589 602 // Next, we do a similar thing for the camera configuration file. The 590 603 // file is read and parsed into psMetadata struct "camera". 591 //592 604 argNum = psArgumentGet(*argc, argv, "-camera"); 593 605 if (argNum > 0) { … … 600 612 char *cameraName = argv[argNum]; // symbolic name of the camera 601 613 602 // look for the CAMERAS list in config-> site603 psMetadata *cameras = psMetadataLookupMetadata(&mdok, config-> site, "CAMERAS");614 // look for the CAMERAS list in config->complete 615 psMetadata *cameras = psMetadataLookupMetadata(&mdok, config->complete, "CAMERAS"); 604 616 if (!cameras) { 605 617 psError(PS_ERR_IO, false, "Unable to find CAMERAS in site configuration.\n"); … … 647 659 "Camera specified on command line", config->camera); 648 660 649 if (!pmConfigCameraSkycellVersion(config-> site, cameraName)) {661 if (!pmConfigCameraSkycellVersion(config->complete, cameraName)) { 650 662 psError(PS_ERR_UNKNOWN, false, 651 663 "Unable to generate skycell versions of specified camera %s.\n", … … 655 667 } 656 668 657 if (!pmConfigCameraMosaickedVersions(config-> site, cameraName)) {669 if (!pmConfigCameraMosaickedVersions(config->complete, cameraName)) { 658 670 psError(PS_ERR_UNKNOWN, false, 659 671 "Unable to generate mosaicked versions of specified camera %s.\n", … … 668 680 if (!config->camera && readCameraConfig) { 669 681 bool mdok; // Status of MD lookup 670 psMetadata *cameras = psMetadataLookupMetadata(&mdok, config-> site, "CAMERAS"); // List of cameras682 psMetadata *cameras = psMetadataLookupMetadata(&mdok, config->complete, "CAMERAS"); // List of cameras 671 683 if (!mdok || !cameras) { 672 psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to find CAMERAS in the s iteconfiguration.\n");684 psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to find CAMERAS in the system configuration.\n"); 673 685 return false; 674 686 } 675 687 676 688 if (!metadataReadFiles(cameras, "camera configuration")) { 677 psError(PS_ERR_UNKNOWN, false, "Unable to read cameras within s iteconfiguration.\n");689 psError(PS_ERR_UNKNOWN, false, "Unable to read cameras within system configuration.\n"); 678 690 psFree(config); 679 691 return NULL; … … 702 714 psFree(iter); 703 715 704 if (!pmConfigCameraSkycellVersionsAll(config-> site)) {716 if (!pmConfigCameraSkycellVersionsAll(config->complete)) { 705 717 psError(PS_ERR_UNKNOWN, false, "Unable to generate skycell versions of cameras.\n"); 706 718 psFree(config); 707 719 return NULL; 708 720 } 709 if (!pmConfigCameraMosaickedVersionsAll(config-> site)) {721 if (!pmConfigCameraMosaickedVersionsAll(config->complete)) { 710 722 psError(PS_ERR_UNKNOWN, false, "Unable to generate mosaicked versions of cameras.\n"); 711 723 psFree(config); … … 715 727 716 728 // Load the recipes from the camera file, if appropriate 717 if(!pmConfigReadRecipes(config, PM_RECIPE_SOURCE_S ITE| PM_RECIPE_SOURCE_CAMERA)) {729 if(!pmConfigReadRecipes(config, PM_RECIPE_SOURCE_SYSTEM | PM_RECIPE_SOURCE_CAMERA)) { 718 730 psError(PS_ERR_IO, false, "Failed to read recipes from camera file"); 719 731 psFree(config); … … 746 758 psArgumentRemove(argNum, argc, argv); 747 759 748 psMetadata *cameras = psMetadataLookupMetadata(NULL, config-> site, "CAMERAS"); // List of cameras760 psMetadata *cameras = psMetadataLookupMetadata(NULL, config->complete, "CAMERAS"); // List of cameras 749 761 if (!cameras) { 750 762 psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to find CAMERAS in the site configuration.\n"); … … 794 806 } else { 795 807 char *dbserver = argv[argNum]; // The camera configuration file to read 796 if (!psMetadataAddStr(config-> site, PS_LIST_TAIL, "DBSERVER", PS_META_REPLACE, NULL, dbserver)) {808 if (!psMetadataAddStr(config->complete, PS_LIST_TAIL, "DBSERVER", PS_META_REPLACE, NULL, dbserver)) { 797 809 psWarning("Failed to overwrite .ipprc DBSERVER value"); 798 810 } … … 809 821 } else { 810 822 char *dbname = argv[argNum]; // The camera configuration file to read 811 if (!psMetadataAddStr(config-> site, PS_LIST_TAIL, "DBNAME", PS_META_REPLACE, NULL, dbname)) {823 if (!psMetadataAddStr(config->complete, PS_LIST_TAIL, "DBNAME", PS_META_REPLACE, NULL, dbname)) { 812 824 psWarning("Failed to overwrite .ipprc DBNAME value"); 813 825 } … … 824 836 } else { 825 837 char *dbuser = argv[argNum]; // The camera configuration file to read 826 if (!psMetadataAddStr(config-> site, PS_LIST_TAIL, "DBUSER", PS_META_REPLACE, NULL, dbuser)) {838 if (!psMetadataAddStr(config->complete, PS_LIST_TAIL, "DBUSER", PS_META_REPLACE, NULL, dbuser)) { 827 839 psWarning("Failed to overwrite .ipprc DBUSER value"); 828 840 } … … 839 851 } else { 840 852 char *dbpassword = argv[argNum]; // The camera configuration file to read 841 if (!psMetadataAddStr(config-> site, PS_LIST_TAIL, "DBPASSWORD", PS_META_REPLACE,853 if (!psMetadataAddStr(config->complete, PS_LIST_TAIL, "DBPASSWORD", PS_META_REPLACE, 842 854 NULL, dbpassword)) { 843 855 psWarning("Failed to overwrite .ipprc DBPASSWORD value"); … … 855 867 } else { 856 868 char *dbport = argv[argNum]; // The camera configuration file to read 857 if (!psMetadataAddS32(config-> site, PS_LIST_TAIL, "DBPORT", PS_META_REPLACE, NULL,869 if (!psMetadataAddS32(config->complete, PS_LIST_TAIL, "DBPORT", PS_META_REPLACE, NULL, 858 870 (psS32)atoi(dbport))) { 859 871 psWarning("Failed to overwrite .ipprc DBPORT value"); … … 1027 1039 if (! config->camera) { 1028 1040 bool mdok; // Metadata lookup status 1029 psMetadata *cameras = psMetadataLookupMetadata(&mdok, config-> site, "CAMERAS");1041 psMetadata *cameras = psMetadataLookupMetadata(&mdok, config->complete, "CAMERAS"); 1030 1042 if (! mdok || !cameras) { 1031 1043 psError(PS_ERR_IO, true, "Unable to find CAMERAS in the configuration."); … … 1114 1126 PS_ASSERT_STRING_NON_EMPTY(cameraName, NULL); 1115 1127 1116 psMetadata *cameras = psMetadataLookupMetadata(NULL, config-> site, "CAMERAS");1128 psMetadata *cameras = psMetadataLookupMetadata(NULL, config->complete, "CAMERAS"); 1117 1129 if (!cameras) { 1118 1130 psError(PS_ERR_IO, true, "Unable to find CAMERAS in the configuration."); … … 1140 1152 { 1141 1153 PS_ASSERT_PTR_NON_NULL(config, NULL); 1142 PS_ASSERT_PTR_NON_NULL(config-> site, NULL);1154 PS_ASSERT_PTR_NON_NULL(config->complete, NULL); 1143 1155 1144 1156 #ifndef HAVE_PSDB … … 1157 1169 1158 1170 // XXX leaky strings 1159 psString dbServer = psMetadataLookupStr(&mdStatus01, config-> site, "DBSERVER");1160 psString dbUsername = psMetadataLookupStr(&mdStatus02, config-> site, "DBUSER");1161 psString dbPassword = psMetadataLookupStr(&mdStatus03, config-> site, "DBPASSWORD");1162 psString dbName = psMetadataLookupStr(&mdStatus04, config-> site, "DBNAME");1163 psS32 dbPort = psMetadataLookupS32(&mdStatus05, config-> site, "DBPORT");1171 psString dbServer = psMetadataLookupStr(&mdStatus01, config->complete, "DBSERVER"); 1172 psString dbUsername = psMetadataLookupStr(&mdStatus02, config->complete, "DBUSER"); 1173 psString dbPassword = psMetadataLookupStr(&mdStatus03, config->complete, "DBPASSWORD"); 1174 psString dbName = psMetadataLookupStr(&mdStatus04, config->complete, "DBNAME"); 1175 psS32 dbPort = psMetadataLookupS32(&mdStatus05, config->complete, "DBPORT"); 1164 1176 if (!mdStatus05) { 1165 1177 dbPort = 0; … … 1352 1364 // replace path://PATH with matched datapath 1353 1365 if (!strncasecmp(filename, "path://", strlen("path://"))) { 1354 PS_ASSERT_METADATA_NON_NULL(config-> site, NULL);1366 PS_ASSERT_METADATA_NON_NULL(config->complete, NULL); 1355 1367 1356 1368 psString newName = psStringCopy(filename); 1357 1369 1358 1370 // filename should be of the form: path://PATH/rest/of/file 1359 // replace PATH with matching name from config-> site:DATAPATH1360 psMetadata *datapath = psMetadataLookupPtr (NULL, config-> site, "DATAPATH");1371 // replace PATH with matching name from config->complete:DATAPATH 1372 psMetadata *datapath = psMetadataLookupPtr (NULL, config->complete, "DATAPATH"); 1361 1373 if (datapath == NULL) { 1362 1374 psError(PS_ERR_UNKNOWN, true, "DATAPATH is not defined in config.site"); … … 1410 1422 // if env isn't set, check the config system 1411 1423 if (!neb_server) { 1412 neb_server = psMetadataLookupStr(&status, config-> site, "NEB_SERVER");1424 neb_server = psMetadataLookupStr(&status, config->complete, "NEB_SERVER"); 1413 1425 if (!status) { 1414 1426 psError(PM_ERR_CONFIG, true, "failed to lookup config value for NEB_SERVER.");
Note:
See TracChangeset
for help on using the changeset viewer.
