annotate toys/other/acpi.c @ 1736:5892daac85ab draft

Switch nsenter to default y.
author Rob Landley <rob@landley.net>
date Thu, 12 Mar 2015 15:34:03 -0500
parents e85e5f3b87c2
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1064
0d7d6fed8141 I got tired of trying to guess how much terminal time I could get in on my phone, so here's a basic acpi.
Isaac Dunham <ibid.ag@gmail.com>
parents:
diff changeset
1 /* acpi.c - show power state
1065
9211bc984285 Cleanup on acpi, switch to default y.
Rob Landley <rob@landley.net>
parents: 1064
diff changeset
2 *
1064
0d7d6fed8141 I got tired of trying to guess how much terminal time I could get in on my phone, so here's a basic acpi.
Isaac Dunham <ibid.ag@gmail.com>
parents:
diff changeset
3 * Written by Isaac Dunham, 2013
1065
9211bc984285 Cleanup on acpi, switch to default y.
Rob Landley <rob@landley.net>
parents: 1064
diff changeset
4 *
1064
0d7d6fed8141 I got tired of trying to guess how much terminal time I could get in on my phone, so here's a basic acpi.
Isaac Dunham <ibid.ag@gmail.com>
parents:
diff changeset
5 * No standard.
1065
9211bc984285 Cleanup on acpi, switch to default y.
Rob Landley <rob@landley.net>
parents: 1064
diff changeset
6
1519
bb4cae772039 acpi: implement -ctV, fix recursion, plug a small leak
Isaac Dunham <ibid.ag@gmail.com>
parents: 1202
diff changeset
7 USE_ACPI(NEWTOY(acpi, "abctV", TOYFLAG_USR|TOYFLAG_BIN))
1064
0d7d6fed8141 I got tired of trying to guess how much terminal time I could get in on my phone, so here's a basic acpi.
Isaac Dunham <ibid.ag@gmail.com>
parents:
diff changeset
8
0d7d6fed8141 I got tired of trying to guess how much terminal time I could get in on my phone, so here's a basic acpi.
Isaac Dunham <ibid.ag@gmail.com>
parents:
diff changeset
9 config ACPI
0d7d6fed8141 I got tired of trying to guess how much terminal time I could get in on my phone, so here's a basic acpi.
Isaac Dunham <ibid.ag@gmail.com>
parents:
diff changeset
10 bool "acpi"
1065
9211bc984285 Cleanup on acpi, switch to default y.
Rob Landley <rob@landley.net>
parents: 1064
diff changeset
11 default y
1064
0d7d6fed8141 I got tired of trying to guess how much terminal time I could get in on my phone, so here's a basic acpi.
Isaac Dunham <ibid.ag@gmail.com>
parents:
diff changeset
12 help
1519
bb4cae772039 acpi: implement -ctV, fix recursion, plug a small leak
Isaac Dunham <ibid.ag@gmail.com>
parents: 1202
diff changeset
13 usage: acpi [-abctV]
1064
0d7d6fed8141 I got tired of trying to guess how much terminal time I could get in on my phone, so here's a basic acpi.
Isaac Dunham <ibid.ag@gmail.com>
parents:
diff changeset
14
1519
bb4cae772039 acpi: implement -ctV, fix recursion, plug a small leak
Isaac Dunham <ibid.ag@gmail.com>
parents: 1202
diff changeset
15 Show status of power sources and thermal devices.
1065
9211bc984285 Cleanup on acpi, switch to default y.
Rob Landley <rob@landley.net>
parents: 1064
diff changeset
16
9211bc984285 Cleanup on acpi, switch to default y.
Rob Landley <rob@landley.net>
parents: 1064
diff changeset
17 -a show power adapters
9211bc984285 Cleanup on acpi, switch to default y.
Rob Landley <rob@landley.net>
parents: 1064
diff changeset
18 -b show batteries
1519
bb4cae772039 acpi: implement -ctV, fix recursion, plug a small leak
Isaac Dunham <ibid.ag@gmail.com>
parents: 1202
diff changeset
19 -c show cooling device state
bb4cae772039 acpi: implement -ctV, fix recursion, plug a small leak
Isaac Dunham <ibid.ag@gmail.com>
parents: 1202
diff changeset
20 -t show temperatures
bb4cae772039 acpi: implement -ctV, fix recursion, plug a small leak
Isaac Dunham <ibid.ag@gmail.com>
parents: 1202
diff changeset
21 -V show everything
1064
0d7d6fed8141 I got tired of trying to guess how much terminal time I could get in on my phone, so here's a basic acpi.
Isaac Dunham <ibid.ag@gmail.com>
parents:
diff changeset
22 */
0d7d6fed8141 I got tired of trying to guess how much terminal time I could get in on my phone, so here's a basic acpi.
Isaac Dunham <ibid.ag@gmail.com>
parents:
diff changeset
23
0d7d6fed8141 I got tired of trying to guess how much terminal time I could get in on my phone, so here's a basic acpi.
Isaac Dunham <ibid.ag@gmail.com>
parents:
diff changeset
24 #define FOR_acpi
0d7d6fed8141 I got tired of trying to guess how much terminal time I could get in on my phone, so here's a basic acpi.
Isaac Dunham <ibid.ag@gmail.com>
parents:
diff changeset
25 #include "toys.h"
0d7d6fed8141 I got tired of trying to guess how much terminal time I could get in on my phone, so here's a basic acpi.
Isaac Dunham <ibid.ag@gmail.com>
parents:
diff changeset
26
0d7d6fed8141 I got tired of trying to guess how much terminal time I could get in on my phone, so here's a basic acpi.
Isaac Dunham <ibid.ag@gmail.com>
parents:
diff changeset
27 GLOBALS(
1065
9211bc984285 Cleanup on acpi, switch to default y.
Rob Landley <rob@landley.net>
parents: 1064
diff changeset
28 int ac;
9211bc984285 Cleanup on acpi, switch to default y.
Rob Landley <rob@landley.net>
parents: 1064
diff changeset
29 int bat;
1519
bb4cae772039 acpi: implement -ctV, fix recursion, plug a small leak
Isaac Dunham <ibid.ag@gmail.com>
parents: 1202
diff changeset
30 int therm;
bb4cae772039 acpi: implement -ctV, fix recursion, plug a small leak
Isaac Dunham <ibid.ag@gmail.com>
parents: 1202
diff changeset
31 int cool;
bb4cae772039 acpi: implement -ctV, fix recursion, plug a small leak
Isaac Dunham <ibid.ag@gmail.com>
parents: 1202
diff changeset
32 char *cpath;
1064
0d7d6fed8141 I got tired of trying to guess how much terminal time I could get in on my phone, so here's a basic acpi.
Isaac Dunham <ibid.ag@gmail.com>
parents:
diff changeset
33 )
0d7d6fed8141 I got tired of trying to guess how much terminal time I could get in on my phone, so here's a basic acpi.
Isaac Dunham <ibid.ag@gmail.com>
parents:
diff changeset
34
1065
9211bc984285 Cleanup on acpi, switch to default y.
Rob Landley <rob@landley.net>
parents: 1064
diff changeset
35 int read_int_at(int dirfd, char *name)
9211bc984285 Cleanup on acpi, switch to default y.
Rob Landley <rob@landley.net>
parents: 1064
diff changeset
36 {
1064
0d7d6fed8141 I got tired of trying to guess how much terminal time I could get in on my phone, so here's a basic acpi.
Isaac Dunham <ibid.ag@gmail.com>
parents:
diff changeset
37 int fd, ret=0;
1065
9211bc984285 Cleanup on acpi, switch to default y.
Rob Landley <rob@landley.net>
parents: 1064
diff changeset
38 FILE *fil;
9211bc984285 Cleanup on acpi, switch to default y.
Rob Landley <rob@landley.net>
parents: 1064
diff changeset
39
9211bc984285 Cleanup on acpi, switch to default y.
Rob Landley <rob@landley.net>
parents: 1064
diff changeset
40 if ((fd = openat(dirfd, name, O_RDONLY)) < 0) return -1;
1571
e85e5f3b87c2 As long as Android's going to require fortify, fixup the warnings it generates.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
41 if (!fscanf(fil = xfdopen(fd, "r"), "%d", &ret)) perror_exit("%s", name);
1064
0d7d6fed8141 I got tired of trying to guess how much terminal time I could get in on my phone, so here's a basic acpi.
Isaac Dunham <ibid.ag@gmail.com>
parents:
diff changeset
42 fclose(fil);
1065
9211bc984285 Cleanup on acpi, switch to default y.
Rob Landley <rob@landley.net>
parents: 1064
diff changeset
43
1064
0d7d6fed8141 I got tired of trying to guess how much terminal time I could get in on my phone, so here's a basic acpi.
Isaac Dunham <ibid.ag@gmail.com>
parents:
diff changeset
44 return ret;
0d7d6fed8141 I got tired of trying to guess how much terminal time I could get in on my phone, so here's a basic acpi.
Isaac Dunham <ibid.ag@gmail.com>
parents:
diff changeset
45 }
0d7d6fed8141 I got tired of trying to guess how much terminal time I could get in on my phone, so here's a basic acpi.
Isaac Dunham <ibid.ag@gmail.com>
parents:
diff changeset
46
0d7d6fed8141 I got tired of trying to guess how much terminal time I could get in on my phone, so here's a basic acpi.
Isaac Dunham <ibid.ag@gmail.com>
parents:
diff changeset
47 int acpi_callback(struct dirtree *tree)
0d7d6fed8141 I got tired of trying to guess how much terminal time I could get in on my phone, so here's a basic acpi.
Isaac Dunham <ibid.ag@gmail.com>
parents:
diff changeset
48 {
1202
4f080cdb2f6e Various cleanups found by Tom Sparrow's static analysis.
Rob Landley <rob@landley.net>
parents: 1065
diff changeset
49 int dfd, fd, len, on;
1065
9211bc984285 Cleanup on acpi, switch to default y.
Rob Landley <rob@landley.net>
parents: 1064
diff changeset
50
1064
0d7d6fed8141 I got tired of trying to guess how much terminal time I could get in on my phone, so here's a basic acpi.
Isaac Dunham <ibid.ag@gmail.com>
parents:
diff changeset
51 errno = 0;
0d7d6fed8141 I got tired of trying to guess how much terminal time I could get in on my phone, so here's a basic acpi.
Isaac Dunham <ibid.ag@gmail.com>
parents:
diff changeset
52
1065
9211bc984285 Cleanup on acpi, switch to default y.
Rob Landley <rob@landley.net>
parents: 1064
diff changeset
53 if (tree->name[0]=='.') return 0;
9211bc984285 Cleanup on acpi, switch to default y.
Rob Landley <rob@landley.net>
parents: 1064
diff changeset
54
1519
bb4cae772039 acpi: implement -ctV, fix recursion, plug a small leak
Isaac Dunham <ibid.ag@gmail.com>
parents: 1202
diff changeset
55 if (!tree->parent)
bb4cae772039 acpi: implement -ctV, fix recursion, plug a small leak
Isaac Dunham <ibid.ag@gmail.com>
parents: 1202
diff changeset
56 return DIRTREE_RECURSE|DIRTREE_SYMFOLLOW;
1065
9211bc984285 Cleanup on acpi, switch to default y.
Rob Landley <rob@landley.net>
parents: 1064
diff changeset
57
1519
bb4cae772039 acpi: implement -ctV, fix recursion, plug a small leak
Isaac Dunham <ibid.ag@gmail.com>
parents: 1202
diff changeset
58 if (0 <= (dfd = open((TT.cpath=dirtree_path(tree, NULL)), O_RDONLY))) {
1065
9211bc984285 Cleanup on acpi, switch to default y.
Rob Landley <rob@landley.net>
parents: 1064
diff changeset
59 if ((fd = openat(dfd, "type", O_RDONLY)) < 0) goto done;
9211bc984285 Cleanup on acpi, switch to default y.
Rob Landley <rob@landley.net>
parents: 1064
diff changeset
60 len = readall(fd, toybuf, sizeof(toybuf));
1064
0d7d6fed8141 I got tired of trying to guess how much terminal time I could get in on my phone, so here's a basic acpi.
Isaac Dunham <ibid.ag@gmail.com>
parents:
diff changeset
61 close(fd);
1065
9211bc984285 Cleanup on acpi, switch to default y.
Rob Landley <rob@landley.net>
parents: 1064
diff changeset
62 if (len < 1) goto done;
9211bc984285 Cleanup on acpi, switch to default y.
Rob Landley <rob@landley.net>
parents: 1064
diff changeset
63
9211bc984285 Cleanup on acpi, switch to default y.
Rob Landley <rob@landley.net>
parents: 1064
diff changeset
64 if (!strncmp(toybuf, "Battery", 7)) {
9211bc984285 Cleanup on acpi, switch to default y.
Rob Landley <rob@landley.net>
parents: 1064
diff changeset
65 if ((toys.optflags & FLAG_b) || (!toys.optflags)) {
1064
0d7d6fed8141 I got tired of trying to guess how much terminal time I could get in on my phone, so here's a basic acpi.
Isaac Dunham <ibid.ag@gmail.com>
parents:
diff changeset
66 int cap = 0, curr = 0, max = 0;
1065
9211bc984285 Cleanup on acpi, switch to default y.
Rob Landley <rob@landley.net>
parents: 1064
diff changeset
67
1064
0d7d6fed8141 I got tired of trying to guess how much terminal time I could get in on my phone, so here's a basic acpi.
Isaac Dunham <ibid.ag@gmail.com>
parents:
diff changeset
68 if ((cap = read_int_at(dfd, "capacity")) < 0) {
1065
9211bc984285 Cleanup on acpi, switch to default y.
Rob Landley <rob@landley.net>
parents: 1064
diff changeset
69 if ((max = read_int_at(dfd, "charge_full")) > 0)
1064
0d7d6fed8141 I got tired of trying to guess how much terminal time I could get in on my phone, so here's a basic acpi.
Isaac Dunham <ibid.ag@gmail.com>
parents:
diff changeset
70 curr = read_int_at(dfd, "charge_now");
1065
9211bc984285 Cleanup on acpi, switch to default y.
Rob Landley <rob@landley.net>
parents: 1064
diff changeset
71 else if ((max = read_int_at(dfd, "energy_full")) > 0)
1064
0d7d6fed8141 I got tired of trying to guess how much terminal time I could get in on my phone, so here's a basic acpi.
Isaac Dunham <ibid.ag@gmail.com>
parents:
diff changeset
72 curr = read_int_at(dfd, "energy_now");
1065
9211bc984285 Cleanup on acpi, switch to default y.
Rob Landley <rob@landley.net>
parents: 1064
diff changeset
73 if (max > 0 && curr >= 0) cap = 100 * curr / max;
1064
0d7d6fed8141 I got tired of trying to guess how much terminal time I could get in on my phone, so here's a basic acpi.
Isaac Dunham <ibid.ag@gmail.com>
parents:
diff changeset
74 }
0d7d6fed8141 I got tired of trying to guess how much terminal time I could get in on my phone, so here's a basic acpi.
Isaac Dunham <ibid.ag@gmail.com>
parents:
diff changeset
75 if (cap >= 0) printf("Battery %d: %d%%\n", TT.bat++, cap);
0d7d6fed8141 I got tired of trying to guess how much terminal time I could get in on my phone, so here's a basic acpi.
Isaac Dunham <ibid.ag@gmail.com>
parents:
diff changeset
76 }
1065
9211bc984285 Cleanup on acpi, switch to default y.
Rob Landley <rob@landley.net>
parents: 1064
diff changeset
77 } else if (toys.optflags & FLAG_a) {
9211bc984285 Cleanup on acpi, switch to default y.
Rob Landley <rob@landley.net>
parents: 1064
diff changeset
78 if ((on = read_int_at(dfd, "online")) >= 0)
9211bc984285 Cleanup on acpi, switch to default y.
Rob Landley <rob@landley.net>
parents: 1064
diff changeset
79 printf("Adapter %d: %s-line\n", TT.ac++, (on ? "on" : "off"));
1064
0d7d6fed8141 I got tired of trying to guess how much terminal time I could get in on my phone, so here's a basic acpi.
Isaac Dunham <ibid.ag@gmail.com>
parents:
diff changeset
80 }
1065
9211bc984285 Cleanup on acpi, switch to default y.
Rob Landley <rob@landley.net>
parents: 1064
diff changeset
81 done:
1064
0d7d6fed8141 I got tired of trying to guess how much terminal time I could get in on my phone, so here's a basic acpi.
Isaac Dunham <ibid.ag@gmail.com>
parents:
diff changeset
82 close(dfd);
0d7d6fed8141 I got tired of trying to guess how much terminal time I could get in on my phone, so here's a basic acpi.
Isaac Dunham <ibid.ag@gmail.com>
parents:
diff changeset
83 }
1519
bb4cae772039 acpi: implement -ctV, fix recursion, plug a small leak
Isaac Dunham <ibid.ag@gmail.com>
parents: 1202
diff changeset
84 free(TT.cpath);
bb4cae772039 acpi: implement -ctV, fix recursion, plug a small leak
Isaac Dunham <ibid.ag@gmail.com>
parents: 1202
diff changeset
85 return 0;
bb4cae772039 acpi: implement -ctV, fix recursion, plug a small leak
Isaac Dunham <ibid.ag@gmail.com>
parents: 1202
diff changeset
86 }
1202
4f080cdb2f6e Various cleanups found by Tom Sparrow's static analysis.
Rob Landley <rob@landley.net>
parents: 1065
diff changeset
87
1519
bb4cae772039 acpi: implement -ctV, fix recursion, plug a small leak
Isaac Dunham <ibid.ag@gmail.com>
parents: 1202
diff changeset
88 int temp_callback(struct dirtree *tree)
bb4cae772039 acpi: implement -ctV, fix recursion, plug a small leak
Isaac Dunham <ibid.ag@gmail.com>
parents: 1202
diff changeset
89 {
bb4cae772039 acpi: implement -ctV, fix recursion, plug a small leak
Isaac Dunham <ibid.ag@gmail.com>
parents: 1202
diff changeset
90 int dfd, temp;
bb4cae772039 acpi: implement -ctV, fix recursion, plug a small leak
Isaac Dunham <ibid.ag@gmail.com>
parents: 1202
diff changeset
91
bb4cae772039 acpi: implement -ctV, fix recursion, plug a small leak
Isaac Dunham <ibid.ag@gmail.com>
parents: 1202
diff changeset
92 if (tree->name[0]=='.') return 0;
bb4cae772039 acpi: implement -ctV, fix recursion, plug a small leak
Isaac Dunham <ibid.ag@gmail.com>
parents: 1202
diff changeset
93 if (!tree->parent || !tree->parent->parent)
bb4cae772039 acpi: implement -ctV, fix recursion, plug a small leak
Isaac Dunham <ibid.ag@gmail.com>
parents: 1202
diff changeset
94 return DIRTREE_RECURSE|DIRTREE_SYMFOLLOW;
bb4cae772039 acpi: implement -ctV, fix recursion, plug a small leak
Isaac Dunham <ibid.ag@gmail.com>
parents: 1202
diff changeset
95 errno = 0;
bb4cae772039 acpi: implement -ctV, fix recursion, plug a small leak
Isaac Dunham <ibid.ag@gmail.com>
parents: 1202
diff changeset
96
bb4cae772039 acpi: implement -ctV, fix recursion, plug a small leak
Isaac Dunham <ibid.ag@gmail.com>
parents: 1202
diff changeset
97 if (0 <= (dfd = open((TT.cpath=dirtree_path(tree, NULL)), O_RDONLY))) {
bb4cae772039 acpi: implement -ctV, fix recursion, plug a small leak
Isaac Dunham <ibid.ag@gmail.com>
parents: 1202
diff changeset
98 if ((0 < (temp = read_int_at(dfd, "temp"))) || !errno) {
bb4cae772039 acpi: implement -ctV, fix recursion, plug a small leak
Isaac Dunham <ibid.ag@gmail.com>
parents: 1202
diff changeset
99 //some tempertures are in milli-C, some in deci-C
bb4cae772039 acpi: implement -ctV, fix recursion, plug a small leak
Isaac Dunham <ibid.ag@gmail.com>
parents: 1202
diff changeset
100 //reputedly some are in deci-K, but I have not seen them
bb4cae772039 acpi: implement -ctV, fix recursion, plug a small leak
Isaac Dunham <ibid.ag@gmail.com>
parents: 1202
diff changeset
101 if (((temp >= 1000) || (temp <= -1000)) && (temp%100 == 0))
bb4cae772039 acpi: implement -ctV, fix recursion, plug a small leak
Isaac Dunham <ibid.ag@gmail.com>
parents: 1202
diff changeset
102 temp /= 100;
bb4cae772039 acpi: implement -ctV, fix recursion, plug a small leak
Isaac Dunham <ibid.ag@gmail.com>
parents: 1202
diff changeset
103 printf("Thermal %d: %d.%d degrees C\n", TT.therm++, temp/10, temp%10);
bb4cae772039 acpi: implement -ctV, fix recursion, plug a small leak
Isaac Dunham <ibid.ag@gmail.com>
parents: 1202
diff changeset
104 }
bb4cae772039 acpi: implement -ctV, fix recursion, plug a small leak
Isaac Dunham <ibid.ag@gmail.com>
parents: 1202
diff changeset
105 close(dfd);
bb4cae772039 acpi: implement -ctV, fix recursion, plug a small leak
Isaac Dunham <ibid.ag@gmail.com>
parents: 1202
diff changeset
106 }
bb4cae772039 acpi: implement -ctV, fix recursion, plug a small leak
Isaac Dunham <ibid.ag@gmail.com>
parents: 1202
diff changeset
107 free(TT.cpath);
bb4cae772039 acpi: implement -ctV, fix recursion, plug a small leak
Isaac Dunham <ibid.ag@gmail.com>
parents: 1202
diff changeset
108 return 0;
bb4cae772039 acpi: implement -ctV, fix recursion, plug a small leak
Isaac Dunham <ibid.ag@gmail.com>
parents: 1202
diff changeset
109 }
bb4cae772039 acpi: implement -ctV, fix recursion, plug a small leak
Isaac Dunham <ibid.ag@gmail.com>
parents: 1202
diff changeset
110
bb4cae772039 acpi: implement -ctV, fix recursion, plug a small leak
Isaac Dunham <ibid.ag@gmail.com>
parents: 1202
diff changeset
111 int cool_callback(struct dirtree *tree)
bb4cae772039 acpi: implement -ctV, fix recursion, plug a small leak
Isaac Dunham <ibid.ag@gmail.com>
parents: 1202
diff changeset
112 {
bb4cae772039 acpi: implement -ctV, fix recursion, plug a small leak
Isaac Dunham <ibid.ag@gmail.com>
parents: 1202
diff changeset
113 int dfd=5, cur, max;
1570
d2eb3c88a724 Whitespace/code style.
Rob Landley <rob@landley.net>
parents: 1519
diff changeset
114
1519
bb4cae772039 acpi: implement -ctV, fix recursion, plug a small leak
Isaac Dunham <ibid.ag@gmail.com>
parents: 1202
diff changeset
115 errno = 0;
bb4cae772039 acpi: implement -ctV, fix recursion, plug a small leak
Isaac Dunham <ibid.ag@gmail.com>
parents: 1202
diff changeset
116 memset(toybuf, 0, sizeof(toybuf));
bb4cae772039 acpi: implement -ctV, fix recursion, plug a small leak
Isaac Dunham <ibid.ag@gmail.com>
parents: 1202
diff changeset
117
1570
d2eb3c88a724 Whitespace/code style.
Rob Landley <rob@landley.net>
parents: 1519
diff changeset
118 if (*tree->name == '.') return 0;
1519
bb4cae772039 acpi: implement -ctV, fix recursion, plug a small leak
Isaac Dunham <ibid.ag@gmail.com>
parents: 1202
diff changeset
119 if (!tree->parent) return DIRTREE_RECURSE|DIRTREE_SYMFOLLOW;
bb4cae772039 acpi: implement -ctV, fix recursion, plug a small leak
Isaac Dunham <ibid.ag@gmail.com>
parents: 1202
diff changeset
120
bb4cae772039 acpi: implement -ctV, fix recursion, plug a small leak
Isaac Dunham <ibid.ag@gmail.com>
parents: 1202
diff changeset
121
bb4cae772039 acpi: implement -ctV, fix recursion, plug a small leak
Isaac Dunham <ibid.ag@gmail.com>
parents: 1202
diff changeset
122 if (0 <= (dfd = open((TT.cpath=dirtree_path(tree, &dfd)), O_RDONLY))) {
bb4cae772039 acpi: implement -ctV, fix recursion, plug a small leak
Isaac Dunham <ibid.ag@gmail.com>
parents: 1202
diff changeset
123 TT.cpath = strcat(TT.cpath, "/type");
bb4cae772039 acpi: implement -ctV, fix recursion, plug a small leak
Isaac Dunham <ibid.ag@gmail.com>
parents: 1202
diff changeset
124 if (readfile(TT.cpath, toybuf, 256) && !errno) {
bb4cae772039 acpi: implement -ctV, fix recursion, plug a small leak
Isaac Dunham <ibid.ag@gmail.com>
parents: 1202
diff changeset
125 toybuf[strlen(toybuf) -1] = 0;
bb4cae772039 acpi: implement -ctV, fix recursion, plug a small leak
Isaac Dunham <ibid.ag@gmail.com>
parents: 1202
diff changeset
126 cur=read_int_at(dfd, "cur_state");
bb4cae772039 acpi: implement -ctV, fix recursion, plug a small leak
Isaac Dunham <ibid.ag@gmail.com>
parents: 1202
diff changeset
127 max=read_int_at(dfd, "max_state");
bb4cae772039 acpi: implement -ctV, fix recursion, plug a small leak
Isaac Dunham <ibid.ag@gmail.com>
parents: 1202
diff changeset
128 if (errno)
bb4cae772039 acpi: implement -ctV, fix recursion, plug a small leak
Isaac Dunham <ibid.ag@gmail.com>
parents: 1202
diff changeset
129 printf("Cooling %d: %s no state information\n", TT.cool++, toybuf);
bb4cae772039 acpi: implement -ctV, fix recursion, plug a small leak
Isaac Dunham <ibid.ag@gmail.com>
parents: 1202
diff changeset
130 else printf("Cooling %d: %s %d of %d\n", TT.cool++, toybuf, cur, max);
bb4cae772039 acpi: implement -ctV, fix recursion, plug a small leak
Isaac Dunham <ibid.ag@gmail.com>
parents: 1202
diff changeset
131 }
bb4cae772039 acpi: implement -ctV, fix recursion, plug a small leak
Isaac Dunham <ibid.ag@gmail.com>
parents: 1202
diff changeset
132 close(dfd);
bb4cae772039 acpi: implement -ctV, fix recursion, plug a small leak
Isaac Dunham <ibid.ag@gmail.com>
parents: 1202
diff changeset
133 }
bb4cae772039 acpi: implement -ctV, fix recursion, plug a small leak
Isaac Dunham <ibid.ag@gmail.com>
parents: 1202
diff changeset
134 free(TT.cpath);
1064
0d7d6fed8141 I got tired of trying to guess how much terminal time I could get in on my phone, so here's a basic acpi.
Isaac Dunham <ibid.ag@gmail.com>
parents:
diff changeset
135 return 0;
0d7d6fed8141 I got tired of trying to guess how much terminal time I could get in on my phone, so here's a basic acpi.
Isaac Dunham <ibid.ag@gmail.com>
parents:
diff changeset
136 }
0d7d6fed8141 I got tired of trying to guess how much terminal time I could get in on my phone, so here's a basic acpi.
Isaac Dunham <ibid.ag@gmail.com>
parents:
diff changeset
137
0d7d6fed8141 I got tired of trying to guess how much terminal time I could get in on my phone, so here's a basic acpi.
Isaac Dunham <ibid.ag@gmail.com>
parents:
diff changeset
138 void acpi_main(void)
0d7d6fed8141 I got tired of trying to guess how much terminal time I could get in on my phone, so here's a basic acpi.
Isaac Dunham <ibid.ag@gmail.com>
parents:
diff changeset
139 {
1570
d2eb3c88a724 Whitespace/code style.
Rob Landley <rob@landley.net>
parents: 1519
diff changeset
140 if (toys.optflags & FLAG_V) toys.optflags = FLAG_a|FLAG_b|FLAG_c|FLAG_t;
1519
bb4cae772039 acpi: implement -ctV, fix recursion, plug a small leak
Isaac Dunham <ibid.ag@gmail.com>
parents: 1202
diff changeset
141 if (!toys.optflags) toys.optflags = FLAG_b;
bb4cae772039 acpi: implement -ctV, fix recursion, plug a small leak
Isaac Dunham <ibid.ag@gmail.com>
parents: 1202
diff changeset
142 if (toys.optflags & (FLAG_a|FLAG_b))
bb4cae772039 acpi: implement -ctV, fix recursion, plug a small leak
Isaac Dunham <ibid.ag@gmail.com>
parents: 1202
diff changeset
143 dirtree_read("/sys/class/power_supply", acpi_callback);
1570
d2eb3c88a724 Whitespace/code style.
Rob Landley <rob@landley.net>
parents: 1519
diff changeset
144 if (toys.optflags & FLAG_t) dirtree_read("/sys/class", temp_callback);
d2eb3c88a724 Whitespace/code style.
Rob Landley <rob@landley.net>
parents: 1519
diff changeset
145 if (toys.optflags & FLAG_c) dirtree_read("/sys/class/thermal", cool_callback);
1519
bb4cae772039 acpi: implement -ctV, fix recursion, plug a small leak
Isaac Dunham <ibid.ag@gmail.com>
parents: 1202
diff changeset
146
1064
0d7d6fed8141 I got tired of trying to guess how much terminal time I could get in on my phone, so here's a basic acpi.
Isaac Dunham <ibid.ag@gmail.com>
parents:
diff changeset
147 }