speechd-discuss
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH v2 1/3] Remove references to TEMP_FAILURE_RETRY


From: Boris Dušek
Subject: [PATCH v2 1/3] Remove references to TEMP_FAILURE_RETRY
Date: Sun, 29 Jul 2012 16:37:00 +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.
---
 include/spd_utils.h          |    6 +++++-
 src/clients/spdsend/server.c |    5 ++---
 src/common/Makefile.am       |    2 +-
 src/common/spd_safeio.c      |   48 ++++++++++++++++++++++++++++++++++++++++++
 src/modules/cicero.c         |    7 +++---
 src/server/output.c          |   15 +------------
 src/server/sem_functions.c   |    6 +++---
 src/server/speaking.c        |    8 +++----
 8 files changed, 66 insertions(+), 31 deletions(-)
 create mode 100644 src/common/spd_safeio.c

diff --git a/include/spd_utils.h b/include/spd_utils.h
index f07d13a..165f7c0 100644
--- a/include/spd_utils.h
+++ b/include/spd_utils.h
@@ -2,7 +2,7 @@
  * spd_utils.h - prototypes for utility functions used
  * in the Speech Dispatcher server and modules.
  *
- * Copyright (C) 2010 Brailcom, o.p.s.
+ * Copyright (C) 2010, 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
@@ -27,4 +27,8 @@
 #include <sys/types.h>
 
 ssize_t spd_getline(char **lineptr, size_t * n, FILE * f);
+
+ssize_t safe_read(int fd, void *buf, size_t count);
+ssize_t safe_write(int fd, const void *buf, size_t count);
+
 #endif /* SPD_UTILS_H */
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/common/Makefile.am b/src/common/Makefile.am
index 139ba32..58da525 100644
--- a/src/common/Makefile.am
+++ b/src/common/Makefile.am
@@ -5,5 +5,5 @@ libcommon_la_CFLAGS = $(ERROR_CFLAGS) $(GLIB_CFLAGS) \
 -DGETTEXT_PACKAGE=\"$(GETTEXT_PACKAGE)\" -DLOCALEDIR=\"$(localedir)\"
 libcommon_la_CPPFLAGS = "-I$(top_srcdir)/include/" $(GLIB_CFLAGS)
 libcommon_la_LIBADD = $(GLIB_LIBS)
-libcommon_la_SOURCES = fdsetconv.c spd_getline.c i18n.c
+libcommon_la_SOURCES = fdsetconv.c spd_getline.c i18n.c spd_safeio.c
 
diff --git a/src/common/spd_safeio.c b/src/common/spd_safeio.c
new file mode 100644
index 0000000..5a66014
--- /dev/null
+++ b/src/common/spd_safeio.c
@@ -0,0 +1,48 @@
+/*
+ * spd_safeio.c - portable implementation of TEMP_FAILURE_RETRY
+ *
+ * Copyright (C) 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
+ * 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.
+ *
+ */
+
+#if HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <unistd.h>
+#include <errno.h>
+
+ssize_t
+safe_read(int fd, void *buf, size_t count)
+{
+       ssize_t r;
+       do {
+               r = read(fd, buf, count);
+       } while (r == -1 && errno == EINTR);
+       return r;
+}
+
+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;
+}
diff --git a/src/modules/cicero.c b/src/modules/cicero.c
index d660c41..5f3abe7 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
@@ -32,6 +32,7 @@
 #include <langinfo.h>
 #include <sys/stat.h>
 #include <semaphore.h>
+#include <spd_utils.h>
 
 #include "module_utils.h"
 
@@ -377,9 +378,7 @@ void *_cicero_speak(void *nothing)
                                                break;
                                        }
                                        if (ret > 0)
-                                               TEMP_FAILURE_RETRY(read
-                                                                  (fd1[0], b,
-                                                                   2));
+                                               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 b38ccd1..09833e9 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,9 @@
 #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..d1ee417 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 <spd_utils.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..f275045 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
@@ -39,6 +39,7 @@
 #include "output.h"
 #include "speaking.h"
 #include "sem_functions.h"
+#include <spd_utils.h>
 
 TSpeechDMessage *current_message = NULL;
 static SPDPriority highest_priority = 0;
@@ -87,10 +88,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.9.6 (Apple Git-31.1)




reply via email to

[Prev in Thread] Current Thread [Next in Thread]