Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

PATCH: Re: Misc. zpty tweaks, plus commentary



Bart Schaefer wrote:

> ...
>
> } > I haven't done anything about it, but this code clearly expects that
> } > no '\0' bytes will ever be sent to or received from the pty.  That's
> } > obviously a fallacy; we shouldn't be treating this data as C strings.
> } 
> } Yes and no. For reading, this already worked (the call to metafy()).
> 
> Lines 467 and 519 sling cmd->old around with strcpy().  The metafy() on
> 525 only works if there's never been read-ahead.

Ouch. Patch below.

> } > (On my RH5.2 linux system, select() always returns 1 after the pty's
> } > command has exited, so read_poll() also returns 1 and cmd->fin never
> } > gets set.  read(), however, gets an I/O error (errno == 5), so `zpty -r'
> } > returns 1 and it's not possible to detect that the command has finished.
> } 
> } Another reason for not using read_poll(), does anyone see a way to
> } allow us to find out if a command has exited and still be able to read 
> } the rest of its output?
> 
> The SIGCHLD handler could deal with this, too.  (The finding-out part, not
> the reading-the-rest part.)

Hmhm.

Bye
 Sven

Index: Src/Modules/zpty.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Modules/zpty.c,v
retrieving revision 1.19
diff -u -r1.19 zpty.c
--- Src/Modules/zpty.c	2000/11/13 10:22:42	1.19
+++ Src/Modules/zpty.c	2000/11/14 11:44:34
@@ -49,6 +49,7 @@
     int fin;
     int read;
     char *old;
+    int olen;
 };
 
 static Ptycmd ptycmds;
@@ -375,6 +376,7 @@
     p->fin = 0;
     p->read = -1;
     p->old = NULL;
+    p->olen = 0;
 
     p->next = ptycmds;
     ptycmds = p;
@@ -462,11 +464,12 @@
 	fflush(stdout);
 
     if (cmd->old) {
-	used = strlen(cmd->old);
+	used = cmd->olen;
 	buf = (char *) zhalloc((blen = 256 + used) + 1);
-	strcpy(buf, cmd->old);
-	zsfree(cmd->old);
+	memcpy(buf, cmd->old, cmd->olen);
+	zfree(cmd->old, cmd->olen);
 	cmd->old = NULL;
+	cmd->olen = 0;
     } else {
 	used = 0;
 	buf = (char *) zhalloc((blen = 256) + 1);
@@ -516,8 +519,8 @@
 #endif
 #endif
 	) {
-	cmd->old = ztrdup(buf);
-	used = 0;
+	cmd->old = (char *) zalloc(cmd->olen = used);
+	memcpy(cmd->old, buf, cmd->olen);
 
 	return 1;
     }

--
Sven Wischnowsky                         wischnow@xxxxxxxxxxxxxxxxxxxxxxx



Messages sorted by: Reverse Date, Date, Thread, Author