From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 9315 invoked from network); 29 Aug 2003 11:04:03 -0000 Received: from sunsite.dk (130.225.247.90) by ns1.primenet.com.au with SMTP; 29 Aug 2003 11:04:03 -0000 Received: (qmail 14971 invoked by alias); 29 Aug 2003 11:03:40 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 6494 Received: (qmail 14960 invoked from network); 29 Aug 2003 11:03:40 -0000 Received: from localhost (HELO sunsite.dk) (127.0.0.1) by localhost with SMTP; 29 Aug 2003 11:03:40 -0000 X-MessageWall-Score: 0 (sunsite.dk) Received: from [212.118.47.27] by sunsite.dk (MessageWall 1.0.8) with SMTP; 29 Aug 2003 11:3:40 -0000 Received: from basalt.office.altlinux.org (localhost.localdomain [127.0.0.1]) by hq2.fandra.org (Postfix) with ESMTP id 4004B13C for ; Fri, 29 Aug 2003 15:03:39 +0400 (MSD) Received: from julia.office.altlinux.ru (julia.office.altlinux.ru [10.1.1.160]) by basalt.office.altlinux.org (Postfix) with ESMTP id 4C89111A for ; Fri, 29 Aug 2003 15:03:35 +0400 (MSD) Received: by julia.office.altlinux.ru (Postfix, from userid 500) id 938ED10893; Fri, 29 Aug 2003 15:03:33 +0400 (MSD) Date: Fri, 29 Aug 2003 15:03:33 +0400 From: Alexey Tourbin To: zsh-users@sunsite.dk Subject: zpty Message-ID: <20030829110333.GB2661@julia.office.altlinux.ru> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="m51xatjYGsM+13rf" Content-Disposition: inline --m51xatjYGsM+13rf Content-Type: multipart/mixed; boundary="O5XBE6gyVG5Rl6Rj" Content-Disposition: inline --O5XBE6gyVG5Rl6Rj Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Hi, I'm new to this mailing list. I've been using zsh for a while. Recently I found out that zpty actually does not work on my Linux system. $ zmodload zsh/zpty $ zpty date date zpty: can't open pseudo terminal: bad file descriptor $ As I digged into the code, I saw those old-style /dev/ptyxx heuristics which may not work on some modern Linux systems because the location is changed to /dev/pts/xx. Meanwhile there's an API in glibc for dealing with pseudo terminals. So I reworked that code a bit. Now it works fine for me. Of course it's not portable, it works with glibc only. But glibc is one of the most popular libc implementation, and it works not on Linux systems only. So please consider whether this can be useful somehow. Thanks, Alexey Tourbin ALT Linux Team --O5XBE6gyVG5Rl6Rj Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="zsh-4.1.1-alt-zpty.patch" --- zsh-4.1.1~/Src/Modules/zpty.c 2003-02-13 14:07:02 +0300 +++ zsh-4.1.1/Src/Modules/zpty.c 2003-08-23 16:21:50 +0400 @@ -27,8 +27,14 @@ * */ +/* getpt(3) requires _GNU_SOURCE */ +#define _GNU_SOURCE #include "zpty.mdh" #include "zpty.pro" +#include +#include +#include +#include /* The number of bytes we normally read when given no pattern and the * upper bound on the number of bytes we read (even if we are give a @@ -154,6 +160,7 @@ getptycmd(char *name) return NULL; } +#if 0 /**** maybe we should use configure here */ /**** and we certainly need more/better #if tests */ @@ -265,9 +272,11 @@ get_pty(int master, int *retfd) close(mfd); return 1; + } #endif /* __SVR4 */ +#endif /* 0 */ static int newptycmd(char *nam, char *pname, char **args, int echo, int nblock) @@ -282,10 +291,20 @@ newptycmd(char *nam, char *pname, char * return 1; } - if (get_pty(1, &master)) { - zwarnnam(nam, "can't open pseudo terminal: %e", NULL, errno); - return 1; + master = getpt(); + if (master < 0) { + zwarnnam(nam, "can't open pseudo terminal: %e", NULL, errno); + return 1; } + if (grantpt(master) < 0) { + zwarnnam(nam, "grantpt: %e", NULL, errno); + return 1; + } + if (unlockpt(master) < 0) { + zwarnnam(nam, "unlockpt: %e", NULL, errno); + return 1; + } + if ((pid = fork()) == -1) { zwarnnam(nam, "can't create pty command %s: %e", pname, errno); close(master); @@ -310,8 +329,21 @@ newptycmd(char *nam, char *pname, char * } #endif - if (get_pty(0, &slave)) - exit(1); + { + const char *name = ptsname(master); + if (!name) + exit(1); + slave = open(name, O_RDWR|O_NOCTTY); + if (slave < 0) + exit(1); + if (isastream(slave)) + { + if (ioctl(slave, I_PUSH, "ptem") < 0 + || ioctl(slave, I_PUSH, "ldterm") < 0) + exit(1); + } + } + #ifdef TIOCGWINSZ /* Set the window size before associating with the terminal * * so that we don't get hit with a SIGWINCH. I'm paranoid. */ @@ -347,10 +379,6 @@ newptycmd(char *nam, char *pname, char * ioctl(slave, TIOCSCTTY, 0); #endif - close(0); - close(1); - close(2); - dup2(slave, 0); dup2(slave, 1); dup2(slave, 2); --O5XBE6gyVG5Rl6Rj-- --m51xatjYGsM+13rf Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.3 (GNU/Linux) iD8DBQE/TzMFfBKgtDjnu0YRAi53AJ9JlElCAUerEokrGkh9nqorClFUSACeLEWl XNxxal7TQcgudcw3OfAYa0o= =fT9P -----END PGP SIGNATURE----- --m51xatjYGsM+13rf--