Subject: bug#33847: 27.0.50; emacsclient does not find server socket

From: Paul Eggert <[email-masked]>
Date: Tue, 25 Dec 2018 22:59:08 -0800

Ulrich Mueller wrote:
> IMHO, unsetting a standard variable like XDG_RUNTIME_DIR (as you've
> suggested above) in the user's session isn't really an option.

You're right, unsetting it for an entire session would mean that you want all 
programs (not just Emacs) to not use XDG_RUNTIME_DIR, and that sounds too 
drastic. I don't recall suggesting that.

> And a
> wrapper script around emacsclient would be just awkward.

It's not *that* awkward, and it may be acceptable if the situation you describe 
is unusual enough.

> Plus, as it is currently implemented, there isn't even a unique way to
> override the socket's location. I notice that emacsclient will now
> honour the EMACS_SOCKET_NAME variable, but then again, server.el doesn't
> use it.

Although I'm not a big fan of environment variables, it might make sense for 
server.el to look at EMACS_SOCKET_NAME, for consistency with emacsclient.

> So if we would want to override the socket's location at the
> distro level (e.g., place it in /run/emacs/${USER}/), how could we do
> that?

There's no mechanism in Emacs to do that now. It would be OK to add one, I expect.

> If it is a security issue, then why isn't the fix in the emacs-26 branch
> as well?

emacs-26 at this point is meant for fixing regressions, and the problem in 
question is not a regression. Anyway, this change was too risky for the emacs-26 
branch.

> Also, why is there still a fallback to TMPDIR, if that's
> considered insecure?

On a system that doesn't set XDG_RUNTIME_DIR it was the best we could easily do. 
If we can come up with something better for those systems, that would be good.

For systems with XDG_RUNTIME_DIR it would probably be better to not reinvent 
this particular wheel. That is, for users who prefer Emacs to run only when they 
are logged in, XDG_RUNTIME_DIR seems to be the way to go. For users who prefer 
Emacs to always be running, even when they are not logged in, we should use some 
other mechanism.

> XDG_RUNTIME_DIR is simply not suitable for the purpose, because (by its
> specification) it will disappear when the login session ends,

I think the idea is that XDG_RUNTIME_DIR disappears when all login sessions end, 
so it might survive the current session.

>> The 'screen' workaround does not appear to apply to Emacs, since Emacs
>> is programmable and if Emacs were made setgid its users could easily
>> modify Emacs's behavior to manipulate the contents of any such
>> /run/emacs directory in any way they pleased.
> 
> No need for Emacs itself to be setgid, because the directory could
> be created by calling an auxiliary setgid program (similar to
> update-game-score).

That might work, as a solution for people who want Emacs to keep running even 
when they entirely log out.