Skip to content

Commit d5fd7d1

Browse files
heliocatleahneukirchen
authored andcommitted
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>
1 parent c1687e7 commit d5fd7d1

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

halt.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,11 @@ int main(int argc, char *argv[]) {
6363
int opt;
6464
action_type action = NOOP;
6565

66-
if (strcmp(__progname, "halt") == 0)
66+
if (strncmp(__progname, "halt", 4) == 0)
6767
action = HALT;
68-
else if (strcmp(__progname, "reboot") == 0)
68+
else if (strncmp(__progname, "reboot", 6) == 0)
6969
action = REBOOT;
70-
else if (strcmp(__progname, "poweroff") == 0)
70+
else if (strncmp(__progname, "poweroff", 8) == 0)
7171
action = POWEROFF;
7272
else
7373
warnx("no default behavior, needs to be called as halt/reboot/poweroff.");

0 commit comments

Comments
 (0)