[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 1/3] Remove references to TEMP_FAILURE_RETRY
From: |
Boris Dušek |
Subject: |
[PATCH 1/3] Remove references to TEMP_FAILURE_RETRY |
Date: |
Tue, 24 Jul 2012 22:08:31 +0200 |
From: Boris Dus?ek <address@hidden>
To: address@hidden
Since TEMP_FAILURE_RETRY uses a non-standard gcc extension, it can't be
portably reimplemented. However since it's used mostly only with read
and write, it's OK to implement safe_read and safe_write functions
directly which behave just like with TEMP_FAILURE_RETRY, and use them
instead of TEMP_FAILURE_RETRY.
---
src/clients/spdsend/server.c | 5 ++---
src/modules/cicero.c | 6 ++----
src/server/output.c | 29 ++++++++++++++++-------------
src/server/output.h | 6 +++++-
src/server/sem_functions.c | 6 +++---
src/server/speaking.c | 7 ++-----
6 files changed, 30 insertions(+), 29 deletions(-)
diff --git a/src/clients/spdsend/server.c b/src/clients/spdsend/server.c
index 02a1be9..8d725dd 100644
--- a/src/clients/spdsend/server.c
+++ b/src/clients/spdsend/server.c
@@ -2,7 +2,7 @@
Author: Milan Zamazal <pdm at brailcom.org>
*/
-/* Copyright (C) 2004 Brailcom, o.p.s.
+/* Copyright (C) 2004, 2012 Brailcom, o.p.s.
COPYRIGHT NOTICE
@@ -49,8 +49,7 @@
#include <unistd.h>
#if !(defined(__GLIBC__) && defined(_GNU_SOURCE))
-/* Added by Willie Walker - TEMP_FAILURE_RETRY, strndup, and getline
- * are gcc-isms
+/* Added by Willie Walker - getline is a gcc-ism
*/
ssize_t getline(char **lineptr, size_t * n, FILE * f);
#endif
diff --git a/src/modules/cicero.c b/src/modules/cicero.c
index d660c41..7f8c4c9 100644
--- a/src/modules/cicero.c
+++ b/src/modules/cicero.c
@@ -1,7 +1,7 @@
/*
* cicero.c - Speech Dispatcher backend for Cicero French TTS engine
*
- * Copyright (C) 2006 Brailcom, o.p.s.
+ * Copyright (C) 2006, 2012 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
@@ -377,9 +377,7 @@ void *_cicero_speak(void *nothing)
break;
}
if (ret > 0)
- TEMP_FAILURE_RETRY(read
- (fd1[0], b,
- 2));
+ while ((-1 == read(fd1[0], b,
2)) && errno == EINTR){}
if (cicero_stop) {
cicero_speaking = 0;
module_report_event_stop();
diff --git a/src/server/output.c b/src/server/output.c
index b38ccd1..a45f163 100644
--- a/src/server/output.c
+++ b/src/server/output.c
@@ -1,7 +1,7 @@
/*
* output.c - Output layer for Speech Dispatcher
*
- * Copyright (C) 2001, 2002, 2003, 2007 Brailcom, o.p.s.
+ * Copyright (C) 2001, 2002, 2003, 2007, 2012 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
@@ -30,22 +30,25 @@
#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) {
+
+ssize_t
+safe_read(int fd, void *buf, size_t count) {
+ ssize_t r;
do {
- ssize_t w = write(fd, buf, count);
+ r = read(fd, buf, count);
+ } while (r == -1 && errno == EINTR);
+ return r;
+}
- if (w == -1 && errno == EINTR) continue;
- return w;
- } while (1);
+ssize_t
+safe_write(int fd, const void *buf, size_t count) {
+ ssize_t w;
+ do {
+ w = write(fd, buf, count);
+ } while (w == -1 && errno == EINTR);
+ return w;
}
-#endif /* TEMP_FAILURE_RETRY */
#if !(defined(__GLIBC__) && defined(_GNU_SOURCE))
/* Added by Willie Walker - strndup is a gcc-ism
diff --git a/src/server/output.h b/src/server/output.h
index 10bbe80..c394de4 100644
--- a/src/server/output.h
+++ b/src/server/output.h
@@ -1,7 +1,7 @@
/*
* output.h - Output layer for Speech Dispatcher header
*
- * Copyright (C) 2001, 2002, 2003 Brailcom, o.p.s.
+ * Copyright (C) 2001, 2002, 2003, 2012 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
@@ -48,3 +48,7 @@ int waitpid_with_timeout(pid_t pid, int *status_ptr, int
options,
size_t timeout);
int output_close(OutputModule * module);
SPDVoice **output_list_voices(char *module_name);
+
+/* Utility functions */
+ssize_t safe_read(int fd, void *buf, size_t count);
+ssize_t safe_write(int fd, const void *buf, size_t count);
diff --git a/src/server/sem_functions.c b/src/server/sem_functions.c
index 0a86f56..b072ede 100644
--- a/src/server/sem_functions.c
+++ b/src/server/sem_functions.c
@@ -2,7 +2,7 @@
/*
* sem_functions.c - Functions for manipulating System V / IPC semaphores
*
- * Copyright (C) 2001, 2002, 2003 Brailcom, o.p.s.
+ * Copyright (C) 2001, 2002, 2003, 2012 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
@@ -28,13 +28,13 @@
#include "speechd.h"
#include "sem_functions.h"
+#include "output.h"
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 ee8c4d4..ea570d3 100644
--- a/src/server/speaking.c
+++ b/src/server/speaking.c
@@ -2,7 +2,7 @@
/*
* speaking.c - Speech Dispatcher speech output functions
*
- * Copyright (C) 2001,2002,2003, 2006, 2007 Brailcom, o.p.s
+ * Copyright (C) 2001,2002,2003, 2006, 2007, 2012 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
@@ -87,10 +87,7 @@ void *speak(void *data)
char buf[1];
MSG(5,
"wait_for_poll: activity in Speech
Dispatcher");
- const ssize_t rd_bytes =
- TEMP_FAILURE_RETRY(read
- (poll_fds[0].fd, buf,
- 1));
+ const ssize_t rd_bytes =
safe_read(poll_fds[0].fd, buf, 1);
if (rd_bytes != 1)
FATAL
("read from polled fd: could not
read 1 byte");
--
1.7.7.5 (Apple Git-26)
- [PATCH 1/3] Remove references to TEMP_FAILURE_RETRY,
Boris Dušek <=
[PATCH 1/3] Remove references to TEMP_FAILURE_RETRY, Trevor Saunders, 2012/07/25