Skip to content

Commit d25d81b

Browse files
committed
Fixed newline timestamping so that the timestamp is associated with the first
char output on the line instead of the preceding newline transition char.
1 parent 0b1f6a4 commit d25d81b

File tree

4 files changed

+45
-13
lines changed

4 files changed

+45
-13
lines changed

ChangeLog

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
1+
2003-10-03 Chris Dunlap <cdunlap@llnl.gov>
2+
3+
* server-logfile.c, server-obj.c, server.h: Fixed newline timestamping
4+
so that the timestamp is associated with the first character output on
5+
the line instead of the preceding newline transition character.
6+
17
2003-10-01 Chris Dunlap <cdunlap@llnl.gov>
28

9+
* : Released 0.1.8.7.
10+
311
* client-tty.c, common.h, server-conf.c, server-esc.c,
412
server-logfile.c, server-obj.c, server.h, etc/conman.conf,
513
man/conman.1.in, man/conman.conf.5.in: Changed console log newline
@@ -27,7 +35,7 @@
2735
2003-09-22 Chris Dunlap <cdunlap@llnl.gov>
2836

2937
* common.c, man/conman.1.in, man/conman.conf.5.in, man/conmand.8.in:
30-
Updated copyright.
38+
Updated copyright.
3139

3240
2003-07-24 Chris Dunlap <cdunlap@llnl.gov>
3341

server-logfile.c

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*****************************************************************************\
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 $
33
*****************************************************************************
44
* Copyright (C) 2001-2002 The Regents of the University of California.
55
* Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER).
@@ -165,6 +165,8 @@ int open_logfile_obj(obj_t *logfile, int gotTrunc)
165165
free(now);
166166
free(msg);
167167

168+
logfile->aux.logfile.lineState = CONMAN_LOG_LINE_INIT;
169+
168170
DPRINTF((10, "Opened %s%slogfile \"%s\" for console [%s].\n",
169171
(logfile->aux.logfile.opts.enableSanitize ? "SANITIZED " : ""),
170172
(logfile->aux.logfile.opts.enableTimestamp ? "TIMESTAMPED " : ""),
@@ -239,30 +241,43 @@ int write_log_data(obj_t *log, const void *src, int len)
239241
* lonely CR to prevent characters from being overwritten.
240242
*/
241243
if (*p == '\r') {
242-
if (log->aux.logfile.lineState == CONMAN_LOG_LINE_IN)
244+
if (log->aux.logfile.lineState == CONMAN_LOG_LINE_DATA) {
243245
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 {
245253
; /* ignore */
254+
}
246255
}
247256
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+
}
249262
*q++ = '\r';
250263
*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;
253265
}
254266
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) ) ) {
256269
; /* ignore */
257270
}
258271
else {
259272
if (log->aux.logfile.lineState == CONMAN_LOG_LINE_CR) {
260273
*q++ = '\r';
261274
*q++ = '\n';
275+
}
276+
if (log->aux.logfile.lineState != CONMAN_LOG_LINE_DATA) {
262277
if (log->aux.logfile.opts.enableTimestamp)
263278
q += write_time_string(0, q, qLast - q);
264279
}
265-
log->aux.logfile.lineState = CONMAN_LOG_LINE_IN;
280+
log->aux.logfile.lineState = CONMAN_LOG_LINE_DATA;
266281

267282
if (log->aux.logfile.opts.enableSanitize) {
268283

server-obj.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*****************************************************************************\
2-
* $Id: server-obj.c,v 1.70.2.5 2003/10/01 23:22:10 dun Exp $
2+
* $Id: server-obj.c,v 1.70.2.6 2003/10/04 02:00:22 dun Exp $
33
*****************************************************************************
44
* Copyright (C) 2001-2002 The Regents of the University of California.
55
* Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER).
@@ -186,7 +186,7 @@ obj_t * create_logfile_obj(server_conf_t *conf, char *name,
186186
}
187187
logfile = create_obj(conf, name, -1, CONMAN_OBJ_LOGFILE);
188188
logfile->aux.logfile.console = console;
189-
logfile->aux.logfile.lineState = CONMAN_LOG_LINE_IN;
189+
logfile->aux.logfile.lineState = CONMAN_LOG_LINE_INIT;
190190
logfile->aux.logfile.opts = *opts;
191191

192192
if ( (logfile->aux.logfile.opts.enableSanitize)
@@ -1376,6 +1376,14 @@ int write_obj_data(obj_t *obj, const void *src, int len, int isInfo)
13761376
assert(obj->bufOutPtr < &obj->buf[MAX_BUF_SIZE]);
13771377

13781378
x_pthread_mutex_unlock(&obj->bufLock);
1379+
1380+
/* If an informational message has been added to the log,
1381+
* re-initialize the console log's newline state.
1382+
*/
1383+
if (isInfo && is_logfile_obj(obj)) {
1384+
obj->aux.logfile.lineState = CONMAN_LOG_LINE_INIT;
1385+
}
1386+
13791387
return(len);
13801388
}
13811389

server.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*****************************************************************************\
2-
* $Id: server.h,v 1.55.2.4 2003/10/01 23:22:10 dun Exp $
2+
* $Id: server.h,v 1.55.2.5 2003/10/04 02:00:22 dun Exp $
33
*****************************************************************************
44
* Copyright (C) 2001-2002 The Regents of the University of California.
55
* Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER).
@@ -83,7 +83,8 @@ typedef struct logfile_opt { /* LOGFILE OBJ OPTIONS: */
8383
} logopt_t;
8484

8585
typedef enum logfile_line_state { /* log CR/LF newline state (2 bits) */
86-
CONMAN_LOG_LINE_IN,
86+
CONMAN_LOG_LINE_INIT,
87+
CONMAN_LOG_LINE_DATA,
8788
CONMAN_LOG_LINE_CR,
8889
CONMAN_LOG_LINE_LF
8990
} log_line_state_t;

0 commit comments

Comments
 (0)