zsh-workers
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: zsh-workers@zsh.org
Subject: Re: zpty non-functional?
Date: Sat, 24 Aug 2013 17:01:57 -0700	[thread overview]
Message-ID: <130824170157.ZM15713@torch.brasslantern.com> (raw)
In-Reply-To: <20130824224839.5830e7fd@pws-pc.ntlworld.com>

On Aug 24, 10:48pm, Peter Stephenson wrote:
}
} Hmm... this is well outside my comfort zone.  I thought the following
} existing code:
} 
} #ifdef TIOCSCTTY
} 	ioctl(slave, TIOCSCTTY, 0);
} #endif
} 
}        TIOCSCTTY int arg
}               Make  the given terminal the controlling terminal of the calling
}               process.
} 
} But it apparently doesn't

It makes the terminal the controlling terminal, but it doesn't make the
process the group leader for that terminal.  I suspect we also need the

	ioctl(slave, TIOCSPGRP, mypid);

[or equivalent, e.g. tcsetpgrp()] that attachtty() is doing.  I'm a bit
surprised that calling attachtty() works, because it relies on SHTTY
having been set to the right thing, and I don't see that anything in
zpty.c is making sure that slave and SHTTY refer to the same fd; but
perhaps it always is for some indirect reason ...

Is it safe/reasonable to add

	SHTTY = slave;

right before the attachtty() call in your patch?

} The following is after the setsid() (or setpgrp() if that fails or
} doesn't exist).  Maybe it should be conditional on one of those
} succeeding (and do we *really* want to do setpgrp() if setsid() fails,
} even with a warning)?  Or maybe I'm missing the point entirely and just
} got lucky?

The manual page for setsid says:

    The only error which can happen is EPERM. It is returned when the
    process group ID of any process equals the PID of the calling
    process. Thus, in particular, setsid fails if the calling process is
    already a process group leader.

A check of the setpgrp() manual page indicates pretty much the same thing;
there is no defined error that can result from setprp(0L, getpid()); the
only errors are from attempting to set the process group of a different
process than the caller.

So only some completely unexpected error (interrupted system call?) could
cause setsid() to fail, in which case trying again with setpgrp() is no
worse off.


  reply	other threads:[~2013-08-25  0:02 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-08-24 12:44 Valodim Skywalker
2013-08-24 20:10 ` Bart Schaefer
2013-08-24 21:48   ` Peter Stephenson
2013-08-25  0:01     ` Bart Schaefer [this message]
2013-08-25 18:59       ` Peter Stephenson
2013-08-25 22:01         ` Bart Schaefer
2013-08-26 19:33           ` Peter Stephenson
2013-08-27  0:54             ` Bart Schaefer
2013-08-27 12:01               ` Peter Stephenson
2013-08-27 14:31                 ` 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=130824170157.ZM15713@torch.brasslantern.com \
    --to=schaefer@brasslantern.com \
    --cc=zsh-workers@zsh.org \
    /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).