From e89360b2dbe0633d02103130da3b4bbde25c7288 Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Tue, 9 May 2000 17:49:30 +0000 Subject: 11285: zftp exit hook --- Src/Modules/zftp.c | 60 ++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 38 insertions(+), 22 deletions(-) (limited to 'Src/Modules/zftp.c') diff --git a/Src/Modules/zftp.c b/Src/Modules/zftp.c index ef85dd330..3252b9d90 100644 --- a/Src/Modules/zftp.c +++ b/Src/Modules/zftp.c @@ -3197,6 +3197,39 @@ bin_zftp(char *name, char **args, char *ops, int func) return ret; } +static void +zftp_cleanup(void) +{ + /* + * There are various parameters hanging around, but they're + * all non-special so are entirely non-life-threatening. + */ + LinkNode nptr; + Zftp_session cursess = zfsess; + for (zfsessno = 0, nptr = firstnode(zfsessions); nptr; + zfsessno++, incnode(nptr)) { + zfsess = (Zftp_session)nptr->dat; + zfclosedata(); + /* + * When closing the current session, do the usual unsetting, + * otherwise don't. + */ + zfclose(zfsess != cursess); + } + zsfree(lastmsg); + zfunsetparam("ZFTP_SESSION"); + freelinklist(zfsessions, (FreeFunc) freesession); + zfree(zfstatusp, sizeof(int)*zfsesscnt); + deletebuiltins("zftp", bintab, sizeof(bintab)/sizeof(*bintab)); +} + +static int +zftpexithook(Hookdef d, void *dummy) +{ + zftp_cleanup(); + return 0; +} + /* The load/unload routines required by the zsh library interface */ /**/ @@ -3211,7 +3244,7 @@ int boot_(Module m) { int ret; - if ((ret = addbuiltins(m->nam, bintab, + if ((ret = addbuiltins("zftp", bintab, sizeof(bintab)/sizeof(*bintab))) == 1) { /* if successful, set some default parameters */ off_t tmout_def = 60; @@ -3223,6 +3256,8 @@ boot_(Module m) zfsessions = znewlinklist(); newsession("default"); + + addhookfunc("exit", zftpexithook); } return !ret; @@ -3232,27 +3267,8 @@ boot_(Module m) int cleanup_(Module m) { - /* - * There are various parameters hanging around, but they're - * all non-special so are entirely non-life-threatening. - */ - LinkNode nptr; - Zftp_session cursess = zfsess; - for (zfsessno = 0, nptr = firstnode(zfsessions); nptr; - zfsessno++, incnode(nptr)) { - zfsess = (Zftp_session)nptr->dat; - zfclosedata(); - /* - * When closing the current session, do the usual unsetting, - * otherwise don't. - */ - zfclose(zfsess != cursess); - } - zsfree(lastmsg); - zfunsetparam("ZFTP_SESSION"); - freelinklist(zfsessions, (FreeFunc) freesession); - zfree(zfstatusp, sizeof(int)*zfsesscnt); - deletebuiltins(m->nam, bintab, sizeof(bintab)/sizeof(*bintab)); + deletehookfunc("exit", zftpexithook); + zftp_cleanup(); return 0; } -- cgit 1.4.1