4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 /* Copyright (c) 1988 AT&T */
28 /* All Rights Reserved */
30 #pragma ident "%Z%%M% %I% %E% SMI"
33 * Return the number of the slot in the utmp file
34 * corresponding to the current user: try for file 0, 1, 2.
35 * Returns -1 if slot not found.
41 #include <sys/types.h>
66 * The UNIX98 Posix conformance test suite requires
67 * ttyslot() to not be a cancellation point.
69 (void) pthread_setcancelstate(PTHREAD_CANCEL_DISABLE
, &cancel_state
);
71 if ((p
= ttyname_r(0, ttynm
, 128)) != NULL
||
72 (p
= ttyname_r(1, ttynm
, 128)) != NULL
||
73 (p
= ttyname_r(2, ttynm
, 128)) != NULL
) {
74 if (strncmp(p
, "/dev/", 5) == 0)
76 if (strcmp(p
, "console") == 0)
79 if ((fp
= fopen(UTMPX_FILE
, "rF")) != NULL
) {
80 while ((fread(&ubuf
, sizeof (ubuf
), 1, fp
)) == 1) {
81 if ((ubuf
.ut_type
== INIT_PROCESS
||
82 ubuf
.ut_type
== LOGIN_PROCESS
||
83 ubuf
.ut_type
== USER_PROCESS
) &&
84 strncmp(p
, ubuf
.ut_line
,
85 sizeof (ubuf
.ut_line
)) == 0) {
88 strncmp(ubuf
.ut_host
, ":0", 2) == 0)
97 (void) pthread_setcancelstate(cancel_state
, NULL
);