Debian Codegraph @

src/sna/sna_acpi.c

raw symbols SCIP
1 /*
2 * Copyright (c) 2013 Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 * SOFTWARE.
22 *
23 * Authors:
24 * Chris Wilson <[email protected]>
25 *
26 */
27
28 #ifdef HAVE_CONFIG_Hcxx . . $ `<built-in>:410:9`!
29 #include "config.h"cxx . . $ `<file>/config.h`/
30 #endif
31
32 #include <sys/types.h>
33 #include <sys/socket.h>
34 #include <sys/un.h>
35 #include <unistd.h>
36 #include <dirent.h>
37 #include <fcntl.h>
38 #include <errno.h>
39
40 #include "sna.h"cxx . . $ `<file>/src/sna/sna.h`/
41
42 #define ACPI_SOCKETcxx . . $ `src/sna/sna_acpi.c:42:9`! "/var/run/acpid.socket"
43
44 int sna_acpi_opencxx . . $ sna_acpi_open(b126dc7c1de90089).(void)
45 {
46 struct sockaddr_uncxx . . $ sockaddr_un# addr;
47 int fd, ret;
48
49 DBGcxx . . $ `src/sna/debug.h:35:9`!(("%s\n", __FUNCTION__));
50
51 fd = socketcxx . . $ socket(2326284602b0bb2d).(AF_UNIXcxx . . $ `<external>/8962547315054503424/socket.h:95:9`!, SOCK_STREAMcxx . . $ `<external>/5956532346368192945/socket_type.h:28:9`!, 0);
52 if (fd < 0)
53 return -1;
54
55 memsetcxx . . $ memset(d1de1e4fb215f1c6).(&addr, 0, sizeof(addr));
56 addr.sun_familycxx . . $ sockaddr_un#sun_family. = AF_UNIXcxx . . $ `<external>/8962547315054503424/socket.h:95:9`!;
57 strcpycxx . . $ strcpy(b7b3a83273496486).(addr.sun_pathcxx . . $ sockaddr_un#sun_path., ACPI_SOCKETcxx . . $ `src/sna/sna_acpi.c:42:9`!);
58
59 ret = connectcxx . . $ connect(1ce9971e209c3c95).(fd, (struct sockaddrcxx . . $ sockaddr# *)&addr, sizeof(addr));
60 if (ret < 0) {
61 closecxx . . $ close(7864480464b09eea).(fd);
62 return -1;
63 }
64
65 DBGcxx . . $ `src/sna/debug.h:35:9`!(("%s: opened socket to APCI daemon, fd=%d\n", __FUNCTION__, fd));
66
67 return fd;
68 }
69
70 void _sna_acpi_wakeupcxx . . $ _sna_acpi_wakeup(a7abbe1bcccb1d5a).(struct snacxx . . $ sna# *sna)
71 {
72 char *eol;
73 int n;
74
75 n = readcxx . . $ read(7e34d0a36f355389).(sna->acpicxx . . $ sna#acpi..fdcxx . . $ sna#$anonymous_type_4#fd.,
76 sna->acpicxx . . $ sna#acpi..eventcxx . . $ sna#$anonymous_type_4#event. + sna->acpicxx . . $ sna#acpi..offsetcxx . . $ sna#$anonymous_type_4#offset.,
77 sna->acpicxx . . $ sna#acpi..remaincxx . . $ sna#$anonymous_type_4#remain.);
78 DBGcxx . . $ `src/sna/debug.h:35:9`!(("%s: read %d bytes from acpid\n", __FUNCTION__, n));
79 if (n <= 0) {
80 /* We will get '0' if we run out of space whilst reading
81 * one event - that should never happen, so treat it as
82 * an error and give up.
83 */
84 if (n < 0)
85 n = errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!;
86 switch (n) {
87 case EAGAINcxx . . $ `<external>/8987895939074593727/errno-base.h:15:9`!:
88 case EINTRcxx . . $ `<external>/8987895939074593727/errno-base.h:8:9`!:
89 return;
90 }
91
92 DBGcxx . . $ `src/sna/debug.h:35:9`!(("%s: error [%d], detaching from acpid\n", __FUNCTION__, n));
93
94 /* XXX reattach later? */
95 RemoveNotifyFdcxx . . $ RemoveNotifyFd(d4f767463ce0a6b3).(sna->acpicxx . . $ sna#acpi..fdcxx . . $ sna#$anonymous_type_4#fd.);
96 sna_acpi_finicxx . . $ sna_acpi_fini(a7abbe1bcccb1d5a).(sna);
97 return;
98 }
99
100 sna->acpicxx . . $ sna#acpi..eventcxx . . $ sna#$anonymous_type_4#event.[sna->acpicxx . . $ sna#acpi..offsetcxx . . $ sna#$anonymous_type_4#offset. + n] = '\0';
101 sna->acpicxx . . $ sna#acpi..offsetcxx . . $ sna#$anonymous_type_4#offset. += n;
102 sna->acpicxx . . $ sna#acpi..remaincxx . . $ sna#$anonymous_type_4#remain. -= n;
103
104 DBGcxx . . $ `src/sna/debug.h:35:9`!(("%s: event string [%d]: '%s'\n", __FUNCTION__, sna->acpi.offset, sna->acpi.event));
105
106 do {
107 eol = strchrcxx . . $ strchr(2050848944e00d54).(sna->acpicxx . . $ sna#acpi..eventcxx . . $ sna#$anonymous_type_4#event., '\n');
108 if (eol == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
109 return;
110
111 if (strncmpcxx . . $ strncmp(fd278af2f295fa2e).(sna->acpicxx . . $ sna#acpi..eventcxx . . $ sna#$anonymous_type_4#event., "ac_adapter", 10) == 0) {
112 char *space = sna->acpicxx . . $ sna#acpi..eventcxx . . $ sna#$anonymous_type_4#event.;
113 int state = -1;
114
115 /* ac_adapter ACAD 00000080 00000001 */
116
117 space = strchrcxx . . $ strchr(2050848944e00d54).(space, ' ');
118 if (space)
119 space = strchrcxx . . $ strchr(2050848944e00d54).(space + 1, ' ');
120 if (space)
121 space = strchrcxx . . $ strchr(2050848944e00d54).(space + 1, ' ');
122 if (space)
123 state = atoicxx . . $ atoi(5c4306d8553b3696).(space + 1);
124
125 DBGcxx . . $ `src/sna/debug.h:35:9`!(("%s: ac_adapter event new state=%d\n", __FUNCTION__, state));
126 if (state)
127 sna->flagscxx . . $ sna#flags. &= ~SNA_POWERSAVEcxx . . $ `src/sna/sna.h:266:9`!;
128 else
129 sna->flagscxx . . $ sna#flags. |= SNA_POWERSAVEcxx . . $ `src/sna/sna.h:266:9`!;
130 }
131
132 n = (sna->acpicxx . . $ sna#acpi..eventcxx . . $ sna#$anonymous_type_4#event. + sna->acpicxx . . $ sna#acpi..offsetcxx . . $ sna#$anonymous_type_4#offset.) - ++eol;
133 memmovecxx . . $ memmove(cc817cb175f282d).(sna->acpicxx . . $ sna#acpi..eventcxx . . $ sna#$anonymous_type_4#event., eol, n+1);
134 sna->acpicxx . . $ sna#acpi..offsetcxx . . $ sna#$anonymous_type_4#offset. = n;
135 sna->acpicxx . . $ sna#acpi..remaincxx . . $ sna#$anonymous_type_4#remain. = sizeof(sna->acpicxx . . $ sna#acpi..eventcxx . . $ sna#$anonymous_type_4#event.) - 1 - n;
136 } while (n);
137 }
138
139 #if HAVE_NOTIFY_FDcxx . . $ `src/compat-api.h:53:9`!
140 static void sna_acpi_notifycxx . . $ sna_acpi_notify(ca236fcaf572b04d).(int fd, int read, void *data)
141 {
142 _sna_acpi_wakeupcxx . . $ _sna_acpi_wakeup(a7abbe1bcccb1d5a).(data);
143 }
144 #endif
145
146 static int read_power_statecxx . . $ read_power_state(5c4306d8553b3696).(const char *path)
147 {
148 DIRcxx . . $ DIR# *dir;
149 struct direntcxx . . $ dirent# *de;
150 int i = -1;
151
152 DBGcxx . . $ `src/sna/debug.h:35:9`!(("%s: searching '%s'\n", __FUNCTION__, path));
153
154 dir = opendircxx . . $ opendir(f465d4b65cec8dd2).(path);
155 if (dir == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
156 return -1;
157
158 while ((de = readdircxx . . $ readdir(ffbaae344e1a615a).(dir))) {
159 char buf[1024];
160 int fd;
161
162 if (*de->d_namecxx . . $ dirent#d_name. == '.')
163 continue;
164
165 DBGcxx . . $ `src/sna/debug.h:35:9`!(("%s: checking '%s'\n", __FUNCTION__, de->d_name));
166
167 snprintfcxx . . $ snprintf(ea502d73e74c754c).(buf, sizeof(buf), "%s/%s/type", path, de->d_namecxx . . $ dirent#d_name.);
168 fd = opencxx . . $ open(e156e3aa1e5c4ad1).(buf, 0);
169 if (fd < 0)
170 continue;
171
172 i = readcxx . . $ read(7e34d0a36f355389).(fd, buf, sizeof(buf));
173 buf[i > 0 ? i - 1: 0] = '\0';
174 closecxx . . $ close(7864480464b09eea).(fd);
175
176 DBGcxx . . $ `src/sna/debug.h:35:9`!(("%s: %s is of type '%s'\n", __FUNCTION__, de->d_name, buf));
177
178 if (strcmpcxx . . $ strcmp(5ae29d726ae57f88).(buf, "Mains"))
179 continue;
180
181 snprintfcxx . . $ snprintf(ea502d73e74c754c).(buf, sizeof(buf), "%s/%s/online", path, de->d_namecxx . . $ dirent#d_name.);
182 fd = opencxx . . $ open(e156e3aa1e5c4ad1).(buf, 0);
183 if (fd < 0)
184 continue;
185
186 i = readcxx . . $ read(7e34d0a36f355389).(fd, buf, sizeof(buf));
187 buf[i > 0 ? i - 1: 0] = '\0';
188 if (i > 0)
189 i = atoicxx . . $ atoi(5c4306d8553b3696).(buf);
190 DBGcxx . . $ `src/sna/debug.h:35:9`!(("%s: %s is online? '%s'\n", __FUNCTION__, de->d_name, buf));
191 closecxx . . $ close(7864480464b09eea).(fd);
192
193 break;
194 }
195 closedircxx . . $ closedir(ac30a447bc7c2f80).(dir);
196
197 return i;
198 }
199
200 void sna_acpi_initcxx . . $ sna_acpi_init(a7abbe1bcccb1d5a).(struct snacxx . . $ sna# *sna)
201 {
202 if (sna->acpicxx . . $ sna#acpi..fdcxx . . $ sna#$anonymous_type_4#fd. < 0)
203 return;
204
205 if (sna->flagscxx . . $ sna#flags. & SNA_PERFORMANCEcxx . . $ `src/sna/sna.h:265:9`!)
206 return;
207
208 DBGcxx . . $ `src/sna/debug.h:35:9`!(("%s: attaching to acpid\n", __FUNCTION__));
209
210 SetNotifyFdcxx . . $ SetNotifyFd(3b0cf3dd9616a2da).(sna->acpicxx . . $ sna#acpi..fdcxx . . $ sna#$anonymous_type_4#fd., sna_acpi_notifycxx . . $ sna_acpi_notify(ca236fcaf572b04d)., X_NOTIFY_READcxx . . $ `<external>/17080983469304696390/os.h:148:9`!, sna);
211 sna->acpicxx . . $ sna#acpi..remaincxx . . $ sna#$anonymous_type_4#remain. = sizeof(sna->acpicxx . . $ sna#acpi..eventcxx . . $ sna#$anonymous_type_4#event.) - 1;
212 sna->acpicxx . . $ sna#acpi..offsetcxx . . $ sna#$anonymous_type_4#offset. = 0;
213
214 /* Read initial states */
215 if (read_power_statecxx . . $ read_power_state(5c4306d8553b3696).("/sys/class/power_supply") == 0) {
216 DBGcxx . . $ `src/sna/debug.h:35:9`!(("%s: AC adapter is currently offline\n", __FUNCTION__));
217 sna->flagscxx . . $ sna#flags. |= SNA_POWERSAVEcxx . . $ `src/sna/sna.h:266:9`!;
218 }
219 }
220
221 void sna_acpi_finicxx . . $ sna_acpi_fini(a7abbe1bcccb1d5a).(struct snacxx . . $ sna# *sna)
222 {
223 if (sna->acpicxx . . $ sna#acpi..fdcxx . . $ sna#$anonymous_type_4#fd. < 0)
224 return;
225
226 closecxx . . $ close(7864480464b09eea).(sna->acpicxx . . $ sna#acpi..fdcxx . . $ sna#$anonymous_type_4#fd.);
227 sna->acpicxx . . $ sna#acpi..fdcxx . . $ sna#$anonymous_type_4#fd. = -1;
228
229 sna->flagscxx . . $ sna#flags. &= ~SNA_POWERSAVEcxx . . $ `src/sna/sna.h:266:9`!;
230 }