Unsightly errors due to race on closing stdin when handling signals in s6-log

From: Earl Chew <earl_chew_at_yahoo.com>
Date: Wed, 22 Dec 2021 21:49:50 -0800

I saw the recent announcement for "Winter 2021-2022 release" and started
poking around to update my deployments.

While doing so I see I have the following commit that I had neglected to
forward to the mailing list.

IIRC the use case involves signal handling, which causes
prepare_to_exit() to be called in handle_signals(). Once the signal
handler returns, stdin is closed. The mainline continues to refer to the
now closed file descriptor, and emits errors as consequence. The process
terminates, but the path to exit is unsightly.

Earl


diff --git a/src/daemontools-extras/s6-log.c
b/src/daemontools-extras/s6-log.c
index 92e3886..9b91ce0 100644
--- a/src/daemontools-extras/s6-log.c
+++ b/src/daemontools-extras/s6-log.c
_at__at_ -1010,7 +1010,11 _at__at_ static void script_run (scriptelem_t const
*script, unsigned int scriptlen, char

  static void prepare_to_exit (void)
  {
+  int fd ;
    fd_close(0) ;
+  fd = open_read("/dev/null") ;
+  if (fd < 0) strerr_warnwu1sys("reopen stdin") ;
+  else if (fd_move(0, fd)) strerr_warnwu1sys("move stdin") ;
    flagexiting = 1 ;
  }
Received on Thu Dec 23 2021 - 06:49:50 CET

This archive was generated by hypermail 2.4.0 : Thu Dec 23 2021 - 06:50:28 CET