Changeset 15385 for trunk/psModules/src/config/pmConfig.c
- Timestamp:
- Oct 25, 2007, 4:41:15 PM (19 years ago)
- File:
-
- 1 edited
-
trunk/psModules/src/config/pmConfig.c (modified) (17 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/src/config/pmConfig.c
r15364 r15385 37 37 #define PS_DEFAULT_SITE ".ipprc" // Default site config file 38 38 39 #define DEFAULT_LOG STDERR_FILENO // Default file descriptor for log messages 40 #define DEFAULT_TRACE STDERR_FILENO // Default file descriptor for trace messages 41 39 42 static bool readCameraConfig = true; // Read the camera config on startup (with pmConfigRead)? 40 43 static psArray *configPath = NULL; // Search path for configuration files … … 59 62 psFree(config->arguments); 60 63 psFree(config->database); 64 65 // Close log and trace files 66 if (config->logFD != STDOUT_FILENO && config->logFD != STDERR_FILENO) { 67 close(config->logFD); 68 } 69 if (config->traceFD != STDOUT_FILENO && config->traceFD != STDERR_FILENO) { 70 close(config->traceFD); 71 } 72 73 return; 61 74 } 62 75 … … 79 92 config->defaultRecipe = NULL; 80 93 94 config->traceFD = DEFAULT_TRACE; 95 config->logFD = DEFAULT_LOG; 96 81 97 // the file structure is used to carry pmFPAfiles 82 98 config->files = psMetadataAlloc (); … … 124 140 } 125 141 142 126 143 void pmConfigSet(const char *path) 127 144 { … … 144 161 psFree(configPath); 145 162 configPath = NULL; 163 164 return; 146 165 } 147 166 … … 379 398 psArgumentRemove(argNum, argc, argv); 380 399 if (argNum >= *argc) { 381 psLogMsg("psModules.config", PS_LOG_WARN, 382 "-site command-line switch provided without the required filename --- ignored.\n"); 400 psWarning("-site command-line switch provided without the required filename --- ignored.\n"); 383 401 } else { 384 402 siteName = psStringCopy(argv[argNum]); … … 446 464 447 465 argNum = psArgumentGet(*argc, argv, "-log"); 448 if (argNum > 0) 449 { 466 if (argNum > 0) { 450 467 psArgumentRemove(argNum, argc, argv); 451 468 if (argNum >= *argc) { 452 ps LogMsg("psModules.config", PS_LOG_WARN, "-log command-line switch provided without the"453 "required log destination--- ignored.\n");469 psWarning("-log command-line switch provided without the required log destination " 470 "--- ignored.\n"); 454 471 } else { 455 if (!psLogSetDestination(psMessageDestination(argv[argNum]))) { 456 psLogMsg("psModules.config", PS_LOG_WARN, "Unable to set log destination to %s\n", 457 argv[argNum]); 458 } 472 config->logFD = psMessageDestination(argv[argNum]); 459 473 psArgumentRemove(argNum, argc, argv); 460 474 } 461 } else 462 { 475 } else { 463 476 // Set logging destination 464 477 psString logDest = psMetadataLookupStr(&mdok, config->site, "LOGDEST"); 465 478 if (mdok && logDest && strlen(logDest) > 0) { 466 // XXX: Only stdout and stderr are provided for now; this section should be 467 // expanded in the future to do files, and perhaps even sockets. 468 if (!psLogSetDestination(psMessageDestination(logDest))) { 469 psLogMsg("psModules.config", PS_LOG_WARN, "Unable to set log destination to %s\n", 470 argv[argNum]); 471 } 472 } 479 config->logFD = psMessageDestination(logDest); 480 } 481 } 482 if (!psLogSetDestination(config->logFD)) { 483 psWarning("Unable to set log destination to file number %d --- ignored", config->logFD); 473 484 } 474 485 475 486 // Set trace levels 476 487 psMetadata *trace = psMetadataLookupMetadata(&mdok, config->site, "TRACE"); 477 if (mdok && trace) 478 { 488 if (mdok && trace) { 479 489 psMetadataIterator *traceIter = psMetadataIteratorAlloc(trace, PS_LIST_HEAD, NULL); // Iterator 480 490 psMetadataItem *traceItem = NULL; // Item from MD iteration 481 491 while ((traceItem = psMetadataGetAndIncrement(traceIter))) { 482 492 if (traceItem->type != PS_DATA_S32) { 483 psLogMsg("psModules.config", PS_LOG_WARN, 484 "The level for trace component %s is not of type S32 (%x)\n", 493 psWarning("The level for trace component %s is not of type S32 (%x)\n", 485 494 traceItem->name, traceItem->type); 486 495 continue; 487 496 } 488 psTrace("psModules.config", 7, "Setting trace level for %s to %d\n", traceItem->name, traceItem->data.S32); 497 psTrace("psModules.config", 7, "Setting trace level for %s to %d\n", 498 traceItem->name, traceItem->data.S32); 489 499 (void)psTraceSetLevel(traceItem->name, traceItem->data.S32); 490 500 } … … 494 504 // Set trace formats 495 505 psString traceFormat = psMetadataLookupStr(&mdok, config->site, "TRACEFORMAT"); 496 if (mdok && traceFormat) 497 { 506 if (mdok && traceFormat) { 498 507 psTrace("psModules.config", 7, "Setting trace format to %s\n", traceFormat); 499 508 (void)psTraceSetFormat(traceFormat); … … 502 511 // Set trace destinations 503 512 #ifndef PS_NO_TRACE 504 psString traceDest = psMetadataLookupStr(&mdok, config->site, "TRACEDEST"); 505 if (mdok && traceDest && strlen(traceDest) > 0) 506 { 507 psTrace("psModules.config", 7, "Setting trace destination to %s\n", traceDest); 508 // XXX: Only stdout and stderr are provided for now; this section should be 509 // expanded in the future to do files, and perhaps even sockets. 510 if (!psTraceSetDestination(psMessageDestination(traceDest))) { 511 psLogMsg("psModules.config", PS_LOG_WARN, "Unable to set trace destination to %s\n", traceDest); 512 513 } 513 argNum = psArgumentGet(*argc, argv, "-tracedest"); 514 if (argNum > 0) { 515 psArgumentRemove(argNum, argc, argv); 516 if (argNum >= *argc) { 517 psWarning("-tracedest command-line switch provided without the required trace destination " 518 "--- ignored.\n"); 519 } else { 520 config->traceFD = psMessageDestination(argv[argNum]); 521 psArgumentRemove(argNum, argc, argv); 522 } 523 } else { 524 psString traceDest = psMetadataLookupStr(&mdok, config->site, "TRACEDEST"); 525 if (mdok && traceDest && strlen(traceDest) > 0) { 526 psTrace("psModules.config", 7, "Setting trace destination to %s\n", traceDest); 527 config->traceFD = psMessageDestination(traceDest); 528 } 529 } 530 if (!psTraceSetDestination(config->traceFD)) { 531 psWarning("Unable to set log destination to file %d\n", config->traceFD); 514 532 } 515 533 #endif … … 741 759 psArgumentRemove(argNum, argc, argv); 742 760 if (argNum >= *argc) { 743 psLogMsg("psModules.config", PS_LOG_WARN, 744 "-dbserver command-line switch provided without the required server name --- "); 761 psWarning("-dbserver command-line switch provided without the required server name --- "); 745 762 } else { 746 763 char *dbserver = argv[argNum]; // The camera configuration file to read 747 764 if (!psMetadataAddStr(config->site, PS_LIST_TAIL, "DBSERVER", PS_META_REPLACE, NULL, dbserver)) { 748 psLogMsg("psModules.config", PS_LOG_WARN, 749 "failed to overwrite .ipprc DBSERVER value --- "); 765 psWarning("Failed to overwrite .ipprc DBSERVER value"); 750 766 } 751 767 … … 758 774 psArgumentRemove(argNum, argc, argv); 759 775 if (argNum >= *argc) { 760 psLogMsg("psModules.config", PS_LOG_WARN, 761 "-dbname command-line switch provided without the required database name --- "); 776 psWarning("-dbname command-line switch provided without the required database name"); 762 777 } else { 763 778 char *dbname = argv[argNum]; // The camera configuration file to read 764 779 if (!psMetadataAddStr(config->site, PS_LIST_TAIL, "DBNAME", PS_META_REPLACE, NULL, dbname)) { 765 psLogMsg("psModules.config", PS_LOG_WARN, 766 "failed to overwrite .ipprc DBNAME value --- "); 780 psWarning("Failed to overwrite .ipprc DBNAME value"); 767 781 } 768 782 … … 775 789 psArgumentRemove(argNum, argc, argv); 776 790 if (argNum >= *argc) { 777 psLogMsg("psModules.config", PS_LOG_WARN, 778 "-dbuser command-line switch provided without the required database name --- "); 791 psWarning("-dbuser command-line switch provided without the required database name"); 779 792 } else { 780 793 char *dbuser = argv[argNum]; // The camera configuration file to read 781 794 if (!psMetadataAddStr(config->site, PS_LIST_TAIL, "DBUSER", PS_META_REPLACE, NULL, dbuser)) { 782 psLogMsg("psModules.config", PS_LOG_WARN, 783 "failed to overwrite .ipprc DBUSER value --- "); 795 psWarning("Failed to overwrite .ipprc DBUSER value"); 784 796 } 785 797 … … 792 804 psArgumentRemove(argNum, argc, argv); 793 805 if (argNum >= *argc) { 794 psLogMsg("psModules.config", PS_LOG_WARN, 795 "-dbpassword command-line switch provided without the required password --- "); 806 psWarning("-dbpassword command-line switch provided without the required password"); 796 807 } else { 797 808 char *dbpassword = argv[argNum]; // The camera configuration file to read 798 if (!psMetadataAddStr(config->site, PS_LIST_TAIL, "DBPASSWORD", PS_META_REPLACE, NULL, dbpassword)) {799 psLogMsg("psModules.config", PS_LOG_WARN,800 "failed to overwrite .ipprc DBPASSWORD value ---");809 if (!psMetadataAddStr(config->site, PS_LIST_TAIL, "DBPASSWORD", PS_META_REPLACE, 810 NULL, dbpassword)) { 811 psWarning("Failed to overwrite .ipprc DBPASSWORD value"); 801 812 } 802 813 … … 809 820 psArgumentRemove(argNum, argc, argv); 810 821 if (argNum >= *argc) { 811 psLogMsg("psModules.config", PS_LOG_WARN, 812 "-dbpport command-line switch provided without the required port number --- "); 822 psWarning("-dbpport command-line switch provided without the required port number"); 813 823 } else { 814 824 char *dbport = argv[argNum]; // The camera configuration file to read 815 if (!psMetadataAddS32(config->site, PS_LIST_TAIL, "DBPORT", PS_META_REPLACE, NULL, (psS32)atoi(dbport))) {816 psLogMsg("psModules.config", PS_LOG_WARN,817 "failed to overwrite .ipprc DBPORT value ---");825 if (!psMetadataAddS32(config->site, PS_LIST_TAIL, "DBPORT", PS_META_REPLACE, NULL, 826 (psS32)atoi(dbport))) { 827 psWarning("Failed to overwrite .ipprc DBPORT value"); 818 828 } 819 829 … … 963 973 result = true; 964 974 } else { 965 psLogMsg("psModules.config", PS_LOG_WARN, 966 "Camera %s, format %s also matches header --- ignored.\n", 975 psWarning("Camera %s, format %s also matches header --- ignored.\n", 967 976 cameraName, formatsItem->name); 968 977 } … … 1087 1096 1088 1097 if (!pmConfigFileRead(&camera, cameraPath, cameraName)) { 1089 ps LogMsg("psModules.config", PS_LOG_WARN,"Trouble reading reading camera configuration %s", cameraName);1098 psWarning("Trouble reading reading camera configuration %s", cameraName); 1090 1099 psFree(camera); 1091 1100 return NULL; … … 1124 1133 } 1125 1134 if (!(mdStatus01 && mdStatus02 && mdStatus03 && mdStatus04)) { 1126 psLogMsg("psModules.config", PS_LOG_WARN, 1127 "Could not determine database server, name, user, and password from site metadata.\n"); 1135 psWarning("Could not determine database server, name, user, and password from site metadata.\n"); 1128 1136 return NULL; 1129 1137 }
Note:
See TracChangeset
for help on using the changeset viewer.
