Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

not all user environment variables are bypassed into $EDITOR #742

Closed
real-or-random opened this issue Aug 9, 2023 · 5 comments
Closed

Comments

@real-or-random
Copy link

Pikaur v1.18.2
Pacman v6.0.2 - libalpm v13.0.2 - pyalpm v0.10.6
[Optional] Prerequisites:

Have this in the environment:

VISUAL="emacsclient --tty"
Description:

pikaur can't open the emacs (client) anymore. (I run emacs as daemon, and then you can use use emacsclient to open a new editor view. I think this regression is caused by 075e7eb:

The log shows:

Do you want to edit PKGBUILD for xyz package? [Y/n] 
emacsclient: Should XDG_RUNTIME_DIR='/run/user/1000' be in the environment?
emacsclient: (Be careful: XDG_RUNTIME_DIR is security-related.)
emacsclient: can't find socket; have you started the server?
emacsclient: To start the server in Emacs, type "M-x server-start".
emacsclient: No socket or alternate editor.  Please use:  

Indeed, sudo --user=<myuser> --preserve-env=XDG_RUNTIME_DIR emacsclient test works whereas sudo --user=<myuser> emacsclient test does not work. I think one solution is to XDG_RUNTIME_DIR to PRESERVE_ENV but I'm not convinced that this is the proper way. Other users/editors will likely need other variables. I think a proper solution is to run the editor in the initial environment and with the initial permissions (before elevating permissions), instead of elevating and dropping again.

A workaround for me is VISUAL="env XDG_RUNTIME_DIR=/run/user/1000 emacsclient --tty" .

@actionless
Copy link
Owner

I think a proper solution is to run the editor in the initial environment and with the initial permissions (before elevating permissions), instead of elevating and dropping again.

you can get back to that behavior with this config option: https://github.com/actionless/pikaur#privilegeescalationtarget-default-pikaur

but actually while we were discussing that new preserve-env thing with another user - it came up in conversation, that it might make sense in the future to make preserve-env list configurable via pikaur.conf

@actionless actionless changed the title emacsclient does not work any more as an EDITOR not all user environment variables are bypassed into $EDITOR Aug 9, 2023
@actionless
Copy link
Owner

actually i just hit that problem myself trying to build colmap-git which require setting some env vars 😺 so i think to come up with some nice way for that tonight

@actionless
Copy link
Owner

Thanks for reporting!
You can check with pikaur-git AUR package if it works for you now.

@veox
Copy link

veox commented Feb 7, 2024

The new version v1.18.4 works as previously if XDG_RUNTIME_DIR is added to preserveenv in ~/.config/pikaur.conf for me, with a similar case to that of OP's: emacs --fg-daemon running per-user (started via that user's systemd service), and EDITOR being set to emacsclient -c -nw.

At the root of the issue is this:

  • emacs is run as a user's daemon;
  • EDITOR is a call to emacsclient, which wants to connect to a daemon;
  • XDG_RUNTIME_DIR is not preserved by default when elevating permissions (and probably rightfully so!);
  • emacsclient doesn't know where to connect to.

Passing XDG_RUNTIME_DIR has strings attached that lead who knows where.

I'd suggest also passing ALTERNATE_EDITOR in preserveenv instead; this seems a safer compromise.

Those of us who use emacs in daemon mode often know to set ALTERNATE_EDITOR to a non-daemon emacs or mg or anything.

@actionless
Copy link
Owner

@veox yeah you that would be weird to bypass XDG_RUNTIME_DIR - they should consider adding (if they don't have) an env var or cli arg for specifying to which emacs server to connect emacs-client

as a workaround try changing here https://github.com/actionless/pikaur?tab=readme-ov-file#privilegeescalationtarget-default-pikaur to pacman (it would change sudo logic a bit)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants