public inbox for cygwin-cvs@sourceware.org
help / color / mirror / Atom feed
From: Takashi Yano <tyan0@sourceware.org>
To: cygwin-cvs@sourceware.org
Subject: [newlib-cygwin] Cygwin: ctty: Add comments for the special values: -1 and -2.
Date: Tue, 10 Jan 2023 13:15:57 +0000 (GMT)	[thread overview]
Message-ID: <20230110131557.3B148385843E@sourceware.org> (raw)

https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=3b7df69aaa5752f78537eafa5838f65a1ddfc938

commit 3b7df69aaa5752f78537eafa5838f65a1ddfc938
Author: Takashi Yano <takashi.yano@nifty.ne.jp>
Date:   Tue Jan 10 22:04:40 2023 +0900

    Cygwin: ctty: Add comments for the special values: -1 and -2.
    
    _pinfo::ctty has two special values other than the device id of
    the allocated ctty:
    -1: CTTY is not initialized yet. Can be associated with the TTY
        which is associated with the session leader.
    -2: CTTY has been released by setsid(). Can be associate only with
        new TTY which is not associated with any other session as CTTY,
        but cannot be associate with the TTYs already associated with
        other sessions.
    This patch adds the comments in some source files.
    
    Suggested-by: Corinna Vinschen <corinna@vinschen.de>
    Signedoff-by: Takashi Yano <takashi.yano@nifty.ne.jp>

Diff:
---
 winsup/cygwin/pinfo.cc    | 5 ++++-
 winsup/cygwin/syscalls.cc | 4 +++-
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/winsup/cygwin/pinfo.cc b/winsup/cygwin/pinfo.cc
index ece346037..fc618b9b8 100644
--- a/winsup/cygwin/pinfo.cc
+++ b/winsup/cygwin/pinfo.cc
@@ -97,7 +97,7 @@ pinfo_init (char **envp, int envc)
 
       myself.thisproc (NULL);
       myself->pgid = myself->sid = myself->pid;
-      myself->ctty = -1;
+      myself->ctty = -1; /* -1 means not initialized yet. */
       myself->uid = ILLEGAL_UID;
       myself->gid = ILLEGAL_GID;
       environ_init (NULL, 0);	/* call after myself has been set up */
@@ -531,6 +531,9 @@ _pinfo::set_ctty (fhandler_termios *fh, int flags)
   if (fh && (ctty <= 0 || ctty == tc.ntty) && !(flags & O_NOCTTY))
     {
       if (tc.getsid () && tc.getsid () != sid && ctty == -2)
+	/* ctty == -2 means CTTY has been released by setsid().
+	   Can be associated only with a new TTY which is not
+	   associated with any other session. */
 	; /* Do nothing if another session is associated with the TTY. */
       else
 	{
diff --git a/winsup/cygwin/syscalls.cc b/winsup/cygwin/syscalls.cc
index fff8af009..15ddbb0a8 100644
--- a/winsup/cygwin/syscalls.cc
+++ b/winsup/cygwin/syscalls.cc
@@ -1176,7 +1176,9 @@ setsid (void)
     syscall_printf ("hmm.  pgid %d pid %d", myself->pgid, myself->pid);
   else
     {
-      myself->ctty = -2;
+      myself->ctty = -2; /* -2 means CTTY has been released by setsid().
+			    Can be associated only with a new TTY which
+			    is not associated with any session. */
       myself->sid = myself->pid;
       myself->pgid = myself->pid;
       if (cygheap->ctty)

                 reply	other threads:[~2023-01-10 13:15 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=20230110131557.3B148385843E@sourceware.org \
    --to=tyan0@sourceware.org \
    --cc=cygwin-cvs@sourceware.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.
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 read-only IMAP folder(s) and NNTP newsgroup(s).