4

I am trying to run an identical emacsserver setup as the emacs I normally use.

I am having issues because the emacsserver has a different exec-path variable when it starts than when normal emacs does.

To start emacsserver I am using: /usr/bin/emacs --daemon in a systemd script. To start emacs normally I just type emacs

emacsserver (which I connect to by typing emacsclient) has the following value forexec-path`:

    exec-path is a variable defined in `C source code'.
    Its value is
    ("PATH" "/usr/local/sbin" "/usr/local/bin" "/usr/sbin" "/usr/bin" "/sbin" "/bin" "/usr/lib/emacs/24.5/x86_64-linux-gnu")

Whereas "normal" emacs has the full path I normally use:

exec-path is a variable defined in `C source code'.
Its value is
("/usr/local/sbin" "/usr/local/bin" "/usr/sbin" "/usr/bin" "/sbin" "/bin" "/usr/games" "/usr/local/games" "/snap/bin" "/bin" "/usr/local/bin" "/sbin" "/usr/bin" "/usr/local/sbin" "/opt/node-v4.2.1-linux-x64/bin" "/opt/node-v4.2.1-li\
nux-x64/bin/node" "/home/optonox/.npm-global/bin" "/usr/local/mongodb/bin" "/snap/bin" "/bin" "/usr/local/bin" "/sbin" "/usr/bin" "/usr/local/sbin" "/opt/node-v4.2.1-linux-x64/bin" "/opt/node-v4.2.1-linux-x64/bin/node" "/home/optono\
x/.npm-global/bin" "/usr/local/mongodb/bin" "/usr/lib/emacs/24.5/x86_64-linux-gnu") 

Why is this happening / can I start it normally somehow?

2 Answers 2

4

exec_path is initialized from the EMACSPATH and PATH environment variables. Emacs also adds the directory containing the emacs binary to the end. This is done at startup by init_callproc_1 in callproc.c (http://git.savannah.gnu.org/cgit/emacs.git/tree/src/callproc.c#n1466)

The systemd.exec man page has a section about the environment variables it sets whenever it starts a process. Here's what it has to say about PATH:

   $PATH
       Colon-separated list of directories to use when launching executables. Systemd uses a fixed value of
       /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin.

Since that matches very well with your exec-path, the only real mystery is why you're ending up with the string "PATH" in there; that's kinda weird.

4
  • I see so the real fix is to try to somehow set the path in systemd. Because that seems hard, I wonder, is there an easy way to set the path in emacs? It seems like there should be an argument passed in.
    – Startec
    Commented Oct 19, 2016 at 6:51
  • You can customize exec-path to whatever value you want, or you can change the environment that systemd launches emacs in. For example, you could add Environment="EMACSPATH=/foo/bar:…" to your systemd unit file.
    – db48x
    Commented Oct 19, 2016 at 7:09
  • I'm assuming EMACSPATH is just an example variable correct? I would really want to set PATH correct?
    – Startec
    Commented Oct 19, 2016 at 17:54
  • 1
    No. Emacs will use the values from both EMACSPATH and PATH, as you can see in the source code that I linked to. I recommend setting EMACSPATH unless you specifically need to set PATH for some reason you haven't mentioned in your question. It's safer, because only Emacs will use it.
    – db48x
    Commented Oct 20, 2016 at 3:47
1

Old question, new answer...

I was in the same position, and met success following the advice in 1 to install the package exec-path-from-shell and add to my ~/.emacs.d/init.el

(require 'exec-path-from-shell)
(exec-path-from-shell-initialize)

For me, this solution was necessitated by not having any other means than systemd to get an emacs --daemon to reliably persist between between (dropped) sessions.

1
  • thanks, it works perfectly! Commented Nov 23, 2021 at 0:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.