]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
[gdb] Handle EINTR in ser-event.c
authorTom de Vries <tdevries@suse.de>
Fri, 22 Nov 2024 16:44:29 +0000 (17:44 +0100)
committerTom de Vries <tdevries@suse.de>
Fri, 22 Nov 2024 16:44:29 +0000 (17:44 +0100)
Use gdb syscall wrappers to handle EINTR in ser-event.c.

Tested on aarch64-linux.

gdb/ser-event.c
gdbsupport/eintr.h

index fe1c460aa1fecf0a7c5fe1ee1e8e5e91cc479c30..b039e86060fb08b096be321fda7904dcf5996561 100644 (file)
@@ -19,6 +19,7 @@
 #include "ser-event.h"
 #include "serial.h"
 #include "gdbsupport/filestuff.h"
+#include "gdbsupport/eintr.h"
 
 /* On POSIX hosts, a serial_event is basically an abstraction for the
    classical self-pipe trick.
@@ -62,8 +63,8 @@ serial_event_open (struct serial *scb, const char *name)
     if (gdb_pipe_cloexec (fds) == -1)
       internal_error ("creating serial event pipe failed.");
 
-    fcntl (fds[0], F_SETFL, O_NONBLOCK);
-    fcntl (fds[1], F_SETFL, O_NONBLOCK);
+    gdb::fcntl (fds[0], F_SETFL, O_NONBLOCK);
+    gdb::fcntl (fds[1], F_SETFL, O_NONBLOCK);
 
     scb->fd = fds[0];
     state->write_fd = fds[1];
@@ -91,9 +92,9 @@ serial_event_close (struct serial *scb)
 {
   struct serial_event_state *state = (struct serial_event_state *) scb->state;
 
-  close (scb->fd);
+  gdb::close (scb->fd);
 #ifndef USE_WIN32API
-  close (state->write_fd);
+  gdb::close (state->write_fd);
 #else
   CloseHandle (state->event);
 #endif
@@ -179,14 +180,9 @@ serial_event_set (struct serial_event *event)
   struct serial *ser = (struct serial *) event;
   struct serial_event_state *state = (struct serial_event_state *) ser->state;
 #ifndef USE_WIN32API
-  int r;
   char c = '+';                /* Anything.  */
 
-  do
-    {
-      r = write (state->write_fd, &c, 1);
-    }
-  while (r < 0 && errno == EINTR);
+  gdb::write (state->write_fd, &c, 1);
 #else
   SetEvent (state->event);
 #endif
@@ -205,9 +201,9 @@ serial_event_clear (struct serial_event *event)
     {
       char c;
 
-      r = read (ser->fd, &c, 1);
+      r = gdb::read (ser->fd, &c, 1);
     }
-  while (r > 0 || (r < 0 && errno == EINTR));
+  while (r > 0);
 #else
   struct serial_event_state *state = (struct serial_event_state *) ser->state;
   ResetEvent (state->event);
index fa2af61559293eb43b15382db80648bff37661ec..3980e3f5ac1cb4b0807d9a7fa8f25bf4596b84e0 100644 (file)
@@ -101,6 +101,17 @@ read (int fd, void *buf, size_t count)
   return gdb::handle_eintr (-1, ::read, fd, buf, count);
 }
 
+template<typename... Args> int fcntl (int fd, int op, Args... args)
+{
+  return gdb::handle_eintr (-1, ::fcntl, fd, op, args...);
+}
+
+inline ssize_t
+write (int fd, const void *buf, size_t count)
+{
+  return gdb::handle_eintr (-1, ::write, fd, buf, count);
+}
+
 } /* namespace gdb */
 
 #endif /* GDBSUPPORT_EINTR_H */