From 5b59b163d2ea38b6ffa47c22b38e60760fbcf4e4 Mon Sep 17 00:00:00 2001 From: XANTRONIX Development Date: Mon, 5 Oct 2020 01:01:17 -0400 Subject: [PATCH] Bring interfaces down when an error is encountered Modify src/server.c to bring interfaces down when an I/O error is encountered --- bin/if.c | 2 ++ bin/pattyd.c | 4 ++++ src/if.c | 3 ++- src/server.c | 8 +++++++- 4 files changed, 15 insertions(+), 2 deletions(-) diff --git a/bin/if.c b/bin/if.c index b774716..6298828 100644 --- a/bin/if.c +++ b/bin/if.c @@ -125,6 +125,8 @@ static patty_ax25_if *create_kiss(struct context *ctx, int argc, char **argv) { goto error_if_addr_set; } + patty_ax25_if_up(iface); + return iface; error_if_addr_set: diff --git a/bin/pattyd.c b/bin/pattyd.c index 083dc04..9303b80 100644 --- a/bin/pattyd.c +++ b/bin/pattyd.c @@ -127,6 +127,8 @@ static int handle_if(struct context *ctx, fflush(stdout); } + + patty_ax25_if_up(iface); } if (patty_daemon_if_add(ctx->daemon, iface, ifname) < 0) { @@ -323,6 +325,8 @@ static int handle_standalone(patty_daemon *daemon, if (isatty(fd) && (pty = ptsname(fd)) != NULL) { printf("if %s pty %s\n", DEFAULT_IFNAME, pty); } + + patty_ax25_if_up(iface); } if (patty_daemon_if_add(daemon, iface, DEFAULT_IFNAME) < 0) { diff --git a/src/if.c b/src/if.c index 7ae4267..b9d4667 100644 --- a/src/if.c +++ b/src/if.c @@ -282,7 +282,8 @@ int patty_ax25_if_fd(patty_ax25_if *iface) { } int patty_ax25_if_ready(patty_ax25_if *iface, fd_set *fds) { - return iface->driver->ready(iface->phy, fds); + return iface->status == PATTY_AX25_IF_UP? + iface->driver->ready(iface->phy, fds): 0; } ssize_t patty_ax25_if_fill(patty_ax25_if *iface) { diff --git a/src/server.c b/src/server.c index d7252cb..b7ba7b3 100644 --- a/src/server.c +++ b/src/server.c @@ -2087,7 +2087,13 @@ static int handle_ifaces(patty_ax25_server *server) { struct if_entry *entry = item->value; if (handle_iface(server, entry) < 0) { - goto error_io; + if (errno == EIO) { + patty_ax25_if_down(entry->iface); + + fd_clear(server, entry->fd); + } else { + goto error_io; + } } item = item->next;