Hi Michael,
Michael Biebl <[email protected]> writes:
> a/ # of initscripts: 1192 (+3 symlinks)
> $ find . -type f | wc -l
> 1192
<Nitpick>
Slightly wrong, you are also matching non-executable files.
The actual number of init scripts is 1189 as determined by
$ find . -type f -perm 755 | wc -l
</Nitpick>
> f/ # of Usage lines using continuations:
> $ grep -vE "^\s*#.*" */*/* | grep '[Uu]sage.*\\$' | wc -l
> 10
Good catch. Of those, ifupdown-extra_0.22/init.d/networking-routes is a
false-positive but the other 9 are valid cases.
> Comments:
> 1/ I think it would be nice to check for [{|]reload[}|"] as delimiters,
> even if d/ currently doesn't turn up any additional hits. Just to be
> future-proof.
Done.
> 2/ f/ makes make think we should handle line continuations. This should
> probably be done like the existing code, using a STATE variable, i.e. we
> enter that state once we find ".*\\$" and leave it again as soon as this
> is no longer the case.
Also done. With the previous version of my patch:
$ systemctl show -p CanReload openarena-server.service
CanReload=no
$ systemctl show -p CanReload pulseaudio.service
CanReload=yes
$ systemctl show -p CanReload libvirt-guests.service
CanReload=no
With the latest (attached) version of my patch:
$ systemctl show -p CanReload openarena-server.service
CanReload=no
$ systemctl show -p CanReload pulseaudio.service
CanReload=yes
$ systemctl show -p CanReload libvirt-guests.service
CanReload=yes
--- systemd-44.orig/src/service.c 2012-03-12 21:49:16.000000000 +0100
+++ systemd-44/src/service.c 2012-10-15 00:25:38.357247732 +0200
@@ -494,7 +494,7 @@
return c;
}
-static int sysv_exec_commands(Service *s) {
+static int sysv_exec_commands(Service *s, const bool supports_reload) {
ExecCommand *c;
assert(s);
@@ -508,9 +508,11 @@
return -ENOMEM;
exec_command_append_list(s->exec_command+SERVICE_EXEC_STOP, c);
- if (!(c = exec_command_new(s->sysv_path, "reload")))
- return -ENOMEM;
- exec_command_append_list(s->exec_command+SERVICE_EXEC_RELOAD, c);
+ if (supports_reload) {
+ if (!(c = exec_command_new(s->sysv_path, "reload")))
+ return -ENOMEM;
+ exec_command_append_list(s->exec_command+SERVICE_EXEC_RELOAD, c);
+ }
return 0;
}
@@ -524,10 +526,12 @@
NORMAL,
DESCRIPTION,
LSB,
- LSB_DESCRIPTION
+ LSB_DESCRIPTION,
+ USAGE_CONTINUATION
} state = NORMAL;
char *short_description = NULL, *long_description = NULL, *chkconfig_description = NULL, *description;
struct stat st;
+ bool supports_reload = false;
assert(s);
assert(path);
@@ -574,8 +578,29 @@
line++;
t = strstrip(l);
- if (*t != '#')
+ if (*t != '#') {
+ /* Try to figure out whether this init script supports
+ * the reload operation. This heuristic looks for
+ * "Usage: " lines which include the reload option. */
+ if ( state == USAGE_CONTINUATION ||
+ (state == NORMAL && strcasestr(t, "usage"))) {
+ if (strcasestr(t, "{reload|") ||
+ strcasestr(t, "{reload}") ||
+ strcasestr(t, "{reload\"") ||
+ strcasestr(t, "|reload|") ||
+ strcasestr(t, "|reload}") ||
+ strcasestr(t, "|reload\"")) {
+ supports_reload = true;
+ state = NORMAL;
+ } else if (t[strlen(t)-1] == '\\') {
+ state = USAGE_CONTINUATION;
+ } else {
+ state = NORMAL;
+ }
+ }
+
continue;
+ }
if (state == NORMAL && streq(t, "### BEGIN INIT INFO")) {
state = LSB;
@@ -868,7 +893,7 @@
}
}
- if ((r = sysv_exec_commands(s)) < 0)
+ if ((r = sysv_exec_commands(s, supports_reload)) < 0)
goto finish;
if (s->sysv_runlevels &&
chars_intersect(RUNLEVELS_BOOT, s->sysv_runlevels) &&
--
Best regards,
Michael