xref: /dragonfly/lib/libc/gen/getttyent.3 (revision d13dc3a1)
1.\" Copyright (c) 1989, 1991, 1993
2.\"	The Regents of the University of California.  All rights reserved.
3.\"
4.\" Redistribution and use in source and binary forms, with or without
5.\" modification, are permitted provided that the following conditions
6.\" are met:
7.\" 1. Redistributions of source code must retain the above copyright
8.\"    notice, this list of conditions and the following disclaimer.
9.\" 2. Redistributions in binary form must reproduce the above copyright
10.\"    notice, this list of conditions and the following disclaimer in the
11.\"    documentation and/or other materials provided with the distribution.
12.\" 3. Neither the name of the University nor the names of its contributors
13.\"    may be used to endorse or promote products derived from this software
14.\"    without specific prior written permission.
15.\"
16.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
17.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26.\" SUCH DAMAGE.
27.\"
28.\"     @(#)getttyent.3	8.1 (Berkeley) 6/4/93
29.\" $FreeBSD: src/lib/libc/gen/getttyent.3,v 1.15 2007/01/09 00:27:54 imp Exp $
30.\"
31.Dd September 20, 2023
32.Dt GETTTYENT 3
33.Os
34.Sh NAME
35.Nm getttyent ,
36.Nm getttynam ,
37.Nm setttyent ,
38.Nm endttyent ,
39.Nm isdialuptty ,
40.Nm isnettty
41.Nd
42.Xr ttys 5
43file routines
44.Sh LIBRARY
45.Lb libc
46.Sh SYNOPSIS
47.In ttyent.h
48.Ft struct ttyent *
49.Fn getttyent void
50.Ft struct ttyent *
51.Fn getttynam "const char *name"
52.Ft int
53.Fn setttyent void
54.Ft int
55.Fn endttyent void
56.Ft int
57.Fn isdialuptty "const char *name"
58.Ft int
59.Fn isnettty "const char *name"
60.Sh DESCRIPTION
61The
62.Fn getttyent ,
63and
64.Fn getttynam
65functions
66each return a pointer to an object, with the following structure,
67containing the broken-out fields of a line from the tty description
68file.
69.Bd -literal
70struct ttyent {
71	char	*ty_name;	/* terminal device name */
72	char	*ty_getty;	/* command to execute, usually getty */
73	char	*ty_type;	/* terminal type for termcap */
74	int	ty_status;	/* status flags */
75	char	*ty_window;	/* command to start up window manager */
76	char	*ty_comment;	/* comment field */
77	char	*ty_group;	/* tty group name */
78};
79.Ed
80.Pp
81The fields are as follows:
82.Bl -tag -width ".Fa ty_comment"
83.It Fa ty_name
84The name of the character-special file.
85.It Fa ty_getty
86The name of the command invoked by
87.Xr init 8
88to initialize tty line characteristics.
89.It Fa ty_type
90The name of the default terminal type connected to this tty line.
91.It Fa ty_status
92A mask of bit fields which indicate various actions allowed on this
93tty line.
94The possible flags are as follows:
95.Bl -tag -width ".Dv TTY_IFCONSOLE"
96.It Dv TTY_ON
97Enables logins (i.e.,
98.Xr init 8
99will start the command referenced by
100.Fa ty_getty
101on this entry).
102.It Dv TTY_SECURE
103Allow users with a uid of 0 to login on this terminal.
104.It Dv TTY_DIALUP
105Identifies a tty as a dialin line.
106If this flag is set, then
107.Fn isdialuptty
108will return a non-zero value.
109.It Dv TTY_NETWORK
110Identifies a tty used for network connections.
111If this flag is set, then
112.Fn isnettty
113will return a non-zero value.
114.It TTY_IFCONSOLE
115Only enables a tty if it's the console.
116.It TTY_IFEXISTS
117Only enables a tty if it exists.
118.El
119.It Fa ty_window
120The command to execute for a window system associated with the line.
121.It Fa ty_group
122A group name to which the tty belongs.
123If no group is specified in the ttys description file,
124then the tty is placed in an anonymous group called
125.Dq none .
126.It Fa ty_comment
127Any trailing comment field, with any leading hash marks
128.Pq #
129or whitespace removed.
130.El
131.Pp
132If any of the fields pointing to character strings are unspecified,
133they are returned as null pointers.
134The field
135.Fa ty_status
136will be zero if no flag values are specified.
137.Pp
138See
139.Xr ttys 5
140for a more complete discussion of the meaning and usage of the
141fields.
142.Pp
143The
144.Fn getttyent
145function
146reads the next line from the ttys file, opening the file if necessary.
147The
148.Fn setttyent
149function
150rewinds the file if open, or opens the file if it is unopened.
151The
152.Fn endttyent
153function
154closes any open files.
155.Pp
156The
157.Fn getttynam
158function
159searches from the beginning of the file until a matching
160.Fa name
161is found
162(or until
163.Dv EOF
164is encountered).
165.Sh RETURN VALUES
166The routines
167.Fn getttyent
168and
169.Fn getttynam
170return a null pointer on
171.Dv EOF
172or error.
173The
174.Fn setttyent
175function
176and
177.Fn endttyent
178return 0 on failure and 1 on success.
179.Pp
180The routines
181.Fn isdialuptty
182and
183.Fn isnettty
184return non-zero if the dialup or network flag is set for the
185tty entry relating to the tty named by the argument, and
186zero otherwise.
187.Sh FILES
188.Bl -tag -width ".Pa /etc/ttys" -compact
189.It Pa /etc/ttys
190.El
191.Sh SEE ALSO
192.Xr login 1 ,
193.Xr gettytab 5 ,
194.Xr termcap 5 ,
195.Xr ttys 5 ,
196.Xr getty 8 ,
197.Xr init 8
198.Sh HISTORY
199The
200.Fn getttyent ,
201.Fn getttynam ,
202.Fn setttyent ,
203and
204.Fn endttyent
205functions appeared in
206.Bx 4.3 .
207.Sh BUGS
208These functions use static data storage;
209if the data is needed for future use, it should be
210copied before any subsequent calls overwrite it.
211