Page MenuHomeFreeBSD

D13430.id36412.diff
No OneTemporary

D13430.id36412.diff

Index: head/usr.sbin/acpi/acpiconf/acpiconf.c
===================================================================
--- head/usr.sbin/acpi/acpiconf/acpiconf.c
+++ head/usr.sbin/acpi/acpiconf/acpiconf.c
@@ -92,7 +92,7 @@
uint32_t volt;
if (num < 0 || num > 64)
- err(EX_USAGE, "invalid battery %d", num);
+ errx(EX_USAGE, "invalid battery %d", num);
/* Print battery design information. */
battio.unit = num;
@@ -205,8 +205,9 @@
int
main(int argc, char *argv[])
{
- char *prog;
- int c, sleep_type;
+ char *prog, *end;
+ int c, sleep_type, battery, ack;
+ int iflag = 0, kflag = 0, sflag = 0;
prog = argv[0];
if (argc < 2)
@@ -218,16 +219,24 @@
while ((c = getopt(argc, argv, "hi:k:s:")) != -1) {
switch (c) {
case 'i':
- acpi_battinfo(atoi(optarg));
+ iflag = 1;
+ battery = strtol(optarg, &end, 10);
+ if ((size_t)(end - optarg) != strlen(optarg))
+ errx(EX_USAGE, "invalid battery");
break;
case 'k':
- acpi_sleep_ack(atoi(optarg));
+ kflag = 1;
+ ack = strtol(optarg, &end, 10);
+ if ((size_t)(end - optarg) != strlen(optarg))
+ errx(EX_USAGE, "invalid ack argument");
break;
case 's':
+ sflag = 1;
if (optarg[0] == 'S')
- sleep_type = optarg[1] - '0';
- else
- sleep_type = optarg[0] - '0';
+ optarg++;
+ sleep_type = strtol(optarg, &end, 10);
+ if ((size_t)(end - optarg) != strlen(optarg))
+ errx(EX_USAGE, "invalid sleep type");
if (sleep_type < 1 || sleep_type > 4)
errx(EX_USAGE, "invalid sleep type (%d)",
sleep_type);
@@ -241,7 +250,25 @@
argc -= optind;
argv += optind;
- if (sleep_type != -1)
+ if (iflag != 0 && kflag != 0 && sflag != 0)
+ 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");
+ if (sflag != 0)
+ 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");
+ acpi_sleep_ack(ack);
+ }
+
+
+ if (sflag != 0)
acpi_sleep(sleep_type);
close(acpifd);

File Metadata

Mime Type
text/plain
Expires
Fri, Aug 7, 1:52 AM (11 h, 26 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
36142770
Default Alt Text
D13430.id36412.diff (2 KB)

Event Timeline