From owner-svn-src-stable-11@freebsd.org Tue Jul 18 06:45:15 2017 Return-Path: Delivered-To: svn-src-stable-11@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 2985FC7DF6A; Tue, 18 Jul 2017 06:45:15 +0000 (UTC) (envelope-from ngie@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id EBF8622C3; Tue, 18 Jul 2017 06:45:14 +0000 (UTC) (envelope-from ngie@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v6I6jEwd090755; Tue, 18 Jul 2017 06:45:14 GMT (envelope-from ngie@FreeBSD.org) Received: (from ngie@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v6I6jD6q090750; Tue, 18 Jul 2017 06:45:13 GMT (envelope-from ngie@FreeBSD.org) Message-Id: <201707180645.v6I6jD6q090750@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ngie set sender to ngie@FreeBSD.org using -f From: Ngie Cooper Date: Tue, 18 Jul 2017 06:45:13 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r321107 - in stable/11: lib/libsbuf share/man/man9 sys/kern sys/sys X-SVN-Group: stable-11 X-SVN-Commit-Author: ngie X-SVN-Commit-Paths: in stable/11: lib/libsbuf share/man/man9 sys/kern sys/sys X-SVN-Commit-Revision: 321107 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-11@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 11-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 18 Jul 2017 06:45:15 -0000 Author: ngie Date: Tue Jul 18 06:45:13 2017 New Revision: 321107 URL: https://svnweb.freebsd.org/changeset/base/321107 Log: MFC r307873,r314397,r314399,r314419,r314420,r314533,r316553: r307873 (by marcel): Include instead of when compiled as part of libsbuf. The former is the standard header, and allows us to compile libsbuf on macOS/linux. r314397 (by scottl): Implement sbuf_prf(), which takes an sbuf and outputs it to stdout in the non-kernel case and to the console+log in the kernel case. For the kernel case it hooks the putbuf() machinery underneath printf(9) so that the buffer is written completely atomically and without a copy into another temporary buffer. This is useful for fixing compound console/log messages that become broken and interleaved when multiple threads are competing for the console. r314399 (by scottl): Add prototype for sbuf_putbuf() r314419 (by jkim): Include stdio.h to fix libsbuf build. r314420 (by scottl): Provide a comment on why stdio.h needs to be included. r314533 (by scottl): Expose the sbuf_putbuf() symbol to libsbuf. There are a few other symbols that are present but not exposed, like get/set/clear flags, not sure if they need to be exposed at this point. r316553: sbuf(3): expose sbuf_{clear,get,set}_flags(3) via libsbuf These functions were added to sbuf(9) in r279992, but never exposed to userspace. Expose them now so they can be used/tested. Modified: stable/11/lib/libsbuf/Symbol.map stable/11/lib/libsbuf/Version.def stable/11/share/man/man9/sbuf.9 stable/11/sys/kern/subr_prf.c stable/11/sys/sys/sbuf.h Directory Properties: stable/11/ (props changed) Modified: stable/11/lib/libsbuf/Symbol.map ============================================================================== --- stable/11/lib/libsbuf/Symbol.map Tue Jul 18 06:15:05 2017 (r321106) +++ stable/11/lib/libsbuf/Symbol.map Tue Jul 18 06:45:13 2017 (r321107) @@ -21,6 +21,9 @@ FBSD_1.2 { sbuf_len; sbuf_done; sbuf_delete; + sbuf_clear_flags; + sbuf_get_flags; + sbuf_set_flags; }; FBSD_1.3 { @@ -31,3 +34,8 @@ FBSD_1.3 { FBSD_1.4 { sbuf_hexdump; }; + +FBSD_1.5 { + sbuf_putbuf; +}; + Modified: stable/11/lib/libsbuf/Version.def ============================================================================== --- stable/11/lib/libsbuf/Version.def Tue Jul 18 06:15:05 2017 (r321106) +++ stable/11/lib/libsbuf/Version.def Tue Jul 18 06:45:13 2017 (r321107) @@ -8,3 +8,6 @@ FBSD_1.3 { FBSD_1.4 { } FBSD_1.3; + +FBSD_1.5 { +} FBSD_1.4; Modified: stable/11/share/man/man9/sbuf.9 ============================================================================== --- stable/11/share/man/man9/sbuf.9 Tue Jul 18 06:15:05 2017 (r321106) +++ stable/11/share/man/man9/sbuf.9 Tue Jul 18 06:45:13 2017 (r321107) @@ -57,7 +57,8 @@ .Nm sbuf_delete , .Nm sbuf_start_section , .Nm sbuf_end_section , -.Nm sbuf_hexdump +.Nm sbuf_hexdump , +.Nm sbuf_putbuf .Nd safe string composition .Sh SYNOPSIS .In sys/types.h @@ -124,6 +125,8 @@ .Fa "const char *hdr" .Fa "int flags" .Fc +.Ft void +.Fn sbuf_putbuf "struct sbuf *s" .In sys/sysctl.h .Ft struct sbuf * .Fn sbuf_new_for_sysctl "struct sbuf *s" "char *buf" "int length" "struct sysctl_req *req" @@ -472,6 +475,12 @@ representation of the bytes if possible. See the .Xr hexdump 3 man page for more details on the interface. +.Pp +The +.Fn sbuf_putbuf +function printfs the sbuf to stdout if in userland, and to the console +and log if in the kernel. +It does not drain the buffer or update any pointers. .Sh NOTES If an operation caused an .Fa sbuf Modified: stable/11/sys/kern/subr_prf.c ============================================================================== --- stable/11/sys/kern/subr_prf.c Tue Jul 18 06:15:05 2017 (r321106) +++ stable/11/sys/kern/subr_prf.c Tue Jul 18 06:45:13 2017 (r321107) @@ -72,8 +72,20 @@ __FBSDID("$FreeBSD$"); * Note that stdarg.h and the ANSI style va_start macro is used for both * ANSI and traditional C compilers. */ +#ifdef _KERNEL #include +#else +#include +#endif +/* + * This is needed for sbuf_putbuf() when compiled into userland. Due to the + * shared nature of this file, it's the only place to put it. + */ +#ifndef _KERNEL +#include +#endif + #ifdef _KERNEL #define TOCONS 0x01 @@ -406,6 +418,23 @@ vprintf(const char *fmt, va_list ap) } static void +prf_putbuf(char *bufr, int flags, int pri) +{ + + if (flags & TOLOG) + msglogstr(bufr, pri, /*filter_cr*/1); + + if (flags & TOCONS) { + if ((panicstr == NULL) && (constty != NULL)) + msgbuf_addstr(&consmsgbuf, -1, + bufr, /*filter_cr*/ 0); + + if ((constty == NULL) ||(always_console_output)) + cnputs(bufr); + } +} + +static void putbuf(int c, struct putchar_arg *ap) { /* Check if no console output buffer was provided. */ @@ -426,19 +455,8 @@ putbuf(int c, struct putchar_arg *ap) /* Check if the buffer needs to be flushed. */ if (ap->remain == 2 || c == '\n') { + prf_putbuf(ap->p_bufr, ap->flags, ap->pri); - if (ap->flags & TOLOG) - msglogstr(ap->p_bufr, ap->pri, /*filter_cr*/1); - - if (ap->flags & TOCONS) { - if ((panicstr == NULL) && (constty != NULL)) - msgbuf_addstr(&consmsgbuf, -1, - ap->p_bufr, /*filter_cr*/ 0); - - if ((constty == NULL) ||(always_console_output)) - cnputs(ap->p_bufr); - } - ap->p_next = ap->p_bufr; ap->remain = ap->n_bufr; *ap->p_next = '\0'; @@ -1214,5 +1232,21 @@ counted_warning(unsigned *counter, const char *msg) break; } } +} +#endif + +#ifdef _KERNEL +void +sbuf_putbuf(struct sbuf *sb) +{ + + prf_putbuf(sbuf_data(sb), TOLOG | TOCONS, -1); +} +#else +void +sbuf_putbuf(struct sbuf *sb) +{ + + printf("%s", sbuf_data(sb)); } #endif Modified: stable/11/sys/sys/sbuf.h ============================================================================== --- stable/11/sys/sys/sbuf.h Tue Jul 18 06:15:05 2017 (r321106) +++ stable/11/sys/sys/sbuf.h Tue Jul 18 06:45:13 2017 (r321107) @@ -99,6 +99,7 @@ void sbuf_start_section(struct sbuf *, ssize_t *); ssize_t sbuf_end_section(struct sbuf *, ssize_t, size_t, int); void sbuf_hexdump(struct sbuf *, const void *, int, const char *, int); +void sbuf_putbuf(struct sbuf *); #ifdef _KERNEL struct uio;