]> git.cameronkatri.com Git - freebsd-patches.git/blob - acpiconf-8-Add-libxo-3-support.patch
Remove upstreamed patch
[freebsd-patches.git] / acpiconf-8-Add-libxo-3-support.patch
1 From fbb0ec5e3cc2f5b6d9cd023fd5cf7ae38b97ad6a Mon Sep 17 00:00:00 2001
2 From: Cameron Katri <me@cameronkatri.com>
3 Date: Thu, 20 May 2021 15:03:17 -0400
4 Subject: [PATCH] acpiconf(8): Add libxo(3) support
5
6 ---
7 usr.sbin/acpi/acpiconf/Makefile | 2 +
8 usr.sbin/acpi/acpiconf/acpiconf.8 | 12 ++-
9 usr.sbin/acpi/acpiconf/acpiconf.c | 122 ++++++++++++++++--------------
10 3 files changed, 80 insertions(+), 56 deletions(-)
11
12 diff --git a/usr.sbin/acpi/acpiconf/Makefile b/usr.sbin/acpi/acpiconf/Makefile
13 index 0bbadc1e8fb..479cf9563b2 100644
14 --- a/usr.sbin/acpi/acpiconf/Makefile
15 +++ b/usr.sbin/acpi/acpiconf/Makefile
16 @@ -5,4 +5,6 @@ PROG= acpiconf
17 MAN= acpiconf.8
18 WARNS?= 3
19
20 +LIBADD= xo
21 +
22 .include <bsd.prog.mk>
23 diff --git a/usr.sbin/acpi/acpiconf/acpiconf.8 b/usr.sbin/acpi/acpiconf/acpiconf.8
24 index 53888d8489e..7e4e7c9564c 100644
25 --- a/usr.sbin/acpi/acpiconf/acpiconf.8
26 +++ b/usr.sbin/acpi/acpiconf/acpiconf.8
27 @@ -27,7 +27,7 @@
28 .\"
29 .\" $FreeBSD$
30 .\"
31 -.Dd December 27, 2018
32 +.Dd May 19, 2021
33 .Dt ACPICONF 8
34 .Os
35 .Sh NAME
36 @@ -35,6 +35,7 @@
37 .Nd control ACPI power management
38 .Sh SYNOPSIS
39 .Nm
40 +.Op Fl -libxo
41 .Op Fl h
42 .Op Fl i Ar batt
43 .Op Fl k Ar ack
44 @@ -46,6 +47,13 @@ utility allows the user control of the ACPI power management
45 functions.
46 The following command-line options are recognized:
47 .Bl -tag -width ".Fl s Ar type"
48 +.It Fl -libxo
49 +Generate output via
50 +.Xr libxo 3
51 +in a selection of different human and machine readable formats.
52 +See
53 +.Xr xo_parse_args 3
54 +for details on command line arguments.
55 .It Fl h
56 Displays a summary of available options.
57 .It Fl i Ar batt
58 @@ -96,6 +104,8 @@ for more information about
59 .Va $local_startup .
60 .El
61 .Sh SEE ALSO
62 +.Xr libxo 3 ,
63 +.Xr xo_parse_args 3 ,
64 .Xr acpi 4 ,
65 .Xr acpidump 8 ,
66 .Xr apm 8 ,
67 diff --git a/usr.sbin/acpi/acpiconf/acpiconf.c b/usr.sbin/acpi/acpiconf/acpiconf.c
68 index 8a31657fb98..f4d5e06b0d3 100644
69 --- a/usr.sbin/acpi/acpiconf/acpiconf.c
70 +++ b/usr.sbin/acpi/acpiconf/acpiconf.c
71 @@ -37,6 +37,7 @@
72 #include <sys/ioctl.h>
73 #include <sysexits.h>
74 #include <unistd.h>
75 +#include <libxo/xo.h>
76
77 #include <dev/acpica/acpiio.h>
78
79 @@ -53,7 +54,7 @@ acpi_init(void)
80 if (acpifd == -1)
81 acpifd = open(ACPIDEV, O_RDONLY);
82 if (acpifd == -1)
83 - err(EX_OSFILE, ACPIDEV);
84 + xo_err(EX_OSFILE, ACPIDEV);
85 }
86
87 /* Prepare to sleep and then wait for the signal that sleeping can occur. */
88 @@ -65,7 +66,7 @@ acpi_sleep(int sleep_type)
89 /* Notify OS that we want to sleep. devd(8) gets this notify. */
90 ret = ioctl(acpifd, ACPIIO_REQSLPSTATE, &sleep_type);
91 if (ret != 0)
92 - err(EX_IOERR, "request sleep type (%d) failed", sleep_type);
93 + xo_err(EX_IOERR, "request sleep type (%d) failed", sleep_type);
94 }
95
96 /* Ack or abort a pending suspend request. */
97 @@ -76,7 +77,7 @@ acpi_sleep_ack(int err_val)
98
99 ret = ioctl(acpifd, ACPIIO_ACKSLPSTATE, &err_val);
100 if (ret != 0)
101 - err(EX_IOERR, "ack sleep type failed");
102 + xo_err(EX_IOERR, "ack sleep type failed");
103 }
104
105 /* should be a acpi define, but doesn't appear to be */
106 @@ -92,78 +93,82 @@ acpi_battinfo(int num)
107 uint32_t volt;
108
109 if (num < 0 || num > 64)
110 - errx(EX_USAGE, "invalid battery %d", num);
111 + xo_errx(EX_USAGE, "invalid battery %d", num);
112
113 /* Print battery design information. */
114 battio.unit = num;
115 if (ioctl(acpifd, ACPIIO_BATT_GET_BIX, &battio) == -1)
116 - err(EX_IOERR, "get battery info (%d) failed", num);
117 + xo_err(EX_IOERR, "get battery info (%d) failed", num);
118 amp = battio.bix.units;
119 pwr_units = amp ? "mA" : "mW";
120 if (battio.bix.dcap == UNKNOWN_CAP)
121 - printf("Design capacity:\tunknown\n");
122 + xo_emit("{Lc:Design capacity}{P:\t}{:design-capacity/unknown}\n");
123 else
124 - printf("Design capacity:\t%d %sh\n", battio.bix.dcap,
125 - pwr_units);
126 + xo_emit("{Lc:Design capacity}{P:\t}{:design-capacity/%d}{Uw:/%sh}\n",
127 + battio.bix.dcap, pwr_units);
128 if (battio.bix.lfcap == UNKNOWN_CAP)
129 - printf("Last full capacity:\tunknown\n");
130 + xo_emit("{Lc:Last full capacity}{P:\t}{:last-full-capacity/unknown}\n");
131 else
132 - printf("Last full capacity:\t%d %sh\n", battio.bix.lfcap,
133 - pwr_units);
134 - printf("Technology:\t\t%s\n", battio.bix.btech == 0 ?
135 + xo_emit("{Lc:Last full capacity}{P:\t}{:last-full-capacity/%d}{Uw:/%sh}\n",
136 + battio.bix.lfcap, pwr_units);
137 + xo_emit("{Lc:Technology}{P:\t\t}{:technology}\n", battio.bix.btech == 0 ?
138 "primary (non-rechargeable)" : "secondary (rechargeable)");
139 if (ACPI_BIX_REV_MIN_CHECK(battio.bix.rev, ACPI_BIX_REV_1)) {
140 - printf("Battery Swappable Capability:\t");
141 + xo_emit("{Lc:Battery Swappable Capability}{P:\t}");
142 if (battio.bix.scap == ACPI_BIX_SCAP_NO)
143 - printf("Non-swappable\n");
144 + xo_emit("{:swappable/Non-swappable/no}\n");
145 else if (battio.bix.scap == ACPI_BIX_SCAP_COLD)
146 - printf("cold swap\n");
147 + xo_emit("{:swappable/cold swap/cold}\n");
148 else if (battio.bix.scap == ACPI_BIX_SCAP_HOT)
149 - printf("hot swap\n");
150 + xo_emit("{:swappable/hot swap/hot}\n");
151 else
152 - printf("unknown\n");
153 + xo_emit("{:swappable/unknown}\n");
154 }
155 if (battio.bix.dvol == UNKNOWN_CAP)
156 - printf("Design voltage:\t\tunknown\n");
157 + xo_emit("{Lc:Design voltage}{P:\t\t}{:voltage/unknown}\n");
158 else
159 - printf("Design voltage:\t\t%d mV\n", battio.bix.dvol);
160 - printf("Capacity (warn):\t%d %sh\n", battio.bix.wcap, pwr_units);
161 - printf("Capacity (low):\t\t%d %sh\n", battio.bix.lcap, pwr_units);
162 + xo_emit("{Lc:Design voltage}{P:\t\t}{:voltage/%d}{Uw:mV}\n", battio.bix.dvol);
163 + xo_emit("{Lc:Capacity (warn)}{P:\t}{:warn-capacity/%d}{Uw:/%sh}\n",
164 + battio.bix.wcap, pwr_units);
165 + xo_emit("{Lc:Capacity (low)}{P:\t\t}{:low-capacity/%d}{Uw:/%sh}\n",
166 + battio.bix.lcap, pwr_units);
167 if (ACPI_BIX_REV_MIN_CHECK(battio.bix.rev, ACPI_BIX_REV_0)) {
168 if (battio.bix.cycles != ACPI_BATT_UNKNOWN)
169 - printf("Cycle Count:\t\t%d\n", battio.bix.cycles);
170 - printf("Mesurement Accuracy:\t%d %%\n",
171 + xo_emit("{Lc:Cycle Count}{P:\t\t}{:cycles/%d}\n", battio.bix.cycles);
172 + xo_emit("{Lc:Mesurement Accuracy}{P:\t}{:accuracy/%d}{Uw:%%}\n",
173 battio.bix.accuracy / 1000);
174 if (battio.bix.stmax != ACPI_BATT_UNKNOWN)
175 - printf("Max Sampling Time:\t%d ms\n",
176 + xo_emit("{Lc:Max Sampling Time}{P:\t}{:sampling-max/%d}{Uw:ms}\n",
177 battio.bix.stmax);
178 if (battio.bix.stmin != ACPI_BATT_UNKNOWN)
179 - printf("Min Sampling Time:\t%d ms\n",
180 + xo_emit("{Lc:Min Sampling Time}{P:\t}{:sampling-min/%d}{Uw:ms}\n",
181 battio.bix.stmin);
182 - printf("Max Average Interval:\t%d ms\n",
183 + xo_emit("{Lc:Max Average Interval}{P:\t}{:avg-interval-max/%d}{Uw:ms}\n",
184 battio.bix.aimax);
185 - printf("Min Average Interval:\t%d ms\n",
186 + xo_emit("{Lc:Min Average Interval}{P:\t}{:avg-interval-min/%d}{Uw:ms}\n",
187 battio.bix.aimin);
188 }
189 - printf("Low/warn granularity:\t%d %sh\n", battio.bix.gra1, pwr_units);
190 - printf("Warn/full granularity:\t%d %sh\n", battio.bix.gra2, pwr_units);
191 - printf("Model number:\t\t%s\n", battio.bix.model);
192 - printf("Serial number:\t\t%s\n", battio.bix.serial);
193 - printf("Type:\t\t\t%s\n", battio.bix.type);
194 - printf("OEM info:\t\t%s\n", battio.bix.oeminfo);
195 + xo_emit("{Lc:Low\\/warn granularity}{P:\t}{:granularity-lw/%d}{Uw:/%sh}\n",
196 + battio.bix.gra1, pwr_units);
197 + xo_emit("{Lc:Warn\\/full granularity}{P:\t}{:granularity-wf/%d}{Uw:/%sh}\n",
198 + battio.bix.gra2, pwr_units);
199 + xo_emit("{Lc:Model number}{P:\t\t}{:model}\n", battio.bix.model);
200 + xo_emit("{Lc:Serial number}{P:\t\t}{:serial}\n", battio.bix.serial);
201 + xo_emit("{Lc:Type}{P:\t\t\t}{:type}\n", battio.bix.type);
202 + xo_emit("{Lc:OEM info}{P:\t\t}{:oeminfo}\n", battio.bix.oeminfo);
203
204 /* Fetch battery voltage information. */
205 volt = UNKNOWN_VOLTAGE;
206 battio.unit = num;
207 if (ioctl(acpifd, ACPIIO_BATT_GET_BST, &battio) == -1)
208 - err(EX_IOERR, "get battery status (%d) failed", num);
209 + xo_err(EX_IOERR, "get battery status (%d) failed", num);
210 if (battio.bst.state != ACPI_BATT_STAT_NOT_PRESENT)
211 volt = battio.bst.volt;
212
213 /* Print current battery state information. */
214 battio.unit = num;
215 if (ioctl(acpifd, ACPIIO_BATT_GET_BATTINFO, &battio) == -1)
216 - err(EX_IOERR, "get battery user info (%d) failed", num);
217 + xo_err(EX_IOERR, "get battery user info (%d) failed", num);
218 if (battio.battinfo.state != ACPI_BATT_STAT_NOT_PRESENT) {
219 const char *state;
220 switch (battio.battinfo.state & ACPI_BATT_STAT_BST_MASK) {
221 @@ -188,36 +193,36 @@ acpi_battinfo(int num)
222 default:
223 state = "invalid";
224 }
225 - printf("State:\t\t\t%s\n", state);
226 + xo_emit("{Lc:State}{P:\t\t\t}{:state}\n", state);
227 if (battio.battinfo.cap == -1)
228 - printf("Remaining capacity:\tunknown\n");
229 + xo_emit("{Lc:Remaining capacity}{P:\t}{:remaining-capacity/unknown}\n");
230 else
231 - printf("Remaining capacity:\t%d%%\n",
232 + xo_emit("{Lc:Remaining capacity}{P:\t}{:remaining-capacity/%d}{D:%%}\n",
233 battio.battinfo.cap);
234 if (battio.battinfo.min == -1)
235 - printf("Remaining time:\t\tunknown\n");
236 + xo_emit("{Lc:Remaining time}{P:\t\t}{:remaining-time/unknown}\n");
237 else {
238 hours = battio.battinfo.min / 60;
239 min = battio.battinfo.min % 60;
240 - printf("Remaining time:\t\t%d:%02d\n", hours, min);
241 + xo_emit("{Lc:Remaining time}{P:\t\t}{:remaining-time/%d:%02d}\n", hours, min);
242 }
243 if (battio.battinfo.rate == -1)
244 - printf("Present rate:\t\tunknown\n");
245 + xo_emit("{Lc:Present rate}{P:\t\t}{:present-rate/unknown}\n");
246 else if (amp && volt != UNKNOWN_VOLTAGE) {
247 - printf("Present rate:\t\t%d mA (%d mW)\n",
248 + xo_emit("{Lc:Present rate}{P:\t\t}{:present-rate/%d}{Uw:mA} {D:(}{:present-rate-mw/%d}{Uw:mW}{D:)}\n",
249 battio.battinfo.rate,
250 battio.battinfo.rate * volt / 1000);
251 } else
252 - printf("Present rate:\t\t%d %s\n",
253 + xo_emit("{Lc:Present rate}{P:\t\t}{:present-rate/%d}{Uw:/%s}\n",
254 battio.battinfo.rate, pwr_units);
255 } else
256 - printf("State:\t\t\tnot present\n");
257 + xo_emit("{Lc:State}{P:\t\t\t}{:state/not present}\n");
258
259 /* Print battery voltage information. */
260 if (volt == UNKNOWN_VOLTAGE)
261 - printf("Present voltage:\tunknown\n");
262 + xo_emit("{Lc:Present voltage}{P:\t}{q:present-voltage/unknown}\n");
263 else
264 - printf("Present voltage:\t%d mV\n", volt);
265 + xo_emit("{Lc:Present voltage}{P:\t}{q:present-voltage/%d}{Uw:mV}\n", volt);
266
267 return (0);
268 }
269 @@ -225,7 +230,9 @@ acpi_battinfo(int num)
270 static void
271 usage(const char* prog)
272 {
273 - printf("usage: %s [-h] [-i batt] [-k ack] [-s 1-4]\n", prog);
274 + xo_error("usage: %s [-h] [-i batt] [-k ack] [-s 1-4]\n", prog);
275 + xo_close_container("acpiconf");
276 + xo_finish();
277 exit(0);
278 }
279
280 @@ -237,6 +244,9 @@ main(int argc, char *argv[])
281 int iflag = 0, kflag = 0, sflag = 0;
282
283 prog = argv[0];
284 +
285 + argc = xo_parse_args(argc, argv);
286 + xo_open_container("acpiconf");
287 if (argc < 2)
288 usage(prog);
289 /* NOTREACHED */
290 @@ -249,13 +259,13 @@ main(int argc, char *argv[])
291 iflag = 1;
292 battery = strtol(optarg, &end, 10);
293 if ((size_t)(end - optarg) != strlen(optarg))
294 - errx(EX_USAGE, "invalid battery");
295 + xo_errx(EX_USAGE, "invalid battery");
296 break;
297 case 'k':
298 kflag = 1;
299 ack = strtol(optarg, &end, 10);
300 if ((size_t)(end - optarg) != strlen(optarg))
301 - errx(EX_USAGE, "invalid ack argument");
302 + xo_errx(EX_USAGE, "invalid ack argument");
303 break;
304 case 's':
305 sflag = 1;
306 @@ -263,9 +273,9 @@ main(int argc, char *argv[])
307 optarg++;
308 sleep_type = strtol(optarg, &end, 10);
309 if ((size_t)(end - optarg) != strlen(optarg))
310 - errx(EX_USAGE, "invalid sleep type");
311 + xo_errx(EX_USAGE, "invalid sleep type");
312 if (sleep_type < 1 || sleep_type > 4)
313 - errx(EX_USAGE, "invalid sleep type (%d)",
314 + xo_errx(EX_USAGE, "invalid sleep type (%d)",
315 sleep_type);
316 break;
317 case 'h':
318 @@ -278,19 +288,19 @@ main(int argc, char *argv[])
319 argv += optind;
320
321 if (iflag != 0 && kflag != 0 && sflag != 0)
322 - errx(EX_USAGE, "-i, -k and -s are mutually exclusive");
323 + xo_errx(EX_USAGE, "-i, -k and -s are mutually exclusive");
324
325 if (iflag != 0) {
326 if (kflag != 0)
327 - errx(EX_USAGE, "-i and -k are mutually exclusive");
328 + xo_errx(EX_USAGE, "-i and -k are mutually exclusive");
329 if (sflag != 0)
330 - errx(EX_USAGE, "-i and -s are mutually exclusive");
331 + xo_errx(EX_USAGE, "-i and -s are mutually exclusive");
332 acpi_battinfo(battery);
333 }
334
335 if (kflag != 0) {
336 if (sflag != 0)
337 - errx(EX_USAGE, "-k and -s are mutually exclusive");
338 + xo_errx(EX_USAGE, "-k and -s are mutually exclusive");
339 acpi_sleep_ack(ack);
340 }
341
342 @@ -299,5 +309,7 @@ main(int argc, char *argv[])
343 acpi_sleep(sleep_type);
344
345 close(acpifd);
346 + xo_close_container("acpiconf");
347 + xo_finish();
348 exit (0);
349 }
350 --
351 2.31.1
352