IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Sep 8, 2005, 3:11:23 PM (21 years ago)
Author:
drobbin
Message:

Took xml/parser.h out of MDConfig, added psMessageDestination

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/sys/psLogMsg.c

    r4952 r4979  
    1212 *  @author GLG, MHPCC
    1313 *
    14  *  @version $Revision: 1.50 $ $Name: not supported by cvs2svn $
    15  *  @date $Date: 2005-09-07 00:36:12 $
     14 *  @version $Revision: 1.51 $ $Name: not supported by cvs2svn $
     15 *  @date $Date: 2005-09-09 01:11:22 $
    1616 *
    1717 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    9090bool psLogSetDestination(int fd)
    9191{
    92     //    char protocol[5];
    93     //    char location[257];
    94     //    char dest[257];
    9592    FILE *fp;
    9693    // if logDest has not been initialized, do so before using it
     
    9895        logDest = stderr;
    9996    }
     97    if (fd == -1)
     98        return false;
    10099
    101100    if ( fd == 1 ) {
     
    117116        }
    118117        logDest = NULL;
    119         return true;
     118        //        return true;
    120119    } else if (fd > 2) {
    121120        if (logDest != NULL && logDest != stderr && logDest != stdout) {
     
    125124        logDest = fp;
    126125        //        fclose(fp);
    127         return true;
    128     }
    129 
    130     /*
    131         if (dest == NULL || strcmp(dest, "none") == 0) {
    132             if (logDest != NULL && logDest != stderr && logDest != stdout) {
    133                 fclose(logDest);
    134             }
    135             logDest = NULL;
    136             return true;
    137         }
    138         if (sscanf(dest, "%4s:%256s", protocol, location) < 2) {
    139             psError(PS_ERR_LOCATION_INVALID, true,
    140                     PS_ERRORTEXT_psLogMsg_DESTINATION_MALFORMED,
    141                     dest);
    142             return false;
    143         }
    144     */
    145     /*
    146 
    147         if (strcmp(protocol, "dest") == 0) {
    148             if (strcmp(location, "stderr") == 0) {
    149                 if (logDest != NULL && logDest != stderr && logDest != stdout) {
    150                     fclose(logDest);
    151                 }
    152                 logDest = stderr;
    153                 return true;
    154             }
    155             if (strcmp(location, "stdout") == 0) {
    156                 if (logDest != NULL && logDest != stderr && logDest != stdout) {
    157                     fclose(logDest);
    158                 }
    159                 logDest = stdout;
    160                 return true;
    161             }
    162             psError(PS_ERR_LOCATION_INVALID, true, PS_ERRORTEXT_psLogMsg_DEST_LOCATION_INVALID,
    163                     location);
    164             return 1;
    165         } else if (strcmp(protocol, "file") == 0) {
    166             FILE *file = fopen(location, "w");
    167 
    168             if (file == NULL) {
    169                 psError(PS_ERR_IO, true, PS_ERRORTEXT_psLogMsg_OPEN_FILE_FAILED,
    170                         location);
    171                 return false;
    172             }
    173             if (logDest != NULL && logDest != stderr && logDest != stdout) {
    174                 fclose(logDest);
    175             }
    176             logDest = file;
    177             return true;
    178         }
    179     */
     126        //        return true;
     127    }
     128
    180129    return true;
    181130
     
    253202}
    254203
     204int psMessageDestination (const char *dest)
     205{
     206    char protocol[5];
     207    char location[257];
     208    if (logDest == (FILE *) 1) {
     209        logDest = stderr;
     210    }
     211
     212    if (dest == NULL || strcmp(dest, "none") == 0) {
     213        if (logDest != NULL && logDest != stderr && logDest != stdout) {
     214            fclose(logDest);
     215        }
     216        logDest = NULL;
     217        return 0;
     218    }
     219    if (sscanf(dest, "%4s:%256s", protocol, location) < 2) {
     220        psError(PS_ERR_LOCATION_INVALID, true,
     221                PS_ERRORTEXT_psLogMsg_DESTINATION_MALFORMED,
     222                dest);
     223        return -1;
     224    }
     225    if (strcmp(protocol, "dest") == 0) {
     226        if (strcmp(location, "stderr") == 0) {
     227            if (logDest != NULL && logDest != stderr && logDest != stdout) {
     228                fclose(logDest);
     229            }
     230            logDest = stderr;
     231            return 2;
     232        }
     233        if (strcmp(location, "stdout") == 0) {
     234            if (logDest != NULL && logDest != stderr && logDest != stdout) {
     235                fclose(logDest);
     236            }
     237            logDest = stdout;
     238            return 1;
     239        }
     240        psError(PS_ERR_LOCATION_INVALID, true, PS_ERRORTEXT_psLogMsg_DEST_LOCATION_INVALID,
     241                location);
     242        return -1;
     243    } else if (strcmp(protocol, "file") == 0) {
     244        //        FILE *file = fopen(location, "w");
     245        int fileD = creat(location, 0666);
     246
     247        if (fileD == 0) {
     248            psError(PS_ERR_IO, true, PS_ERRORTEXT_psLogMsg_OPEN_FILE_FAILED,
     249                    location);
     250            return -1;
     251        }
     252        if (logDest != NULL && logDest != stderr && logDest != stdout) {
     253            fclose(logDest);
     254        }
     255        logDest = fdopen(fileD, "w");
     256        return fileD;
     257    }
     258    return -1;
     259}
     260
    255261#ifndef HOST_NAME_MAX                // should be in limits.h
    256262#define HOST_NAME_MAX 256
Note: See TracChangeset for help on using the changeset viewer.