* net/tramp-sh.el (tramp-open-connection-setup-interactive-shell)
[bpt/emacs.git] / lisp / net / tramp-sh.el
index 1c6f084..428bd64 100644 (file)
@@ -3457,8 +3457,10 @@ Fall back to normal file name handler if no Tramp handler exists."
 (defun tramp-maybe-send-script (vec script name)
   "Define in remote shell function NAME implemented as SCRIPT.
 Only send the definition if it has not already been done."
-  (let* ((p (tramp-get-connection-process vec))
-        (scripts (tramp-get-connection-property p "scripts" nil)))
+  ;; We cannot let-bind (tramp-get-connection-process vec) because it
+  ;; might be nil.
+  (let ((scripts (tramp-get-connection-property
+                 (tramp-get-connection-process vec) "scripts" nil)))
     (unless (member name scripts)
       (tramp-with-progress-reporter vec 5 (format "Sending script `%s'" name)
        ;; The script could contain a call of Perl.  This is masked with `%s'.
@@ -3467,7 +3469,8 @@ Only send the definition if it has not already been done."
         (format "%s () {\n%s\n}" name
                 (format script (tramp-get-remote-perl vec)))
         "Script %s sending failed" name)
-       (tramp-set-connection-property p "scripts" (cons name scripts))))))
+       (tramp-set-connection-property
+        (tramp-get-connection-process vec) "scripts" (cons name scripts))))))
 
 (defun tramp-set-auto-save ()
   (when (and ;; ange-ftp has its own auto-save mechanism
@@ -3637,11 +3640,11 @@ file exists and nonzero exit status otherwise."
       (when extra-args (setq shell (concat shell " " extra-args)))
       (tramp-send-command
        vec (format "exec env ENV='' PROMPT_COMMAND='' PS1=%s PS2='' PS3='' %s"
-                  (shell-quote-argument tramp-end-of-output) shell)
+                  (tramp-shell-quote-argument tramp-end-of-output) shell)
        t))
     ;; Setting prompts.
     (tramp-send-command
-     vec (format "PS1=%s" (shell-quote-argument tramp-end-of-output)) t)
+     vec (format "PS1=%s" (tramp-shell-quote-argument tramp-end-of-output)) t)
     (tramp-send-command vec "PS2=''" t)
     (tramp-send-command vec "PS3=''" t)
     (tramp-send-command vec "PROMPT_COMMAND=''" t)))
@@ -3733,7 +3736,7 @@ process to set up.  VEC specifies the connection."
 
   (tramp-message vec 5 "Setting shell prompt")
   (tramp-send-command
-   vec (format "PS1=%s" (shell-quote-argument tramp-end-of-output)) t)
+   vec (format "PS1=%s" (tramp-shell-quote-argument tramp-end-of-output)) t)
   (tramp-send-command vec "PS2=''" t)
   (tramp-send-command vec "PS3=''" t)
   (tramp-send-command vec "PROMPT_COMMAND=''" t)
@@ -4505,27 +4508,30 @@ DONT-SUPPRESS-ERR is non-nil, stderr won't be sent to /dev/null."
   "Run COMMAND, check exit status, throw error if exit status not okay.
 Similar to `tramp-send-command-and-check' but accepts two more arguments
 FMT and ARGS which are passed to `error'."
-  (unless (tramp-send-command-and-check vec command)
-    (apply 'tramp-error vec 'file-error fmt args)))
+  (or (tramp-send-command-and-check vec command)
+      (apply 'tramp-error vec 'file-error fmt args)))
 
 (defun tramp-send-command-and-read (vec command &optional noerror)
   "Run COMMAND and return the output, which must be a Lisp expression.
 In case there is no valid Lisp expression and NOERROR is nil, it
 raises an error."
-  (tramp-barf-unless-okay vec command "`%s' returns with error" command)
-  (with-current-buffer (tramp-get-connection-buffer vec)
-    ;; Read the expression.
-    (goto-char (point-min))
-    (condition-case nil
-       (prog1 (read (current-buffer))
-         ;; Error handling.
-         (when (re-search-forward "\\S-" (point-at-eol) t)
-           (error nil)))
-      (error (unless noerror
-              (tramp-error
-               vec 'file-error
-               "`%s' does not return a valid Lisp expression: `%s'"
-               command (buffer-string)))))))
+  (when (if noerror
+           (tramp-send-command-and-check vec command)
+         (tramp-barf-unless-okay
+          vec command "`%s' returns with error" command))
+    (with-current-buffer (tramp-get-connection-buffer vec)
+      ;; Read the expression.
+      (goto-char (point-min))
+      (condition-case nil
+         (prog1 (read (current-buffer))
+           ;; Error handling.
+           (when (re-search-forward "\\S-" (point-at-eol) t)
+             (error nil)))
+       (error (unless noerror
+                (tramp-error
+                 vec 'file-error
+                 "`%s' does not return a valid Lisp expression: `%s'"
+                 command (buffer-string))))))))
 
 (defun tramp-convert-file-attributes (vec attr)
   "Convert file-attributes ATTR generated by perl script, stat or ls.