From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7868) id 3B148385843E; Tue, 10 Jan 2023 13:15:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3B148385843E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1673356557; bh=XTZTMtldzsXtgk031d/MgvxeuqMDZbQv8txbfkGPGwg=; h=From:To:Subject:Date:From; b=gRPJ8tcBkqO34iD2AAtZOPmf9vhSJ98AWKs7ldgraBXRZXgFAuSe2VTEPsoMxrtsk CuMb3xd2dW9g9hG2UiGYG7RnhorSCsq1DBaz7L/rJAqGkamLSiOLOkqDkc6AJCLFPZ iOlggNnhc/klpt9cg5DBVwXz07m5cgUQIradwKgI= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Takashi Yano To: cygwin-cvs@sourceware.org Subject: [newlib-cygwin] Cygwin: ctty: Add comments for the special values: -1 and -2. X-Act-Checkin: newlib-cygwin X-Git-Author: Takashi Yano X-Git-Refname: refs/heads/master X-Git-Oldrev: 8e77725f3183e91762b2cac3682c7a3f0f4483f9 X-Git-Newrev: 3b7df69aaa5752f78537eafa5838f65a1ddfc938 Message-Id: <20230110131557.3B148385843E@sourceware.org> Date: Tue, 10 Jan 2023 13:15:57 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dnewlib-cygwin.git;h=3D3b7df69aaa5= 752f78537eafa5838f65a1ddfc938 commit 3b7df69aaa5752f78537eafa5838f65a1ddfc938 Author: Takashi Yano Date: Tue Jan 10 22:04:40 2023 +0900 Cygwin: ctty: Add comments for the special values: -1 and -2. =20 _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. =20 Suggested-by: Corinna Vinschen Signedoff-by: Takashi Yano 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) =20 myself.thisproc (NULL); myself->pgid =3D myself->sid =3D myself->pid; - myself->ctty =3D -1; + myself->ctty =3D -1; /* -1 means not initialized yet. */ myself->uid =3D ILLEGAL_UID; myself->gid =3D 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 <=3D 0 || ctty =3D=3D tc.ntty) && !(flags & O_NOCTTY)) { if (tc.getsid () && tc.getsid () !=3D sid && ctty =3D=3D -2) + /* ctty =3D=3D -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 =3D -2; + myself->ctty =3D -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 =3D myself->pid; myself->pgid =3D myself->pid; if (cygheap->ctty)