troglobit / finit

Fast init for Linux. Cookies included
https://troglobit.com/projects/finit/
MIT License
633 stars 63 forks source link

Allow \ in .conf files to allow multiple lines for run/task/service #186

Closed hongkongkiwi closed 2 years ago

hongkongkiwi commented 3 years ago

I saw that there is an open task for a new .svc format #148 which breaks the service up into multiline syntax.

Before this new format is implemented, I was wondering if it's possible to just allow \ to breakup lines (like in shell scripts). This would mean we could have multiline service definitions with minimal work.... e.g.

service [2345] \
env:-/etc/conf.d/gpsd \
-N -s $GPSD_SERIAL_SPEED -S $GPSD_PORT \
 -F "$GPSD_SOCK" -D $GPSD_DEBUG_LEVEL \
$GPSD_OPTIONS "$GPSD_DEVICE" \
-- GPS Daemon
troglobit commented 3 years ago

No, I'd much rather we implement the new format instead. There's just too much that can go wrong with this proposal, because I've actually tried once before.

troglobit commented 2 years ago

Since yesterday I've looked into this again, in part due to your comment in #148, but also because I've been hit by the problem of long lines myself the last six months ... I admit I was wrong for closing this, sorry.

Looking into the matter a bit further, I realized one of the libraries we use carry fparseln(), from NetBSD, which sort of exist for this very use-case.

Only downside is that it's a bit too competent, not only does it prune .conf lines starting with comment, it also drops comments trailing a line ... unless it's escaped. Nevertheless, I think fparseln() is the way forward here -- even though some uses may experience some regressions.

Our own test/initctl-status-subset.sh immediately caught the problem. It has the following services:

task manual:yes name:foo :1 serv -- Foo #1
task manual:yes name:foo :2 serv -- Foo #2
task manual:yes name:foo :3 serv -- Foo #3

The test fails since it cannot find any service with decription "Foo #1". However, escaping them works, so that needs to go into the documentation and ChangeLog for this upcoming release:

task manual:yes name:foo :1 serv -- Foo \#1
task manual:yes name:foo :2 serv -- Foo \#2
task manual:yes name:foo :3 serv -- Foo \#3
troglobit commented 2 years ago

There, fixed.

hongkongkiwi commented 2 years ago

This is really helpful! Thank you.

Hmm yes, apart from comments and \ what other characters need escaping here?

troglobit commented 2 years ago

None, only \ has special meaning. The thing with # is that trailing comments was not supported before, but with the new implementation it is. So you need to escape \ and # only.