zsh-workers
 help / color / mirror / code / Atom feed
From: Borsenkow Andrej <Andrej.Borsenkow@mow.siemens.ru>
To: "'tvignaud@mandrakesoft.com'" <tvignaud@mandrakesoft.com>
Cc: "'Zsh hackers list'" <zsh-workers@sunsite.dk>
Subject: Mandrake patch for "make it work on serial ports"
Date: Fri, 6 Sep 2002 15:43:41 +0400	[thread overview]
Message-ID: <6134254DE87BD411908B00A0C99B044F041173D1@mowd019a.mow.siemens.ru> (raw)

[-- Attachment #1: Type: text/plain, Size: 408 bytes --]

The following patch is currently used on Mandrake (attached for
zsh-workers). It basically always opens input in non-blocking mode. I am
really interested to know when this patch is needed. Having open block on
lack of carrier is perfectly sensible and long-adopted approach... 

Therry, I am sorry but I really had some problems and was away for quite
some time. Thank you for making new release.

-andrej


[-- Attachment #2: zsh-serial.patch --]
[-- Type: application/octet-stream, Size: 1869 bytes --]

--- zsh-4.0.4/Src/builtin.c.open	Tue Oct 16 02:49:17 2001
+++ zsh-4.0.4/Src/builtin.c	Wed May 15 11:55:32 2002
@@ -3489,7 +3489,7 @@ bin_read(char *name, char **args, char *
 	if (!zleactive) {
 	    if (SHTTY == -1) {
 		/* need to open /dev/tty specially */
-		if ((SHTTY = open("/dev/tty", O_RDWR|O_NOCTTY)) != -1) {
+		if ((SHTTY = block_open("/dev/tty", O_RDWR|O_NOCTTY)) != -1) {
 		    haso = 1;
 		    oshout = shout;
 		    init_shout();
--- zsh-4.0.4/Src/init.c.open	Wed Oct 24 04:16:32 2001
+++ zsh-4.0.4/Src/init.c	Wed May 15 12:00:07 2002
@@ -397,7 +397,7 @@ init_io(void)
     if (isatty(0)) {
 	zsfree(ttystrname);
 	if ((ttystrname = ztrdup(ttyname(0)))) {
-	    SHTTY = movefd(open(ttystrname, O_RDWR | O_NOCTTY));
+	    SHTTY = movefd(block_open(ttystrname, O_RDWR | O_NOCTTY));
 #ifdef TIOCNXCL
 	    /*
 	     * See if the terminal claims to be busy.  If so, and fd 0
@@ -438,7 +438,7 @@ init_io(void)
 	ttystrname = ztrdup(ttyname(1));
     }
     if (SHTTY == -1 &&
-	(SHTTY = movefd(open("/dev/tty", O_RDWR | O_NOCTTY))) != -1) {
+	(SHTTY = movefd(block_open("/dev/tty", O_RDWR | O_NOCTTY))) != -1) {
 	zsfree(ttystrname);
 	ttystrname = ztrdup(ttyname(SHTTY));
     }
@@ -1235,3 +1235,33 @@ zsh_main(int argc, char **argv)
 		: "use 'logout' to logout.", NULL, 0);
     }
 }
+
+/**/
+int
+block_open (const char *tty, int flags)
+{
+    int saved_errno;
+    int fd;
+
+    if ((flags & O_NONBLOCK) == 0) {
+	fd = open (tty, flags | O_NONBLOCK);
+	if (fd == -1)
+	    return fd;
+	flags = fcntl(fd, F_GETFL);
+	if (flags == -1)
+	    goto bad;
+	flags &= ~O_NONBLOCK;
+	if (fcntl(fd, F_SETFL, flags) == -1)
+	    goto bad;
+    }
+    else
+	fd = open (tty, flags);
+
+    return fd;
+
+bad:
+    saved_errno = errno;
+    close (fd);
+    errno = saved_errno;
+    return -1;
+}

             reply	other threads:[~2002-09-06 11:34 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-09-06 11:43 Borsenkow Andrej [this message]
2002-09-06 14:43 ` Bart Schaefer

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=6134254DE87BD411908B00A0C99B044F041173D1@mowd019a.mow.siemens.ru \
    --to=andrej.borsenkow@mow.siemens.ru \
    --cc=tvignaud@mandrakesoft.com \
    --cc=zsh-workers@sunsite.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).