From d5fd7d1ff201db49c10704db0d51cdbb23bc177b Mon Sep 17 00:00:00 2001 From: Colin Booth Date: Mon, 8 Mar 2021 22:02:06 -0800 Subject: 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 --- halt.c | 6 +++--- 1 file 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."); -- cgit 1.4.1