comparison lisp/net/tramp.el @ 111926:992f5b43dbfc

* net/tramp.el (tramp-handle-start-file-process): Protect buffer-modified value. (Bug#7557) (tramp-action-password): Delete region, do not narrow. (tramp-process-actions): Do not widen.
author Michael Albinus <michael.albinus@gmx.de>
date Wed, 08 Dec 2010 21:07:25 +0100
parents 202eb704e80b
children 656e54e27a1b
comparison
equal deleted inserted replaced
111925:b2e1ce1e5b73 111926:992f5b43dbfc
4520 ;; this, its original contents must be saved, and restored once 4520 ;; this, its original contents must be saved, and restored once
4521 ;; connection has been setup. 4521 ;; connection has been setup.
4522 (defun tramp-handle-start-file-process (name buffer program &rest args) 4522 (defun tramp-handle-start-file-process (name buffer program &rest args)
4523 "Like `start-file-process' for Tramp files." 4523 "Like `start-file-process' for Tramp files."
4524 (with-parsed-tramp-file-name default-directory nil 4524 (with-parsed-tramp-file-name default-directory nil
4525 (unwind-protect 4525 ;; When PROGRAM is nil, we just provide a tty.
4526 ;; When PROGRAM is nil, we just provide a tty. 4526 (let ((command
4527 (let ((command 4527 (when (stringp program)
4528 (when (stringp program) 4528 (format "cd %s; exec %s"
4529 (format "cd %s; exec %s" 4529 (tramp-shell-quote-argument localname)
4530 (tramp-shell-quote-argument localname) 4530 (mapconcat 'tramp-shell-quote-argument
4531 (mapconcat 'tramp-shell-quote-argument 4531 (cons program args) " "))))
4532 (cons program args) " ")))) 4532 (tramp-process-connection-type
4533 (tramp-process-connection-type 4533 (or (null program) tramp-process-connection-type))
4534 (or (null program) tramp-process-connection-type)) 4534 (bmp (and (buffer-live-p buffer) (buffer-modified-p buffer)))
4535 (name1 name) 4535 (name1 name)
4536 (i 0)) 4536 (i 0))
4537 (unless buffer 4537 (unwind-protect
4538 ;; BUFFER can be nil. We use a temporary buffer. 4538 (save-excursion
4539 (setq buffer (generate-new-buffer tramp-temp-buffer-name))) 4539 (save-restriction
4540 (while (get-process name1) 4540 (unless buffer
4541 ;; NAME must be unique as process name. 4541 ;; BUFFER can be nil. We use a temporary buffer.
4542 (setq i (1+ i) 4542 (setq buffer (generate-new-buffer tramp-temp-buffer-name)))
4543 name1 (format "%s<%d>" name i))) 4543 (while (get-process name1)
4544 (setq name name1) 4544 ;; NAME must be unique as process name.
4545 ;; Set the new process properties. 4545 (setq i (1+ i)
4546 (tramp-set-connection-property v "process-name" name) 4546 name1 (format "%s<%d>" name i)))
4547 (tramp-set-connection-property v "process-buffer" buffer) 4547 (setq name name1)
4548 ;; Activate narrowing in order to save BUFFER contents. 4548 ;; Set the new process properties.
4549 ;; Clear also the modification time; otherwise we might be 4549 (tramp-set-connection-property v "process-name" name)
4550 ;; interrupted by `verify-visited-file-modtime'. 4550 (tramp-set-connection-property v "process-buffer" buffer)
4551 (with-current-buffer (tramp-get-connection-buffer v) 4551 ;; Activate narrowing in order to save BUFFER contents.
4552 (clear-visited-file-modtime) 4552 ;; Clear also the modification time; otherwise we might
4553 (narrow-to-region (point-max) (point-max))) 4553 ;; be interrupted by `verify-visited-file-modtime'.
4554 (if command 4554 (with-current-buffer (tramp-get-connection-buffer v)
4555 ;; Send the command. 4555 (let ((buffer-undo-list t))
4556 (tramp-send-command v command nil t) ; nooutput 4556 (clear-visited-file-modtime)
4557 ;; Check, whether a pty is associated. 4557 (narrow-to-region (point-max) (point-max))
4558 (tramp-maybe-open-connection v) 4558 (if command
4559 (unless (process-get (tramp-get-connection-process v) 'remote-tty) 4559 ;; Send the command.
4560 (tramp-error 4560 (tramp-send-command v command nil t) ; nooutput
4561 v 'file-error "pty association is not supported for `%s'" name))) 4561 ;; Check, whether a pty is associated.
4562 (let ((p (tramp-get-connection-process v))) 4562 (tramp-maybe-open-connection v)
4563 ;; Set sentinel and query flag for this process. 4563 (unless (process-get
4564 (tramp-set-connection-property p "vector" v) 4564 (tramp-get-connection-process v) 'remote-tty)
4565 (set-process-sentinel p 'tramp-process-sentinel) 4565 (tramp-error
4566 (tramp-set-process-query-on-exit-flag p t) 4566 v 'file-error
4567 ;; Return process. 4567 "pty association is not supported for `%s'" name)))))
4568 p)) 4568 (let ((p (tramp-get-connection-process v)))
4569 ;; Save exit. 4569 ;; Set sentinel and query flag for this process.
4570 (with-current-buffer (tramp-get-connection-buffer v) 4570 (tramp-set-connection-property p "vector" v)
4571 (if (string-match tramp-temp-buffer-name (buffer-name)) 4571 (set-process-sentinel p 'tramp-process-sentinel)
4572 (progn 4572 (tramp-set-process-query-on-exit-flag p t)
4573 (set-process-buffer (tramp-get-connection-process v) nil) 4573 ;; Return process.
4574 (kill-buffer (current-buffer))) 4574 p)))
4575 (widen) 4575 ;; Save exit.
4576 (goto-char (point-max)))) 4576 (with-current-buffer (tramp-get-connection-buffer v)
4577 (tramp-set-connection-property v "process-name" nil) 4577 (if (string-match tramp-temp-buffer-name (buffer-name))
4578 (tramp-set-connection-property v "process-buffer" nil)))) 4578 (progn
4579 (set-process-buffer (tramp-get-connection-process v) nil)
4580 (kill-buffer (current-buffer)))
4581 (set-buffer-modified-p bmp)))
4582 (tramp-set-connection-property v "process-name" nil)
4583 (tramp-set-connection-property v "process-buffer" nil)))))
4579 4584
4580 (defun tramp-handle-process-file 4585 (defun tramp-handle-process-file
4581 (program &optional infile destination display &rest args) 4586 (program &optional infile destination display &rest args)
4582 "Like `process-file' for Tramp files." 4587 "Like `process-file' for Tramp files."
4583 ;; The implementation is not complete yet. 4588 ;; The implementation is not complete yet.
6705 (defun tramp-action-password (proc vec) 6710 (defun tramp-action-password (proc vec)
6706 "Query the user for a password." 6711 "Query the user for a password."
6707 (with-current-buffer (process-buffer proc) 6712 (with-current-buffer (process-buffer proc)
6708 (tramp-check-for-regexp proc tramp-password-prompt-regexp) 6713 (tramp-check-for-regexp proc tramp-password-prompt-regexp)
6709 (tramp-message vec 3 "Sending %s" (match-string 1)) 6714 (tramp-message vec 3 "Sending %s" (match-string 1))
6715 (tramp-message vec 6 "\n%s" (buffer-string)))
6710 (tramp-enter-password proc) 6716 (tramp-enter-password proc)
6711 ;; Hide password prompt. 6717 ;; Remove password prompt, in order not to find it next iteration.
6712 (narrow-to-region (point-max) (point-max)))) 6718 (delete-region (point-min) (point-max)))
6713 6719
6714 (defun tramp-action-succeed (proc vec) 6720 (defun tramp-action-succeed (proc vec)
6715 "Signal success in finding shell prompt." 6721 "Signal success in finding shell prompt."
6716 (throw 'tramp-action 'ok)) 6722 (throw 'tramp-action 'ok))
6717 6723
6818 (if timeout 6824 (if timeout
6819 (with-timeout (timeout) 6825 (with-timeout (timeout)
6820 (tramp-process-one-action proc vec actions)) 6826 (tramp-process-one-action proc vec actions))
6821 (tramp-process-one-action proc vec actions))))) 6827 (tramp-process-one-action proc vec actions)))))
6822 (with-current-buffer (tramp-get-connection-buffer vec) 6828 (with-current-buffer (tramp-get-connection-buffer vec)
6823 (widen)
6824 (tramp-message vec 6 "\n%s" (buffer-string))) 6829 (tramp-message vec 6 "\n%s" (buffer-string)))
6825 (unless (eq exit 'ok) 6830 (unless (eq exit 'ok)
6826 (tramp-clear-passwd vec) 6831 (tramp-clear-passwd vec)
6827 (tramp-error-with-buffer 6832 (tramp-error-with-buffer
6828 nil vec 'file-error 6833 nil vec 'file-error