* lisp/net/tramp-compat.el (tramp-compat-process-live-p): New defun.
* lisp/net/tramp.el (tramp-connectable-p, tramp-handle-file-remote-p)
(tramp-handle-file-notify-valid-p)
(tramp-action-process-alive, tramp-action-out-of-band)
(tramp-wait-for-regexp):
* lisp/net/tramp-adb.el (tramp-adb-parse-device-names)
(tramp-adb-maybe-open-connection):
* lisp/net/tramp-cache.el (tramp-get-connection-property):
* tramp-gvfs.el (tramp-gvfs-handle-file-notify-add-watch):
* lisp/net/tramp-gw.el (tramp-gw-gw-proc-sentinel)
(tramp-gw-aux-proc-sentinel, tramp-gw-open-connection):
* tramp-sh.el (tramp-process-sentinel)
(tramp-sh-handle-file-notify-add-watch)
(tramp-maybe-open-connection):
* lisp/net/lisp/net/lisp/net/tramp-smb.el (tramp-smb-action-with-tar)
(tramp-smb-handle-copy-directory, tramp-smb-action-get-acl)
(tramp-smb-handle-process-file, tramp-smb-action-set-acl)
(tramp-smb-get-cifs-capabilities)
(tramp-smb-get-stat-capability)
(tramp-smb-maybe-open-connection, tramp-smb-wait-for-output)
(tramp-smb-kill-winexe-function): Use it.
result)
(tramp-message v 6 "%s" (mapconcat 'identity (process-command p) " "))
(set-process-query-on-exit-flag p nil)
- (while (eq 'run (process-status p))
+ (while (tramp-compat-process-live-p p)
(accept-process-output p 0.1))
(accept-process-output p 0.1)
(tramp-message v 6 "\n%s" (buffer-string))
(when (and user (not (tramp-get-file-property vec "" "su-command-p" t)))
(tramp-error vec 'file-error "Cannot switch to user `%s'" user))
- (unless
- (and p (processp p) (memq (process-status p) '(run open)))
+ (unless (tramp-compat-process-live-p p)
(save-match-data
(when (and p (processp p)) (delete-process p))
(if (zerop (length device))
vec 6 "%s" (mapconcat 'identity (process-command p) " "))
;; Wait for initial prompt.
(tramp-adb-wait-for-output p 30)
- (unless (eq 'run (process-status p))
+ (unless (tramp-compat-process-live-p p)
(tramp-error vec 'file-error "Terminated!"))
(tramp-set-connection-property p "vector" vec)
(set-process-query-on-exit-flag p nil)
(value
;; If the key is an auxiliary process object, check whether
;; the process is still alive.
- (if (and (processp key) (not (memq (process-status key) '(run open))))
+ (if (and (processp key) (not (tramp-compat-process-live-p key)))
default
(if (hash-table-p hash)
(gethash property hash default)
process-name))))
(setq result t)))))))))
+;; `process-running-live-p' is introduced in Emacs 24.
+(defalias 'tramp-compat-process-live-p
+ (if (fboundp 'process-running-live-p)
+ 'process-running-live-p
+ (lambda (process)
+ "Returns non-nil if PROCESS is alive.
+A process is considered alive if its status is `run', `open',
+`listen', `connect' or `stop'. Value is nil if PROCESS is not a
+process."
+ (and (processp process)
+ (memq (process-status process)
+ '(run open listen connect stop))))))
+
;; `default-toplevel-value' has been declared in Emacs 24.
(unless (fboundp 'default-toplevel-value)
(defalias 'default-toplevel-value 'symbol-value))
;; There might be an error if the monitor is not supported.
;; Give the filter a chance to read the output.
(tramp-accept-process-output p 1)
- (unless (memq (process-status p) '(run open))
+ (unless (tramp-compat-process-live-p p)
(tramp-error
v 'file-notify-error "Monitoring not supported for `%s'" file-name))
p))))
(defun tramp-gw-gw-proc-sentinel (proc _event)
"Delete auxiliary process when we are deleted."
- (unless (memq (process-status proc) '(run open))
+ (unless (tramp-compat-process-live-p proc)
(tramp-message
tramp-gw-vector 4 "Deleting auxiliary process `%s'" tramp-gw-gw-proc)
(let* ((tramp-verbose 0)
(defun tramp-gw-aux-proc-sentinel (proc _event)
"Activate the different filters for involved gateway and auxiliary processes."
- (when (memq (process-status proc) '(run open))
+ (when (tramp-compat-process-live-p proc)
;; A new process has been spawned from `tramp-gw-aux-proc'.
(tramp-message
tramp-gw-vector 4
tramp-gw-gw-vector gw-vec)
;; Start listening auxiliary process.
- (unless (and (processp tramp-gw-aux-proc)
- (memq (process-status tramp-gw-aux-proc) '(listen)))
+ (unless (tramp-compat-process-live-p tramp-gw-aux-proc)
(let ((aux-vec
(vector "aux" (tramp-file-name-user gw-vec)
(tramp-file-name-host gw-vec) nil nil)))
(defun tramp-process-sentinel (proc event)
"Flush file caches."
- (unless (memq (process-status proc) '(run open))
+ (unless (tramp-compat-process-live-p proc)
(let ((vec (tramp-get-connection-property proc "vector" nil)))
(when vec
(tramp-message vec 5 "Sentinel called: `%S' `%s'" proc event)
;; There might be an error if the monitor is not supported.
;; Give the filter a chance to read the output.
(tramp-accept-process-output p 1)
- (unless (memq (process-status p) '(run open))
+ (unless (tramp-compat-process-live-p p)
(tramp-error
v 'file-notify-error "Monitoring not supported for `%s'" file-name))
p))))
;; If Tramp opens the same connection within a short time frame,
;; there is a problem. We shall signal this.
- (unless (or (and p (processp p) (memq (process-status p) '(run open)))
+ (unless (or (tramp-compat-process-live-p p)
(not (equal (butlast (append vec nil) 2)
(car tramp-current-connection)))
(> (tramp-time-diff
(tramp-get-connection-property
p "last-cmd-time" '(0 0 0)))
60)
- p (processp p) (memq (process-status p) '(run open)))
+ (tramp-compat-process-live-p p))
(tramp-send-command vec "echo are you awake" t t)
- (unless (and (memq (process-status p) '(run open))
+ (unless (and (tramp-compat-process-live-p p)
(tramp-wait-for-output p 10))
;; The error will be caught locally.
(tramp-error vec 'file-error "Awake did fail")))
;; New connection must be opened.
(condition-case err
- (unless (and p (processp p) (memq (process-status p) '(run open)))
+ (unless (tramp-compat-process-live-p p)
;; If `non-essential' is non-nil, don't reopen a new connection.
;; This variable has been introduced with Emacs 24.1.
(defun tramp-smb-action-with-tar (proc vec)
"Untar from connection buffer."
- (if (not (memq (process-status proc) '(run open)))
+ (if (not (tramp-compat-process-live-p proc))
(throw 'tramp-action 'process-died)
(with-current-buffer (tramp-get-connection-buffer vec)
(set-process-query-on-exit-flag p nil)
(tramp-process-actions p v nil tramp-smb-actions-with-tar)
- (while (memq (process-status p) '(run open))
+ (while (tramp-compat-process-live-p p)
(sit-for 0.1))
(tramp-message v 6 "\n%s" (buffer-string))))
(defun tramp-smb-action-get-acl (proc vec)
"Read ACL data from connection buffer."
- (when (not (memq (process-status proc) '(run open)))
+ (unless (tramp-compat-process-live-p proc)
;; Accept pending output.
(while (tramp-accept-process-output proc 0.1))
(with-current-buffer (tramp-get-connection-buffer vec)
(narrow-to-region (point-max) (point-max))
(let ((p (tramp-get-connection-process v)))
(tramp-smb-send-command v "exit $lasterrorcode")
- (while (memq (process-status p) '(run open))
+ (while (tramp-compat-process-live-p p)
(sleep-for 0.1)
(setq ret (process-exit-status p))))
(delete-region (point-min) (point-max))
(defun tramp-smb-action-set-acl (proc vec)
"Read ACL data from connection buffer."
- (when (not (memq (process-status proc) '(run open)))
+ (unless (tramp-compat-process-live-p proc)
;; Accept pending output.
(while (tramp-accept-process-output proc 0.1))
(with-current-buffer (tramp-get-connection-buffer vec)
(defun tramp-smb-get-cifs-capabilities (vec)
"Check, whether the SMB server supports POSIX commands."
;; When we are not logged in yet, we return nil.
- (if (let ((p (tramp-get-connection-process vec)))
- (and p (processp p) (memq (process-status p) '(run open))))
+ (if (tramp-compat-process-live-p (tramp-get-connection-process vec))
(with-tramp-connection-property
(tramp-get-connection-process vec) "cifs-capabilities"
(save-match-data
"Check, whether the SMB server supports the STAT command."
;; When we are not logged in yet, we return nil.
(if (and (tramp-smb-get-share vec)
- (let ((p (tramp-get-connection-process vec)))
- (and p (processp p) (memq (process-status p) '(run open)))))
+ (tramp-compat-process-live-p (tramp-get-connection-process vec)))
(with-tramp-connection-property
(tramp-get-connection-process vec) "stat-capability"
(tramp-smb-send-command vec "stat \"/\""))))
(tramp-get-connection-property
p "last-cmd-time" '(0 0 0)))
60)
- p (processp p) (memq (process-status p) '(run open))
+ (tramp-compat-process-live-p p)
(re-search-forward tramp-smb-errors nil t))
(delete-process p)
(setq p nil)))
;; Check whether it is still the same share.
- (unless
- (and p (processp p) (memq (process-status p) '(run open))
- (or argument
- (string-equal
- share
- (tramp-get-connection-property p "smb-share" ""))))
+ (unless (and (tramp-compat-process-live-p p)
+ (or argument
+ (string-equal
+ share
+ (tramp-get-connection-property p "smb-share" ""))))
(save-match-data
;; There might be unread output from checking for share names.
;; Algorithm: get waiting output. See if last line contains
;; `tramp-smb-prompt' sentinel or `tramp-smb-errors' strings.
;; If not, wait a bit and again get waiting output.
- (while (and (not found) (not err) (memq (process-status p) '(run open)))
+ (while (and (not found) (not err) (tramp-compat-process-live-p p))
;; Accept pending output.
(tramp-accept-process-output p 0.1)
(setq err (re-search-forward tramp-smb-errors nil t)))
;; When the process is still alive, read pending output.
- (while (and (not found) (memq (process-status p) '(run open)))
+ (while (and (not found) (tramp-compat-process-live-p p))
;; Accept pending output.
(tramp-accept-process-output p 0.1)
"Send SIGKILL to the winexe process."
(ignore-errors
(let ((p (get-buffer-process (current-buffer))))
- (when (and p (processp p) (memq (process-status p) '(run open)))
+ (when (tramp-compat-process-live-p p)
(signal-process (process-id p) 'SIGINT)))))
(defun tramp-smb-call-winexe (vec)
(erase-buffer)
(let ((proc (start-process (buffer-name) (current-buffer)
\"ssh\" \"-l\" user host \"wc\" \"-c\")))
- (when (memq (process-status proc) \\='(run open))
+ (when (process-live-p proc)
(process-send-string proc (make-string sent ?\\ ))
(process-send-eof proc)
(process-send-eof proc))
(while (not (progn (goto-char (point-min))
(re-search-forward \"\\\\w+\" (point-max) t)))
(accept-process-output proc 1))
- (when (memq (process-status proc) \\='(run open))
+ (when (process-live-p proc)
(setq received (string-to-number (match-string 0)))
(delete-process proc)
(message \"Bytes sent: %s\\tBytes received: %s\" sent received)
This is true, if either the remote host is already connected, or if we are
not in completion mode."
(and (tramp-tramp-file-p filename)
- (with-parsed-tramp-file-name filename nil
- (or (not (tramp-completion-mode-p))
- (let* ((tramp-verbose 0)
- (p (tramp-get-connection-process v)))
- (and p (processp p) (memq (process-status p) '(run open))))))))
+ (or (not (tramp-completion-mode-p))
+ (tramp-compat-process-live-p
+ (tramp-get-connection-process
+ (tramp-dissect-file-name filename))))))
(defun tramp-completion-handle-expand-file-name (name &optional dir)
"Like `expand-file-name' for Tramp files."
(when (tramp-tramp-file-p filename)
(let* ((v (tramp-dissect-file-name filename))
(p (tramp-get-connection-process v))
- (c (and p (processp p) (memq (process-status p) '(run open))
+ (c (and (tramp-compat-process-live-p p)
(tramp-get-connection-property p "connected" nil))))
;; We expand the file name only, if there is already a connection.
(with-parsed-tramp-file-name
(defun tramp-handle-file-notify-valid-p (proc)
"Like `file-notify-valid-p' for Tramp files."
- (and proc (processp proc) (memq (process-status proc) '(run open))
+ (and (tramp-compat-process-live-p proc)
;; Sometimes, the process is still in status `run' when the
;; file or directory to be watched is deleted already.
(with-current-buffer (process-buffer proc)
(defun tramp-action-process-alive (proc _vec)
"Check, whether a process has finished."
- (unless (memq (process-status proc) '(run open))
+ (unless (tramp-compat-process-live-p proc)
(throw 'tramp-action 'process-died)))
(defun tramp-action-out-of-band (proc vec)
"Check, whether an out-of-band copy has finished."
;; There might be pending output for the exit status.
(tramp-accept-process-output proc 0.1)
- (cond ((and (memq (process-status proc) '(stop exit))
+ (cond ((and (not (tramp-compat-process-live-p proc))
(zerop (process-exit-status proc)))
(tramp-message vec 3 "Process has finished.")
(throw 'tramp-action 'ok))
(with-timeout (timeout)
(while (not found)
(tramp-accept-process-output proc 1)
- (unless (memq (process-status proc) '(run open))
+ (unless (tramp-compat-process-live-p proc)
(tramp-error-with-buffer
nil proc 'file-error "Process has died"))
(setq found (tramp-check-for-regexp proc regexp)))))
(t
(while (not found)
(tramp-accept-process-output proc 1)
- (unless (memq (process-status proc) '(run open))
+ (unless (tramp-compat-process-live-p proc)
(tramp-error-with-buffer
nil proc 'file-error "Process has died"))
(setq found (tramp-check-for-regexp proc regexp)))))