aboutsummaryrefslogtreecommitdiffstats
path: root/acpiconf-8-Add-libxo-3-support.patch
diff options
context:
space:
mode:
authorCameron Katri <me@cameronkatri.com>2021-05-30 17:21:13 -0400
committerCameron Katri <me@cameronkatri.com>2021-05-30 17:21:13 -0400
commit85c2054fdbac56a5f60001d504190317b1729ee7 (patch)
tree0179f5d50ba16b0f81dea05c17fac88b0b4ec37f /acpiconf-8-Add-libxo-3-support.patch
downloadfreebsd-patches-85c2054fdbac56a5f60001d504190317b1729ee7.tar.gz
freebsd-patches-85c2054fdbac56a5f60001d504190317b1729ee7.tar.zst
freebsd-patches-85c2054fdbac56a5f60001d504190317b1729ee7.zip
Initial
Diffstat (limited to 'acpiconf-8-Add-libxo-3-support.patch')
-rw-r--r--acpiconf-8-Add-libxo-3-support.patch352
1 files changed, 352 insertions, 0 deletions
diff --git a/acpiconf-8-Add-libxo-3-support.patch b/acpiconf-8-Add-libxo-3-support.patch
new file mode 100644
index 0000000..641c18f
--- /dev/null
+++ b/acpiconf-8-Add-libxo-3-support.patch
@@ -0,0 +1,352 @@
+From b01ad1d67883953d2f0f22b792a8613b8c31d28d Mon Sep 17 00:00:00 2001
+From: Cameron Katri <me@cameronkatri.com>
+Date: Thu, 20 May 2021 15:03:17 -0400
+Subject: [PATCH] acpiconf(8): Add libxo(3) support
+
+---
+ usr.sbin/acpi/acpiconf/Makefile | 2 +
+ usr.sbin/acpi/acpiconf/acpiconf.8 | 12 ++-
+ usr.sbin/acpi/acpiconf/acpiconf.c | 122 ++++++++++++++++--------------
+ 3 files changed, 80 insertions(+), 56 deletions(-)
+
+diff --git a/usr.sbin/acpi/acpiconf/Makefile b/usr.sbin/acpi/acpiconf/Makefile
+index 0bbadc1e8fb..479cf9563b2 100644
+--- a/usr.sbin/acpi/acpiconf/Makefile
++++ b/usr.sbin/acpi/acpiconf/Makefile
+@@ -5,4 +5,6 @@ PROG= acpiconf
+ MAN= acpiconf.8
+ WARNS?= 3
+
++LIBADD= xo
++
+ .include <bsd.prog.mk>
+diff --git a/usr.sbin/acpi/acpiconf/acpiconf.8 b/usr.sbin/acpi/acpiconf/acpiconf.8
+index 53888d8489e..7e4e7c9564c 100644
+--- a/usr.sbin/acpi/acpiconf/acpiconf.8
++++ b/usr.sbin/acpi/acpiconf/acpiconf.8
+@@ -27,7 +27,7 @@
+ .\"
+ .\" $FreeBSD$
+ .\"
+-.Dd December 27, 2018
++.Dd May 19, 2021
+ .Dt ACPICONF 8
+ .Os
+ .Sh NAME
+@@ -35,6 +35,7 @@
+ .Nd control ACPI power management
+ .Sh SYNOPSIS
+ .Nm
++.Op Fl -libxo
+ .Op Fl h
+ .Op Fl i Ar batt
+ .Op Fl k Ar ack
+@@ -46,6 +47,13 @@ utility allows the user control of the ACPI power management
+ functions.
+ The following command-line options are recognized:
+ .Bl -tag -width ".Fl s Ar type"
++.It Fl -libxo
++Generate output via
++.Xr libxo 3
++in a selection of different human and machine readable formats.
++See
++.Xr xo_parse_args 3
++for details on command line arguments.
+ .It Fl h
+ Displays a summary of available options.
+ .It Fl i Ar batt
+@@ -96,6 +104,8 @@ for more information about
+ .Va $local_startup .
+ .El
+ .Sh SEE ALSO
++.Xr libxo 3 ,
++.Xr xo_parse_args 3 ,
+ .Xr acpi 4 ,
+ .Xr acpidump 8 ,
+ .Xr apm 8 ,
+diff --git a/usr.sbin/acpi/acpiconf/acpiconf.c b/usr.sbin/acpi/acpiconf/acpiconf.c
+index 8a31657fb98..35c40ff1ab7 100644
+--- a/usr.sbin/acpi/acpiconf/acpiconf.c
++++ b/usr.sbin/acpi/acpiconf/acpiconf.c
+@@ -37,6 +37,7 @@
+ #include <sys/ioctl.h>
+ #include <sysexits.h>
+ #include <unistd.h>
++#include <libxo/xo.h>
+
+ #include <dev/acpica/acpiio.h>
+
+@@ -53,7 +54,7 @@ acpi_init(void)
+ if (acpifd == -1)
+ acpifd = open(ACPIDEV, O_RDONLY);
+ if (acpifd == -1)
+- err(EX_OSFILE, ACPIDEV);
++ xo_err(EX_OSFILE, ACPIDEV);
+ }
+
+ /* Prepare to sleep and then wait for the signal that sleeping can occur. */
+@@ -65,7 +66,7 @@ acpi_sleep(int sleep_type)
+ /* Notify OS that we want to sleep. devd(8) gets this notify. */
+ ret = ioctl(acpifd, ACPIIO_REQSLPSTATE, &sleep_type);
+ if (ret != 0)
+- err(EX_IOERR, "request sleep type (%d) failed", sleep_type);
++ xo_err(EX_IOERR, "request sleep type (%d) failed", sleep_type);
+ }
+
+ /* Ack or abort a pending suspend request. */
+@@ -76,7 +77,7 @@ acpi_sleep_ack(int err_val)
+
+ ret = ioctl(acpifd, ACPIIO_ACKSLPSTATE, &err_val);
+ if (ret != 0)
+- err(EX_IOERR, "ack sleep type failed");
++ xo_err(EX_IOERR, "ack sleep type failed");
+ }
+
+ /* should be a acpi define, but doesn't appear to be */
+@@ -92,78 +93,82 @@ acpi_battinfo(int num)
+ uint32_t volt;
+
+ if (num < 0 || num > 64)
+- errx(EX_USAGE, "invalid battery %d", num);
++ xo_errx(EX_USAGE, "invalid battery %d", num);
+
+ /* Print battery design information. */
+ battio.unit = num;
+ if (ioctl(acpifd, ACPIIO_BATT_GET_BIX, &battio) == -1)
+- err(EX_IOERR, "get battery info (%d) failed", num);
++ xo_err(EX_IOERR, "get battery info (%d) failed", num);
+ amp = battio.bix.units;
+ pwr_units = amp ? "mA" : "mW";
+ if (battio.bix.dcap == UNKNOWN_CAP)
+- printf("Design capacity:\tunknown\n");
++ xo_emit("{Lc:Design capacity}{P:\t}{:design-capacity/unknown}\n");
+ else
+- printf("Design capacity:\t%d %sh\n", battio.bix.dcap,
+- pwr_units);
++ xo_emit("{Lc:Design capacity}{P:\t}{:design-capacity/%d}{Uw:/%sh}\n",
++ battio.bix.dcap, pwr_units);
+ if (battio.bix.lfcap == UNKNOWN_CAP)
+- printf("Last full capacity:\tunknown\n");
++ xo_emit("{Lc:Last full capacity}{P:\t}{:last-full-capacity/unknown}\n");
+ else
+- printf("Last full capacity:\t%d %sh\n", battio.bix.lfcap,
+- pwr_units);
+- printf("Technology:\t\t%s\n", battio.bix.btech == 0 ?
++ xo_emit("{Lc:Last full capacity}{P:\t}{:last-full-capacity/%d}{Uw:/%sh}\n",
++ battio.bix.lfcap, pwr_units);
++ xo_emit("{Lc:Technology}{P:\t\t}{:technology}\n", battio.bix.btech == 0 ?
+ "primary (non-rechargeable)" : "secondary (rechargeable)");
+ if (ACPI_BIX_REV_MIN_CHECK(battio.bix.rev, ACPI_BIX_REV_1)) {
+- printf("Battery Swappable Capability:\t");
++ xo_emit("{Lc:Battery Swappable Capability}{P:\t}");
+ if (battio.bix.scap == ACPI_BIX_SCAP_NO)
+- printf("Non-swappable\n");
++ xo_emit("{:swappable/Non-swappable/no}\n");
+ else if (battio.bix.scap == ACPI_BIX_SCAP_COLD)
+- printf("cold swap\n");
++ xo_emit("{:swappable/cold swap/cold}\n");
+ else if (battio.bix.scap == ACPI_BIX_SCAP_HOT)
+- printf("hot swap\n");
++ xo_emit("{:swappable/hot swap/hot}\n");
+ else
+- printf("unknown\n");
++ xo_emit("{:swappable/unknown}\n");
+ }
+ if (battio.bix.dvol == UNKNOWN_CAP)
+- printf("Design voltage:\t\tunknown\n");
++ xo_emit("{Lc:Design voltage}{P:\t\t}{:voltage/unknown}\n");
+ else
+- printf("Design voltage:\t\t%d mV\n", battio.bix.dvol);
+- printf("Capacity (warn):\t%d %sh\n", battio.bix.wcap, pwr_units);
+- printf("Capacity (low):\t\t%d %sh\n", battio.bix.lcap, pwr_units);
++ xo_emit("{Lc:Design voltage}{P:\t\t}{:voltage/%d}{Uw:mV}\n", battio.bix.dvol);
++ xo_emit("{Lc:Capacity (warn)}{P:\t}{:warn-capacity/%d}{Uw:/%sh}\n",
++ battio.bix.wcap, pwr_units);
++ xo_emit("{Lc:Capacity (low)}{P:\t\t}{:low-capacity/%d}{Uw:/%sh}\n",
++ battio.bix.lcap, pwr_units);
+ if (ACPI_BIX_REV_MIN_CHECK(battio.bix.rev, ACPI_BIX_REV_0)) {
+ if (battio.bix.cycles != ACPI_BATT_UNKNOWN)
+- printf("Cycle Count:\t\t%d\n", battio.bix.cycles);
+- printf("Mesurement Accuracy:\t%d %%\n",
++ xo_emit("{Lc:Cycle Count}{P:\t\t}{:cycles/%d}\n", battio.bix.cycles);
++ xo_emit("{Lc:Mesurement Accuracy}{P:\t}{:accuracy/%d}{Uw:%%}\n",
+ battio.bix.accuracy / 1000);
+ if (battio.bix.stmax != ACPI_BATT_UNKNOWN)
+- printf("Max Sampling Time:\t%d ms\n",
++ xo_emit("{Lc:Max Sampling Time}{P:\t}{:sampling-max/%d}{Uw:ms}\n",
+ battio.bix.stmax);
+ if (battio.bix.stmin != ACPI_BATT_UNKNOWN)
+- printf("Min Sampling Time:\t%d ms\n",
++ xo_emit("{Lc:Min Sampling Time}{P:\t}{:sampling-min/%d}{Uw:ms}\n",
+ battio.bix.stmin);
+- printf("Max Average Interval:\t%d ms\n",
++ xo_emit("{Lc:Max Average Interval}{P:\t}{:avg-interval-max/%d}{Uw:ms}\n",
+ battio.bix.aimax);
+- printf("Min Average Interval:\t%d ms\n",
++ xo_emit("{Lc:Min Average Interval}{P:\t}{:avg-interval-min/%d}{Uw:ms}\n",
+ battio.bix.aimin);
+ }
+- printf("Low/warn granularity:\t%d %sh\n", battio.bix.gra1, pwr_units);
+- printf("Warn/full granularity:\t%d %sh\n", battio.bix.gra2, pwr_units);
+- printf("Model number:\t\t%s\n", battio.bix.model);
+- printf("Serial number:\t\t%s\n", battio.bix.serial);
+- printf("Type:\t\t\t%s\n", battio.bix.type);
+- printf("OEM info:\t\t%s\n", battio.bix.oeminfo);
++ xo_emit("Low/warn granularity:{P:\t}{:granularity-lw/%d}{Uw:/%sh}\n",
++ battio.bix.gra1, pwr_units);
++ xo_emit("Warn/full granularity:{P:\t}{:granularity-wf/%d}{Uw:/%sh}\n",
++ battio.bix.gra2, pwr_units);
++ xo_emit("{Lc:Model number}{P:\t\t}{:model}\n", battio.bix.model);
++ xo_emit("{Lc:Serial number}{P:\t\t}{:serial}\n", battio.bix.serial);
++ xo_emit("{Lc:Type}{P:\t\t\t}{:type}\n", battio.bix.type);
++ xo_emit("{Lc:OEM info}{P:\t\t}{:oeminfo}\n", battio.bix.oeminfo);
+
+ /* Fetch battery voltage information. */
+ volt = UNKNOWN_VOLTAGE;
+ battio.unit = num;
+ if (ioctl(acpifd, ACPIIO_BATT_GET_BST, &battio) == -1)
+- err(EX_IOERR, "get battery status (%d) failed", num);
++ xo_err(EX_IOERR, "get battery status (%d) failed", num);
+ if (battio.bst.state != ACPI_BATT_STAT_NOT_PRESENT)
+ volt = battio.bst.volt;
+
+ /* Print current battery state information. */
+ battio.unit = num;
+ if (ioctl(acpifd, ACPIIO_BATT_GET_BATTINFO, &battio) == -1)
+- err(EX_IOERR, "get battery user info (%d) failed", num);
++ xo_err(EX_IOERR, "get battery user info (%d) failed", num);
+ if (battio.battinfo.state != ACPI_BATT_STAT_NOT_PRESENT) {
+ const char *state;
+ switch (battio.battinfo.state & ACPI_BATT_STAT_BST_MASK) {
+@@ -188,36 +193,36 @@ acpi_battinfo(int num)
+ default:
+ state = "invalid";
+ }
+- printf("State:\t\t\t%s\n", state);
++ xo_emit("{Lc:State}{P:\t\t\t}{:state}\n", state);
+ if (battio.battinfo.cap == -1)
+- printf("Remaining capacity:\tunknown\n");
++ xo_emit("{Lc:Remaining capacity}{P:\t}{:remaining-capacity/unknown}\n");
+ else
+- printf("Remaining capacity:\t%d%%\n",
++ xo_emit("{Lc:Remaining capacity}{P:\t}{:remaining-capacity/%d}{D:%%}\n",
+ battio.battinfo.cap);
+ if (battio.battinfo.min == -1)
+- printf("Remaining time:\t\tunknown\n");
++ xo_emit("{Lc:Remaining time}{P:\t\t}{:remaining-time/unknown}\n");
+ else {
+ hours = battio.battinfo.min / 60;
+ min = battio.battinfo.min % 60;
+- printf("Remaining time:\t\t%d:%02d\n", hours, min);
++ xo_emit("{Lc:Remaining time}{P:\t\t}{:remaining-time/%d:%02d}\n", hours, min);
+ }
+ if (battio.battinfo.rate == -1)
+- printf("Present rate:\t\tunknown\n");
++ xo_emit("{Lc:Present rate}{P:\t\t}{:present-rate/unknown}\n");
+ else if (amp && volt != UNKNOWN_VOLTAGE) {
+- printf("Present rate:\t\t%d mA (%d mW)\n",
++ xo_emit("{Lc:Present rate}{P:\t\t}{:present-rate/%d}{Uw:mA} {D:(}{:present-rate-mw/%d}{Uw:mW}{D:)}\n",
+ battio.battinfo.rate,
+ battio.battinfo.rate * volt / 1000);
+ } else
+- printf("Present rate:\t\t%d %s\n",
++ xo_emit("{Lc:Present rate}{P:\t\t}{:present-rate/%d}{Uw:/%s}\n",
+ battio.battinfo.rate, pwr_units);
+ } else
+- printf("State:\t\t\tnot present\n");
++ xo_emit("{Lc:State}{P:\t\t\t}{:state/not present}\n");
+
+ /* Print battery voltage information. */
+ if (volt == UNKNOWN_VOLTAGE)
+- printf("Present voltage:\tunknown\n");
++ xo_emit("{Lc:Present voltage}{P:\t}{q:present-voltage/unknown}\n");
+ else
+- printf("Present voltage:\t%d mV\n", volt);
++ xo_emit("{Lc:Present voltage}{P:\t}{q:present-voltage/%d}{Uw:mV}\n", volt);
+
+ return (0);
+ }
+@@ -225,7 +230,9 @@ acpi_battinfo(int num)
+ static void
+ usage(const char* prog)
+ {
+- printf("usage: %s [-h] [-i batt] [-k ack] [-s 1-4]\n", prog);
++ xo_error("usage: %s [-h] [-i batt] [-k ack] [-s 1-4]\n", prog);
++ xo_close_container("acpiconf");
++ xo_finish();
+ exit(0);
+ }
+
+@@ -237,6 +244,9 @@ main(int argc, char *argv[])
+ int iflag = 0, kflag = 0, sflag = 0;
+
+ prog = argv[0];
++
++ argc = xo_parse_args(argc, argv);
++ xo_open_container("acpiconf");
+ if (argc < 2)
+ usage(prog);
+ /* NOTREACHED */
+@@ -249,13 +259,13 @@ main(int argc, char *argv[])
+ iflag = 1;
+ battery = strtol(optarg, &end, 10);
+ if ((size_t)(end - optarg) != strlen(optarg))
+- errx(EX_USAGE, "invalid battery");
++ xo_errx(EX_USAGE, "invalid battery");
+ break;
+ case 'k':
+ kflag = 1;
+ ack = strtol(optarg, &end, 10);
+ if ((size_t)(end - optarg) != strlen(optarg))
+- errx(EX_USAGE, "invalid ack argument");
++ xo_errx(EX_USAGE, "invalid ack argument");
+ break;
+ case 's':
+ sflag = 1;
+@@ -263,9 +273,9 @@ main(int argc, char *argv[])
+ optarg++;
+ sleep_type = strtol(optarg, &end, 10);
+ if ((size_t)(end - optarg) != strlen(optarg))
+- errx(EX_USAGE, "invalid sleep type");
++ xo_errx(EX_USAGE, "invalid sleep type");
+ if (sleep_type < 1 || sleep_type > 4)
+- errx(EX_USAGE, "invalid sleep type (%d)",
++ xo_errx(EX_USAGE, "invalid sleep type (%d)",
+ sleep_type);
+ break;
+ case 'h':
+@@ -278,19 +288,19 @@ main(int argc, char *argv[])
+ argv += optind;
+
+ if (iflag != 0 && kflag != 0 && sflag != 0)
+- errx(EX_USAGE, "-i, -k and -s are mutually exclusive");
++ xo_errx(EX_USAGE, "-i, -k and -s are mutually exclusive");
+
+ if (iflag != 0) {
+ if (kflag != 0)
+- errx(EX_USAGE, "-i and -k are mutually exclusive");
++ xo_errx(EX_USAGE, "-i and -k are mutually exclusive");
+ if (sflag != 0)
+- errx(EX_USAGE, "-i and -s are mutually exclusive");
++ xo_errx(EX_USAGE, "-i and -s are mutually exclusive");
+ acpi_battinfo(battery);
+ }
+
+ if (kflag != 0) {
+ if (sflag != 0)
+- errx(EX_USAGE, "-k and -s are mutually exclusive");
++ xo_errx(EX_USAGE, "-k and -s are mutually exclusive");
+ acpi_sleep_ack(ack);
+ }
+
+@@ -299,5 +309,7 @@ main(int argc, char *argv[])
+ acpi_sleep(sleep_type);
+
+ close(acpifd);
++ xo_close_container("acpiconf");
++ xo_finish();
+ exit (0);
+ }
+--
+2.31.1
+