Christian Weisgerber wrote:
>> --- shutdown.c 16 Jan 2015 06:40:01 -0000 1.38
>> +++ shutdown.c 19 Jan 2015 12:03:03 -0000
>> @@ -134,6 +134,7 @@ main(int argc, char *argv[])
>> nosync = 1;
>> break;
>> case 'p':
>> + dohalt = 1;
>> dopower = 1;
>> break;
>> case 'r':
>
> I don't like this. Instead, all the places that handle dohalt and
> doreboot should be extended with dopower; see the FreeBSD code.
>
Is this more to your liking ?
Make -h, -p and -r distinct, incompatible, options. (removes support for -hp)
Like FreeBSD, it seems reasonable to also mark -k as incompatible with the
other three options.
Give -p a distinct code path, sort of.
BTW the previous patch emitted an incorrect message when specifying -pr.
Index: shutdown.c
===================================================================
RCS file: /cvs/src/sbin/shutdown/shutdown.c,v
retrieving revision 1.38
diff -u -p -r1.38 shutdown.c
--- shutdown.c 16 Jan 2015 06:40:01 -0000 1.38
+++ shutdown.c 20 Jan 2015 11:13:46 -0000
@@ -153,14 +153,9 @@ main(int argc, char *argv[])
"shutdown: incompatible switches -f and -n.\n");
usage();
}
- if (doreboot && dohalt) {
+ if (dohalt + killflg + dopower + doreboot > 1) {
(void)fprintf(stderr,
- "shutdown: incompatible switches -h and -r.\n");
- usage();
- }
- if (dopower && !dohalt) {
- (void)fprintf(stderr,
- "shutdown: switch -p must be used with -h.\n");
+ "shutdown: incompatible switches -h, -k, -p and -r.\n");
usage();
}
getoffset(*argv++);
@@ -363,7 +358,7 @@ die_you_gravy_sucking_pig_dog(void)
syslog(LOG_ERR, "shutdown: can't exec %s: %m.", _PATH_REBOOT);
warn(_PATH_REBOOT);
}
- else if (dohalt) {
+ else if (dohalt || dopower) {
execle(_PATH_HALT, "halt", "-l",
(dopower ? "-p" : (nosync ? "-n" : (dodump ? "-d" : NULL))),
(nosync ? "-n" : (dodump ? "-d" : NULL)),