From 2af94d6c929ad3e5b96a9884d500d3effc28755c Mon Sep 17 00:00:00 2001 From: Tom de Vries Date: Fri, 22 Nov 2024 17:44:29 +0100 Subject: [PATCH] [gdb] Handle EINTR in ser-event.c Use gdb syscall wrappers to handle EINTR in ser-event.c. Tested on aarch64-linux. --- gdb/ser-event.c | 20 ++++++++------------ gdbsupport/eintr.h | 11 +++++++++++ 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/gdb/ser-event.c b/gdb/ser-event.c index fe1c460aa1f..b039e86060f 100644 --- a/gdb/ser-event.c +++ b/gdb/ser-event.c @@ -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); diff --git a/gdbsupport/eintr.h b/gdbsupport/eintr.h index fa2af615592..3980e3f5ac1 100644 --- a/gdbsupport/eintr.h +++ b/gdbsupport/eintr.h @@ -101,6 +101,17 @@ read (int fd, void *buf, size_t count) return gdb::handle_eintr (-1, ::read, fd, buf, count); } +template 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 */