View Issue Details

IDProjectCategoryView StatusLast Update
00001441003.1(2008)/Issue 7Base Definitions and Headerspublic2022-10-20 15:27
ReporterEdSchouten Assigned Toajosey  
PrioritynormalSeverityEditorialTypeEnhancement Request
Status ClosedResolutionRejected 
NameEd Schouten
Organization
User Reference
SectionChapter 11: TTYs
Page Numbern/a
Line Numbern/a
Interp Status---
Final Accepted Text
Summary0000144: Standard lacks a (possibly XSI) interface to associate a session to a TTY; tcsetsid()
DescriptionAccording to the General Terminal Interface chapter, it is implementation defined whether a session associates to a TTY when O_NOCTTY is not passed to open():

The controlling terminal for a session is allocated by the session leader in an implementation-defined manner. If a session leader has no controlling terminal, and opens a terminal device file that is not already associated with a session without using the O_NOCTTY option (see open()), it is implementation-defined whether the terminal becomes the controlling terminal of the session leader.

Unfortunately, the standard does not specify a way to associate them when the implementation does not do this by default (i.e. the BSDs). This means it's practically impossible to implement a network login service or terminal emulator only using the interfaces described in POSIX.
Desired ActionStandardizing things like TIOCSCTTY wouldn't be a good way to go. Some time ago I looked at this and it seems QNX has a solution for this that seems to be quite elegant:

http://www.qnx.com/developers/docs/6.4.0/neutrino/lib_ref/t/tcsetsid.html

It's basically the counterpart of the already existing tcgetsid().

I propose adding this function to the standard, marked as XSI, where a minimal implementation only has to support the situation where the `pid' argument is equal to the session ID of the current process. This would be desirable anyway.

An implementation on operating systems that have TIOCSCTTY could then look as follows:

int
tcsetsid(int fd, pid_t pid)
{

    if (pid != getsid(0)) {
        errno = EINVAL;
        return -1;
    }

    return ioctl(fd, TIOCSCTTY, NULL);
}
TagsNo tags attached.
Attached Files
tcsetsid.txt (1,665 bytes)   
Page 415, below line 13907, add:

	int tcsetsid(int, pid_t);

Page 416, line 13924, add reference to tcgetsid().

Add new article for tcsetsid():

NAME

	tcsetsid - set the process group ID for the session leader for
	           the controlling terminal

SYNPOSIS

	#include <termios.h>

	int tcsetsid(int fildes, pid_t pid);

DESCRIPTION

	The tcsetsid() function shall set the process ID of the session
	leader associated with the terminal to sid.  The application
	shall ensure that the file associated with fildes is a terminal
	that is not already associated with a session leader.  The
	application shall ensure that the value of pid matches the
	process ID of the calling process.  This process must also be a
	session leader.

RETURN VALUE

	Upon successful completion, 0 shall be returned. Otherwise, -1
	shall be returned and errno set to indicate the error.

ERRORS

	The tcsetsid() function shall fail if:

	[EBADF]
		The fildes argument is not a valid file descriptor.
	[ENOTTY]
		The file associated with fildes is not a terminal.
	[EPERM]
		The value of sid does not match the process ID of the
		calling process.

RATIONALE

	By enforcing that pid must match the process ID of the calling
	process, this function can be implemented on top of the
	TIOCSCTTY ioctl() present in some implementations, while still
	permitting extensions in future versions of the standard.

	On implementations supporting the TIOCSCTTY ioctl(), the
	tcsetsid() function can simply be implemented as follows:

	#include <termios.h>
	int tcsetsid(int fildes, pid_t pid)
	{
		if (pid != getpid()) {
			errno = EPERM;
			return -1;
		}
		return ioctl(fildes, TIOCSCTTY);
	}
tcsetsid.txt (1,665 bytes)   
tcsetsid_v2.txt (1,871 bytes)   
Page 415, below line 13907, add:

	int tcsetsid(int, pid_t);

Page 416, line 13924, add reference to tcgetsid().

Add new article for tcsetsid():

NAME

	tcsetsid - set the process group ID for the session leader for
	           the controlling terminal

SYNPOSIS

	#include <termios.h>

	int tcsetsid(int fildes, pid_t pid);

DESCRIPTION

	The tcsetsid() function shall set the process ID of the session
	leader associated with the terminal to pid.  The application
	shall ensure that the file associated with fildes is a terminal
	that is not already associated with a different session leader.
	The application shall ensure that the value of pid matches the
	process ID of the calling process.  This process must also be a
	session leader.

	If the calling process is already associated with the terminal
	associated with fildes, the function shall have no effect.

RETURN VALUE

	Upon successful completion, 0 shall be returned. Otherwise, -1
	shall be returned and errno set to indicate the error.

ERRORS

	The tcsetsid() function shall fail if:

	[EBADF]
		The fildes argument is not a valid file descriptor.
	[ENOTTY]
		The file associated with fildes is not a terminal.
	[EPERM]
		The value of pid does not match the process ID of the
		calling process or the terminal is already associated
		with a different session leader.

RATIONALE

	By enforcing that pid must match the process ID of the calling
	process, this function can be implemented on top of the
	TIOCSCTTY ioctl() present in some implementations, while still
	permitting extensions in future versions of the standard.

	On implementations supporting the TIOCSCTTY ioctl(), the
	tcsetsid() function can simply be implemented as follows:

	#include <termios.h>
	int tcsetsid(int fildes, pid_t pid)
	{
		if (pid != getpid()) {
			errno = EPERM;
			return -1;
		}
		return ioctl(fildes, TIOCSCTTY);
	}
tcsetsid_v2.txt (1,871 bytes)   

Activities

nick

2009-09-24 15:36

manager   bugnote:0000237

The rules for introducing new material into the standard are provided in austin-112r3 (http://www.opengroup.org/austin/docs/austin_112r3.txt).

The material introduced must have a copyright release from the original owner.

The text needs to be fully formed ... the exact words you would propose being added to the standard.

Since you have suggested that the new interface be marked XSI, the best method for moving forward would be to lobby members of The Open Group's platform working group.

EdSchouten

2010-02-21 00:00

updater   bugnote:0000388

I was just looking through my bug reports.

So what is meant with "material introduced"? Say, I come up with a specification of the function with the same prototype, would that mean I introduced the material? Or is QNX in this case the originating party?

I was just thinking, wouldn't it make more sense to add this to the base definitions, because if its high importance? Maybe tcsetsid() should also become a base definition while there.

Are there certain templates or formats which I can use? If not, should I just write a plain-text file using certain annotation?

EdSchouten

2010-02-21 00:13

updater   bugnote:0000389

Never mind "Maybe tcsetsid() should also become a base definition while there." It seems tcsetsid() is already part of the base definitions.

EdSchouten

2011-03-30 17:54

updater   bugnote:0000730

Because tcgetsid() is part of base, it would make sense to add tcsetsid() to base as well. I've attached a proposed change to the 7th edition of the standard to include tcsetsid().

msbrown

2011-03-31 15:30

manager   bugnote:0000732

Thanks for your submission! We are considering this for inclusion into the next revision (hence the tag "issue8"); we will not be considering this for an Issue 7 addendum as it is new function.

We are currently attempting to get copyright clearance for this interface. In the meantime we will be going over the text you have submitted.

EdSchouten

2011-04-03 11:15

updater   bugnote:0000736

I've corrected some small typos and also documented that tcsetsid() shall have no effect on already associated terminals.

soumendraganguly

2020-12-22 23:19

reporter   bugnote:0005188

I was wondering if alongside tcgetwinsize() and tcsetwinsize(), we could also attempt to include tcsetsid() in issue 8. Please see https://austingroupbugs.net/view.php?id=1151.

As EdSchouten had mentioned, tcgetsid() is already a part of the standard. FreeBSD and QNX additionally include tcsetsid().

Some implementations such as BSDs, Glibc, Solaris, ... include a library function called login_tty(), which prepares a terminal for a new login session; that procedure involves setting a controlling terminal. I am attempting to introduce a Python version of this [os.login_tty()]. Implementing this usually involves calls to setsid(), open(), close(), ttyname(), dup2(), which are currently a part of the standard; it is only when we attempt to set the controlling tty, we have to resort to using implementation-specific methods such as ioctl()+TIOCSCTTY or passing a tty file descriptor to open() without
supplying the O_NOCTTY flag. Since it is not favorable to standardize TIOCSCTTY, I request that EdSchouten's original proposal to standardize tcsetsid() be reconsidered.

Don Cragun

2022-10-20 15:27

manager   bugnote:0006007

Because we have been unable to get a copyright release for this interface in the last 11 years, this bug is being rejected. If someone can obtain copyright release, please submit a new bug with the appropriate release information.

Issue History

Date Modified Username Field Change
2009-09-05 17:22 EdSchouten New Issue
2009-09-05 17:22 EdSchouten Status New => Under Review
2009-09-05 17:22 EdSchouten Assigned To => ajosey
2009-09-05 17:22 EdSchouten Name => Ed Schouten
2009-09-05 17:22 EdSchouten Section => Chapter 11: TTYs
2009-09-05 17:22 EdSchouten Page Number => n/a
2009-09-05 17:22 EdSchouten Line Number => n/a
2009-09-24 15:36 nick Note Added: 0000237
2009-09-24 15:37 msbrown Interp Status => ---
2009-09-24 15:37 msbrown Status Under Review => Resolved
2009-09-24 15:37 msbrown Resolution Open => Future Enhancement
2010-02-21 00:00 EdSchouten Note Added: 0000388
2010-02-21 00:13 EdSchouten Note Added: 0000389
2010-09-09 15:48 geoffclare Tag Attached: issue8
2011-03-30 17:53 EdSchouten File Added: tcsetsid.txt
2011-03-30 17:54 EdSchouten Note Added: 0000730
2011-03-30 17:55 EdSchouten Status Resolved => Under Review
2011-03-30 17:55 EdSchouten Resolution Future Enhancement => Reopened
2011-03-31 15:30 msbrown Note Added: 0000732
2011-04-03 11:14 EdSchouten File Added: tcsetsid_v2.txt
2011-04-03 11:15 EdSchouten Note Added: 0000736
2020-12-22 23:19 soumendraganguly Note Added: 0005188
2022-10-17 16:03 geoffclare Tag Detached: issue8
2022-10-20 15:27 Don Cragun Note Added: 0006007
2022-10-20 15:27 Don Cragun Status Under Review => Closed
2022-10-20 15:27 Don Cragun Resolution Reopened => Rejected