1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
|
From 979d85c842898463192c7e7dae87798c1df6d471 Mon Sep 17 00:00:00 2001
From: Michael Forney <mforney@mforney.org>
Date: Fri, 30 Apr 2021 20:02:41 -0700
Subject: [PATCH] Avoid use of statement-expressions
---
Makefile.am | 2 +-
acpi_listen.c | 6 +++---
acpid.c | 4 ++--
event.c | 5 +++--
input_layer.c | 4 ++--
libc_compat.h | 40 ----------------------------------------
libnetlink.c | 17 +++++++++--------
netlink.c | 4 ++--
proc.c | 5 +++--
ud_socket.c | 5 +++--
10 files changed, 28 insertions(+), 64 deletions(-)
delete mode 100644 libc_compat.h
diff --git a/Makefile.am b/Makefile.am
index 417528f..1c80ca4 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -14,7 +14,7 @@ bin_PROGRAMS = acpi_listen
acpid_SOURCES = acpid.c acpi_ids.c connection_list.c event.c input_layer.c inotify_handler.c libnetlink.c log.c netlink.c proc.c sock.c ud_socket.c \
acpid.h acpi_genetlink.h acpi_ids.h config.h connection_list.h event.h genetlink.h inotify_handler.h input_layer.h \
- libnetlink.h log.h netlink.h proc.h sock.h ud_socket.h libc_compat.h
+ libnetlink.h log.h netlink.h proc.h sock.h ud_socket.h
acpi_listen_SOURCES = acpi_listen.c log.c ud_socket.c
diff --git a/acpi_listen.c b/acpi_listen.c
index 63a1cc3..674cc80 100644
--- a/acpi_listen.c
+++ b/acpi_listen.c
@@ -39,8 +39,6 @@
#include "acpid.h"
#include "ud_socket.h"
-#include "libc_compat.h"
-
static int handle_cmdline(int *argc, char ***argv);
static char *read_line(int fd);
@@ -217,8 +215,10 @@ read_line(int fd)
memset(buf+i, 0, buflen-i);
while (i < buflen) {
- r = TEMP_FAILURE_RETRY (read(fd, buf+i, 1) );
+ r = read(fd, buf+i, 1);
if (r < 0) {
+ if (errno == EINTR)
+ continue;
/* we should do something with the data */
fprintf(stderr, "ERR: read(): %s\n",
strerror(errno));
diff --git a/acpid.c b/acpid.c
index cb1875a..6538578 100644
--- a/acpid.c
+++ b/acpid.c
@@ -41,7 +41,6 @@
#include "input_layer.h"
#include "inotify_handler.h"
#include "netlink.h"
-#include "libc_compat.h"
static int handle_cmdline(int *argc, char ***argv);
static void close_fds(void);
@@ -153,7 +152,8 @@ main(int argc, char **argv)
readfds = *get_fdset();
/* wait on data */
- nready = TEMP_FAILURE_RETRY(select(get_highestfd() + 1, &readfds, NULL, NULL, NULL));
+ do nready = select(get_highestfd() + 1, &readfds, NULL, NULL, NULL);
+ while (nready == -1 && errno == EINTR);
if (nready < 0) {
acpid_log(LOG_ERR, "select(): %s", strerror(errno));
diff --git a/event.c b/event.c
index 6c67062..033466e 100644
--- a/event.c
+++ b/event.c
@@ -39,7 +39,6 @@
#include "log.h"
#include "sock.h"
#include "ud_socket.h"
-#include "libc_compat.h"
#include "event.h"
/*
@@ -754,8 +753,10 @@ safe_write(int fd, const char *buf, int len)
int ntries = NTRIES;
do {
- r = TEMP_FAILURE_RETRY (write(fd, buf+ttl, len-ttl) );
+ r = write(fd, buf+ttl, len-ttl);
if (r < 0) {
+ if (errno == EINTR)
+ continue;
if (errno != EAGAIN) {
/* a legit error */
return r;
diff --git a/input_layer.c b/input_layer.c
index 00246b3..f6bddef 100644
--- a/input_layer.c
+++ b/input_layer.c
@@ -42,7 +42,6 @@
#include "log.h"
#include "connection_list.h"
#include "event.h"
-#include "libc_compat.h"
#include "input_layer.h"
@@ -352,7 +351,8 @@ static void process_input(int fd)
struct connection *c;
char str2[100];
- nbytes = TEMP_FAILURE_RETRY ( read(fd, &event, sizeof(event)) );
+ do nbytes = read(fd, &event, sizeof(event));
+ while (nbytes == -1 && errno == EINTR);
if (nbytes == 0) {
acpid_log(LOG_WARNING, "input layer connection closed");
diff --git a/libc_compat.h b/libc_compat.h
deleted file mode 100644
index 39f2336..0000000
--- a/libc_compat.h
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * libc_compat.h - implement defs/macros missing from some libcs
- *
- * Copyright (C) 1999-2000 Andrew Henroid
- * Copyright (C) 2001 Sun Microsystems
- * Portions Copyright (C) 2004 Tim Hockin (thockin@hockin.org)
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-#ifndef LIBC_COMPAT_H__
-#define LIBC_COMPAT_H__
-
-/* Evaluate EXPRESSION, and repeat as long as it returns -1 with `errno'
- set to EINTR. This macro is present on glibc/uclibc but may not be in other cases. */
-
-#ifndef ____GLIBC__
-#ifndef TEMP_FAILURE_RETRY
-#define TEMP_FAILURE_RETRY(expression) \
- (__extension__ \
- ({ long int __result; \
- do __result = (long int) (expression); \
- while (__result == -1L && errno == EINTR); \
- __result; }))
-#endif
-#endif /* __GLIBC__ */
-
-#endif /* LIBC_COMPAT_H__ */
diff --git a/libnetlink.c b/libnetlink.c
index d94bd5f..7ad00df 100644
--- a/libnetlink.c
+++ b/libnetlink.c
@@ -31,8 +31,6 @@
#include <time.h>
#include <sys/uio.h>
-#include "libc_compat.h"
-
#include "libnetlink.h"
void rtnl_close(struct rtnl_handle *rth)
@@ -180,10 +178,11 @@ int rtnl_dump_filter(struct rtnl_handle *rth,
struct nlmsghdr *h;
iov.iov_len = sizeof(buf);
- status = TEMP_FAILURE_RETRY ( recvmsg(rth->fd, &msg, MSG_CMSG_CLOEXEC) );
+ status = recvmsg(rth->fd, &msg, MSG_CMSG_CLOEXEC);
if (status < 0) {
- perror("OVERRUN");
+ if (errno != EINTR)
+ perror("OVERRUN");
continue;
}
@@ -281,10 +280,11 @@ int rtnl_talk(struct rtnl_handle *rtnl, struct nlmsghdr *n, pid_t peer,
while (1) {
iov.iov_len = sizeof(buf);
- status = TEMP_FAILURE_RETRY ( recvmsg(rtnl->fd, &msg, MSG_CMSG_CLOEXEC) );
+ status = recvmsg(rtnl->fd, &msg, MSG_CMSG_CLOEXEC);
if (status < 0) {
- perror("OVERRUN");
+ if (errno != EINTR)
+ perror("OVERRUN");
continue;
}
if (status == 0) {
@@ -383,10 +383,11 @@ int rtnl_listen(struct rtnl_handle *rtnl,
iov.iov_base = buf;
while (1) {
iov.iov_len = sizeof(buf);
- status = TEMP_FAILURE_RETRY ( recvmsg(rtnl->fd, &msg, MSG_CMSG_CLOEXEC) );
+ status = recvmsg(rtnl->fd, &msg, MSG_CMSG_CLOEXEC);
if (status < 0) {
- perror("OVERRUN");
+ if (errno != EINTR)
+ perror("OVERRUN");
continue;
}
if (status == 0) {
diff --git a/netlink.c b/netlink.c
index 8254762..695bb33 100644
--- a/netlink.c
+++ b/netlink.c
@@ -48,7 +48,6 @@
#include "libnetlink.h"
#include "genetlink.h"
#include "acpi_genetlink.h"
-#include "libc_compat.h"
#include "acpi_ids.h"
#include "connection_list.h"
@@ -151,7 +150,8 @@ process_netlink(int fd)
iov.iov_len = sizeof(buf);
/* read the data into the buffer */
- status = TEMP_FAILURE_RETRY ( recvmsg(fd, &msg, MSG_CMSG_CLOEXEC) );
+ do status = recvmsg(fd, &msg, MSG_CMSG_CLOEXEC);
+ while (status == -1 && errno == EINTR);
/* if there was a problem, print a message and keep trying */
if (status < 0) {
diff --git a/proc.c b/proc.c
index f96b913..295cb73 100644
--- a/proc.c
+++ b/proc.c
@@ -31,7 +31,6 @@
#include "log.h"
#include "event.h"
#include "connection_list.h"
-#include "libc_compat.h"
#include "proc.h"
@@ -137,8 +136,10 @@ read_line(int fd)
/* only go to BUFLEN-1 so there will always be a 0 at the end */
while (i < BUFLEN-1) {
- r = TEMP_FAILURE_RETRY(read(fd, buf+i, 1));
+ r = read(fd, buf+i, 1);
if (r < 0) {
+ if (errno == EINTR)
+ continue;
/* we should do something with the data */
acpid_log(LOG_ERR, "read(): %s",
strerror(errno));
diff --git a/ud_socket.c b/ud_socket.c
index 83b2aa9..15a3b4a 100644
--- a/ud_socket.c
+++ b/ud_socket.c
@@ -21,7 +21,6 @@
#include "acpid.h"
#include "log.h"
#include "ud_socket.h"
-#include "libc_compat.h"
int
ud_create_socket(const char *name, mode_t socketmode)
@@ -87,8 +86,10 @@ ud_accept(int listenfd, struct ucred *cred)
struct sockaddr_un cliaddr;
socklen_t len = sizeof(struct sockaddr_un);
- newsock = TEMP_FAILURE_RETRY (accept4(listenfd, (struct sockaddr *)&cliaddr, &len, SOCK_CLOEXEC|SOCK_NONBLOCK));
+ newsock = accept4(listenfd, (struct sockaddr *)&cliaddr, &len, SOCK_CLOEXEC|SOCK_NONBLOCK);
if (newsock < 0) {
+ if (errno == EINTR)
+ continue;
return newsock;
}
if (cred) {
--
2.37.3
|