summary refs log tree commit diff
diff options
context:
space:
mode:
authorColin Booth <colin@heliocat.net>2021-03-08 22:02:06 -0800
committerLeah Neukirchen <leah@vuxu.org>2021-03-10 12:37:04 +0100
commitd5fd7d1ff201db49c10704db0d51cdbb23bc177b (patch)
tree7923a09978dc2d82656ab70b6e3fdfb493a3edc7
parentc1687e7f431e8ec0bd23a9b616715f43055068ce (diff)
downloadrunit-void-d5fd7d1ff201db49c10704db0d51cdbb23bc177b.tar.gz
runit-void-d5fd7d1ff201db49c10704db0d51cdbb23bc177b.tar.xz
runit-void-d5fd7d1ff201db49c10704db0d51cdbb23bc177b.zip
halt: switch __progname tests to use strncmp
The pending change to allow for alternate init power controls requires
that the halt binary provided here be somewhat less strict in its
argv[0] matching in order to allow for halt, reboot, and poweroff to
still function in situations where the binary has been renamed.

This switches from strcmp(__progname, "string") to strncmp(__progname,
"string", len), where len is the name of the power command sans any
suffix.

Signed-off-by: Colin Booth <colin@heliocat.net>
-rw-r--r--halt.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/halt.c b/halt.c
index 3f1062e..bb6f8ff 100644
--- a/halt.c
+++ b/halt.c
@@ -63,11 +63,11 @@ int main(int argc, char *argv[]) {
   int opt;
   action_type action = NOOP;
 
-  if (strcmp(__progname, "halt") == 0)
+  if (strncmp(__progname, "halt", 4) == 0)
     action = HALT;
-  else if (strcmp(__progname, "reboot") == 0)
+  else if (strncmp(__progname, "reboot", 6) == 0)
     action = REBOOT;
-  else if (strcmp(__progname, "poweroff") == 0)
+  else if (strncmp(__progname, "poweroff", 8) == 0)
     action = POWEROFF;
   else
     warnx("no default behavior, needs to be called as halt/reboot/poweroff.");