xref: /titanic_44/usr/src/uts/common/sys/session.h (revision 32529ec11ac8e93a62985721612a18ee6bb8659a)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
28 /*	  All Rights Reserved  	*/
29 
30 
31 #ifndef _SYS_SESSION_H
32 #define	_SYS_SESSION_H
33 
34 #pragma ident	"%Z%%M%	%I%	%E% SMI"
35 
36 #ifdef	__cplusplus
37 extern "C" {
38 #endif
39 
40 typedef struct sess {
41 	uint_t		s_ref; 		/* reference count */
42 	dev_t		s_dev;		/* tty's device number */
43 	struct vnode	*s_vp;		/* tty's vnode */
44 	struct pid	*s_sidp;	/* session ID info */
45 	struct cred	*s_cred;	/* allocation credentials */
46 	kmutex_t	s_lock;		/* sync s_vp use with freectty */
47 	kcondvar_t	s_wait_cv;	/* Condvar for sleeping */
48 	int		s_cnt;		/* # of active users of this session */
49 	int		s_flag;		/* session state flag see below */
50 } sess_t;
51 
52 #define	SESS_CLOSE	1		/* session about to close */
53 #define	s_sid s_sidp->pid_id
54 
55 #if defined(_KERNEL)
56 
57 extern sess_t session0;
58 
59 #define	SESS_HOLD(sp)	(++(sp)->s_ref)
60 #define	SESS_RELE(sp)	sess_rele(sp)
61 
62 /*
63  * Used to synchronize session vnode users with freectty()
64  */
65 
66 #define	TTY_HOLD(sp)	{ \
67 	mutex_enter(&(sp)->s_lock); \
68 	(++(sp)->s_cnt); \
69 	mutex_exit(&(sp)->s_lock); \
70 }
71 
72 #define	TTY_RELE(sp)	{ \
73 	mutex_enter(&(sp)->s_lock); \
74 	if ((--(sp)->s_cnt) == 0) \
75 		cv_signal(&(sp)->s_wait_cv); \
76 	mutex_exit(&(sp)->s_lock); \
77 }
78 
79 /* forward referenced structure tags */
80 struct vnode;
81 struct proc;
82 
83 extern void sess_rele(sess_t *);
84 extern void sess_create(void);
85 extern void freectty(sess_t *);
86 extern void alloctty(struct proc *, struct vnode *);
87 extern dev_t cttydev(struct proc *);
88 
89 #endif /* defined(_KERNEL) */
90 
91 #ifdef	__cplusplus
92 }
93 #endif
94 
95 #endif	/* _SYS_SESSION_H */
96