From 73f899cae1cfb9507d72ef5ec9a9d0a02af9d005 Mon Sep 17 00:00:00 2001 From: "Brian S. Dean" Date: Sun, 12 May 2002 01:47:50 +0000 Subject: [PATCH] To perform even basic error checking, one must have an exit code that indicates that not everything worked as expected. Exit non-zero if we timed out while transmitting or receiving a file or if the file did not exist, etc. MFC After: 3 days (re@ willing) --- usr.bin/tftp/main.c | 8 ++++---- usr.bin/tftp/tftp.c | 4 ++++ 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/usr.bin/tftp/main.c b/usr.bin/tftp/main.c index 7da91841a5b9..ad3658b76ff8 100644 --- a/usr.bin/tftp/main.c +++ b/usr.bin/tftp/main.c @@ -87,6 +87,7 @@ char line[MAXLINE]; int margc; char *margv[20]; jmp_buf toplevel; +volatile int txrx_error; void get(int, char **); void help(int, char **); @@ -164,7 +165,7 @@ main(argc, argv) signal(SIGINT, intr); if (argc > 1) { if (setjmp(toplevel) != 0) - exit(0); + exit(txrx_error); setpeer(argc, argv); } if (setjmp(toplevel) != 0) @@ -651,7 +652,7 @@ command() } else { if (fgets(line, sizeof line , stdin) == 0) { if (feof(stdin)) { - exit(0); + exit(txrx_error); } else { continue; } @@ -739,8 +740,7 @@ quit(argc, argv) int argc __unused; char *argv[] __unused; { - - exit(0); + exit(txrx_error); } /* diff --git a/usr.bin/tftp/tftp.c b/usr.bin/tftp/tftp.c index b2cc8683b7b7..bac262f9ad7d 100644 --- a/usr.bin/tftp/tftp.c +++ b/usr.bin/tftp/tftp.c @@ -72,6 +72,7 @@ extern int trace; extern int verbose; extern int rexmtval; extern int maxtimeout; +extern volatile int txrx_error; #define PKTSIZE SEGSIZE+4 char ackbuf[PKTSIZE]; @@ -173,6 +174,7 @@ xmitfile(fd, name, mode) if (ap->th_opcode == ERROR) { printf("Error code %d: %s\n", ap->th_code, ap->th_msg); + txrx_error = 1; goto abort; } if (ap->th_opcode == ACK) { @@ -289,6 +291,7 @@ recvfile(fd, name, mode) if (dp->th_opcode == ERROR) { printf("Error code %d: %s\n", dp->th_code, dp->th_msg); + txrx_error = 1; goto abort; } if (dp->th_opcode == DATA) { @@ -479,6 +482,7 @@ timer(sig) printf("Transfer timed out.\n"); longjmp(toplevel, -1); } + txrx_error = 1; longjmp(timeoutbuf, 1); }