@@ -185,8 +185,9 @@ void timestamp_and_send(int pipe_fd, int fd, const char *prefix) {
185
185
186
186
// Send a message to the parent process to indicate that the child
187
187
// process has started
188
- if (snprintf (msg_payload .text , BUFFER_SIZE , "%s started" , prefix ) >= BUFFER_SIZE ) { // NOLINT
189
- _error ("Message truncated in timestamp_and_send" );
188
+ if (snprintf (msg_payload .text , BUFFER_SIZE , "%s started" , prefix ) >=
189
+ BUFFER_SIZE ) { // NOLINT
190
+ _error ("Message truncated in timestamp_and_send" );
190
191
}
191
192
msg_payload .timestamp .tv_sec = 0 ;
192
193
msg_payload .timestamp .tv_nsec = 0 ;
@@ -309,9 +310,10 @@ void process_msg_payload(FILE *stream, FILE *logfile, const char *color,
309
310
int hours = elapsed_sec / 3600 ;
310
311
int minutes = (elapsed_sec % 3600 ) / 60 ;
311
312
int seconds = elapsed_sec % 60 ;
312
- if (snprintf (timestamp , sizeof (timestamp ), "%02d:%02d:%02d.%06ld " , hours , minutes , seconds , // NOLINT
313
- (elapsed_nsec / 1000 )) >= sizeof (timestamp )) {
314
- _error ("Timestamp truncated in process_msg_payload" );
313
+ if (snprintf (timestamp , sizeof (timestamp ), "%02d:%02d:%02d.%06ld " , hours ,
314
+ minutes , seconds , // NOLINT
315
+ (elapsed_nsec / 1000 )) >= sizeof (timestamp )) {
316
+ _error ("Timestamp truncated in process_msg_payload" );
315
317
}
316
318
} else {
317
319
struct tm * time_info = localtime (& msg_payload -> timestamp .tv_sec );
@@ -326,8 +328,8 @@ void process_msg_payload(FILE *stream, FILE *logfile, const char *color,
326
328
size_t current_len = strlen (timestamp );
327
329
size_t remaining = sizeof (timestamp ) - current_len ;
328
330
if (snprintf (timestamp + current_len , remaining , ".%06ld " , // NOLINT
329
- msg_payload -> timestamp .tv_nsec / 1000 ) >= remaining ) {
330
- _error ("Nanoseconds truncated in process_msg_payload" );
331
+ msg_payload -> timestamp .tv_nsec / 1000 ) >= remaining ) {
332
+ _error ("Nanoseconds truncated in process_msg_payload" );
331
333
}
332
334
}
333
335
} else {
@@ -607,9 +609,9 @@ int main(int argc, char *argv[]) {
607
609
struct pollfd pfds [2 ];
608
610
nfds_t num_open_fds = 2 ; // We start with two open file descriptors
609
611
pfds [0 ].fd = stdout_msg_pipe [0 ];
610
- pfds [0 ].events = POLLIN ;
612
+ pfds [0 ].events = POLLIN | POLLHUP ;
611
613
pfds [1 ].fd = stderr_msg_pipe [0 ];
612
- pfds [1 ].events = POLLIN ;
614
+ pfds [1 ].events = POLLIN | POLLHUP ;
613
615
614
616
int loopcount = 0 ;
615
617
int ms_delta = 0 ;
@@ -650,7 +652,13 @@ int main(int argc, char *argv[]) {
650
652
msg -> msg_payload = msg_payload ;
651
653
push (& stdout_head , & stdout_tail , msg , & stdout_queuelen );
652
654
} else {
653
- perror ("read(stdout_msg_pipe[0])" );
655
+ if (pfds [0 ].revents & POLLHUP ) {
656
+ // POLLIN and POLLHUP both set, but reads are failing
657
+ // so stop polling for POLLIN events.
658
+ pfds [0 ].events = POLLHUP ;
659
+ } else {
660
+ perror ("read(stdout_msg_pipe[0])" );
661
+ }
654
662
}
655
663
} else if (pfds [0 ].revents & POLLHUP ) {
656
664
_debug (2 , "closing stdout_msg_pipe[0]" );
@@ -669,7 +677,13 @@ int main(int argc, char *argv[]) {
669
677
msg -> msg_payload = msg_payload ;
670
678
push (& stderr_head , & stderr_tail , msg , & stderr_queuelen );
671
679
} else {
672
- perror ("read(stderr_msg_pipe[0])" );
680
+ if (pfds [1 ].revents & POLLHUP ) {
681
+ // POLLIN and POLLHUP both set, but reads are failing
682
+ // so stop polling for POLLIN events.
683
+ pfds [1 ].events = POLLHUP ;
684
+ } else {
685
+ perror ("read(stderr_msg_pipe[0])" );
686
+ }
673
687
}
674
688
} else if (pfds [1 ].revents & POLLHUP ) {
675
689
_debug (2 , "closing stderr_msg_pipe[0]" );
0 commit comments