IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
May 3, 2010, 8:50:52 AM (16 years ago)
Author:
eugene
Message:

updates from trunk

Location:
branches/simtest_nebulous_branches
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/simtest_nebulous_branches

  • branches/simtest_nebulous_branches/psModules

  • branches/simtest_nebulous_branches/psModules/src/config/pmConfig.c

    r24496 r27840  
    4343#define DEFAULT_TRACE STDERR_FILENO     // Default file descriptor for trace messages
    4444
     45#define CHECK_FILE_RETRY 5              // Number of retries when checking a file
     46#define CHECK_FILE_WAIT 250000          // Wait between retries (usec) when checking a file
     47
    4548static bool readCameraConfig = true;    // Read the camera config on startup (with pmConfigRead)?
    4649static psArray *configPath = NULL;      // Search path for configuration files
    4750
    4851static bool checkPath(const char *filename, bool create, bool trunc);
     52static psString resolveConfigFile(const char *name);
    4953
    5054bool pmConfigReadParamsSet(bool newReadCameraConfig)
     
    174178        char *envName = envStart + 1;   // Start of the environment variable name
    175179        if (envName[0] == '\0') {
    176             psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Path %s contains a bad environment variable.\n", dir);
     180            psError(PM_ERR_CONFIG, true, "Path %s contains a bad environment variable.\n", dir);
    177181            return NULL;
    178182        }
     
    180184            envName++;
    181185            if (envName[0] == '\0') {
    182                 psError(PS_ERR_BAD_PARAMETER_VALUE, true,
     186                psError(PM_ERR_CONFIG, true,
    183187                        "Path %s contains a bad environment variable.\n", dir);
    184188                return NULL;
     
    272276
    273277    if (configPath == NULL) {
    274         psError(PS_ERR_IO, true, "Cannot find %s configuration file (%s) in path\n", description, name);
     278        psError(PM_ERR_CONFIG, true, "Cannot find %s configuration file (%s) in path\n", description, name);
    275279        return false;
    276280    }
     
    296300    }
    297301
    298     psError(PS_ERR_IO, true, "Cannot find %s configuration file %s in path\n", description, name);
     302    psError(PM_ERR_CONFIG, true, "Cannot find %s configuration file %s in path\n", description, name);
    299303    return false;
    300304
     
    302306    *config = psMetadataConfigRead(NULL, &numBadLines, realName, true);
    303307    if (numBadLines > 0) {
    304         psError(PS_ERR_IO, false, "%d bad lines in %s configuration file (%s)",
     308        psError(PM_ERR_CONFIG, false, "%d bad lines in %s configuration file (%s)",
    305309                numBadLines, description, realName);
    306310        psFree (realName);
     
    309313    }
    310314    if (!*config) {
    311         psError(PS_ERR_IO, true, "Unable to read %s configuration from %s",
     315        psError(PM_ERR_CONFIG, true, "Unable to read %s configuration from %s",
    312316                description, realName);
    313317        psFree (realName);
     
    328332    }
    329333    if (item->type != PS_DATA_STRING) {
    330         psTrace("config", 2, "Element %s in %s metadata is not of type STR.\n",
     334        psError(PM_ERR_CONFIG, true, "Element %s in %s metadata is not of type STR.\n",
    331335                item->name, description);
    332336        return false;
     
    336340    psMetadata *new = NULL;         // New metadata
    337341    if (!pmConfigFileRead(&new, item->data.str, item->name)) {
    338         psError(PM_ERR_CONFIG, false, "Trouble reading reading %s %s.\n",
     342        psError(psErrorCodeLast(), false, "Trouble reading reading %s %s.\n",
    339343                description, item->name);
    340344        psFree(new);
     
    361365    while ((item = psMetadataGetAndIncrement(iter))) {
    362366        if (!pmConfigFileIngest(item, description)) {
    363             psError(PM_ERR_CONFIG, false, "Unable to read %s %s.", description, item->name);
     367            psError(psErrorCodeLast(), false, "Unable to read %s %s.", description, item->name);
    364368            psFree(iter);
    365369            return false;
     
    382386    psMetadata *formats = psMetadataLookupMetadata(&mdok, camera, "FORMATS"); // Formats
    383387    if (!mdok || !formats) {
    384         psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to find FORMATS in camera configuration %s.\n", name);
     388        psError(PM_ERR_CONFIG, true, "Unable to find FORMATS in camera configuration %s.\n", name);
    385389        return false;
    386390    }
    387391    if (!metadataReadFiles(formats, "camera format")) {
    388         psError(PS_ERR_UNKNOWN, false, "Unable to read formats within camera configuration %s.\n", name);
     392        psError(psErrorCodeLast(), false, "Unable to read formats within camera configuration %s.\n", name);
    389393        return false;
    390394    }
     
    447451            psWarning("-ipprc command-line switch provided without the required filename --- ignored.\n");
    448452        } else {
    449             configFile = psStringCopy(argv[argNum]);
     453            configFile = resolveConfigFile(argv[argNum]);
    450454            psArgumentRemove(argNum, argc, argv);
    451455        }
     
    486490    psMetadataItem *siteItem = psMetadataLookup(config->user, "SITE");
    487491    if (!siteItem) {
    488         psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Unable to find SITE in user configuration.");
     492        psError(PM_ERR_CONFIG, true, "Unable to find SITE in user configuration.");
    489493        psFree(config);
    490494        return NULL;
    491495    }
    492496    if (!pmConfigFileIngest(siteItem, "site configuration")) {
    493         psError(PS_ERR_UNKNOWN, false, "Unable to read site configuration");
     497        psError(psErrorCodeLast(), false, "Unable to read site configuration");
    494498        psFree(config);
    495499        return NULL;
     
    500504    psMetadataItem *systemItem = psMetadataLookup(config->user, "SYSTEM");
    501505    if (!systemItem) {
    502         psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Unable to find SYSTEM in user configuration.");
     506        psError(PM_ERR_CONFIG, true, "Unable to find SYSTEM in user configuration.");
    503507        psFree(config);
    504508        return NULL;
    505509    }
    506510    if (!pmConfigFileIngest(systemItem, "system configuration")) {
    507         psError(PS_ERR_UNKNOWN, false, "Unable to read system configuration");
     511        psError(psErrorCodeLast(), false, "Unable to read system configuration");
    508512        psFree(config);
    509513        return NULL;
     
    551555            psString resolved = pmConfigConvertFilename(logDest, config, true, false); // Resolved filename
    552556            if (!resolved || strlen(resolved) == 0) {
    553                 psWarning("Unable to resolve log destination: %s --- ignored", logDest);
    554             } else {
    555                 pmConfigRunFilenameAddWrite(config, "LOG", logDest);
    556                 config->logFD = psMessageDestination(resolved);
    557             }
     557                psError(psErrorCodeLast(), false, "Unable to resolve log destination: %s", logDest);
     558                psFree(logDest);
     559                return NULL;
     560            }
     561            pmConfigRunFilenameAddWrite(config, "LOG", logDest);
     562            config->logFD = psMessageDestination(resolved);
    558563            psFree(resolved);
    559564            psFree(logDest);
     
    610615            psString resolved = pmConfigConvertFilename(traceDest, config, true, false); // Resolved filename
    611616            if (!resolved || strlen(resolved) == 0) {
    612                 psWarning("Unable to resolve trace destination: %s --- ignored", traceDest);
    613             } else {
    614                 pmConfigRunFilenameAddWrite(config, "TRACE", traceDest);
    615                 config->traceFD = psMessageDestination(resolved);
    616             }
     617                psError(psErrorCodeLast(), false, "Unable to resolve trace destination: %s", traceDest);
     618                psFree(traceDest);
     619                return NULL;
     620            }
     621            pmConfigRunFilenameAddWrite(config, "TRACE", traceDest);
     622            config->traceFD = psMessageDestination(resolved);
    617623            psFree(resolved);
    618624            psFree(traceDest);
     
    659665                seed = strtoll(argv[argNum], &end, 0);
    660666                if (strlen(end) > 0) {
    661                     psError(PS_ERR_IO, true, "Unable to read random number generator seed: %s", argv[argNum]);
     667                    psError(PM_ERR_CONFIG, true, "Unable to read random number generator seed: %s",
     668                            argv[argNum]);
    662669                    psFree(config);
    663670                    return NULL;
     
    684691            psMetadata *cameras = psMetadataLookupMetadata(&mdok, config->system, "CAMERAS");
    685692            if (!cameras) {
    686                 psError(PS_ERR_IO, false, "Unable to find CAMERAS in site configuration.\n");
     693                psError(PM_ERR_CONFIG, false, "Unable to find CAMERAS in site configuration.\n");
    687694                psFree(config);
    688695                return NULL;
     
    692699            char *cameraFile = psMetadataLookupStr(&mdok, cameras, cameraName); // The filename
    693700            if (!cameraFile) {
    694                 psError(PS_ERR_IO, false, "%s is not listed in the site CAMERAS list\n", cameraName);
     701                psError(PM_ERR_CONFIG, false, "%s is not listed in the site CAMERAS list\n", cameraName);
    695702                psFree(config);
    696703                return NULL;
     
    699706            // load this camera's configuration informatoin
    700707            if (!pmConfigFileRead(&config->camera, cameraFile, "camera")) {
    701                 psError(PM_ERR_CONFIG, false, "Problem reading %s", cameraName);
     708                psError(psErrorCodeLast(), false, "Problem reading %s", cameraName);
    702709                psFree(config);
    703710                return NULL;
     
    710717            // Read in the formats
    711718            if (!cameraReadFormats(config->camera, cameraFile)) {
    712                 psError(PS_ERR_UNKNOWN, false, "Unable to read formats within camera configuration %s.\n",
     719                psError(psErrorCodeLast(), false, "Unable to read formats within camera configuration %s.\n",
    713720                        cameraFile);
    714721                psFree(config);
     
    718725            // Read in any camera-specific calibrations
    719726            if (!cameraReadCalibrations(config->camera, cameraName)) {
    720                 psError(PS_ERR_UNKNOWN, false,
     727                psError(psErrorCodeLast(), false,
    721728                        "Unable to read calibrations within camera configuration %s.\n",
    722729                        cameraName);
     
    729736
    730737            if (!pmConfigCameraSkycellVersion(config->system, cameraName)) {
    731                 psError(PS_ERR_UNKNOWN, false,
     738                psError(psErrorCodeLast(), false,
    732739                        "Unable to generate skycell versions of specified camera %s.\n",
    733740                        cameraName);
     
    737744
    738745            if (!pmConfigCameraMosaickedVersions(config->system, cameraName)) {
    739                 psError(PS_ERR_UNKNOWN, false,
     746                psError(psErrorCodeLast(), false,
    740747                        "Unable to generate mosaicked versions of specified camera %s.\n",
    741748                        cameraName);
     
    751758        psMetadata *cameras = psMetadataLookupMetadata(&mdok, config->system, "CAMERAS"); // List of cameras
    752759        if (!mdok || !cameras) {
    753             psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to find CAMERAS in the system configuration.\n");
     760            psError(PM_ERR_CONFIG, true, "Unable to find CAMERAS in the system configuration.\n");
    754761            return false;
    755762        }
    756763
    757764        if (!metadataReadFiles(cameras, "camera configuration")) {
    758             psError(PS_ERR_UNKNOWN, false, "Unable to read cameras within system configuration.\n");
     765            psError(psErrorCodeLast(), false, "Unable to read cameras within system configuration.\n");
    759766            psFree(config);
    760767            return NULL;
     
    784791
    785792        if (!pmConfigCameraSkycellVersionsAll(config->system)) {
    786             psError(PS_ERR_UNKNOWN, false, "Unable to generate skycell versions of cameras.\n");
     793            psError(psErrorCodeLast(), false, "Unable to generate skycell versions of cameras.\n");
    787794            psFree(config);
    788795            return NULL;
    789796        }
    790797        if (!pmConfigCameraMosaickedVersionsAll(config->system)) {
    791             psError(PS_ERR_UNKNOWN, false, "Unable to generate mosaicked versions of cameras.\n");
     798            psError(psErrorCodeLast(), false, "Unable to generate mosaicked versions of cameras.\n");
    792799            psFree(config);
    793800            return NULL;
     
    797804    // Load the recipes from the camera file, if appropriate
    798805    if(!pmConfigReadRecipes(config, PM_RECIPE_SOURCE_SYSTEM | PM_RECIPE_SOURCE_CAMERA)) {
    799         psError(PS_ERR_IO, false, "Failed to read recipes from camera file");
     806        psError(psErrorCodeLast(), false, "Failed to read recipes from camera file");
    800807        psFree(config);
    801808        return NULL;
     
    812819
    813820    if (!pmConfigReadRecipes(config, PM_RECIPE_SOURCE_CL)) {
    814         psError(PS_ERR_IO, false, "Failed to read recipes from command-line");
     821        psError(psErrorCodeLast(), false, "Failed to read recipes from command-line");
    815822        psFree(config);
    816823        return NULL;
     
    821828        psArgumentRemove(argNum, argc, argv);
    822829        if (argNum + 1 >= *argc) {
    823             psError(PS_ERR_BAD_PARAMETER_SIZE, true,
     830            psError(PM_ERR_CONFIG, true,
    824831                    "Filerule switch (-F) provided without old and new filerule.");
    825832            psFree(config);
     
    834841        psMetadata *cameras = psMetadataLookupMetadata(NULL, config->system, "CAMERAS"); // List of cameras
    835842        if (!cameras) {
    836             psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to find CAMERAS in the site configuration.\n");
     843            psError(PM_ERR_CONFIG, false, "Unable to find CAMERAS in the site configuration.\n");
    837844            return false;
    838845        }
     
    9951002    psMetadata *rule = psMetadataLookupMetadata(&mdStatus, cameraFormat, "RULE");
    9961003    if (! mdStatus || ! rule) {
    997         psError(PS_ERR_UNKNOWN, false, "Unable to read rule for camera.");
     1004        psError(PM_ERR_CONFIG, false, "Unable to read rule for camera.");
    9981005        *valid = false;
    9991006        return false;
     
    10041011    psArray *keys = psListToArray (keyList);
    10051012    if (! keys) {
    1006         psError(PS_ERR_UNKNOWN, false, "Unable to read rule for camera.");
     1013        psError(PM_ERR_CONFIG, false, "Unable to read rule for camera.");
    10071014        *valid = false;
    10081015        return false;
     
    10531060        }
    10541061
    1055         psError(PS_ERR_UNKNOWN, false, "Invalid type for RULE %s.", ruleItem->name);
     1062        psError(PM_ERR_CONFIG, false, "Invalid type for RULE %s.", ruleItem->name);
    10561063        *valid = false;
    10571064        psFree (keyList);
     
    10881095    psMetadata *formats = psMetadataLookupMetadata(&mdok, camera, "FORMATS"); // List of formats
    10891096    if (!mdok || !formats) {
    1090         psError(PS_ERR_UNKNOWN, false, "Unable to find list of FORMATS in camera %s", cameraName);
     1097        psError(PM_ERR_CONFIG, false, "Unable to find list of FORMATS in camera %s", cameraName);
    10911098        *status = false;
    10921099        return false;
     
    10941101
    10951102    if (!metadataReadFiles(formats, "camera format")) {
    1096         psError(PS_ERR_UNKNOWN, false, "Unable to read cameras formats within camera configuration.\n");
     1103        psError(psErrorCodeLast(), false, "Unable to read cameras formats within camera configuration.\n");
    10971104        *status = false;
    10981105        return false;
     
    11101117        bool valid = false;
    11111118        if (!pmConfigValidateCameraFormat(&valid, testFormat, header)) {
    1112             psError (PS_ERR_UNKNOWN, false, "Error in config scripts for camera %s, format %s\n",
     1119            psError (psErrorCodeLast(), false, "Error in config scripts for camera %s, format %s\n",
    11131120                     cameraName, formatsItem->name);
    11141121            *status = false;
     
    11561163        psMetadata *cameras = psMetadataLookupMetadata(&mdok, config->system, "CAMERAS");
    11571164        if (! mdok || !cameras) {
    1158             psError(PS_ERR_IO, true, "Unable to find CAMERAS in the configuration.");
     1165            psError(PM_ERR_CONFIG, true, "Unable to find CAMERAS in the configuration.");
    11591166            return NULL;
    11601167        }
    11611168
    11621169        if (!metadataReadFiles(cameras, "camera configuration")) {
    1163             psError(PS_ERR_UNKNOWN, false, "Unable to read cameras within site configuration.\n");
     1170            psError(psErrorCodeLast(), false, "Unable to read cameras within site configuration.\n");
    11641171            return NULL;
    11651172        }
     
    11901197            } else {
    11911198                if (!status) {
    1192                     psError(PS_ERR_IO, false, "Error reading camera config data for %s", camerasItem->name);
     1199                    psError(psErrorCodeLast(), false, "Error reading camera config data for %s",
     1200                            camerasItem->name);
    11931201                    return NULL;
    11941202                }
     
    11991207        // Done looking at all cameras
    12001208        if (!config->camera) {
    1201             psError(PS_ERR_IO, false, "Unable to find a camera that matches input FITS header!");
     1209            psError(PM_ERR_CONFIG, true, "Unable to find a camera that matches input FITS header!");
    12021210            return NULL;
    12031211        }
     
    12051213        // Now we have the camera, we can read the recipes
    12061214        if (readRecipes && !pmConfigReadRecipes(config, PM_RECIPE_SOURCE_CAMERA | PM_RECIPE_SOURCE_CL)) {
    1207             psError(PS_ERR_IO, false, "Error reading recipes from camera config for %s", config->cameraName);
     1215            psError(psErrorCodeLast(), false, "Error reading recipes from camera config for %s",
     1216                    config->cameraName);
    12081217            return NULL;
    12091218        }
     
    12811290
    12821291    if (!found) {
    1283         psError(PS_ERR_IO, true, "Unable to find a format with the specified camera (%s) that matches the "
    1284                 "given header.\n", baseName);
     1292        psError(PM_ERR_CONFIG, true,
     1293                "Unable to find a format with the specified camera (%s) that matches the given header.",
     1294                baseName);
    12851295        psFree (baseName);
    12861296        return NULL;
     
    13131323    psMetadata *cameras = psMetadataLookupMetadata(NULL, config->system, "CAMERAS");
    13141324    if (!cameras) {
    1315         psError(PS_ERR_IO, true, "Unable to find CAMERAS in the configuration.");
     1325        psError(PM_ERR_CONFIG, true, "Unable to find CAMERAS in the configuration.");
    13161326        return NULL;
    13171327    }
     
    13191329    psMetadataItem *item = psMetadataLookup(cameras, cameraName); // Item with camera of interest
    13201330    if (!pmConfigFileIngest(item, "camera configuration")) {
    1321         psError(PS_ERR_UNKNOWN, false, "Unable to ingest camera configuration.");
     1331        psError(psErrorCodeLast(), false, "Unable to ingest camera configuration.");
    13221332        return NULL;
    13231333    }
     
    13351345        item = psMetadataLookup(config->site, name);
    13361346        if (!item) {
    1337             psError(PS_ERR_BAD_PARAMETER_VALUE, true,
     1347            psError(PM_ERR_CONFIG, true,
    13381348                    "Unable to find %s in user or site configuration", name);
    13391349            return NULL;
     
    13411351    }
    13421352    if (item->type != type) {
    1343         psError(PS_ERR_BAD_PARAMETER_TYPE, true,
     1353        psError(PM_ERR_CONFIG, true,
    13441354                "Type of %s (%x) in user/site configuration does not match expected (%x)",
    13451355                name, item->type, type);
     
    13581368#ifndef HAVE_PSDB
    13591369
    1360     psError(PS_ERR_UNKNOWN, false,
     1370    psError(PM_ERR_PROG, false,
    13611371            "Cannot configure database: psModules was compiled without database support.");
    13621372    return NULL;
     
    14071417    psMetadata *rules = psMetadataLookupMetadata(&mdok, format, "RULE"); // How to identify this format
    14081418    if (!mdok || !rules) {
    1409         psError(PS_ERR_IO, true, "Unable to find RULE in camera format.\n");
     1419        psError(PM_ERR_CONFIG, true, "Unable to find RULE in camera format.\n");
    14101420        return false;
    14111421    }
     
    14151425    while ((rulesItem = psMetadataGetAndIncrement(rulesIter))) {
    14161426        if (!PS_DATA_IS_PRIMITIVE(rulesItem->type) && rulesItem->type != PS_DATA_STRING) {
    1417             psError(PS_ERR_UNKNOWN, false, "Invalid type for RULE %s.", rulesItem->name);
     1427            psError(PM_ERR_CONFIG, false, "Invalid type for RULE %s.", rulesItem->name);
    14181428            return false;
    14191429        }
     
    14471457          case PS_METADATA_ITEM_COMPARE_OP_NE:
    14481458            // It's not at all obvious what the value should be, so return an error.
    1449             psError(PS_ERR_IO, true,
     1459            psError(PM_ERR_CONFIG, true,
    14501460                    "RULE %s (defined by an OPeration) is not present or not consistent in output header",
    14511461                    rulesItem->name);
     
    15301540              default:
    15311541                // rigid format, no comments allowed?
    1532                 psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Unable to parse file list: spaces detected.");
     1542                psError(PM_ERR_CONFIG, true, "Unable to parse file list: spaces detected.");
    15331543                psFree(input);
    15341544                fclose(f);
     
    15631573    if (!files) {
    15641574        psAbort("error parsing argument list");
    1565         psError(PS_ERR_IO, false, "error parsing argument list");
     1575        psError(psErrorCodeLast(), false, "error parsing argument list");
    15661576        psFree (files);
    15671577        return false;
     
    15901600
    15911601        char *point = newName + strlen("file:");
    1592         while (*point == '/')
     1602        while (*point == '/') {
    15931603            point ++;
     1604        }
    15941605        char *tmpName = NULL;
    15951606        psStringAppend (&tmpName, "/%s", point);
     
    15991610        if (!checkPath(newName, create, trunc)) {
    16001611            // let checkPath()'s psError() call float up
    1601             psError(PS_ERR_UNKNOWN, false, "error from checkPath for file:// (%s)", newName);
     1612            psError(psErrorCodeLast(), false, "error from checkPath for file:// (%s)", newName);
    16021613            psFree (newName);
    16031614            return NULL;
     
    16171628        psMetadata *datapath = psMetadataLookupPtr (NULL, config->site, "DATAPATH");
    16181629        if (datapath == NULL) {
    1619             psError(PS_ERR_UNKNOWN, true, "DATAPATH is not defined in config.site");
     1630            psError(PM_ERR_CONFIG, true, "DATAPATH is not defined in config.site");
    16201631            psFree (newName);
    16211632            return NULL;
     
    16251636        char *mark = strchr (point, '/');
    16261637        if (mark == NULL) {
    1627             psError(PS_ERR_UNKNOWN, true, "syntax error in PATH-style name %s", newName);
     1638            psError(PM_ERR_CONFIG, true, "syntax error in PATH-style name %s", newName);
    16281639            psFree (newName);
    16291640            return false;
     
    16331644        char *realpath = psMetadataLookupStr (NULL, datapath, path);
    16341645        if (realpath == NULL) {
    1635             psError(PS_ERR_UNKNOWN, true,
     1646            psError(PM_ERR_CONFIG, true,
    16361647                    "path (%s) not defined in config.site:DATAPATH for PATH-style name %s",
    16371648                    path, newName);
     
    16491660        if (!checkPath(newName, create, trunc)) {
    16501661            // let checkPath()'s psError() call float up
    1651             psError(PS_ERR_UNKNOWN, false, "error from checkPath for path:// (%s)", newName);
     1662            psError(psErrorCodeLast(), false, "error from checkPath for path:// (%s)", newName);
    16521663            psFree (newName);
    16531664            return NULL;
     
    17111722        nebServerFree(server);
    17121723
    1713         if (trunc) {
    1714             if(truncate(path, 0) != 0) {
    1715                 psError(PS_ERR_IO, true, "Failed to truncate Nebulous file %s (real name %s)\n",
    1716                         filename, path);
    1717                 return NULL;
    1718             }
     1724        // Check to ensure it's there.  Will create the file if Nebulous failed to do so.
     1725        if (!checkPath(path, create, trunc)) {
     1726            psError(psErrorCodeLast(), false, "Cannot find file %s", path);
     1727            psFree(path);
     1728            return NULL;
    17191729        }
    17201730
     
    17411751    psMetadataItem *item = psMetadataLookup(camera, "FILERULES"); // Item with the file rule of interest
    17421752    if (!item) {
    1743         psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to find FILERULES in the camera configuration.");
     1753        psError(PM_ERR_CONFIG, false, "Unable to find FILERULES in the camera configuration.");
    17441754        return NULL;
    17451755    }
     
    17741784    psMetadataItem *item = psMetadataLookup(camera, "FITSTYPES"); // Item with the file rule of interest
    17751785    if (!item) {
    1776         psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to find FITSTYPES in the camera configuration.");
     1786        psError(PM_ERR_CONFIG, false, "Unable to find FITSTYPES in the camera configuration.");
    17771787        return NULL;
    17781788    }
     
    18011811
    18021812    // re-try access up to 5 times (1.25sec) to reduce NFS lurches
    1803     for (int i = 0; i < 5; i++) {
     1813    for (int i = 0; i < CHECK_FILE_RETRY; i++) {
    18041814        if (access(filename, R_OK) == 0) {
    18051815            // file already exists
     
    18261836            return true;
    18271837        }
    1828         usleep (250000);
     1838        usleep(CHECK_FILE_WAIT);
    18291839    }
    18301840
     
    18341844    return false;
    18351845}
     1846
     1847static psString resolveConfigFile(const char *nameArg)
     1848{
     1849    // if config file name is nebulous path resolve it
     1850    // otherwise just return a copy of the argument
     1851    if (strncasecmp(nameArg, "neb://", strlen("neb://"))) {
     1852        return psStringCopy(nameArg);
     1853    }
     1854
     1855#ifdef HAVE_NEBCLIENT
     1856    char *neb_server = getenv("NEB_SERVER");
     1857
     1858    // if env isn't set, check the config system
     1859    if (!neb_server) {
     1860        psError(PM_ERR_CONFIG, true, "NEB_SERVER environment variable must be set in order to resolve config file.");
     1861            return NULL;
     1862    }
     1863
     1864    nebServer *server = nebServerAlloc(neb_server);
     1865    if (!server) {
     1866        psError(PM_ERR_SYS, true, "failed to create a nebServer object.");
     1867        return NULL;
     1868    }
     1869
     1870    char *nebfile = nebFind(server, nameArg);
     1871    nebServerFree(server);
     1872    if (!nebfile) {
     1873        // object does not exist
     1874        psError(PM_ERR_SYS, true, "failed to resolve nebulous path: %s.", nameArg);
     1875        return NULL;
     1876    }
     1877    // XXX: do I need to free nebfile?
     1878
     1879    return psStringCopy(nebfile);
     1880#else
     1881    psError(PM_ERR_PROG, true, "psModules was compiled without nebulous support.");
     1882    return NULL;
     1883#endif // ifdef HAVE_NEBCLIENT
     1884}
Note: See TracChangeset for help on using the changeset viewer.