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))
                 (data (process-get proc :eshell-pending))
                 ;; Only get the status for the primary subprocess,
                 ;; not the pipe process (if any).
                 (status (when primary (process-exit-status proc)))
                 (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--mark-as-output 0 (length string) string)
              (eshell-interactive-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 ()
                        (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)))
                            (eshell-close-handles
                             status
                             (when status (list 'quote (= status 0)))
                             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)))))))
              (funcall finish-io)))
        (when-let ((entry (assq proc eshell-process-list)))
          (eshell-remove-process-entry entry))))))