]> code.delx.au - gnu-emacs/blobdiff - lisp/net/tramp-sh.el
Merge from emacs-24; up to 2012-05-07T14:57:18Z!michael.albinus@gmx.de
[gnu-emacs] / lisp / net / tramp-sh.el
index a92f4231700ee8f31b2c51fb255240a40fa235a1..2c1af3e83faa4f196c404bee13a74a845aa348f6 100644 (file)
@@ -512,9 +512,9 @@ detected as prompt when being sent on echoing hosts, therefore.")
 ;; IRIX64: /usr/bin
 ;;;###tramp-autoload
 (defcustom tramp-remote-path
-  '(tramp-default-remote-path "/bin" "/usr/bin" "/usr/sbin"
-    "/usr/local/bin" "/local/bin" "/local/freeware/bin" "/local/gnu/bin"
-    "/usr/freeware/bin" "/usr/pkg/bin" "/usr/contrib/bin"
+  '(tramp-default-remote-path "/bin" "/usr/bin" "/sbin" "/usr/sbin"
+    "/usr/local/bin" "/usr/local/sbin" "/local/bin" "/local/freeware/bin"
+    "/local/gnu/bin" "/usr/freeware/bin" "/usr/pkg/bin" "/usr/contrib/bin"
     "/opt/bin" "/opt/sbin" "/opt/local/bin")
   "List of directories to search for executables on remote host.
 For every remote host, this variable will be set buffer local,
@@ -2738,51 +2738,64 @@ the result will be a local, non-Tramp, filename."
          (bmp (and (buffer-live-p buffer) (buffer-modified-p buffer)))
          (name1 name)
          (i 0))
-      (unwind-protect
-         (save-excursion
-           (save-restriction
-             (unless buffer
-               ;; BUFFER can be nil.  We use a temporary buffer.
-               (setq buffer (generate-new-buffer tramp-temp-buffer-name)))
-             (while (get-process name1)
-               ;; NAME must be unique as process name.
-               (setq i (1+ i)
-                     name1 (format "%s<%d>" name i)))
-             (setq name name1)
-             ;; Set the new process properties.
-             (tramp-set-connection-property v "process-name" name)
-             (tramp-set-connection-property v "process-buffer" buffer)
-             ;; Activate narrowing in order to save BUFFER contents.
-             ;; Clear also the modification time; otherwise we might
-             ;; be interrupted by `verify-visited-file-modtime'.
-             (with-current-buffer (tramp-get-connection-buffer v)
-               (let ((buffer-undo-list t))
+
+      (unless buffer
+       ;; BUFFER can be nil.  We use a temporary buffer.
+       (setq buffer (generate-new-buffer tramp-temp-buffer-name)))
+      (while (get-process name1)
+       ;; NAME must be unique as process name.
+       (setq i (1+ i)
+             name1 (format "%s<%d>" name i)))
+      (setq name name1)
+      ;; Set the new process properties.
+      (tramp-set-connection-property v "process-name" name)
+      (tramp-set-connection-property v "process-buffer" buffer)
+
+      (with-current-buffer (tramp-get-connection-buffer v)
+       (unwind-protect
+           (save-excursion
+             (save-restriction
+               ;; Activate narrowing in order to save BUFFER
+               ;; contents.  Clear also the modification time;
+               ;; otherwise we might be interrupted by
+               ;; `verify-visited-file-modtime'.
+               (let ((buffer-undo-list t)
+                     (buffer-read-only nil)
+                     (mark (point)))
                  (clear-visited-file-modtime)
                  (narrow-to-region (point-max) (point-max))
+                 ;; We call `tramp-maybe-open-connection', in order
+                 ;; to cleanup the prompt afterwards.
+                 (tramp-maybe-open-connection v)
+                 (widen)
+                 (delete-region mark (point))
+                 (narrow-to-region (point-max) (point-max))
+                 ;; Now do it.
                  (if command
                      ;; Send the command.
                      (tramp-send-command v command nil t) ; nooutput
                    ;; Check, whether a pty is associated.
-                   (tramp-maybe-open-connection v)
                    (unless (tramp-compat-process-get
                             (tramp-get-connection-process v) 'remote-tty)
                      (tramp-error
                       v 'file-error
-                      "pty association is not supported for `%s'" name)))))
-             (let ((p (tramp-get-connection-process v)))
-               ;; Set query flag for this process.
-               (tramp-compat-set-process-query-on-exit-flag p t)
-               ;; Return process.
-               p)))
-       ;; Save exit.
-       (with-current-buffer (tramp-get-connection-buffer v)
+                      "pty association is not supported for `%s'" name))))
+               (let ((p (tramp-get-connection-process v)))
+                 ;; Set query flag for this process.  We ignore errors,
+                 ;; because the process could have finished already.
+                 (ignore-errors
+                   (tramp-compat-set-process-query-on-exit-flag p t))
+                 ;; Return process.
+                 p)))
+
+         ;; Save exit.
          (if (string-match tramp-temp-buffer-name (buffer-name))
              (progn
                (set-process-buffer (tramp-get-connection-process v) nil)
                (kill-buffer (current-buffer)))
-           (set-buffer-modified-p bmp)))
-       (tramp-set-connection-property v "process-name" nil)
-       (tramp-set-connection-property v "process-buffer" nil)))))
+           (set-buffer-modified-p bmp))
+         (tramp-set-connection-property v "process-name" nil)
+         (tramp-set-connection-property v "process-buffer" nil))))))
 
 (defun tramp-sh-handle-process-file
   (program &optional infile destination display &rest args)
@@ -3599,11 +3612,14 @@ file exists and nonzero exit status otherwise."
        (setq item (pop alist))
        (when (string-match (car item) shell)
          (setq extra-args (cdr item))))
-      (when extra-args (setq shell (concat shell " " extra-args)))
       (tramp-send-command
-       vec (format "exec env ENV='' PROMPT_COMMAND='' PS1=%s PS2='' PS3='' %s"
-                  (tramp-shell-quote-argument tramp-end-of-output) shell)
+       vec (format
+           "exec env ENV='' PROMPT_COMMAND='' PS1=%s PS2='' PS3='' %s %s"
+           (tramp-shell-quote-argument tramp-end-of-output)
+           shell (or extra-args ""))
        t))
+    (tramp-set-connection-property
+     (tramp-get-connection-process vec) "remote-shell" shell)
     ;; Setting prompts.
     (tramp-send-command
      vec (format "PS1=%s" (tramp-shell-quote-argument tramp-end-of-output)) t)
@@ -3614,8 +3630,12 @@ file exists and nonzero exit status otherwise."
 (defun tramp-find-shell (vec)
   "Opens a shell on the remote host which groks tilde expansion."
   (with-current-buffer (tramp-get-buffer vec)
-    (let ((default-shell (tramp-get-method-parameter
-                         (tramp-file-name-method vec) 'tramp-remote-shell))
+    (let ((default-shell
+           (or
+            (tramp-get-connection-property
+             (tramp-get-connection-process vec) "remote-shell" nil)
+            (tramp-get-method-parameter
+             (tramp-file-name-method vec) 'tramp-remote-shell)))
          shell)
       (setq shell
            (with-connection-property vec "remote-shell"
@@ -3692,8 +3712,9 @@ process to set up.  VEC specifies the connection."
     ;; discarded as well.
     (tramp-open-shell
      vec
-     (tramp-get-method-parameter
-      (tramp-file-name-method vec) 'tramp-remote-shell))
+     (or (tramp-get-connection-property vec "remote-shell" nil)
+        (tramp-get-method-parameter
+         (tramp-file-name-method vec) 'tramp-remote-shell)))
 
     ;; Disable echo.
     (tramp-message vec 5 "Setting up remote shell environment")