diff options
| author | Po Lu | 2024-02-29 10:59:09 +0800 |
|---|---|---|
| committer | Po Lu | 2024-02-29 10:59:09 +0800 |
| commit | 15ed441fd53ddb476a2a21c8717697a74cf094e1 (patch) | |
| tree | aed26cafb6b0b45581c1977f305a4ea78f8408c9 | |
| parent | 05195e129fc933db32c9e08a155a94bfa4d75b54 (diff) | |
| download | emacs-15ed441fd53ddb476a2a21c8717697a74cf094e1.tar.gz emacs-15ed441fd53ddb476a2a21c8717697a74cf094e1.zip | |
Fix subprocess creation in directories managed by tramp-androidsu
* lisp/net/tramp-androidsu.el
(tramp-androidsu-maybe-open-connection): Set connection property
remote-namespace to t or nil subject to whether su runs in the
global mount namespace.
(tramp-androidsu-adb-handle-make-process): Delete function.
(tramp-androidsu-make-process): New function.
(tramp-androidsu-file-name-handler-alist): Switch to
tramp-androidsu-make-process.
| -rw-r--r-- | lisp/net/tramp-androidsu.el | 134 |
1 files changed, 119 insertions, 15 deletions
diff --git a/lisp/net/tramp-androidsu.el b/lisp/net/tramp-androidsu.el index fd9edb6a92e..1623a0341b2 100644 --- a/lisp/net/tramp-androidsu.el +++ b/lisp/net/tramp-androidsu.el | |||
| @@ -118,11 +118,10 @@ multibyte mode and waits for the shell prompt to appear." | |||
| 118 | ;; Set sentinel. Initialize variables. | 118 | ;; Set sentinel. Initialize variables. |
| 119 | (set-process-sentinel p #'tramp-process-sentinel) | 119 | (set-process-sentinel p #'tramp-process-sentinel) |
| 120 | (tramp-post-process-creation p vec) | 120 | (tramp-post-process-creation p vec) |
| 121 | |||
| 122 | ;; Replace `login-args' place holders. | 121 | ;; Replace `login-args' place holders. |
| 123 | (setq command (format "exec su - %s || exit" | 122 | (setq command (format "exec su - %s || exit" |
| 124 | (or user "root"))) | 123 | (or user "root"))) |
| 125 | 124 | (tramp-set-connection-property vec "remote-namespace" nil) | |
| 126 | ;; Attempt to execute the shell inside the global mount | 125 | ;; Attempt to execute the shell inside the global mount |
| 127 | ;; namespace if requested. | 126 | ;; namespace if requested. |
| 128 | (when tramp-androidsu-mount-global-namespace | 127 | (when tramp-androidsu-mount-global-namespace |
| @@ -140,6 +139,8 @@ multibyte mode and waits for the shell prompt to appear." | |||
| 140 | (tramp-adb-send-command-and-check | 139 | (tramp-adb-send-command-and-check |
| 141 | vec "su -mm -c 'exit 24'" 24))) | 140 | vec "su -mm -c 'exit 24'" 24))) |
| 142 | (when tramp-androidsu-su-mm-supported | 141 | (when tramp-androidsu-su-mm-supported |
| 142 | (tramp-set-connection-property | ||
| 143 | vec "remote-namespace" t) | ||
| 143 | (setq command (format "exec su -mm - %s || exit" | 144 | (setq command (format "exec su -mm - %s || exit" |
| 144 | (or user "root")))))) | 145 | (or user "root")))))) |
| 145 | ;; Send the command. | 146 | ;; Send the command. |
| @@ -156,27 +157,21 @@ multibyte mode and waits for the shell prompt to appear." | |||
| 156 | 157 | ||
| 157 | ;; Set connection-local variables. | 158 | ;; Set connection-local variables. |
| 158 | (tramp-set-connection-local-variables vec) | 159 | (tramp-set-connection-local-variables vec) |
| 159 | |||
| 160 | ;; Change prompt. | 160 | ;; Change prompt. |
| 161 | (tramp-adb-send-command | 161 | (tramp-adb-send-command |
| 162 | vec (format "PS1=%s" | 162 | vec (format "PS1=%s" |
| 163 | (tramp-shell-quote-argument tramp-end-of-output))) | 163 | (tramp-shell-quote-argument tramp-end-of-output))) |
| 164 | |||
| 165 | ;; Disable line editing. | 164 | ;; Disable line editing. |
| 166 | (tramp-adb-send-command | 165 | (tramp-adb-send-command |
| 167 | vec "set +o vi +o vi-esccomplete +o vi-tabcomplete +o emacs") | 166 | vec "set +o vi +o vi-esccomplete +o vi-tabcomplete +o emacs") |
| 168 | |||
| 169 | ;; Dump option settings in the traces. | 167 | ;; Dump option settings in the traces. |
| 170 | (when (>= tramp-verbose 9) | 168 | (when (>= tramp-verbose 9) |
| 171 | (tramp-adb-send-command vec "set -o")) | 169 | (tramp-adb-send-command vec "set -o")) |
| 172 | |||
| 173 | ;; Disable Unicode. | 170 | ;; Disable Unicode. |
| 174 | (tramp-adb-send-command vec "set +U") | 171 | (tramp-adb-send-command vec "set +U") |
| 175 | |||
| 176 | ;; Disable echo expansion. | 172 | ;; Disable echo expansion. |
| 177 | (tramp-adb-send-command | 173 | (tramp-adb-send-command |
| 178 | vec "stty -inlcr -onlcr -echo kill '^U' erase '^H'" t) | 174 | vec "stty -inlcr -onlcr -echo kill '^U' erase '^H'" t) |
| 179 | |||
| 180 | ;; Check whether the echo has really been disabled. | 175 | ;; Check whether the echo has really been disabled. |
| 181 | ;; Some implementations, like busybox, don't support | 176 | ;; Some implementations, like busybox, don't support |
| 182 | ;; disabling. | 177 | ;; disabling. |
| @@ -191,14 +186,12 @@ multibyte mode and waits for the shell prompt to appear." | |||
| 191 | (tramp-adb-send-command vec | 186 | (tramp-adb-send-command vec |
| 192 | "stty icanon erase ^H cols 32767" | 187 | "stty icanon erase ^H cols 32767" |
| 193 | t))) | 188 | t))) |
| 194 | |||
| 195 | ;; Set the remote PATH to a suitable value. | 189 | ;; Set the remote PATH to a suitable value. |
| 196 | (tramp-set-connection-property vec "remote-path" | 190 | (tramp-set-connection-property vec "remote-path" |
| 197 | "/system/bin:/system/xbin") | 191 | '("/system/bin" |
| 198 | 192 | "/system/xbin")) | |
| 199 | ;; Mark it as connected. | 193 | ;; Mark it as connected. |
| 200 | (tramp-set-connection-property p "connected" t)))) | 194 | (tramp-set-connection-property p "connected" t)))) |
| 201 | |||
| 202 | ;; Cleanup, and propagate the signal. | 195 | ;; Cleanup, and propagate the signal. |
| 203 | ((error quit) | 196 | ((error quit) |
| 204 | (tramp-cleanup-connection vec t) | 197 | (tramp-cleanup-connection vec t) |
| @@ -386,8 +379,119 @@ FUNCTION." | |||
| 386 | (defalias 'tramp-androidsu-handle-make-nearby-temp-file | 379 | (defalias 'tramp-androidsu-handle-make-nearby-temp-file |
| 387 | (tramp-androidsu-generate-wrapper #'tramp-handle-make-nearby-temp-file)) | 380 | (tramp-androidsu-generate-wrapper #'tramp-handle-make-nearby-temp-file)) |
| 388 | 381 | ||
| 389 | (defalias 'tramp-androidsu-adb-handle-make-process | 382 | (defun tramp-androidsu-make-process (&rest args) |
| 390 | (tramp-androidsu-generate-wrapper #'tramp-adb-handle-make-process)) | 383 | "Like `tramp-handle-make-process', but modified for Android." |
| 384 | (when args | ||
| 385 | (with-parsed-tramp-file-name (expand-file-name default-directory) nil | ||
| 386 | (let ((default-directory tramp-compat-temporary-file-directory) | ||
| 387 | (name (plist-get args :name)) | ||
| 388 | (buffer (plist-get args :buffer)) | ||
| 389 | (command (plist-get args :command)) | ||
| 390 | (coding (plist-get args :coding)) | ||
| 391 | (noquery (plist-get args :noquery)) | ||
| 392 | (connection-type | ||
| 393 | (or (plist-get args :connection-type) process-connection-type)) | ||
| 394 | (filter (plist-get args :filter)) | ||
| 395 | (sentinel (plist-get args :sentinel)) | ||
| 396 | (stderr (plist-get args :stderr))) | ||
| 397 | (unless (stringp name) | ||
| 398 | (signal 'wrong-type-argument (list #'stringp name))) | ||
| 399 | (unless (or (bufferp buffer) (string-or-null-p buffer)) | ||
| 400 | (signal 'wrong-type-argument (list #'bufferp buffer))) | ||
| 401 | (unless (consp command) | ||
| 402 | (signal 'wrong-type-argument (list #'consp command))) | ||
| 403 | (unless (or (null coding) | ||
| 404 | (and (symbolp coding) (memq coding coding-system-list)) | ||
| 405 | (and (consp coding) | ||
| 406 | (memq (car coding) coding-system-list) | ||
| 407 | (memq (cdr coding) coding-system-list))) | ||
| 408 | (signal 'wrong-type-argument (list #'symbolp coding))) | ||
| 409 | (when (eq connection-type t) | ||
| 410 | (setq connection-type 'pty)) | ||
| 411 | (unless (or (and (consp connection-type) | ||
| 412 | (memq (car connection-type) '(nil pipe pty)) | ||
| 413 | (memq (cdr connection-type) '(nil pipe pty))) | ||
| 414 | (memq connection-type '(nil pipe pty))) | ||
| 415 | (signal 'wrong-type-argument (list #'symbolp connection-type))) | ||
| 416 | (unless (or (null filter) (eq filter t) (functionp filter)) | ||
| 417 | (signal 'wrong-type-argument (list #'functionp filter))) | ||
| 418 | (unless (or (null sentinel) (functionp sentinel)) | ||
| 419 | (signal 'wrong-type-argument (list #'functionp sentinel))) | ||
| 420 | (unless (or (null stderr) (bufferp stderr)) | ||
| 421 | (signal 'wrong-type-argument (list #'bufferp stderr))) | ||
| 422 | (let* ((buffer | ||
| 423 | (if buffer | ||
| 424 | (get-buffer-create buffer) | ||
| 425 | ;; BUFFER can be nil. We use a temporary buffer. | ||
| 426 | (generate-new-buffer tramp-temp-buffer-name))) | ||
| 427 | (orig-command command) | ||
| 428 | (env (mapcar | ||
| 429 | (lambda (elt) | ||
| 430 | (when (tramp-compat-string-search "=" elt) elt)) | ||
| 431 | tramp-remote-process-environment)) | ||
| 432 | ;; We use as environment the difference to toplevel | ||
| 433 | ;; `process-environment'. | ||
| 434 | (env (dolist (elt process-environment env) | ||
| 435 | (when | ||
| 436 | (and | ||
| 437 | (tramp-compat-string-search "=" elt) | ||
| 438 | (not | ||
| 439 | (member | ||
| 440 | elt (default-toplevel-value 'process-environment)))) | ||
| 441 | (setq env (cons elt env))))) | ||
| 442 | ;; Add remote path if exists. | ||
| 443 | (env (let ((remote-path | ||
| 444 | (string-join (tramp-get-remote-path v) ":"))) | ||
| 445 | (setenv-internal env "PATH" remote-path 'keep))) | ||
| 446 | (env (setenv-internal | ||
| 447 | env "INSIDE_EMACS" (tramp-inside-emacs) 'keep)) | ||
| 448 | (env (mapcar #'tramp-shell-quote-argument (delq nil env))) | ||
| 449 | ;; Quote command. | ||
| 450 | (command (mapconcat #'tramp-shell-quote-argument command " ")) | ||
| 451 | ;; Set cwd and environment variables. | ||
| 452 | (command | ||
| 453 | (append | ||
| 454 | `("cd" ,(tramp-shell-quote-argument localname) "&&" "(" "env") | ||
| 455 | env `(,command ")"))) | ||
| 456 | ;; Add remote shell if needed. | ||
| 457 | (command | ||
| 458 | (if (consp (tramp-get-method-parameter v 'tramp-direct-async)) | ||
| 459 | (append | ||
| 460 | (tramp-get-method-parameter v 'tramp-direct-async) | ||
| 461 | `(,(string-join command " "))) | ||
| 462 | command)) | ||
| 463 | p) | ||
| 464 | ;; Generate a command to start the process using `su' with | ||
| 465 | ;; suitable options for specifying the mount namespace and | ||
| 466 | ;; suchlike. | ||
| 467 | (setq | ||
| 468 | p (make-process | ||
| 469 | :name name :buffer buffer | ||
| 470 | :command (if (tramp-get-connection-property v "remote-namespace") | ||
| 471 | (append (list "su" "-mm" "-" (or user "root") "-c") | ||
| 472 | command) | ||
| 473 | (append (list "su" "-" (or user "root") "-c") | ||
| 474 | command)) | ||
| 475 | :coding coding :noquery noquery :connection-type connection-type | ||
| 476 | :sentinel sentinel :stderr stderr)) | ||
| 477 | ;; Set filter. Prior Emacs 29.1, it doesn't work reliably | ||
| 478 | ;; to provide it as `make-process' argument when filter is | ||
| 479 | ;; t. See Bug#51177. | ||
| 480 | (when filter | ||
| 481 | (set-process-filter p filter)) | ||
| 482 | (tramp-post-process-creation p v) | ||
| 483 | ;; Query flag is overwritten in `tramp-post-process-creation', | ||
| 484 | ;; so we reset it. | ||
| 485 | (set-process-query-on-exit-flag p (null noquery)) | ||
| 486 | ;; This is needed for ssh or PuTTY based processes, and | ||
| 487 | ;; only if the respective options are set. Perhaps, the | ||
| 488 | ;; setting could be more fine-grained. | ||
| 489 | ;; (process-put p 'tramp-shared-socket t) | ||
| 490 | (process-put p 'remote-command orig-command) | ||
| 491 | (tramp-set-connection-property p "remote-command" orig-command) | ||
| 492 | (when (bufferp stderr) | ||
| 493 | (tramp-taint-remote-process-buffer stderr)) | ||
| 494 | p))))) | ||
| 391 | 495 | ||
| 392 | (defalias 'tramp-androidsu-sh-handle-make-symbolic-link | 496 | (defalias 'tramp-androidsu-sh-handle-make-symbolic-link |
| 393 | (tramp-androidsu-generate-wrapper | 497 | (tramp-androidsu-generate-wrapper |
| @@ -508,7 +612,7 @@ FUNCTION." | |||
| 508 | (make-directory-internal . ignore) | 612 | (make-directory-internal . ignore) |
| 509 | (make-lock-file-name . tramp-androidsu-handle-make-lock-file-name) | 613 | (make-lock-file-name . tramp-androidsu-handle-make-lock-file-name) |
| 510 | (make-nearby-temp-file . tramp-androidsu-handle-make-nearby-temp-file) | 614 | (make-nearby-temp-file . tramp-androidsu-handle-make-nearby-temp-file) |
| 511 | (make-process . tramp-androidsu-adb-handle-make-process) | 615 | (make-process . tramp-androidsu-make-process) |
| 512 | (make-symbolic-link . tramp-androidsu-sh-handle-make-symbolic-link) | 616 | (make-symbolic-link . tramp-androidsu-sh-handle-make-symbolic-link) |
| 513 | (memory-info . tramp-androidsu-handle-memory-info) | 617 | (memory-info . tramp-androidsu-handle-memory-info) |
| 514 | (process-attributes . tramp-androidsu-handle-process-attributes) | 618 | (process-attributes . tramp-androidsu-handle-process-attributes) |