Function: eshell-sentinel

eshell-sentinel is a byte-compiled function defined in esh-proc.el.gz.

Signature

(eshell-sentinel PROC STRING)

Documentation

Generic sentinel for command processes. Reports only signals.

PROC is the process that's exiting. STRING is the exit message.

Source Code

;; Defined in /usr/src/emacs/lisp/eshell/esh-proc.el.gz
(defun eshell-sentinel (proc string)
  "Generic sentinel for command processes.  Reports only signals.
PROC is the process that's exiting.  STRING is the exit message."
  (eshell-debug-command 'process
    "sentinel for external process `%s': %S" proc string)
  (when (and (buffer-live-p (process-buffer proc))
             (not (string= string "run")))
    (with-current-buffer (process-buffer proc)
      (unwind-protect
          (let* ((handles (process-get proc :eshell-handles))
                 (index (process-get proc :eshell-handle-index))
                 (primary (= index eshell-output-handle))
                 (set-exit-info (process-get proc :eshell-set-exit-info))
                 (data (process-get proc :eshell-pending))
                 (stderr-live (process-get proc :eshell-stderr-live)))
            ;; Write the exit message for the last process in the
            ;; foreground pipeline if its status is abnormal and
            ;; stderr is already writing to the terminal.
            (when (and (eq proc (eshell-tail-process))
                       (eshell-interactive-output-p eshell-error-handle handles)
                       (not (string-match "^\\(finished\\|exited\\)"
                                          string)))
              (eshell-interactive-output-filter (process-buffer proc) string))
            (process-put proc :eshell-pending nil)
            ;; If we're in the middle of handling output from this
            ;; process then schedule the EOF for later.
            (letrec ((wait-for-stderr (and primary
                                           (not (process-live-p proc))))
                     (finish-io
                      (lambda ()
                        (if (buffer-live-p (process-buffer proc))
                            (with-current-buffer (process-buffer proc)
                              (if (or (process-get proc :eshell-busy)
                                      (and wait-for-stderr (car stderr-live)))
                                  (progn
                                    (eshell-debug-command 'process
                                      "i/o busy for process `%s'" proc)
                                    (run-at-time 0 nil finish-io))
                                (when data
                                  (ignore-error eshell-pipe-broken
                                    (eshell-output-object
                                     data index handles)))
                                (when set-exit-info
                                  (let ((status (process-exit-status proc)))
                                    (eshell-set-exit-info status (= status 0))))
                                (eshell-close-handles handles)
                                ;; Clear the handles to mark that we're 100%
                                ;; finished with the I/O for this process.
                                (process-put proc :eshell-handles nil)
                                (eshell-debug-command 'process
                                  "finished external process `%s'" proc)
                                (if primary
                                    (run-hook-with-args 'eshell-kill-hook
                                                        proc string)
                                  (setcar stderr-live nil))))
                          (eshell-debug-command 'process
                            "buffer for external process `%s' already killed"
                            proc)))))
              (funcall finish-io)))
        (when-let* ((entry (assq proc eshell-process-list)))
          (eshell-remove-process-entry entry))))))