|
1 | 1 | /*****************************************************************************\ |
2 | | - * $Id: server-logfile.c,v 1.11.2.5 2003/10/01 23:22:10 dun Exp $ |
| 2 | + * $Id: server-logfile.c,v 1.11.2.6 2003/10/04 02:00:22 dun Exp $ |
3 | 3 | ***************************************************************************** |
4 | 4 | * Copyright (C) 2001-2002 The Regents of the University of California. |
5 | 5 | * Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER). |
@@ -165,6 +165,8 @@ int open_logfile_obj(obj_t *logfile, int gotTrunc) |
165 | 165 | free(now); |
166 | 166 | free(msg); |
167 | 167 |
|
| 168 | + logfile->aux.logfile.lineState = CONMAN_LOG_LINE_INIT; |
| 169 | + |
168 | 170 | DPRINTF((10, "Opened %s%slogfile \"%s\" for console [%s].\n", |
169 | 171 | (logfile->aux.logfile.opts.enableSanitize ? "SANITIZED " : ""), |
170 | 172 | (logfile->aux.logfile.opts.enableTimestamp ? "TIMESTAMPED " : ""), |
@@ -239,30 +241,43 @@ int write_log_data(obj_t *log, const void *src, int len) |
239 | 241 | * lonely CR to prevent characters from being overwritten. |
240 | 242 | */ |
241 | 243 | if (*p == '\r') { |
242 | | - if (log->aux.logfile.lineState == CONMAN_LOG_LINE_IN) |
| 244 | + if (log->aux.logfile.lineState == CONMAN_LOG_LINE_DATA) { |
243 | 245 | log->aux.logfile.lineState = CONMAN_LOG_LINE_CR; |
244 | | - else |
| 246 | + } |
| 247 | + else if (log->aux.logfile.lineState == CONMAN_LOG_LINE_INIT) { |
| 248 | + if (log->aux.logfile.opts.enableTimestamp) |
| 249 | + q += write_time_string(0, q, qLast - q); |
| 250 | + log->aux.logfile.lineState = CONMAN_LOG_LINE_CR; |
| 251 | + } |
| 252 | + else { |
245 | 253 | ; /* ignore */ |
| 254 | + } |
246 | 255 | } |
247 | 256 | else if (*p == '\n') { |
248 | | - log->aux.logfile.lineState = CONMAN_LOG_LINE_LF; |
| 257 | + if ( (log->aux.logfile.lineState == CONMAN_LOG_LINE_INIT) |
| 258 | + || (log->aux.logfile.lineState == CONMAN_LOG_LINE_LF) ) { |
| 259 | + if (log->aux.logfile.opts.enableTimestamp) |
| 260 | + q += write_time_string(0, q, qLast - q); |
| 261 | + } |
249 | 262 | *q++ = '\r'; |
250 | 263 | *q++ = '\n'; |
251 | | - if (log->aux.logfile.opts.enableTimestamp) |
252 | | - q += write_time_string(0, q, qLast - q); |
| 264 | + log->aux.logfile.lineState = CONMAN_LOG_LINE_LF; |
253 | 265 | } |
254 | 266 | else if ( (*p == '\0') |
255 | | - && (log->aux.logfile.lineState != CONMAN_LOG_LINE_IN) ) { |
| 267 | + && ( (log->aux.logfile.lineState == CONMAN_LOG_LINE_CR) |
| 268 | + || (log->aux.logfile.lineState == CONMAN_LOG_LINE_LF) ) ) { |
256 | 269 | ; /* ignore */ |
257 | 270 | } |
258 | 271 | else { |
259 | 272 | if (log->aux.logfile.lineState == CONMAN_LOG_LINE_CR) { |
260 | 273 | *q++ = '\r'; |
261 | 274 | *q++ = '\n'; |
| 275 | + } |
| 276 | + if (log->aux.logfile.lineState != CONMAN_LOG_LINE_DATA) { |
262 | 277 | if (log->aux.logfile.opts.enableTimestamp) |
263 | 278 | q += write_time_string(0, q, qLast - q); |
264 | 279 | } |
265 | | - log->aux.logfile.lineState = CONMAN_LOG_LINE_IN; |
| 280 | + log->aux.logfile.lineState = CONMAN_LOG_LINE_DATA; |
266 | 281 |
|
267 | 282 | if (log->aux.logfile.opts.enableSanitize) { |
268 | 283 |
|
|
0 commit comments