Ted Unangst wrote:

> On Tue, Jan 20, 2015 at 19:29, Remco wrote:
>> 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.
> 
> I hate this. I type shutdown -hp all the time.


I think this is the best I can come up with in making -p imply -h without
changing anything else:


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 10:51:56 -0000
@@ -158,9 +158,9 @@ main(int argc, char *argv[])
                    "shutdown: incompatible switches -h and -r.\n");
                usage();
        }
-       if (dopower && !dohalt) {
+       if (dopower && doreboot) {
                (void)fprintf(stderr,
-                   "shutdown: switch -p must be used with -h.\n");
+                   "shutdown: incompatible switches -p and -r.\n");
                usage();
        }
        getoffset(*argv++);
@@ -363,7 +363,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)),

Reply via email to