[gdb] Handle EINTR in ser-event.c

Use gdb syscall wrappers to handle EINTR in ser-event.c.

Tested on aarch64-linux.
This commit is contained in:
Tom de Vries 2024-11-22 17:44:29 +01:00
parent 4e4dfc4728
commit 2af94d6c92
2 changed files with 19 additions and 12 deletions

View 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);

View 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 */