Index: /trunk/psModules/src/config/pmConfig.c
===================================================================
--- /trunk/psModules/src/config/pmConfig.c	(revision 15384)
+++ /trunk/psModules/src/config/pmConfig.c	(revision 15385)
@@ -37,4 +37,7 @@
 #define PS_DEFAULT_SITE ".ipprc"  // Default site config file
 
+#define DEFAULT_LOG STDERR_FILENO       // Default file descriptor for log messages
+#define DEFAULT_TRACE STDERR_FILENO     // Default file descriptor for trace messages
+
 static bool readCameraConfig = true;    // Read the camera config on startup (with pmConfigRead)?
 static psArray *configPath = NULL;      // Search path for configuration files
@@ -59,4 +62,14 @@
     psFree(config->arguments);
     psFree(config->database);
+
+    // Close log and trace files
+    if (config->logFD != STDOUT_FILENO && config->logFD != STDERR_FILENO) {
+        close(config->logFD);
+    }
+    if (config->traceFD != STDOUT_FILENO && config->traceFD != STDERR_FILENO) {
+        close(config->traceFD);
+    }
+
+    return;
 }
 
@@ -79,4 +92,7 @@
     config->defaultRecipe = NULL;
 
+    config->traceFD = DEFAULT_TRACE;
+    config->logFD = DEFAULT_LOG;
+
     // the file structure is used to carry pmFPAfiles
     config->files = psMetadataAlloc ();
@@ -124,4 +140,5 @@
 }
 
+
 void pmConfigSet(const char *path)
 {
@@ -144,4 +161,6 @@
     psFree(configPath);
     configPath = NULL;
+
+    return;
 }
 
@@ -379,6 +398,5 @@
         psArgumentRemove(argNum, argc, argv);
         if (argNum >= *argc) {
-            psLogMsg("psModules.config", PS_LOG_WARN,
-                     "-site command-line switch provided without the required filename --- ignored.\n");
+            psWarning("-site command-line switch provided without the required filename --- ignored.\n");
         } else {
             siteName = psStringCopy(argv[argNum]);
@@ -446,45 +464,37 @@
 
         argNum = psArgumentGet(*argc, argv, "-log");
-        if (argNum > 0)
-        {
+        if (argNum > 0) {
             psArgumentRemove(argNum, argc, argv);
             if (argNum >= *argc) {
-                psLogMsg("psModules.config", PS_LOG_WARN, "-log command-line switch provided without the "
-                         "required log destination --- ignored.\n");
+                psWarning("-log command-line switch provided without the required log destination "
+                          "--- ignored.\n");
             } else {
-                if (!psLogSetDestination(psMessageDestination(argv[argNum]))) {
-                    psLogMsg("psModules.config", PS_LOG_WARN, "Unable to set log destination to %s\n",
-                             argv[argNum]);
-                }
+                config->logFD = psMessageDestination(argv[argNum]);
                 psArgumentRemove(argNum, argc, argv);
             }
-        } else
-        {
+        } else {
             // Set logging destination
             psString logDest = psMetadataLookupStr(&mdok, config->site, "LOGDEST");
             if (mdok && logDest && strlen(logDest) > 0) {
-                // XXX: Only stdout and stderr are provided for now; this section should be
-                // expanded in the future to do files, and perhaps even sockets.
-                if (!psLogSetDestination(psMessageDestination(logDest))) {
-                    psLogMsg("psModules.config", PS_LOG_WARN, "Unable to set log destination to %s\n",
-                             argv[argNum]);
-                }
-            }
+                config->logFD = psMessageDestination(logDest);
+            }
+        }
+        if (!psLogSetDestination(config->logFD)) {
+            psWarning("Unable to set log destination to file number %d --- ignored", config->logFD);
         }
 
         // Set trace levels
         psMetadata *trace = psMetadataLookupMetadata(&mdok, config->site, "TRACE");
-        if (mdok && trace)
-        {
+        if (mdok && trace) {
             psMetadataIterator *traceIter = psMetadataIteratorAlloc(trace, PS_LIST_HEAD, NULL); // Iterator
             psMetadataItem *traceItem = NULL; // Item from MD iteration
             while ((traceItem = psMetadataGetAndIncrement(traceIter))) {
                 if (traceItem->type != PS_DATA_S32) {
-                    psLogMsg("psModules.config", PS_LOG_WARN,
-                             "The level for trace component %s is not of type S32 (%x)\n",
+                    psWarning("The level for trace component %s is not of type S32 (%x)\n",
                              traceItem->name, traceItem->type);
                     continue;
                 }
-                psTrace("psModules.config", 7, "Setting trace level for %s to %d\n", traceItem->name, traceItem->data.S32);
+                psTrace("psModules.config", 7, "Setting trace level for %s to %d\n",
+                        traceItem->name, traceItem->data.S32);
                 (void)psTraceSetLevel(traceItem->name, traceItem->data.S32);
             }
@@ -494,6 +504,5 @@
         // Set trace formats
         psString traceFormat = psMetadataLookupStr(&mdok, config->site, "TRACEFORMAT");
-        if (mdok && traceFormat)
-        {
+        if (mdok && traceFormat) {
             psTrace("psModules.config", 7, "Setting trace format to %s\n", traceFormat);
             (void)psTraceSetFormat(traceFormat);
@@ -502,14 +511,23 @@
         // Set trace destinations
         #ifndef PS_NO_TRACE
-        psString traceDest = psMetadataLookupStr(&mdok, config->site, "TRACEDEST");
-        if (mdok && traceDest && strlen(traceDest) > 0)
-        {
-            psTrace("psModules.config", 7, "Setting trace destination to %s\n", traceDest);
-            // XXX: Only stdout and stderr are provided for now; this section should be
-            // expanded in the future to do files, and perhaps even sockets.
-            if (!psTraceSetDestination(psMessageDestination(traceDest))) {
-                psLogMsg("psModules.config", PS_LOG_WARN, "Unable to set trace destination to %s\n", traceDest);
-
-            }
+        argNum = psArgumentGet(*argc, argv, "-tracedest");
+        if (argNum > 0) {
+            psArgumentRemove(argNum, argc, argv);
+            if (argNum >= *argc) {
+                psWarning("-tracedest command-line switch provided without the required trace destination "
+                          "--- ignored.\n");
+            } else {
+                config->traceFD = psMessageDestination(argv[argNum]);
+                psArgumentRemove(argNum, argc, argv);
+            }
+        } else {
+            psString traceDest = psMetadataLookupStr(&mdok, config->site, "TRACEDEST");
+            if (mdok && traceDest && strlen(traceDest) > 0) {
+                psTrace("psModules.config", 7, "Setting trace destination to %s\n", traceDest);
+                config->traceFD = psMessageDestination(traceDest);
+            }
+        }
+        if (!psTraceSetDestination(config->traceFD)) {
+            psWarning("Unable to set log destination to file %d\n", config->traceFD);
         }
         #endif
@@ -741,11 +759,9 @@
         psArgumentRemove(argNum, argc, argv);
         if (argNum >= *argc) {
-            psLogMsg("psModules.config", PS_LOG_WARN,
-                     "-dbserver command-line switch provided without the required server name --- ");
+            psWarning("-dbserver command-line switch provided without the required server name --- ");
         } else {
             char *dbserver = argv[argNum]; // The camera configuration file to read
             if (!psMetadataAddStr(config->site, PS_LIST_TAIL, "DBSERVER", PS_META_REPLACE, NULL, dbserver)) {
-                psLogMsg("psModules.config", PS_LOG_WARN,
-                         "failed to overwrite .ipprc DBSERVER value --- ");
+                psWarning("Failed to overwrite .ipprc DBSERVER value");
             }
 
@@ -758,11 +774,9 @@
         psArgumentRemove(argNum, argc, argv);
         if (argNum >= *argc) {
-            psLogMsg("psModules.config", PS_LOG_WARN,
-                     "-dbname command-line switch provided without the required database name --- ");
+            psWarning("-dbname command-line switch provided without the required database name");
         } else {
             char *dbname = argv[argNum]; // The camera configuration file to read
             if (!psMetadataAddStr(config->site, PS_LIST_TAIL, "DBNAME", PS_META_REPLACE, NULL, dbname)) {
-                psLogMsg("psModules.config", PS_LOG_WARN,
-                         "failed to overwrite .ipprc DBNAME value --- ");
+                psWarning("Failed to overwrite .ipprc DBNAME value");
             }
 
@@ -775,11 +789,9 @@
         psArgumentRemove(argNum, argc, argv);
         if (argNum >= *argc) {
-            psLogMsg("psModules.config", PS_LOG_WARN,
-                     "-dbuser command-line switch provided without the required database name --- ");
+            psWarning("-dbuser command-line switch provided without the required database name");
         } else {
             char *dbuser = argv[argNum]; // The camera configuration file to read
             if (!psMetadataAddStr(config->site, PS_LIST_TAIL, "DBUSER", PS_META_REPLACE, NULL, dbuser)) {
-                psLogMsg("psModules.config", PS_LOG_WARN,
-                         "failed to overwrite .ipprc DBUSER value --- ");
+                psWarning("Failed to overwrite .ipprc DBUSER value");
             }
 
@@ -792,11 +804,10 @@
         psArgumentRemove(argNum, argc, argv);
         if (argNum >= *argc) {
-            psLogMsg("psModules.config", PS_LOG_WARN,
-                     "-dbpassword command-line switch provided without the required password --- ");
+            psWarning("-dbpassword command-line switch provided without the required password");
         } else {
             char *dbpassword = argv[argNum]; // The camera configuration file to read
-            if (!psMetadataAddStr(config->site, PS_LIST_TAIL, "DBPASSWORD", PS_META_REPLACE, NULL, dbpassword)) {
-                psLogMsg("psModules.config", PS_LOG_WARN,
-                         "failed to overwrite .ipprc DBPASSWORD value --- ");
+            if (!psMetadataAddStr(config->site, PS_LIST_TAIL, "DBPASSWORD", PS_META_REPLACE,
+                                  NULL, dbpassword)) {
+                psWarning("Failed to overwrite .ipprc DBPASSWORD value");
             }
 
@@ -809,11 +820,10 @@
         psArgumentRemove(argNum, argc, argv);
         if (argNum >= *argc) {
-            psLogMsg("psModules.config", PS_LOG_WARN,
-                     "-dbpport command-line switch provided without the required port number --- ");
+            psWarning("-dbpport command-line switch provided without the required port number");
         } else {
             char *dbport = argv[argNum]; // The camera configuration file to read
-            if (!psMetadataAddS32(config->site, PS_LIST_TAIL, "DBPORT", PS_META_REPLACE, NULL, (psS32)atoi(dbport))) {
-                psLogMsg("psModules.config", PS_LOG_WARN,
-                         "failed to overwrite .ipprc DBPORT value --- ");
+            if (!psMetadataAddS32(config->site, PS_LIST_TAIL, "DBPORT", PS_META_REPLACE, NULL,
+                                  (psS32)atoi(dbport))) {
+                psWarning("Failed to overwrite .ipprc DBPORT value");
             }
 
@@ -963,6 +973,5 @@
                 result = true;
             } else {
-                psLogMsg("psModules.config", PS_LOG_WARN,
-                         "Camera %s, format %s also matches header --- ignored.\n",
+                psWarning("Camera %s, format %s also matches header --- ignored.\n",
                          cameraName, formatsItem->name);
             }
@@ -1087,5 +1096,5 @@
 
     if (!pmConfigFileRead(&camera, cameraPath, cameraName)) {
-        psLogMsg("psModules.config", PS_LOG_WARN, "Trouble reading reading camera configuration %s", cameraName);
+        psWarning("Trouble reading reading camera configuration %s", cameraName);
         psFree(camera);
         return NULL;
@@ -1124,6 +1133,5 @@
     }
     if (!(mdStatus01 && mdStatus02 && mdStatus03 && mdStatus04)) {
-        psLogMsg("psModules.config", PS_LOG_WARN,
-                 "Could not determine database server, name, user, and password from site metadata.\n");
+        psWarning("Could not determine database server, name, user, and password from site metadata.\n");
         return NULL;
     }
Index: /trunk/psModules/src/config/pmConfig.h
===================================================================
--- /trunk/psModules/src/config/pmConfig.h	(revision 15384)
+++ /trunk/psModules/src/config/pmConfig.h	(revision 15385)
@@ -5,6 +5,6 @@
  *  @author Eugene Magnier, IfA
  *
- *  @version $Revision: 1.31 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2007-10-04 20:15:48 $
+ *  @version $Revision: 1.32 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2007-10-26 02:41:15 $
  *  Copyright 2005-2006 Institute for Astronomy, University of Hawaii
  */
@@ -36,6 +36,5 @@
 /// This structure stores the configuration information: the site, camera and recipe configuration, the
 /// command-line arguments, the pmFPAfiles used, and the database handle.
-typedef struct
-{
+typedef struct {
     psMetadata *site;                   ///< Site configuration
     psMetadata *camera;                 ///< Camera specification
@@ -51,12 +50,7 @@
     pmRecipeSource recipesRead;         ///< Which recipe sources have been read
     psMetadata *recipeSymbols;          ///< Where each recipe came from
-
-    // dropping the argc, argv info from pmConfig
-    # if (0)
-    int *argc;                          ///< Number of command-line arguments
-    char **argv;                        ///< Command-line arguments (raw version)
-    # endif
-}
-pmConfig;
+    int traceFD;                        ///< File descriptor for trace messages
+    int logFD;                          ///< File descriptor for log messages
+} pmConfig;
 
 /// Allocator for pmConfig
