On Mon, Jul 17, 2017 at 02:08:31AM +0200, Marco Bonetti wrote: > Hello tech@, > This is a diff that implements a new value (3) for machdep.lidaction to allow > a laptop powerdown with a lid close. Since this functionality is very close > to machdep.kbdreset=1, the diff follows the same behaviour and prevents > setting machdep.lidaction when securelevel is greater than 0. Let me know > what you think. > > Cheers, > Marco >
morning. "power down", since it is a verb. jmc > Index: etc/etc.amd64/sysctl.conf > =================================================================== > RCS file: /cvs/src/etc/etc.amd64/sysctl.conf,v > retrieving revision 1.7 > diff -u -p -u -p -r1.7 sysctl.conf > --- etc/etc.amd64/sysctl.conf 2 Mar 2017 10:38:09 -0000 1.7 > +++ etc/etc.amd64/sysctl.conf 16 Jul 2017 23:38:33 -0000 > @@ -1,3 +1,3 @@ > #machdep.allowaperture=2 # See xf86(4) > #machdep.kbdreset=1 # permit console CTRL-ALT-DEL to do a nice halt > -#machdep.lidaction=0 # 1=suspend, 2=hibernate laptop upon lid closing > +#machdep.lidaction=0 # 1=suspend, 2=hibernate, 3=powerdown laptop > upon lid closing > Index: etc/etc.i386/sysctl.conf > =================================================================== > RCS file: /cvs/src/etc/etc.i386/sysctl.conf,v > retrieving revision 1.21 > diff -u -p -u -p -r1.21 sysctl.conf > --- etc/etc.i386/sysctl.conf 2 Mar 2017 10:38:09 -0000 1.21 > +++ etc/etc.i386/sysctl.conf 16 Jul 2017 23:38:33 -0000 > @@ -1,4 +1,4 @@ > #machdep.allowaperture=2 # See xf86(4) > #machdep.apmhalt=1 # 1=powerdown hack, try if halt -p doesn't work > #machdep.kbdreset=1 # permit console CTRL-ALT-DEL to do a nice halt > -#machdep.lidaction=0 # 1=suspend, 2=hibernate laptop upon lid closing > +#machdep.lidaction=0 # 1=suspend, 2=hibernate, 3=powerdown laptop > upon lid closing > Index: etc/etc.loongson/sysctl.conf > =================================================================== > RCS file: /cvs/src/etc/etc.loongson/sysctl.conf,v > retrieving revision 1.4 > diff -u -p -u -p -r1.4 sysctl.conf > --- etc/etc.loongson/sysctl.conf 2 Mar 2017 10:38:09 -0000 1.4 > +++ etc/etc.loongson/sysctl.conf 16 Jul 2017 23:38:33 -0000 > @@ -1 +1 @@ > -#machdep.lidaction=0 # 1=suspend, 2=hibernate laptop upon lid closing > +#machdep.lidaction=0 # 1=suspend, 2=hibernate, 3=powerdown laptop > upon lid closing > Index: sys/arch/amd64/amd64/machdep.c > =================================================================== > RCS file: /cvs/src/sys/arch/amd64/amd64/machdep.c,v > retrieving revision 1.231 > diff -u -p -u -p -r1.231 machdep.c > --- sys/arch/amd64/amd64/machdep.c 12 Jul 2017 06:26:32 -0000 1.231 > +++ sys/arch/amd64/amd64/machdep.c 16 Jul 2017 23:38:42 -0000 > @@ -477,15 +477,20 @@ cpu_sysctl(int *name, u_int namelen, voi > case CPU_XCRYPT: > return (sysctl_rdint(oldp, oldlenp, newp, amd64_has_xcrypt)); > case CPU_LIDACTION: > - val = lid_action; > - error = sysctl_int(oldp, oldlenp, newp, newlen, &val); > - if (!error) { > - if (val < 0 || val > 2) > - error = EINVAL; > - else > - lid_action = val; > - } > - return (error); > + if (securelevel > 0) > + return (sysctl_rdint(oldp, oldlenp, newp, > + lid_action)); > + else { > + val = lid_action; > + error = sysctl_int(oldp, oldlenp, newp, newlen, &val); > + if (!error) { > + if (val < 0 || val > 3) > + error = EINVAL; > + else > + lid_action = val; > + } > + return (error); > + } > #if NPCKBC > 0 && NUKBD > 0 > case CPU_FORCEUKBD: > if (forceukbd) > Index: sys/arch/i386/i386/machdep.c > =================================================================== > RCS file: /cvs/src/sys/arch/i386/i386/machdep.c,v > retrieving revision 1.604 > diff -u -p -u -p -r1.604 machdep.c > --- sys/arch/i386/i386/machdep.c 12 Jul 2017 06:26:32 -0000 1.604 > +++ sys/arch/i386/i386/machdep.c 16 Jul 2017 23:38:42 -0000 > @@ -3551,15 +3551,20 @@ cpu_sysctl(int *name, u_int namelen, voi > case CPU_XCRYPT: > return (sysctl_rdint(oldp, oldlenp, newp, i386_has_xcrypt)); > case CPU_LIDACTION: > - val = lid_action; > - error = sysctl_int(oldp, oldlenp, newp, newlen, &val); > - if (!error) { > - if (val < 0 || val > 2) > - error = EINVAL; > - else > - lid_action = val; > - } > - return (error); > + if (securelevel > 0) > + return (sysctl_rdint(oldp, oldlenp, newp, > + lid_action)); > + else { > + val = lid_action; > + error = sysctl_int(oldp, oldlenp, newp, newlen, &val); > + if (!error) { > + if (val < 0 || val > 3) > + error = EINVAL; > + else > + lid_action = val; > + } > + return (error); > + } > #if NPCKBC > 0 && NUKBD > 0 > case CPU_FORCEUKBD: > if (forceukbd) > Index: sys/arch/loongson/loongson/machdep.c > =================================================================== > RCS file: /cvs/src/sys/arch/loongson/loongson/machdep.c,v > retrieving revision 1.79 > diff -u -p -u -p -r1.79 machdep.c > --- sys/arch/loongson/loongson/machdep.c 12 Jul 2017 06:26:33 -0000 > 1.79 > +++ sys/arch/loongson/loongson/machdep.c 16 Jul 2017 23:38:42 -0000 > @@ -1032,7 +1032,7 @@ cpu_sysctl(int *name, u_int namelen, voi > val = lid_action; > error = sysctl_int(oldp, oldlenp, newp, newlen, &val); > if (!error) { > - if (val < 0 || val > 2) > + if (val < 0 || val > 3) > error = EINVAL; > else > lid_action = val; > Index: sys/dev/acpi/acpibtn.c > =================================================================== > RCS file: /cvs/src/sys/dev/acpi/acpibtn.c,v > retrieving revision 1.44 > diff -u -p -u -p -r1.44 acpibtn.c > --- sys/dev/acpi/acpibtn.c 2 Mar 2017 10:38:10 -0000 1.44 > +++ sys/dev/acpi/acpibtn.c 16 Jul 2017 23:38:42 -0000 > @@ -242,6 +242,8 @@ acpibtn_notify(struct aml_node *node, in > sc->sc_acpi, ACPI_SLEEP_HIBERNATE); > break; > #endif > + case 3: > + goto powerdown; > default: > break; > } > @@ -265,6 +267,7 @@ sleep: > break; > case ACPIBTN_POWER: > if (notify_type == 0x80) > +powerdown: > acpi_addtask(sc->sc_acpi, acpi_powerdown_task, > sc->sc_acpi, 0); > break; > > > -- > Marco Bonetti >