aboutsummaryrefslogtreecommitdiffstats
path: root/testing/speech-dispatcher/0001-Provide-fallback-for-systems-without-TEMP_FAILURE_RE.patch
blob: c4699024488a062f5e9b413e2ad6541fa382f314 (plain)
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
From 98504410b7f77cad7457bfdfcd593e2898c3b461 Mon Sep 17 00:00:00 2001
From: Felix Janda <felix.janda@posteo.de>
Date: Mon, 23 Mar 2015 21:03:12 +0100
Subject: [PATCH] Provide fallback for systems without TEMP_FAILURE_RETRY

Reviewed-by: Luke Yelavich <themuso@themuso.com>
---
 include/safe_io.h          | 55 ++++++++++++++++++++++++++++++++++++++++++++++
 src/modules/cicero.c       |  6 ++---
 src/server/output.c        | 18 +--------------
 src/server/sem_functions.c |  5 +++--
 src/server/speaking.c      |  5 ++---
 5 files changed, 63 insertions(+), 26 deletions(-)
 create mode 100644 include/safe_io.h

diff --git a/include/safe_io.h b/include/safe_io.h
new file mode 100644
index 0000000..37cfe7f
--- /dev/null
+++ b/include/safe_io.h
@@ -0,0 +1,55 @@
+/*
+ * safe_io.h - Wrapper around read and write
+ *
+ * Copyright (C) 2001, 2002, 2003, 2007 Brailcom, o.p.s.
+ *
+ * This 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, or (at your option)
+ * any later version.
+ *
+ * This software 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 package; see the file COPYING.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <unistd.h>
+#include <errno.h>
+
+#ifdef TEMP_FAILURE_RETRY	/* GNU libc */
+#define safe_read(fd, buf, count) TEMP_FAILURE_RETRY(read(fd, buf, count))
+#define safe_write(fd, buf, count) TEMP_FAILURE_RETRY(write(fd, buf, count))
+#else /* TEMP_FAILURE_RETRY */
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+static inline ssize_t
+safe_read(int fd, void *buf, size_t count) {
+	do {
+		ssize_t w = read(fd, buf, count);
+
+		if (w == -1 && errno == EINTR) continue;
+		return w;
+	} while (1);
+}
+static inline ssize_t
+safe_write(int fd, const void *buf, size_t count) {
+	do {
+		ssize_t w = write(fd, buf, count);
+
+		if (w == -1 && errno == EINTR) continue;
+		return w;
+	} while (1);
+}
+#endif /* TEMP_FAILURE_RETRY */
diff --git a/src/modules/cicero.c b/src/modules/cicero.c
index 237796e..62332a5 100644
--- a/src/modules/cicero.c
+++ b/src/modules/cicero.c
@@ -26,6 +26,7 @@
 #endif
 
 #include <speechd_types.h>
+#include <safe_io.h>
 #include <errno.h>
 #include <sys/poll.h>
 #include <fcntl.h>
@@ -376,10 +377,7 @@ void *_cicero_speak(void *nothing)
 						cicero_speaking = 0;
 						break;
 					}
-					if (ret > 0)
-						TEMP_FAILURE_RETRY(read
-								   (fd1[0], b,
-								    2));
+					if (ret > 0) safe_read(fd1[0], b, 2);
 					if (cicero_stop) {
 						cicero_speaking = 0;
 						module_report_event_stop();
diff --git a/src/server/output.c b/src/server/output.c
index 40b7e8c..ef98a45 100644
--- a/src/server/output.c
+++ b/src/server/output.c
@@ -26,27 +26,11 @@
 #endif
 
 #include <fdsetconv.h>
+#include <safe_io.h>
 #include <spd_utils.h>
 #include "output.h"
 #include "parse.h"
 
-#ifdef TEMP_FAILURE_RETRY	/* GNU libc */
-#define safe_write(fd, buf, count) TEMP_FAILURE_RETRY(write(fd, buf, count))
-#else /* TEMP_FAILURE_RETRY */
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif
-static inline ssize_t
-safe_write(int fd, const void *buf, size_t count) {
-	do {
-		ssize_t w = write(fd, buf, count);
-
-		if (w == -1 && errno == EINTR) continue;
-		return w;
-	} while (1);
-}
-#endif /* TEMP_FAILURE_RETRY */
-
 #if !(defined(__GLIBC__) && defined(_GNU_SOURCE))
 /* Added by Willie Walker - strndup is a gcc-ism
  */
diff --git a/src/server/sem_functions.c b/src/server/sem_functions.c
index 0a86f56..430e74c 100644
--- a/src/server/sem_functions.c
+++ b/src/server/sem_functions.c
@@ -26,6 +26,8 @@
 #include <config.h>
 #endif
 
+#include <safe_io.h>
+
 #include "speechd.h"
 #include "sem_functions.h"
 
@@ -33,8 +35,7 @@ void speaking_semaphore_post(void)
 {
 	char buf[1];
 	buf[0] = 42;
-	const ssize_t wr_bytes =
-	    TEMP_FAILURE_RETRY(write(speaking_pipe[1], buf, 1));
+	const ssize_t wr_bytes = safe_write(speaking_pipe[1], buf, 1);
 	if (wr_bytes != 1)
 		FATAL("write to polled fd: could not write 1 byte");
 }
diff --git a/src/server/speaking.c b/src/server/speaking.c
index bd27008..f2dc289 100644
--- a/src/server/speaking.c
+++ b/src/server/speaking.c
@@ -29,6 +29,7 @@
 #include <glib.h>
 #include <poll.h>
 #include <unistd.h>
+#include <safe_io.h>
 #include "speechd.h"
 #include "server.h"
 #include "index_marking.h"
@@ -88,9 +89,7 @@ void *speak(void *data)
 				MSG(5,
 				    "wait_for_poll: activity in Speech Dispatcher");
 				const ssize_t rd_bytes =
-				    TEMP_FAILURE_RETRY(read
-						       (poll_fds[0].fd, buf,
-							1));
+				    safe_read(poll_fds[0].fd, buf, 1);
 				if (rd_bytes != 1)
 					FATAL
 					    ("read from polled fd: could not read 1 byte");
-- 
2.4.0