IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Mar 31, 2006, 5:00:23 PM (20 years ago)
Author:
magnier
Message:

pmConfigRead now loads site from ~/.ipprc and searches the PATH therein for the other config files

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/rel10_ifa/psModules/src/config/pmConfig.c

    r6734 r6754  
    33 *  @author PAP, IfA
    44 *
    5  *  @version $Revision: 1.7.4.7 $ $Name: not supported by cvs2svn $
    6  *  @date $Date: 2006-03-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 $
    77 *
    88 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    1313#include <unistd.h>
    1414#include <assert.h>
     15#include <sys/types.h>
     16#include <sys/stat.h>
    1517#include "pslib.h"
    1618#include "pmConfig.h"
    1719
    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
     23static psArray *configPath = NULL;
    2024
    2125static void configFree(pmConfig *config)
     
    5761    const char *description)            // Description of file
    5862{
     63    char *realName = NULL;
    5964    unsigned int numBadLines = 0;
     65    struct stat filestat;
    6066
    6167    psLogMsg(__func__, PS_LOG_INFO, "Loading %s configuration from file %s\n",
    6268             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
     114found:
     115    *config = psMetadataConfigParse(NULL, &numBadLines, realName, true);
    64116    if (numBadLines > 0) {
    65117        psLogMsg(__func__, PS_LOG_WARN, "%d bad lines in %s configuration file (%s)\n",
    66                  description, name);
     118                 description, realName);
    67119    }
    68120    if (!*config) {
    69121        psError(PS_ERR_IO, false, "Unable to read %s configuration from %s\n",
    70                 description, name);
     122                description, realName);
     123        psFree (realName);
    71124        return false;
    72125    }
    73126
     127    psFree (realName);
    74128    return true;
    75129}
     
    115169                     "-site command-line switch provided without the required filename --- ignored.\n");
    116170        } else {
    117             siteName = argv[argNum];
     171            siteName = psStringCopy(argv[argNum]);
    118172            psArgumentRemove(argNum, argc, argv);
    119173        }
     
    124178    if (!siteName) {
    125179        siteName = getenv(PS_SITE);
     180        if (siteName) {
     181            siteName = psStringCopy (siteName);
     182        }
    126183    }
    127184
     
    129186    // Last chance is ~/.ipprc
    130187    //
    131     bool cleanupSiteName = false; // Do I have to psFree siteName?
    132188    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
    139196    // file and store in psMetadata struct site.
    140197    //
     
    144201        return NULL;
    145202    }
    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
    152217    // Next, we do a similar thing for the camera configuration file.  The
    153218    // file is read and parsed into psMetadata struct "camera".
     
    350415                            )
    351416{
     417    psMetadata *testFormat;
     418
    352419    assert(format);
    353420    assert(camera);
     
    374441        }
    375442        psTrace(__func__, 5, "Reading camera format for %s...\n", formatsItem->name);
    376         unsigned int badLines = 0;  // Number of bad lines in reading camera configuration
     443        // unsigned int badLines = 0;  // Number of bad lines in reading camera configuration
    377444        // 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);
    379454        if (badLines > 0) {
    380455            psLogMsg(__func__, PS_LOG_WARN, "%d bad lines encountered while reading camera"
    381456                     "format %s\n", badLines, formatsItem->name);
    382457        }
     458        # endif
     459
    383460        if (pmConfigValidateCameraFormat(testFormat, header)) {
    384461            if (!*format) {
     
    408485    psMetadata *format = NULL;          // The winning format
    409486    bool mdok = false;                  // Metadata lookup status
     487    psMetadata *testCamera = NULL;
    410488
    411489    // If we don't know what sort of camera we have, we try all that we know
     
    430508
    431509            psTrace(__func__, 5, "Reading camera configuration for %s...\n", camerasItem->name);
    432             unsigned int badLines = 0;  // Number of bad lines in reading camera configuration
     510            // unsigned int badLines = 0;  // Number of bad lines in reading camera configuration
    433511            // 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);
    435521            if (badLines > 0) {
    436522                psLogMsg(__func__, PS_LOG_WARN, "%d bad lines encountered while reading camera"
    437523                         "configuration %s\n", badLines, camerasItem->name);
    438524            }
     525            # endif
     526
    439527            if (! testCamera) {
    440528                psLogMsg(__func__, PS_LOG_WARN, "Unable to interpret camera configuration for %s (%s) --- "
Note: See TracChangeset for help on using the changeset viewer.