summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkraxel <kraxel>2007-08-22 15:14:47 +0000
committerkraxel <kraxel>2007-08-22 15:14:47 +0000
commit5be59f4107ae6b307bfe4f6fc7194e665a029aa5 (patch)
treee7a9ed61639d4acc4fb6801f7278f8e17e11d159
parent7437de2ebf01e1f7c8116398c84e6ded07751196 (diff)
downloadamtterm-5be59f4107ae6b307bfe4f6fc7194e665a029aa5.tar.gz
polish error reporting
-rw-r--r--amtterm.c19
-rw-r--r--gamt.c4
-rw-r--r--redir.c31
-rw-r--r--redir.h1
4 files changed, 32 insertions, 23 deletions
diff --git a/amtterm.c b/amtterm.c
index 22fb5b5..fe4679f 100644
--- a/amtterm.c
+++ b/amtterm.c
@@ -46,16 +46,19 @@ static void state_tty(void *cb_data, enum redir_state old, enum redir_state new)
{
struct redir *r = cb_data;
- if (!r->verbose)
- return;
-
- fprintf(stderr, APPNAME ": %s -> %s (%s)\n",
- redir_state_name(old), redir_state_name(new),
- redir_state_desc(new));
+ if (r->verbose)
+ fprintf(stderr, APPNAME ": %s -> %s (%s)\n",
+ redir_state_name(old), redir_state_name(new),
+ redir_state_desc(new));
switch (new) {
case REDIR_RUN_SOL:
- fprintf(stderr, "serial-over-lan redirection ok\n");
- fprintf(stderr, "connected now, use ^] to escape\n");
+ if (r->verbose)
+ fprintf(stderr,
+ "serial-over-lan redirection ok\n"
+ "connected now, use ^] to escape\n");
+ break;
+ case REDIR_ERROR:
+ fprintf(stderr, APPNAME ": ERROR: %s\n", r->err);
break;
default:
break;
diff --git a/gamt.c b/gamt.c
index 1fb3dbd..d0de501 100644
--- a/gamt.c
+++ b/gamt.c
@@ -249,8 +249,8 @@ static void state_gtk(void *cb_data, enum redir_state old, enum redir_state new)
switch (new) {
case REDIR_ERROR:
- snprintf(buf, sizeof(buf), "%s: %s FAILED", gamt->redir.host,
- redir_state_desc(old));
+ snprintf(buf, sizeof(buf), "%s: %s FAILED (%s)", gamt->redir.host,
+ redir_state_desc(old), gamt->redir.err);
if (old == REDIR_AUTH) {
/* ask for a new password next time ... */
strcpy(amt_pass, "");
diff --git a/redir.c b/redir.c
index 1255114..501b643 100644
--- a/redir.c
+++ b/redir.c
@@ -23,6 +23,7 @@
#include <unistd.h>
#include <string.h>
#include <ctype.h>
+#include <errno.h>
#include "tcp.h"
#include "redir.h"
@@ -90,9 +91,14 @@ static void hexdump(const char *prefix, const unsigned char *data, size_t size)
static ssize_t redir_write(struct redir *r, const char *buf, size_t count)
{
+ int rc;
+
if (r->trace)
hexdump("out", buf, count);
- return write(r->sock, buf, count);
+ rc = write(r->sock, buf, count);
+ if (-1 == rc)
+ snprintf(r->err, sizeof(r->err), "write(socket): %s", strerror(errno));
+ return rc;
}
static void redir_state(struct redir *r, enum redir_state new)
@@ -265,10 +271,10 @@ int redir_sol_recv(struct redir *r)
count = read(r->sock, msg, count);
switch (count) {
case -1:
- perror("read(sock)");
+ snprintf(r->err, sizeof(r->err), "read(socket): %s", strerror(errno));
return -1;
case 0:
- fprintf(stderr, "EOF from socket\n");
+ snprintf(r->err, sizeof(r->err), "EOF from socket");
return -1;
default:
if (r->trace)
@@ -294,10 +300,10 @@ int redir_data(struct redir *r)
rc = read(r->sock, r->buf + r->blen, sizeof(r->buf) - r->blen);
switch (rc) {
case -1:
- perror("read(sock)");
+ snprintf(r->err, sizeof(r->err), "read(socket): %s", strerror(errno));
goto err;
case 0:
- fprintf(stderr, "EOF from socket\n");
+ snprintf(r->err, sizeof(r->err), "EOF from socket");
goto err;
default:
if (r->trace)
@@ -316,7 +322,7 @@ int redir_data(struct redir *r)
if (r->blen < bshift)
goto again;
if (r->buf[1] != STATUS_SUCCESS) {
- fprintf(stderr, "redirection session start failed\n");
+ snprintf(r->err, sizeof(r->err), "redirection session start failed");
goto err;
}
if (-1 == redir_auth(r))
@@ -327,7 +333,7 @@ int redir_data(struct redir *r)
if (r->blen < bshift)
goto again;
if (r->buf[1] != STATUS_SUCCESS) {
- fprintf(stderr, "session authentication failed\n");
+ snprintf(r->err, sizeof(r->err), "session authentication failed");
goto err;
}
if (-1 == redir_sol_start(r))
@@ -338,7 +344,7 @@ int redir_data(struct redir *r)
if (r->blen < bshift)
goto again;
if (r->buf[1] != STATUS_SUCCESS) {
- fprintf(stderr, "serial-over-lan redirection failed\n");
+ snprintf(r->err, sizeof(r->err), "serial-over-lan redirection failed");
goto err;
}
redir_state(r, REDIR_RUN_SOL);
@@ -350,10 +356,8 @@ int redir_data(struct redir *r)
bshift = HEARTBEAT_LENGTH;
if (r->blen < bshift)
goto again;
- if (HEARTBEAT_LENGTH != redir_write(r, r->buf, HEARTBEAT_LENGTH)) {
- perror("write(sock)");
+ if (HEARTBEAT_LENGTH != redir_write(r, r->buf, HEARTBEAT_LENGTH))
goto err;
- }
break;
case SOL_DATA_FROM_HOST:
if (r->blen < 10) /* header length */
@@ -369,7 +373,8 @@ int redir_data(struct redir *r)
redir_stop(r);
break;
default:
- fprintf(stderr, "%s: unknown r->buf 0x%02x\n", __FUNCTION__, r->buf[0]);
+ snprintf(r->err, sizeof(r->err), "%s: unknown r->buf 0x%02x",
+ __FUNCTION__, r->buf[0]);
goto err;
}
@@ -394,7 +399,7 @@ again:
err:
if (r->trace)
- fprintf(stderr, "in : ERROR\n");
+ fprintf(stderr, "in : ERROR (%s)\n", r->err);
redir_state(r, REDIR_ERROR);
close(r->sock);
return -1;
diff --git a/redir.h b/redir.h
index 139c392..92a4bda 100644
--- a/redir.h
+++ b/redir.h
@@ -26,6 +26,7 @@ struct redir {
int verbose;
int trace;
enum redir_state state;
+ unsigned char err[128]; // state == REDIR_ERROR
int sock;
unsigned char buf[64];