davmac314 / dinit

Service monitoring / "init" system
Apache License 2.0
622 stars 49 forks source link

single quote in command cannot be parsed #332

Closed iacore closed 6 months ago

iacore commented 6 months ago

Describe the bug & Reproduction

Create a file dinit.d/a with this content:

type = process
command = /bin/sh -c 'sleep 1 && echo 1'
logfile = /tmp/log-a

Then try to start the service. It fails.

❯ dinitctl start a
Service 'a' started.

❯ cat /tmp/log-a 
1: -c: line 1: unexpected EOF while looking for matching `''
1: -c: line 1: unexpected EOF while looking for matching `''
1: -c: line 1: unexpected EOF while looking for matching `''
1: -c: line 1: unexpected EOF while looking for matching `''

Expected behavior Not sure what is the correct behavior here. Maybe POSIX-compatible shell parsing?

Additional context Add any other context about the problem here.

davmac314 commented 6 months ago

The correct behaviour is what is documented (in the dinit-service manpage). The parsing won't ever be POSIX shell compatible, that's definitely a non-goal.

Your example should work if written with double quotes, as:

command = /bin/sh -c "sleep 1 && echo 1"
iacore commented 6 months ago

Thanks for the clarification!

This part is still unclear to me.

  •      For  settings  which specify a command with arguments, the value is interpreted as a series
         of tokens separated by white space, rather than a single string of characters.
  •      Double quotes (") can be used around all or part of a property value, to prevent whitespace
         collapse and prevent interpretation of other special characters (such as  "#")  inside  the
         quotes.   The  quote characters are not considered part of the property value.  White space
         appearing inside quotes does not act as a delimiter for tokens.

I think it means that normally, there's <key> = <token> on one line, but for commands, it's <key> = <token> <token> <token> <token> ....

Maybe we should swap the order of the two bullet points?