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

Absolute path in command line containing spaces #2132

Closed
kevinboulain opened this issue Dec 10, 2015 · 2 comments
Closed

Absolute path in command line containing spaces #2132

kevinboulain opened this issue Dec 10, 2015 · 2 comments
Labels
bug 🐛 Programming errors, that need preferential fixing pid1

Comments

@kevinboulain
Copy link

kevinboulain commented Dec 10, 2015

Hi there,

Today, I needed to quote a path that may contain spaces but I could not find the correct way to write the .service file.
I tried several things, here is the minimal setup:

# cat > /tmp/space\ bin << EOF
#!/bin/sh
echo blah > /tmp/log
EOF
# chmod +x  /tmp/space\ bin

# cat > /etc/systemd/system/path-with-spaces.service << EOF
[Unit]
Description=path with spaces
After=syslog.service

[Service]
ExecStart='/tmp/space bin'
Type=oneshot

[Install]
WantedBy=multi-user.target
EOF
# systemctl daemon-reload
# systemctl status -l path-with-spaces
● path-with-spaces.service - path with spaces
   Loaded: error (Reason: Invalid argument)
   Active: inactive (dead)

Dec 10 09:47:45 host systemd[1]: [/etc/systemd/system/path-with-spaces.service:6] Executable path is not absolute, ignoring: '/tmp/space bin'
Dec 10 09:47:45 host systemd[1]: path-with-spaces.service lacks ExecStart setting. Refusing.
Dec 10 09:48:10 host systemd[1]: [/etc/systemd/system/path-with-spaces.service:6] Executable path is not absolute, ignoring: '/tmp/space bin'
Dec 10 09:48:10 host systemd[1]: path-with-spaces.service lacks ExecStart setting. Refusing.

With a quick search, it seems this is what is causing the error message:

if (!path_is_absolute(f)) {

And this is the the function that test for an absolute path:
bool path_is_absolute(const char *p) {

So quotes are not supported for the executable path yet?

Backslash (__) does not allow to escape the space in the path too (but it is not indicated in the docs anyway).

Maybe related to #624?

On a side note, is it really necessary to try to reload the .service file even if it contain a syntax error (see pasted log above)?

Regards.

EDIT:
By the way, I'm on a Debian Jessie system (if the information is useful):

# systemd --version
systemd 215 +PAM +AUDIT +SELINUX +IMA +SYSVINIT +LIBCRYPTSETUP +GCRYPT +ACL +XZ -SECCOMP -APPARMOR
@n8henrie
Copy link

I think I have the same issue on Raspbian Jessie, can't seem to use a service file with a space in the path.

Thought it would work:

The command to execute must be an absolute path name. It may contain spaces, but control characters are not allowed.

I've tried ExecStart=

  • /path/with spaces/executable -> Failed at step EXEC spawning /path/with: No such file or directory
  • "/path/with spaces/executable" -> Not an absolute path, ignoring:
  • systemd-escape --path "/path/with spaces/executable" -> path-with\x20spaces-executable" -> Not an absolute path, ignoring:
  • /path/with\sspaces/executable -> Failed at step CHDIR spawning /path/with spaces/executable: No such file or directory
  • /path/with\ spaces/executable -> `The process /path/with\ spaces/executable could not be executed and failed.
  • /path/"with spaces"/executable -> Failed at step EXEC spawning /path/"with: No such file or directory
  • /path/without_spaces/executable -> Runs without issue
$ systemd --version
systemd 215
+PAM +AUDIT +SELINUX +IMA +SYSVINIT +LIBCRYPTSETUP +GCRYPT +ACL +XZ -SECCOMP -APPARMOR

EDIT: Found an acceptable workaround: ExecStart=/usr/bin/env "/path/with spaces/executable"

@poettering poettering added bug 🐛 Programming errors, that need preferential fixing pid1 labels Apr 18, 2016
@evverx
Copy link
Member

evverx commented Sep 12, 2016

Fixed: c853953

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Programming errors, that need preferential fixing pid1
Development

No branches or pull requests

4 participants