From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 1735 invoked from network); 14 Nov 2000 11:48:16 -0000 Received: from sunsite.dk (HELO sunsite.auc.dk) (130.225.51.30) by ns1.primenet.com.au with SMTP; 14 Nov 2000 11:48:16 -0000 Received: (qmail 10610 invoked by alias); 14 Nov 2000 11:48:31 -0000 Mailing-List: contact zsh-workers-help@sunsite.auc.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 13163 Received: (qmail 10602 invoked from network); 14 Nov 2000 11:48:31 -0000 Date: Tue, 14 Nov 2000 12:48:05 +0100 (MET) Message-Id: <200011141148.MAA03939@beta.informatik.hu-berlin.de> From: Sven Wischnowsky To: zsh-workers@sunsite.auc.dk In-reply-to: "Bart Schaefer"'s message of Mon, 13 Nov 2000 16:20:01 +0000 Subject: 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@informatik.hu-berlin.de