Changeset 4951 for trunk/psLib/src/sys/psLogMsg.c
- Timestamp:
- Sep 6, 2005, 2:15:51 PM (21 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/sys/psLogMsg.c (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/sys/psLogMsg.c
r4540 r4951 12 12 * @author GLG, MHPCC 13 13 * 14 * @version $Revision: 1.4 8$ $Name: not supported by cvs2svn $15 * @date $Date: 2005-0 7-12 19:12:01$14 * @version $Revision: 1.49 $ $Name: not supported by cvs2svn $ 15 * @date $Date: 2005-09-07 00:15:48 $ 16 16 * 17 17 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 37 37 #include <time.h> 38 38 #include <unistd.h> 39 #include <fcntl.h> 39 40 40 41 #include "psLogMsg.h" … … 87 88 An psBool: TRUE if successful. 88 89 *****************************************************************************/ 89 bool psLogSetDestination( const char *dest)90 bool psLogSetDestination(int fd) 90 91 { 91 char protocol[5]; 92 char location[257]; 93 92 // char protocol[5]; 93 // char location[257]; 94 // char dest[257]; 95 FILE *fp; 94 96 // if logDest has not been initialized, do so before using it 95 97 if (logDest == (FILE *) 1) { … … 97 99 } 98 100 99 if (dest == NULL || strcmp(dest, "none") == 0) { 101 if ( fd == 1 ) { 102 // fp = stdout; 100 103 if (logDest != NULL && logDest != stderr && logDest != stdout) { 101 104 fclose(logDest); 102 105 } 106 logDest = stdout; 107 } else if (fd == 2) { 108 // fp = stderr; 109 if (logDest != NULL && logDest != stderr && logDest != stdout) { 110 fclose(logDest); 111 } 112 logDest = stderr; 113 } else if (fd == 0) { 114 // fp = NULL; 115 if (logDest != NULL && logDest != stderr && logDest != stdout) { 116 fclose(logDest); 117 } 103 118 logDest = NULL; 104 119 return true; 105 } 106 107 if (sscanf(dest, "%4s:%256s", protocol, location) < 2) { 108 psError(PS_ERR_LOCATION_INVALID, true, 109 PS_ERRORTEXT_psLogMsg_DESTINATION_MALFORMED, 110 dest); 111 return false; 112 } 113 114 if (strcmp(protocol, "dest") == 0) { 115 if (strcmp(location, "stderr") == 0) { 120 } else if (fd > 2) { 121 if (logDest != NULL && logDest != stderr && logDest != stdout) { 122 fclose(logDest); 123 } 124 fp = fdopen(fd, "w"); 125 logDest = fp; 126 // fclose(fp); 127 return true; 128 } 129 130 /* 131 if (dest == NULL || strcmp(dest, "none") == 0) { 116 132 if (logDest != NULL && logDest != stderr && logDest != stdout) { 117 133 fclose(logDest); 118 134 } 119 logDest = stderr;135 logDest = NULL; 120 136 return true; 121 137 } 122 if (strcmp(location, "stdout") == 0) { 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 } 123 173 if (logDest != NULL && logDest != stderr && logDest != stdout) { 124 174 fclose(logDest); 125 175 } 126 logDest = stdout;176 logDest = file; 127 177 return true; 128 178 } 129 psError(PS_ERR_LOCATION_INVALID, true, PS_ERRORTEXT_psLogMsg_DEST_LOCATION_INVALID, 130 location); 131 return 1; 132 } else if (strcmp(protocol, "file") == 0) { 133 FILE *file = fopen(location, "w"); 134 135 if (file == NULL) { 136 psError(PS_ERR_IO, true, PS_ERRORTEXT_psLogMsg_OPEN_FILE_FAILED, 137 location); 138 return false; 139 } 140 if (logDest != NULL && logDest != stderr && logDest != stdout) { 141 fclose(logDest); 142 } 143 logDest = file; 144 return true; 145 } 146 147 psError(PS_ERR_LOCATION_INVALID, true, PS_ERRORTEXT_psLogMsg_UNSUPPORTED_PROTOCOL, 148 protocol); 149 return false; 179 */ 180 return true; 181 150 182 } 151 183
Note:
See TracChangeset
for help on using the changeset viewer.
