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?

Startec
  • 1,354
  • 1
  • 13
  • 30

2 Answers2

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.

db48x
  • 15,741
  • 1
  • 19
  • 23
  • 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 Oct 19 '16 at 06: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 Oct 19 '16 at 07:09
  • I'm assuming `EMACSPATH` is just an example variable correct? I would really want to set `PATH` correct? – Startec Oct 19 '16 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 Oct 20 '16 at 03: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.

malcook
  • 111
  • 2