+
+ }
+
+ if (process_signalfd) {
+ struct signalfd_siginfo sfsi;
+ ssize_t n;
+
+ n = read(signal_fd, &sfsi, sizeof(sfsi));
+ if (n != sizeof(sfsi)) {
+
+ if (n >= 0) {
+ log_error("Failed to read from signalfd: invalid block size");
+ return -EIO;
+ }
+
+ if (errno != EINTR && errno != EAGAIN) {
+ log_error("Failed to read from signalfd: %m");
+ return -errno;
+ }
+ } else {
+
+ if (sfsi.ssi_signo == SIGWINCH) {
+ struct winsize ws;
+
+ /* The window size changed, let's forward that. */
+ if (ioctl(STDIN_FILENO, TIOCGWINSZ, &ws) >= 0)
+ ioctl(master, TIOCSWINSZ, &ws);
+
+ } else if (sfsi.ssi_signo == SIGTERM && kill_pid > 0 && signo > 0 && !tried_orderly_shutdown) {
+
+ if (kill(kill_pid, signo) < 0)
+ quit = true;
+ else {
+ log_info("Trying to halt container. Send SIGTERM again to trigger immediate termination.");
+
+ /* This only works for systemd... */
+ tried_orderly_shutdown = true;
+ }
+
+ } else
+ /* Signals that where
+ * delivered via signalfd that
+ * we didn't know are a reason
+ * for us to quit */
+ quit = true;
+ }
+ }
+
+ if (stdin_hangup || stdout_hangup || master_hangup) {
+ /* Exit the loop if any side hung up and if
+ * there's nothing more to write or nothing we
+ * could write. */
+
+ if ((out_buffer_full <= 0 || stdout_hangup) &&
+ (in_buffer_full <= 0 || master_hangup))
+ return !quit;