Subject: bug#36598: 26.1; (error "‘/tmp/emacs1000’ is not a safe directory because it is a symlink")

From: [email-masked]
Date: Sat, 13 Jul 2019 16:56:19 +0100

On 2019-07-13 15:45, Lars Ingebrigtsen wrote:
> [email-masked] writes:
> 
>> Launch emacs-27, start the server. Now launch emacs-26 and start the
>> server with a different. The problem is that
>> emacs-27 creates the file /tmp/emacs($PID) as a symlink, while
>> emacs-26 doesn't like it.
>> 
>> Probably created by
>> 
>> b663c837249 (Stefan Monnier          2019-05-03  538)
> 
> Could you post a backtrace for the "doesn't like it" case?

Sure. It is Emacs-26 that errors.

As far as I can see, this will only affect the edge case of someone 
running two versions of Emacs. I tend to do this (I run gnus in a 
standalone release emacs, and everything else in another emacs).

Phil

Debugger entered--Lisp error: (error "‘/tmp/emacs1000’ is not a safe 
directory because it is a symlink")
   signal(error ("‘/tmp/emacs1000’ is not a safe directory because it is 
a symlink"))
   error("`%s' is not a safe directory because %s" "/tmp/emacs1000" "it 
is a symlink")
   (progn (error "`%s' is not a safe directory because %s" 
(expand-file-name dir) unsafe))
   (if unsafe (progn (error "`%s' is not a safe directory because %s" 
(expand-file-name dir) unsafe)))
   (let* ((uid (nth 2 attrs)) (w32 (eq system-type (quote windows-nt))) 
(unsafe (cond ((not (eq t (car attrs))) (if (null attrs) "its attributes 
can't be checked" (format "it is a %s" (if ... "symlink" "file")))) 
((and w32 (= 0 uid)) (display-warning (quote server) (format-message 
"Using `%s' to store Emacs-server authentication files.\nDirectories on 
FAT32 filesystems are NOT secure against tampering.\nSee variable 
`server-auth-dir' for details." (file-name-as-directory dir)) :warning) 
nil) ((and (/= uid (user-uid)) (or (not w32) (/= uid 544) (/= ... 500))) 
(format "it is not owned by you (owner = %s (%d))" (user-full-name uid) 
uid)) (w32 nil) ((/= 0 (logand 63 (file-modes dir))) (format "it is 
accessible by others (%03o)" (file-modes dir))) (t nil)))) (if unsafe 
(progn (error "`%s' is not a safe directory because %s" 
(expand-file-name dir) unsafe))))
   (let ((attrs (file-attributes dir (quote integer)))) (if attrs nil 
(let* ((old (default-file-modes))) (unwind-protect (progn (progn 
(set-default-file-modes 448) 448) (make-directory dir t)) (let* ((v 
old)) (progn (set-default-file-modes v) v)))) (setq attrs 
(file-attributes dir (quote integer)))) (let* ((uid (nth 2 attrs)) (w32 
(eq system-type (quote windows-nt))) (unsafe (cond ((not (eq t ...)) (if 
(null attrs) "its attributes can't be checked" (format "it is a %s" 
...))) ((and w32 (= 0 uid)) (display-warning (quote server) 
(format-message "Using `%s' to store Emacs-server authentication 
files.\nDirectories on FAT32 filesystems are NOT secure against 
tampering.\nSee variable `server-auth-dir' for details." ...) :warning) 
nil) ((and (/= uid ...) (or ... ... ...)) (format "it is not owned by 
you (owner = %s (%d))" (user-full-name uid) uid)) (w32 nil) ((/= 0 
(logand 63 ...)) (format "it is accessible by others (%03o)" (file-modes 
dir))) (t nil)))) (if unsafe (progn (error "`%s' is not a safe directory 
because %s" (expand-file-name dir) unsafe)))))
   server-ensure-safe-dir("/tmp/emacs1000")
   (if leave-dead (progn (if (eq t leave-dead) nil (server-log (message 
"Server stopped"))) (setq server-process nil)) (server-ensure-safe-dir 
server-dir) (if server-process (progn (server-log (message "Restarting 
server")))) (let* ((old (default-file-modes))) (unwind-protect (progn 
(progn (set-default-file-modes 448) 448) (add-hook (quote 
suspend-tty-functions) (quote server-handle-suspend-tty)) (add-hook 
(quote delete-frame-functions) (quote server-handle-delete-frame)) 
(add-hook (quote kill-emacs-query-functions) (quote 
server-kill-emacs-query-function)) (add-hook (quote kill-emacs-hook) 
(quote server-force-stop) t) (setq server-process (apply (function 
make-network-process) :name server-name :server t :noquery t :sentinel 
(function server-sentinel) :filter (function server-process-filter) 
:use-external-socket t :coding (quote raw-text-unix) (if server-use-tcp 
(list :family ... :service ... :host ... :plist ...) (list :family ... 
:service server-file :plist ...)))) (if server-process nil (error "Could 
not start server process")) (process-put server-process :server-file 
server-file) (if server-use-tcp (progn (let (...) (process-put 
server-process :auth-key auth-key) (let ... ...))))) (let* ((v old)) 
(progn (set-default-file-modes v) v)))))
   (let* ((server-dir (if server-use-tcp server-auth-dir 
server-socket-dir)) (server-file (expand-file-name server-name 
server-dir))) (if server-process (progn (condition-case nil (progn 
(delete-process server-process)) (error nil)))) (if (not (eq t 
(server-running-p server-name))) (condition-case nil (progn (let 
(delete-by-moving-to-trash) (delete-file server-file))) (error nil)) 
(setq server-mode nil) (display-warning (quote server) (concat "Unable 
to start the Emacs server.\n" (format "There is an existing Emacs 
server, named %S.\n" server-name) (substitute-command-keys "To start the 
server in this Emacs process, stop the existing\nserver or call 
`\\[server-force-delete]' to forcibly disconnect it.")) :warning) (setq 
leave-dead t)) (while server-clients (server-delete-client (car 
server-clients))) (if leave-dead (progn (if (eq t leave-dead) nil 
(server-log (message "Server stopped"))) (setq server-process nil)) 
(server-ensure-safe-dir server-dir) (if server-process (progn 
(server-log (message "Restarting server")))) (let* ((old 
(default-file-modes))) (unwind-protect (progn (progn 
(set-default-file-modes 448) 448) (add-hook (quote 
suspend-tty-functions) (quote server-handle-suspend-tty)) (add-hook 
(quote delete-frame-functions) (quote server-handle-delete-frame)) 
(add-hook (quote kill-emacs-query-functions) (quote 
server-kill-emacs-query-function)) (add-hook (quote kill-emacs-hook) 
(quote server-force-stop) t) (setq server-process (apply (function 
make-network-process) :name server-name :server t :noquery t :sentinel 
(function server-sentinel) :filter (function server-process-filter) 
:use-external-socket t :coding (quote raw-text-unix) (if server-use-tcp 
... ...))) (if server-process nil (error "Could not start server 
process")) (process-put server-process :server-file server-file) (if 
server-use-tcp (progn (let ... ... ...)))) (let* ((v old)) (progn 
(set-default-file-modes v) v))))))
   (progn (let* ((server-dir (if server-use-tcp server-auth-dir 
server-socket-dir)) (server-file (expand-file-name server-name 
server-dir))) (if server-process (progn (condition-case nil (progn 
(delete-process server-process)) (error nil)))) (if (not (eq t 
(server-running-p server-name))) (condition-case nil (progn (let 
(delete-by-moving-to-trash) (delete-file server-file))) (error nil)) 
(setq server-mode nil) (display-warning (quote server) (concat "Unable 
to start the Emacs server.\n" (format "There is an existing Emacs 
server, named %S.\n" server-name) (substitute-command-keys "To start the 
server in this Emacs process, stop the existing\nserver or call 
`\\[server-force-delete]' to forcibly disconnect it.")) :warning) (setq 
leave-dead t)) (while server-clients (server-delete-client (car 
server-clients))) (if leave-dead (progn (if (eq t leave-dead) nil 
(server-log (message "Server stopped"))) (setq server-process nil)) 
(server-ensure-safe-dir server-dir) (if server-process (progn 
(server-log (message "Restarting server")))) (let* ((old 
(default-file-modes))) (unwind-protect (progn (progn 
(set-default-file-modes 448) 448) (add-hook (quote 
suspend-tty-functions) (quote server-handle-suspend-tty)) (add-hook 
(quote delete-frame-functions) (quote server-handle-delete-frame)) 
(add-hook (quote kill-emacs-query-functions) (quote 
server-kill-emacs-query-function)) (add-hook (quote kill-emacs-hook) 
(quote server-force-stop) t) (setq server-process (apply ... :name 
server-name :server t :noquery t :sentinel ... :filter ... 
:use-external-socket t :coding ... ...)) (if server-process nil (error 
"Could not start server process")) (process-put server-process 
:server-file server-file) (if server-use-tcp (progn ...))) (let* ((v 
old)) (progn (set-default-file-modes v) v)))))))
   (if (or (not server-clients) (cond ((and (daemonp) (null (cdr 
(frame-list))) (eq (selected-frame) terminal-frame)) leave-dead) 
(inhibit-prompt t) (t (yes-or-no-p "The current server still has 
clients; delete them? ")))) (progn (let* ((server-dir (if server-use-tcp 
server-auth-dir server-socket-dir)) (server-file (expand-file-name 
server-name server-dir))) (if server-process (progn (condition-case nil 
(progn (delete-process server-process)) (error nil)))) (if (not (eq t 
(server-running-p server-name))) (condition-case nil (progn (let 
(delete-by-moving-to-trash) (delete-file server-file))) (error nil)) 
(setq server-mode nil) (display-warning (quote server) (concat "Unable 
to start the Emacs server.\n" (format "There is an existing Emacs 
server, named %S.\n" server-name) (substitute-command-keys "To start the 
server in this Emacs process, stop the existing\nserver or call 
`\\[server-force-delete]' to forcibly disconnect it.")) :warning) (setq 
leave-dead t)) (while server-clients (server-delete-client (car 
server-clients))) (if leave-dead (progn (if (eq t leave-dead) nil 
(server-log (message "Server stopped"))) (setq server-process nil)) 
(server-ensure-safe-dir server-dir) (if server-process (progn 
(server-log (message "Restarting server")))) (let* ((old 
(default-file-modes))) (unwind-protect (progn (progn ... 448) (add-hook 
... ...) (add-hook ... ...) (add-hook ... ...) (add-hook ... ... t) 
(setq server-process ...) (if server-process nil ...) (process-put 
server-process :server-file server-file) (if server-use-tcp ...)) (let* 
(...) (progn ... v))))))))
   server-start(nil)
   funcall-interactively(server-start nil)
   call-interactively(server-start record nil)
   command-execute(server-start record)
   execute-extended-command(nil "server-start" "server-start")
   funcall-interactively(execute-extended-command nil "server-start" 
"server-start")
   call-interactively(execute-extended-command nil nil)
   command-execute(execute-extended-command)