From 8e6d10121beaa001ea97b8c0225a938d6b189965 Mon Sep 17 00:00:00 2001 From: minima Date: Sun, 27 Jan 2002 15:35:33 +0000 Subject: [PATCH] try to fix EOF on standard input problems --- Changes | 2 ++ cmd/bye.pl | 2 +- src/client.c | 31 ++++++++++++++++++------------- src/sel.c | 20 +++++++++++++++++++- src/sel.h | 8 +++++++- 5 files changed, 47 insertions(+), 16 deletions(-) diff --git a/Changes b/Changes index 5c25b363..e96fda53 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,7 @@ 27Jan02======================================================================= 1. make save work in cron context +2. try to get the C client to handle closes on its standard input better +handled. 22Jan02======================================================================= 1. limit spot dupe checking to first 12 characters 13Jan02======================================================================= diff --git a/cmd/bye.pl b/cmd/bye.pl index f38f93f8..653e9394 100644 --- a/cmd/bye.pl +++ b/cmd/bye.pl @@ -15,7 +15,7 @@ if ($self->is_user && -e "$main::data/logout") { sleep(1); } -$self->send_now('Z', ""); +#$self->send_now('Z', ""); $self->disconnect; diff --git a/src/client.c b/src/client.c index 7b98f661..124ac56b 100644 --- a/src/client.c +++ b/src/client.c @@ -375,12 +375,12 @@ int fcb_handler(sel_t *sp, int in, int out, int err) default: dbg(DBUF,"got errno %d in input", errno); ending++; - return 0; + return 1; } } else if (r == 0) { dbg(DBUF, "ending normally"); ending++; - return 0; + return 1; } dbgdump(DBUF, "in ->", buf, r); @@ -723,7 +723,8 @@ void process_node() void term_timeout(int i) { /* none of this is going to be reused so don't bother cleaning up properly */ - tcflush(0, TCIOFLUSH); + if (isatty(0)) + tcflush(0, TCIOFLUSH); kill(getpid(), 9); /* commit suicide */ } @@ -732,16 +733,23 @@ void terminate(int i) signal(SIGALRM, term_timeout); alarm(10); - while ((in && !is_chain_empty(in->outq)) || - (node && !is_chain_empty(node->outq))) { + if (node && node->sp->sort) { + sel_close(node->sp); + close(node->cnum); + } + while (in && in->sp->sort && !is_chain_empty(in->outq)) { sel_run(); } + sel_run(); + sel_run(); + sel_run(); + sel_run(); + sel_run(); + sel_run(); + sel_run(); + sel_run(); if (in && in->t_set) tcsetattr(0, TCSADRAIN, &in->t); - if (node) { - shutdown(node->cnum, 3); - close(node->cnum); - } exit(i); } @@ -749,10 +757,7 @@ void login_timeout(int i) { write(0, "Timed Out", 10); write(0, &nl, 1); - sel_run(); /* force a coordination */ - if (in && in->t_set) - tcsetattr(0, TCSANOW, &in->t); - exit(i); + terminate(0); } /* diff --git a/src/sel.c b/src/sel.c index 4856dda3..f476ed74 100755 --- a/src/sel.c +++ b/src/sel.c @@ -81,6 +81,16 @@ sel_t *sel_open(int cnum, void *fcb, char *name, int (*handler)(), int sort, int return sp; } +/* + * post a close handler for this connection, to do special things + * in the event of this cnum closing, the default is just to close + */ + +void sel_closehandler(sel_t *sp, void (*handler)()) +{ + sp->closehandler = handler; +} + /* * close (and thus clear down) a slot, it is assumed that you have done whatever * you need to do to close the actual device already @@ -89,6 +99,11 @@ sel_t *sel_open(int cnum, void *fcb, char *name, int (*handler)(), int sort, int void sel_close(sel_t *sp) { if (sp->sort) { + if (sp->closehandler) { + (sp->closehandler)(sp); + } else { + close(sp->cnum); + } chain_flush(sp->msgbase); free(sp->msgbase); free(sp->name); @@ -188,7 +203,10 @@ int sel_error(sel_t *sp, int err) /* * $Log$ - * Revision 1.4 2000-07-20 14:16:00 minima + * Revision 1.5 2002-01-27 15:35:33 minima + * try to fix EOF on standard input problems + * + * Revision 1.4 2000/07/20 14:16:00 minima * can use Sourceforge now! * added user->qra cleaning * added 4 digit qra to user broadcast dxspots if available diff --git a/src/sel.h b/src/sel.h index dde95a42..4dad4168 100755 --- a/src/sel.h +++ b/src/sel.h @@ -8,7 +8,10 @@ * $Header$ * * $Log$ - * Revision 1.3 2000-07-20 14:16:00 minima + * Revision 1.4 2002-01-27 15:35:33 minima + * try to fix EOF on standard input problems + * + * Revision 1.3 2000/07/20 14:16:00 minima * can use Sourceforge now! * added user->qra cleaning * added 4 digit qra to user broadcast dxspots if available @@ -41,6 +44,7 @@ typedef struct { void *fcb; /* any fcb associated with this thing */ reft *msgbase; /* any messages for this port */ int (*handler)(); /* the handler for this thingy */ + int (*closehandler)(); /* special close handler */ } sel_t; extern sel_t *sel; @@ -58,6 +62,8 @@ extern struct timeval sel_tv; void sel_init(int, long, long); /* initialise the select thing */ void sel_run(); /* run the select multiplexor */ sel_t *sel_open(int, void *, char *, int (*)(), int, int);/* initialise a slot */ +void sel_closehandler(sel_t *, void (*)()); /* post a closehandler for this cnum */ + void sel_close(sel_t *); int sel_error(sel_t *, int); /* set/clear error flag */ -- 2.43.0