Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F137363566
D30350.id.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
11 KB
Referenced Files
None
Subscribers
None
D30350.id.diff
View Options
diff --git a/usr.sbin/acpi/acpiconf/Makefile b/usr.sbin/acpi/acpiconf/Makefile
--- a/usr.sbin/acpi/acpiconf/Makefile
+++ b/usr.sbin/acpi/acpiconf/Makefile
@@ -5,4 +5,6 @@
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
--- a/usr.sbin/acpi/acpiconf/acpiconf.8
+++ b/usr.sbin/acpi/acpiconf/acpiconf.8
@@ -27,7 +27,7 @@
.\"
.\" $FreeBSD$
.\"
-.Dd December 27, 2018
+.Dd February 2, 2023
.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 @@
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_options 7
+for details on command line arguments.
.It Fl h
Displays a summary of available options.
.It Fl i Ar batt
@@ -89,14 +97,16 @@
and the
.Va $local_startup
directories that have a "resume" KEYWORD.
-Called scripts are supplied with single "resume"
+Called scripts are supplied with a single "resume"
command line argument. See
.Xr rc.conf 5
for more information about
.Va $local_startup .
.El
.Sh SEE ALSO
+.Xr libxo 3 ,
.Xr acpi 4 ,
+.Xr xo_options 7 ,
.Xr acpidump 8 ,
.Xr apm 8 ,
.Xr apmd 8 ,
diff --git a/usr.sbin/acpi/acpiconf/acpiconf.c b/usr.sbin/acpi/acpiconf/acpiconf.c
--- 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 @@
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 @@
/* 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 @@
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 @@
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("Measurement Accuracy:\t%d %%\n",
+ xo_emit("{Lc:Cycle Count}{P:\t\t}{:cycles/%d}\n", battio.bix.cycles);
+ xo_emit("{Lc:Messurement 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("{Lc:Low\\/warn granularity}{P:\t}{:granularity-lw/%d}{Uw:/%sh}\n",
+ battio.bix.gra1, pwr_units);
+ xo_emit("{Lc: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 @@
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 @@
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,12 @@
int iflag = 0, kflag = 0, sflag = 0;
prog = argv[0];
+
+ argc = xo_parse_args(argc, argv);
+ if (argc < 0)
+ exit(EXIT_FAILURE);
+
+ xo_open_container("acpiconf");
if (argc < 2)
usage(prog);
/* NOTREACHED */
@@ -249,13 +262,13 @@
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 +276,9 @@
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 +291,19 @@
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 +312,7 @@
acpi_sleep(sleep_type);
close(acpifd);
+ xo_close_container("acpiconf");
+ xo_finish();
exit (0);
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Nov 23, 7:39 PM (9 h, 1 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
26028976
Default Alt Text
D30350.id.diff (11 KB)
Attached To
Mode
D30350: acpiconf(8): Add libxo(3) support
Attached
Detach File
Event Timeline
Log In to Comment