about summary refs log tree commit diff
path: root/Src/Modules
diff options
context:
space:
mode:
authorPeter Stephenson <pws@users.sourceforge.net>2000-05-09 17:49:30 +0000
committerPeter Stephenson <pws@users.sourceforge.net>2000-05-09 17:49:30 +0000
commite89360b2dbe0633d02103130da3b4bbde25c7288 (patch)
tree27bb0b0b8bdda9814dfc1d060169912514b13739 /Src/Modules
parentd6245580513cbb99801ea005348eb1fbdf42bf89 (diff)
downloadzsh-e89360b2dbe0633d02103130da3b4bbde25c7288.tar.gz
zsh-e89360b2dbe0633d02103130da3b4bbde25c7288.tar.xz
zsh-e89360b2dbe0633d02103130da3b4bbde25c7288.zip
11285: zftp exit hook
Diffstat (limited to 'Src/Modules')
-rw-r--r--Src/Modules/zftp.c60
1 files changed, 38 insertions, 22 deletions
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;
 }