about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--Src/Modules/zftp.c60
2 files changed, 43 insertions, 22 deletions
diff --git a/ChangeLog b/ChangeLog
index 5dbd4e275..4cf5f7586 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2000-05-09  Peter Stephenson  <pws@cambridgesiliconradio.com>
+
+	* pws: 11285: Src/Modules/zftp.c: move cleanup code to
+	zftp_cleanup() to be called from exit hook.
+
 2000-05-09  Oliver Kiddle  <opk@zsh.org>
 
 	* 11284: Completion/Base/_math: use _math to complete the let builtin
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;
 }