10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*2712Snn35248 * Common Development and Distribution License (the "License"). 6*2712Snn35248 * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 210Sstevel@tonic-gate /* 22*2712Snn35248 * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 230Sstevel@tonic-gate * Use is subject to license terms. 240Sstevel@tonic-gate */ 250Sstevel@tonic-gate 260Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 270Sstevel@tonic-gate /* All Rights Reserved */ 280Sstevel@tonic-gate 290Sstevel@tonic-gate 300Sstevel@tonic-gate #ifndef _SYS_SESSION_H 310Sstevel@tonic-gate #define _SYS_SESSION_H 320Sstevel@tonic-gate 330Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 340Sstevel@tonic-gate 350Sstevel@tonic-gate #ifdef __cplusplus 360Sstevel@tonic-gate extern "C" { 370Sstevel@tonic-gate #endif 380Sstevel@tonic-gate 39*2712Snn35248 /* 40*2712Snn35248 * Session structure overview. 41*2712Snn35248 * 42*2712Snn35248 * Currently, the only structure in the kernel which has a pointer to a 43*2712Snn35248 * session structures is the proc_t via the p_sessp pointer. To 44*2712Snn35248 * access a session proc_t->p_sessp pointer a caller must hold either 45*2712Snn35248 * pidlock or p_splock. These locks only protect the p_sessp pointer 46*2712Snn35248 * itself and do not protect any of the contents of the session structure. 47*2712Snn35248 * To prevent the contents of a the session structure from changing the 48*2712Snn35248 * caller must grab s_lock. 49*2712Snn35248 * 50*2712Snn35248 * No callers should ever update the contents of the session structure 51*2712Snn35248 * directly. Only the session management code should ever modify the 52*2712Snn35248 * contents of the session structure. When the session code attempts 53*2712Snn35248 * to modify the contents of a session structure it must hold multiple 54*2712Snn35248 * locks. The locking order for all the locks that may need to be 55*2712Snn35248 * acquired is: 56*2712Snn35248 * sd_lock -> pidlock -> p_splock -> s_lock 57*2712Snn35248 * 58*2712Snn35248 * If a caller requires access to a session structure for long 59*2712Snn35248 * periods of time or across operations that may block it should 60*2712Snn35248 * use the tty_hold() and sess_hold() interfaces. 61*2712Snn35248 * 62*2712Snn35248 * sess_hold() returns a pointer to a session structure associated 63*2712Snn35248 * with the proc_t that was passed in. It also increments the reference 64*2712Snn35248 * count associated with that session structure to ensure that it 65*2712Snn35248 * can't be freed until after the caller is done with it and calls 66*2712Snn35248 * sess_rele(). This hold doesn't actually protect any of the 67*2712Snn35248 * contents of the session structure. 68*2712Snn35248 * 69*2712Snn35248 * tty_hold() returns a pointer to a session structure associated 70*2712Snn35248 * with the curproc. It also "locks" the contents of the session 71*2712Snn35248 * structure. This hold should be used when the caller will be 72*2712Snn35248 * doing operations on a controlling tty associated with the session. 73*2712Snn35248 * This operation doesn an implicit sess_hold() so that the session 74*2712Snn35248 * structure can't be free'd until after the caller is done with it 75*2712Snn35248 * and invokes tty_rele(). 76*2712Snn35248 * 77*2712Snn35248 * NOTE: Neither of these functions (sess_hold() or tty_hold()) 78*2712Snn35248 * prevent a process from changing its session. Once these functions 79*2712Snn35248 * return a session pointer, that session pointer may no longer be 80*2712Snn35248 * associated with the current process. If a caller wants to prevent 81*2712Snn35248 * a process from changing its session then it must hold pidlock or 82*2712Snn35248 * p_splock. 83*2712Snn35248 */ 84*2712Snn35248 850Sstevel@tonic-gate typedef struct sess { 86*2712Snn35248 struct pid *s_sidp; /* session ID info, never changes */ 87*2712Snn35248 88*2712Snn35248 kmutex_t s_lock; /* protects everything below */ 89*2712Snn35248 uint_t s_ref; /* reference count */ 90*2712Snn35248 boolean_t s_sighuped; /* ctty had sighup sent to it */ 91*2712Snn35248 92*2712Snn35248 boolean_t s_exit; /* sesion leader is exiting */ 93*2712Snn35248 kcondvar_t s_exit_cv; /* Condvar for s_exit */ 94*2712Snn35248 95*2712Snn35248 int s_cnt; /* active users of this ctty */ 96*2712Snn35248 kcondvar_t s_cnt_cv; /* Condvar for s_cnt */ 97*2712Snn35248 98*2712Snn35248 /* 99*2712Snn35248 * The following fields can only be updated while s_lock is held 100*2712Snn35248 * and s_cnt is 0. (ie, no one has a tty_hold() on this session.) 101*2712Snn35248 */ 102*2712Snn35248 dev_t s_dev; /* tty's device number */ 103*2712Snn35248 struct vnode *s_vp; /* tty's vnode */ 104*2712Snn35248 struct cred *s_cred; /* allocation credentials */ 1050Sstevel@tonic-gate } sess_t; 1060Sstevel@tonic-gate 1070Sstevel@tonic-gate #define s_sid s_sidp->pid_id 1080Sstevel@tonic-gate 1090Sstevel@tonic-gate #if defined(_KERNEL) 1100Sstevel@tonic-gate 1110Sstevel@tonic-gate extern sess_t session0; 1120Sstevel@tonic-gate 1130Sstevel@tonic-gate /* forward referenced structure tags */ 1140Sstevel@tonic-gate struct vnode; 1150Sstevel@tonic-gate struct proc; 116*2712Snn35248 struct stdata; 1170Sstevel@tonic-gate 118*2712Snn35248 extern void sess_hold(proc_t *p); 119*2712Snn35248 extern void sess_rele(sess_t *, boolean_t); 120*2712Snn35248 extern sess_t *tty_hold(void); 121*2712Snn35248 extern void tty_rele(sess_t *sp); 122*2712Snn35248 123*2712Snn35248 1240Sstevel@tonic-gate extern void sess_create(void); 125*2712Snn35248 extern int strctty(struct stdata *); 126*2712Snn35248 extern int freectty(boolean_t); 1270Sstevel@tonic-gate extern dev_t cttydev(struct proc *); 128*2712Snn35248 extern void ctty_clear_sighuped(void); 1290Sstevel@tonic-gate 1300Sstevel@tonic-gate #endif /* defined(_KERNEL) */ 1310Sstevel@tonic-gate 1320Sstevel@tonic-gate #ifdef __cplusplus 1330Sstevel@tonic-gate } 1340Sstevel@tonic-gate #endif 1350Sstevel@tonic-gate 1360Sstevel@tonic-gate #endif /* _SYS_SESSION_H */ 137