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 90490 2002-02-10 22:04:44Z phk $
40 */
41
42#include <sys/param.h>
43#include <sys/systm.h>
44#include <sys/kernel.h>
45#include <sys/msgbuf.h>
46#include <sys/malloc.h>
47#include <sys/proc.h>
48#include <sys/sysctl.h>
49#include <sys/tty.h>
50#include <sys/syslog.h>
51#include <sys/cons.h>
--- 56 unchanged lines hidden (view full) ---
108 */
109int
110uprintf(const char *fmt, ...)
111{
112 struct thread *td = curthread;
113 struct proc *p = td->td_proc;
114 va_list ap;
115 struct putchar_arg pca;
116 int retval = 0;
117
118 if (td && td != PCPU_GET(idlethread) && p->p_flag & P_CONTROLT &&
119 p->p_session->s_ttyvp) {
120 va_start(ap, fmt);
121 pca.tty = p->p_session->s_ttyp;
122 pca.flags = TOTTY;
123 retval = kvprintf(fmt, putchar, &pca, 10, ap);
124 va_end(ap);
125 }
126 return (retval);
127}
128
129/*
130 * tprintf prints on the controlling terminal associated
131 * with the given session, possibly to the log as well.
132 */
133void
134tprintf(struct proc *p, int pri, const char *fmt, ...)
135{
136 struct tty *tp = NULL;
137 int flags = 0, shld = 0;
138 va_list ap;
139 struct putchar_arg pca;
140 int retval;
141
142 if (pri != -1)
143 flags |= TOLOG;
144 if (p && p->p_flag & P_CONTROLT && p->p_session->s_ttyvp) {
145 SESSHOLD(p->p_session);
146 shld++;
147 if (ttycheckoutq(p->p_session->s_ttyp, 0)) {
148 flags |= TOTTY;
149 tp = p->p_session->s_ttyp;
150 }
151 }
152 pca.pri = pri;
153 pca.tty = tp;
154 pca.flags = flags;
155 va_start(ap, fmt);
156 retval = kvprintf(fmt, putchar, &pca, 10, ap);
157 va_end(ap);
158 if (shld)
159 SESSRELE(p->p_session);
160 msgbuftrigger = 1;
161}
162
163/*
164 * Ttyprintf displays a message on a tty; it should be used only by
165 * the tty driver, or anything that knows the underlying tty will not
166 * be revoke(2)'d away. Other callers should use tprintf.
167 */
--- 735 unchanged lines hidden ---
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 90490 2002-02-10 22:04:44Z phk $
40 */
41
42#include <sys/param.h>
43#include <sys/systm.h>
44#include <sys/kernel.h>
45#include <sys/msgbuf.h>
46#include <sys/malloc.h>
47#include <sys/proc.h>
48#include <sys/sysctl.h>
49#include <sys/tty.h>
50#include <sys/syslog.h>
51#include <sys/cons.h>
--- 56 unchanged lines hidden (view full) ---
108 */
109int
110uprintf(const char *fmt, ...)
111{
112 struct thread *td = curthread;
113 struct proc *p = td->td_proc;
114 va_list ap;
115 struct putchar_arg pca;
116 int retval = 0;
117
118 if (td && td != PCPU_GET(idlethread) && p->p_flag & P_CONTROLT &&
119 p->p_session->s_ttyvp) {
120 va_start(ap, fmt);
121 pca.tty = p->p_session->s_ttyp;
122 pca.flags = TOTTY;
123 retval = kvprintf(fmt, putchar, &pca, 10, ap);
124 va_end(ap);
125 }
126 return (retval);
127}
128
129/*
130 * tprintf prints on the controlling terminal associated
131 * with the given session, possibly to the log as well.
132 */
133void
134tprintf(struct proc *p, int pri, const char *fmt, ...)
135{
136 struct tty *tp = NULL;
137 int flags = 0, shld = 0;
138 va_list ap;
139 struct putchar_arg pca;
140 int retval;
141
142 if (pri != -1)
143 flags |= TOLOG;
144 if (p && p->p_flag & P_CONTROLT && p->p_session->s_ttyvp) {
145 SESSHOLD(p->p_session);
146 shld++;
147 if (ttycheckoutq(p->p_session->s_ttyp, 0)) {
148 flags |= TOTTY;
149 tp = p->p_session->s_ttyp;
150 }
151 }
152 pca.pri = pri;
153 pca.tty = tp;
154 pca.flags = flags;
155 va_start(ap, fmt);
156 retval = kvprintf(fmt, putchar, &pca, 10, ap);
157 va_end(ap);
158 if (shld)
159 SESSRELE(p->p_session);
160 msgbuftrigger = 1;
161}
162
163/*
164 * Ttyprintf displays a message on a tty; it should be used only by
165 * the tty driver, or anything that knows the underlying tty will not
166 * be revoke(2)'d away. Other callers should use tprintf.
167 */
--- 735 unchanged lines hidden ---