From: Sven Wischnowsky <wischnow@informatik.hu-berlin.de>
To: zsh-workers@sunsite.auc.dk
Subject: PATCH: Re: Misc. zpty tweaks, plus commentary
Date: Tue, 14 Nov 2000 12:48:05 +0100 (MET) [thread overview]
Message-ID: <200011141148.MAA03939@beta.informatik.hu-berlin.de> (raw)
In-Reply-To: "Bart Schaefer"'s message of Mon, 13 Nov 2000 16:20:01 +0000
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
reply other threads:[~2000-11-14 11:48 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=200011141148.MAA03939@beta.informatik.hu-berlin.de \
--to=wischnow@informatik.hu-berlin.de \
--cc=zsh-workers@sunsite.auc.dk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).