Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
PATCH: zftp module cleanup
- X-seq: zsh-workers 11285
- From: Peter Stephenson <pws@xxxxxxxxxxxxxxxxxxxxxxxxx>
- To: zsh-workers@xxxxxxxxxxxxxx (Zsh hackers list)
- Subject: PATCH: zftp module cleanup
- Date: Tue, 09 May 2000 18:42:54 +0100
- In-reply-to: "Your message of Tue, 09 May 2000 14:01:16 +0200." <200005091201.OAA22939@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>
- Mailing-list: contact zsh-workers-help@xxxxxxxxxxxxxx; run by ezmlm
> Which reminds me... shouldn't zftp probably use the exit-hook like
> zpty does? To at least try to cleanly close ftp connections when the
> shell exits?
I thought that's what _cleanup() was for. Having FTP connections closed
cleanly isn't always what you want anyway, however.
Index: Src/Modules/zftp.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Modules/zftp.c,v
retrieving revision 1.1.1.22
diff -u -r1.1.1.22 zftp.c
--- Src/Modules/zftp.c 2000/02/23 15:18:47 1.1.1.22
+++ Src/Modules/zftp.c 2000/05/09 17:40:09
@@ -3195,6 +3195,39 @@
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 */
/**/
@@ -3209,7 +3242,7 @@
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;
@@ -3221,6 +3254,8 @@
zfsessions = znewlinklist();
newsession("default");
+
+ addhookfunc("exit", zftpexithook);
}
return !ret;
@@ -3230,27 +3265,8 @@
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;
}
--
Peter Stephenson <pws@xxxxxxxxxxxxxxxxxxxxxxxxx>
Cambridge Silicon Radio, Unit 300, Science Park, Milton Road,
Cambridge, CB4 0XL, UK Tel: +44 (0)1223 392070
Messages sorted by:
Reverse Date,
Date,
Thread,
Author