views:

1540

answers:

10

I am currently using GNU Emacs 23.0.93.1 in Windows Vista SP1. In my .emacs file I make a call to (server-start) and that is causing an error with the message The directory ~/.emacs.d/server is unsafe. Has anyone seen this and know a fix or workaround? ... other than leaving server turned off ;)

Here is the stack trace:

Debugger entered--Lisp error: (error "The directory ~/.emacs.d/server is unsafe")
  signal(error ("The directory ~/.emacs.d/server is unsafe"))
  error("The directory %s is unsafe" "~/.emacs.d/server")
  server-ensure-safe-dir("~\\.emacs.d\\server\\")
  server-start(nil)
  call-interactively(server-start t nil)
  execute-extended-command(nil)
  call-interactively(execute-extended-command nil nil)
+7  A: 

This is a known Emacs bug on Windows. A workaround is to comment out this line in server-ensure-safe-dir in server.el the you'll want to byte recompile after the change:

;; FIXME: Busted on Windows. 
;; (eql (nth 2 attrs) (user-uid))
brlcad
Your solution fixes my problem. I will investigate this further later and add my findings here. Thanks!
Jonas Gorauskas
+5  A: 

To avoid hacking in the lisp directory, you can just add the following to your .emacs:

(and (= emacs-major-version 23) (defun server-ensure-safe-dir (dir) "Noop" t))

I had the above issue with Emacs in Cygwin and the above command worked.
MikeHoss
+10  A: 

I enjoy to anwer of larsreed, but complite code ready to use:

(require 'server)
(when (and (= emacs-major-version 23)
           (= emacs-minor-version 1)
           (equal window-system 'w32))
  (defun server-ensure-safe-dir (dir) "Noop" t)) ; Suppress error "directory
                                                 ; ~/.emacs.d/server is unsafe"
                                                 ; on windows.
(server-start)

I discass this issue in my blog article http://brain-break.blogspot.com/2009/08/when-moving-from-gnu-emacs-22.html

Also note that in 2009-09-19 fixed bug #4197 about server-ensure-safe-dir so in incoming Emacs 23.2 this workaround not needed.

Under recently released Emacs 23.2 I have such warning:

Warning (server): Using ~/.emacs.d/server to store Emacs-server authentication files. Directories on FAT32 filesystems are NOT secure against tampering. See variable server-auth-dir for details.

To fix this as say warning you can point server-auth-dir to NTFS partition (%APPDATA% usually located Windows %SYSTEMDRIVE% and user usually format system drive as NTFS partition):

(require 'server)
(when (and (eq window-system 'w32) (file-exists-p (getenv "APPDATA")))
  (setq server-auth-dir (concat (getenv "APPDATA") "/.emacs.d/server"))
  (make-directory server-auth-dir)  )
(server-start)
gavenkoa
using emacs23 and windows vista 64b, this fixed it for me. Without the require server didn't work.
Mario
2Mario this because problem lies in FAT32 fs, not Windows itself.
gavenkoa
+1  A: 

I got this error on emacs 23.1 on Windows 2000 as well. I tried gavenkoa's solution, and got rid of the error. A parallel emacs 22.1 installation was not affected.

numericalexample.com
+1  A: 

Running EmacsW32 more specifically:

This is GNU Emacs 23.1.50.1 (i386-mingw-nt6.0.6001) of 2009-11-03 on LENNART-69DE564 (patched)

I placed gavenkoa's solution in the file: c:/Program Files/Emacs/emacs/lisp/auto-server.el after the (require 'server) line. and byte compiled the file restarted, problem solved.

BTW I tried larsreed's fix first and it did not work for me.

tharple
+1  A: 

gavenkoa's solution (in my ~/.emacs) worked for me on Windows 7. Thanks.

David M. Anderson
+2  A: 

Did not work for me in Windows 7.

I instead read the comments in server-ensure-safe-dir and proceeded with taking the ownership for %APPDATA% forlder and subfolders. They were owned by local Administrators, not by me.

That helped!

KTa
To elaborate: Make sure that the directory %HOME%\.emacs.d\server is owned by you, not by the local Administrators group.
Kristopher Johnson
+5  A: 

I found this solution on EmacsWiki:

"The problem is the ownership of the directory ~/.emacs.d/server when you also have “Administrators” rights on your account. Create the directory ~/.emacs.d/server and set the owner of this directory to your login name and the problem is gone. As I have a “Dutch” version of Windows 7 I don’t know the English terms exactly but here’s the procedure:

Click R-mouse on ~/.emacs.d/server and select “Properties” (last item in menu). From Properties select the Tab “Security” and then select the button “Advanced”. Then select the Tab “Owner” and change the owner from “Administrators (\Administrators)” into “ (\”. Now the server code will accept this directory as secure because you are the owner.

Hope this helps for all you guys, it solved the problem for me anyway.

W.K.R. Reutefleut"

It definitely works on Vista, with Emacs 23.2.1.

RealityMonster
Thanks, this works for me.
Ben
Fixed it! I wish this comment had higher google ranking and it should be the answer to this question as well.
Drew
+1  A: 

The solution posted by "RealityMonster," which was quoted from W.K.R. Reutefleut, worked for me, but not the first time. Apparently, it was necessary to close Emacs before making the change in ownership.

Strange that this happens on my Win 2000 computer and not my XP computer. And it happened only after I attempted to synch my XP computer's ~/ to the 2000's.

Raymond Zeitler
+1  A: 

In case this occasionally hits people, my workstation just went through a "domain migration", which added another permission to every file on the box, then I started getting this error. After I added the expression to dummy out "server-ensure-safe-dir" this stopped failing.

(If you're wondering, the migration will be in 2-3 steps. The first one adds the permission for me in the target domain, then I get moved to the target domain, then they might (I'm not sure about this) remove the permission for the old domain. It's a big company, and many users, so they're doing it in separate steps.)

David M. Karr