diff options
author | Tom Tromey <tromey@adacore.com> | 2023-09-01 12:11:37 -0600 |
---|---|---|
committer | Tom Tromey <tromey@adacore.com> | 2023-11-27 12:55:14 -0700 |
commit | a2e0acea420cca881296c6fcf58920f3d7c05a45 (patch) | |
tree | 54f369a7b5a2ead36e15f14e2d0d154a30286fab /gdb/ser-uds.c | |
parent | ad3cf8c64e6e4794fc48d28c90f20cbbfdc51ca4 (diff) | |
download | fsf-binutils-gdb-a2e0acea420cca881296c6fcf58920f3d7c05a45.zip fsf-binutils-gdb-a2e0acea420cca881296c6fcf58920f3d7c05a45.tar.gz fsf-binutils-gdb-a2e0acea420cca881296c6fcf58920f3d7c05a45.tar.bz2 |
Change serial "open" functions to throw exception
remote.c assumes that a failure to open the serial connection will set
errno. This is somewhat true, because the Windows code tries to set
errno appropriately -- but only somewhat, because it isn't clear that
the "pex" code sets it, and the tcp code seems to do the wrong thing.
It seems better to simply have the serial open functions throw on
error.
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30770
Diffstat (limited to 'gdb/ser-uds.c')
-rw-r--r-- | gdb/ser-uds.c | 26 |
1 files changed, 10 insertions, 16 deletions
diff --git a/gdb/ser-uds.c b/gdb/ser-uds.c index 665aab9..e51058b 100644 --- a/gdb/ser-uds.c +++ b/gdb/ser-uds.c @@ -30,36 +30,30 @@ /* Open an AF_UNIX socket. */ -static int +static void uds_open (struct serial *scb, const char *name) { struct sockaddr_un addr; if (strlen (name) > UNIX_PATH_MAX - 1) - { - warning - (_("The socket name is too long. It may be no longer than %s bytes."), - pulongest (UNIX_PATH_MAX - 1L)); - return -1; - } + error (_("The socket name is too long. It may be no longer than %s bytes."), + pulongest (UNIX_PATH_MAX - 1L)); memset (&addr, 0, sizeof addr); addr.sun_family = AF_UNIX; strncpy (addr.sun_path, name, UNIX_PATH_MAX - 1); - int sock = socket (AF_UNIX, SOCK_STREAM, 0); + scb->fd = socket (AF_UNIX, SOCK_STREAM, 0); + if (scb->fd < 0) + perror_with_name (_("could not open socket")); - if (connect (sock, (struct sockaddr *) &addr, + if (connect (scb->fd, (struct sockaddr *) &addr, sizeof (struct sockaddr_un)) < 0) { - close (sock); - scb->fd = -1; - return -1; + int saved = errno; + close (scb->fd); + perror_with_name (_("could not connect to remote"), saved); } - - scb->fd = sock; - - return 0; } static void |