vtprintf

Navdeep Parhar np at FreeBSD.org
Fri Sep 6 19:34:26 UTC 2013


I have the need for a vtprintf in the kernel.  Is the following
patch ok?  See http://people.freebsd.org/~np/vtprintf.diff in case it's
eaten by the mailing list.  I would like to commit this soon.

While here, I could also add a vuprintf if anyone thinks it might be
useful too.  ?

Regards,
Navdeep


diff -r b180598c57ea sys/kern/subr_prf.c
--- a/sys/kern/subr_prf.c	Fri Sep 06 11:52:17 2013 -0700
+++ b/sys/kern/subr_prf.c	Fri Sep 06 12:29:27 2013 -0700
@@ -175,15 +175,24 @@ out:
 }

 /*
- * tprintf prints on the controlling terminal associated with the given
- * session, possibly to the log as well.
+ * tprintf and vtprintf print on the controlling terminal associated
with the
+ * given session, possibly to the log as well.
  */
 void
 tprintf(struct proc *p, int pri, const char *fmt, ...)
 {
+	va_list ap;
+
+	va_start(ap, fmt);
+	vtprintf(p, pri, fmt, ap);
+	va_end(ap);
+}
+
+void
+vtprintf(struct proc *p, int pri, const char *fmt, va_list ap)
+{
 	struct tty *tp = NULL;
 	int flags = 0;
-	va_list ap;
 	struct putchar_arg pca;
 	struct session *sess = NULL;

@@ -208,13 +217,11 @@ tprintf(struct proc *p, int pri, const c
 	pca.tty = tp;
 	pca.flags = flags;
 	pca.p_bufr = NULL;
-	va_start(ap, fmt);
 	if (pca.tty != NULL)
 		tty_lock(pca.tty);
 	kvprintf(fmt, putchar, &pca, 10, ap);
 	if (pca.tty != NULL)
 		tty_unlock(pca.tty);
-	va_end(ap);
 	if (sess != NULL)
 		sess_release(sess);
 	msgbuftrigger = 1;
diff -r b180598c57ea sys/sys/systm.h
--- a/sys/sys/systm.h	Fri Sep 06 11:52:17 2013 -0700
+++ b/sys/sys/systm.h	Fri Sep 06 12:29:27 2013 -0700
@@ -212,6 +212,7 @@ u_long	strtoul(const char *, char **, in
 quad_t	strtoq(const char *, char **, int) __nonnull(1);
 u_quad_t strtouq(const char *, char **, int) __nonnull(1);
 void	tprintf(struct proc *p, int pri, const char *, ...)
__printflike(3, 4);
+void	vtprintf(struct proc *, int, const char *, __va_list)
__printflike(3, 0);
 void	hexdump(const void *ptr, int length, const char *hdr, int flags);
 #define	HD_COLUMN_MASK	0xff
 #define	HD_DELIM_MASK	0xff00


More information about the freebsd-arch mailing list