On Fri, Jul 28, 2017 at 12:09:17AM +0100, Marco Bonetti wrote:
> It looks like spaces and tabs got mangled, I'm resending the diff in-line in
> this email.
>
> Any other comments / OKs ?
>
> 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 24 Jul 2017 23:48:06 -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=power down 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 24 Jul 2017 23:48:06 -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=power down 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 24 Jul 2017 23:48:06 -0000
> @@ -1 +1 @@
> -#machdep.lidaction=0 # 1=suspend, 2=hibernate laptop upon lid closing
> +#machdep.lidaction=0 # 1=suspend, 2=hibernate, 3=power down 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 24 Jul 2017 23:48:11 -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 24 Jul 2017 23:48:12 -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 24 Jul 2017 23:48:12 -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 24 Jul 2017 23:48:12 -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;
I don't have a strong opinion on this one way or another, except
perhaps option overload.. but can't one already set lidaction=0
and then have sensorsd(8) or some script watch the acpibtn lid
sensor?