summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Osterried <thomas@osterried.de>2010-06-05 00:14:04 +0000
committerThomas Osterried <thomas@osterried.de>2010-06-05 00:14:04 +0000
commit8072140d3664b32988c00134844aef58c5c1c9b2 (patch)
treeb3df309483c894fe92473b1d9a2f75b157e72da5
parente3a030cc1baf97809794406719f0cf434f9aed71 (diff)
The last patch introduced cosmetic errors like
GIFADDR: Bad file descriptor after signling termination with ^C In detail: close(3) = 0 sigreturn() = ? (mask now []) ioctl(3, SIOCGIFHWADDR, {ifr_name="eth0", ???}) = -1 EBADF (Bad file descriptor) -> The interrupt handler introduced concurrency issues ;) The patch caused only unexpected behaviour; no security problems. This new patch fixes this problem.
-rw-r--r--listen/listen.c44
1 files changed, 28 insertions, 16 deletions
diff --git a/listen/listen.c b/listen/listen.c
index 64a5d27..b7de1e3 100644
--- a/listen/listen.c
+++ b/listen/listen.c
@@ -55,6 +55,7 @@ static void handle_sigint(int signal)
{
sigint++;
close(sock); /* disturb blocking recvfrom */
+ sock = -1;
}
#define ASCII 0
@@ -74,6 +75,7 @@ int main(int argc, char **argv)
socklen_t asize = sizeof(sa);
struct ifreq ifr;
int proto = ETH_P_AX25;
+ int exit_code = EXIT_SUCCESS;
timestamp = 0;
@@ -141,12 +143,11 @@ int main(int argc, char **argv)
setservent(1);
- signal(SIGINT, handle_sigint);
- signal(SIGTERM, handle_sigint);
-
while (!sigint) {
asize = sizeof(sa);
+ signal(SIGINT, handle_sigint);
+ signal(SIGTERM, handle_sigint);
if ((size =
recvfrom(sock, buffer, sizeof(buffer), 0, &sa,
&asize)) == -1) {
@@ -157,24 +158,35 @@ int main(int argc, char **argv)
if (errno == EINTR) {
refresh();
continue;
- } else if (errno == EBADF && sigint)
- break;
-
- if (color)
- endwin();
- perror("recv");
-
- return 1;
+ } else if (!(errno == EBADF && sigint)) {
+ perror("recv");
+ exit_code = errno;
+ }
+ break;
}
+ signal(SIGINT, SIG_DFL);
+ signal(SIGTERM, SIG_DFL);
+ if (sock == -1 || sigint)
+ break;
if (dev != NULL && strcmp(dev, sa.sa_data) != 0)
continue;
if (proto == ETH_P_ALL) {
strcpy(ifr.ifr_name, sa.sa_data);
- if (ioctl(sock, SIOCGIFHWADDR, &ifr) < 0)
- perror("GIFADDR");
-
+ signal(SIGINT, handle_sigint);
+ signal(SIGTERM, handle_sigint);
+ if (ioctl(sock, SIOCGIFHWADDR, &ifr) == -1) {
+ if (!(errno == EBADF && sigint)) {
+ perror("SIOCGIFHWADDR");
+ exit_code = errno;
+ break;
+ }
+ }
+ signal(SIGINT, SIG_DFL);
+ signal(SIGTERM, SIG_DFL);
+ if (sock == -1 || sigint)
+ break;
if (ifr.ifr_hwaddr.sa_family == AF_AX25) {
display_port(sa.sa_data);
#ifdef NEW_AX25_STACK
@@ -182,7 +194,7 @@ int main(int argc, char **argv)
#else
ki_dump(buffer, size, dumpstyle);
#endif
-/* lprintf(T_DATA, "\n"); */
+/* lprintf(T_DATA, "\n"); */
}
} else {
display_port(sa.sa_data);
@@ -199,7 +211,7 @@ int main(int argc, char **argv)
if (color)
endwin();
- return EXIT_SUCCESS;
+ return exit_code;
}
static void ascii_dump(unsigned char *data, int length)