1/*- 2 * Copyright (c) 1986, 1988, 1991, 1993 3 * The Regents of the University of California. All rights reserved. 4 * (c) UNIX System Laboratories, Inc. 5 * All or some portions of this file are derived from material licensed 6 * to the University of California by American Telephone and Telegraph 7 * Co. or Unix System Laboratories, Inc. and are reproduced herein with 8 * the permission of UNIX System Laboratories, Inc. --- 22 unchanged lines hidden (view full) --- 31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 36 * SUCH DAMAGE. 37 * 38 * @(#)subr_prf.c 8.3 (Berkeley) 1/21/94 |
39 * $FreeBSD: head/sys/kern/subr_prf.c 91140 2002-02-23 11:12:57Z tanimura $ |
40 */ 41 42#include <sys/param.h> 43#include <sys/systm.h> |
44#include <sys/lock.h> 45#include <sys/mutex.h> 46#include <sys/sx.h> |
47#include <sys/kernel.h> 48#include <sys/msgbuf.h> 49#include <sys/malloc.h> 50#include <sys/proc.h> 51#include <sys/sysctl.h> 52#include <sys/tty.h> 53#include <sys/syslog.h> 54#include <sys/cons.h> --- 56 unchanged lines hidden (view full) --- 111 */ 112int 113uprintf(const char *fmt, ...) 114{ 115 struct thread *td = curthread; 116 struct proc *p = td->td_proc; 117 va_list ap; 118 struct putchar_arg pca; |
119 int retval; |
120 |
121 if (td == NULL || td == PCPU_GET(idlethread)) 122 return (0); 123 124 p = td->td_proc; 125 PROC_LOCK(p); 126 if ((p->p_flag & P_CONTROLT) == 0) { 127 PROC_UNLOCK(p); 128 return (0); |
129 } |
130 SESS_LOCK(p->p_session); 131 pca.tty = p->p_session->s_ttyp; 132 SESS_UNLOCK(p->p_session); 133 PROC_UNLOCK(p); 134 if (pca.tty == NULL) 135 return (0); 136 pca.flags = TOTTY; 137 va_start(ap, fmt); 138 retval = kvprintf(fmt, putchar, &pca, 10, ap); 139 va_end(ap); 140 |
141 return (retval); 142} 143 144/* 145 * tprintf prints on the controlling terminal associated 146 * with the given session, possibly to the log as well. 147 */ 148void 149tprintf(struct proc *p, int pri, const char *fmt, ...) 150{ 151 struct tty *tp = NULL; 152 int flags = 0, shld = 0; 153 va_list ap; 154 struct putchar_arg pca; 155 int retval; 156 157 if (pri != -1) 158 flags |= TOLOG; |
159 if (p != NULL) { 160 PGRPSESS_XLOCK(); 161 PROC_LOCK(p); 162 if (p->p_flag & P_CONTROLT && p->p_session->s_ttyvp) { 163 SESS_LOCK(p->p_session); 164 SESSHOLD(p->p_session); |
165 tp = p->p_session->s_ttyp; |
166 SESS_UNLOCK(p->p_session); 167 PROC_UNLOCK(p); 168 shld++; 169 if (ttycheckoutq(tp, 0)) 170 flags |= TOTTY; 171 else 172 tp = NULL; 173 } else 174 PROC_UNLOCK(p); 175 PGRPSESS_XUNLOCK(); |
176 } 177 pca.pri = pri; 178 pca.tty = tp; 179 pca.flags = flags; 180 va_start(ap, fmt); 181 retval = kvprintf(fmt, putchar, &pca, 10, ap); 182 va_end(ap); |
183 if (shld) { 184 PGRPSESS_XLOCK(); 185 SESS_LOCK(p->p_session); |
186 SESSRELE(p->p_session); |
187 SESS_UNLOCK(p->p_session); 188 PGRPSESS_XUNLOCK(); 189 } |
190 msgbuftrigger = 1; 191} 192 193/* 194 * Ttyprintf displays a message on a tty; it should be used only by 195 * the tty driver, or anything that knows the underlying tty will not 196 * be revoke(2)'d away. Other callers should use tprintf. 197 */ --- 735 unchanged lines hidden --- |