aboutsummaryrefslogtreecommitdiff
path: root/sys/kern/subr_prf.c
Commit message (Collapse)AuthorAgeFilesLines
* Always send log(9) messages to the message buffer.Eric van Gyzen2015-04-201-1/+1
| | | | | | | | | | | | | | | | | | It is truer to the semantics of logging for messages to *always* go to the message buffer, where they can eventually be collected and, in fact, be put into a log file. This restores the behavior prior to r70239, which seems to have changed it inadvertently. Submitted by: Eric Badger <eric@badgerio.us> Reviewed by: jhb Approved by: kib (mentor) Obtained from: Dell Inc. MFC after: 1 week Notes: svn path=/head/; revision=281785
* Add a nulterm byte to the returned sysctl string.Ian Lepore2015-03-151-1/+1
| | | | | | | PR: 195668 Notes: svn path=/head/; revision=280016
* Fix usage example in kvprintf(9) and its copy in libstand(3): trailing '\n'Alexey Dokuchaev2015-01-231-2/+2
| | | | | | | | | | | | | | | | in bitfield argument is wrong, as it will be treated as bit 10, causing any code printing >=10 bits with bit 10 on as having a trailing comma. Newline (intended one) should be part of the format string (already present in the examples). Also fix grammar and kill EOL whitespace in comment while here. PR: 195005 Approved by: bdrewery Notes: svn path=/head/; revision=277560
* Pull in r267961 and r267973 again. Fix for issues reported will follow.Hans Petter Selasky2014-06-281-13/+10
| | | | Notes: svn path=/head/; revision=267992
* Revert r267961, r267973:Glen Barber2014-06-271-10/+13
| | | | | | | | | | | | | These changes prevent sysctl(8) from returning proper output, such as: 1) no output from sysctl(8) 2) erroneously returning ENOMEM with tools like truss(1) or uname(1) truss: can not get etype: Cannot allocate memory Notes: svn path=/head/; revision=267985
* Extend the meaning of the CTLFLAG_TUN flag to automatically check ifHans Petter Selasky2014-06-271-13/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | there is an environment variable which shall initialize the SYSCTL during early boot. This works for all SYSCTL types both statically and dynamically created ones, except for the SYSCTL NODE type and SYSCTLs which belong to VNETs. A new flag, CTLFLAG_NOFETCH, has been added to be used in the case a tunable sysctl has a custom initialisation function allowing the sysctl to still be marked as a tunable. The kernel SYSCTL API is mostly the same, with a few exceptions for some special operations like iterating childrens of a static/extern SYSCTL node. This operation should probably be made into a factored out common macro, hence some device drivers use this. The reason for changing the SYSCTL API was the need for a SYSCTL parent OID pointer and not only the SYSCTL parent OID list pointer in order to quickly generate the sysctl path. The motivation behind this patch is to avoid parameter loading cludges inside the OFED driver subsystem. Instead of adding special code to the OFED driver subsystem to post-load tunables into dynamically created sysctls, we generalize this in the kernel. Other changes: - Corrected a possibly incorrect sysctl name from "hw.cbb.intr_mask" to "hw.pcic.intr_mask". - Removed redundant TUNABLE statements throughout the kernel. - Some minor code rewrites in connection to removing not needed TUNABLE statements. - Added a missing SYSCTL_DECL(). - Wrapped two very long lines. - Avoid malloc()/free() inside sysctl string handling, in case it is called to initialize a sysctl from a tunable, hence malloc()/free() is not ready when sysctls from the sysctl dataset are registered. - Bumped FreeBSD version to indicate SYSCTL API change. MFC after: 2 weeks Sponsored by: Mellanox Technologies Notes: svn path=/head/; revision=267961
* Fix grammar error and trailing newline.Bryan Drewery2014-04-231-2/+1
| | | | | | | | Submitted by: danfe MFC after: 3 days Notes: svn path=/head/; revision=264795
* Combine similar code from vprintf(9) and log(9).Bryan Drewery2014-03-141-39/+25
| | | | | | | MFC after: 2 weeks Notes: svn path=/head/; revision=263129
* Rework the EARLY_PRINTF mechanism. Instead of defining a special eprintf()Ian Lepore2014-02-121-22/+0
| | | | | | | | | | | | | | | | | routine, now a platform can provide a pointer to an early_putc() routine which is used instead of cn_putc(). Control can be handed off from early printf support to standard console support by NULLing out the pointer during standard console init. This leverages all the existing error reporting that uses printf calls, such as panic() which can now be usefully employed even in early platform init code (useful at least to those who maintain that code and build kernels with EARLY_PRINTF defined). Reviewed by: imp, eadler Notes: svn path=/head/; revision=261786
* Implement generic support for early printf. Thought I can't find theWarner Losh2014-01-221-0/+22
| | | | | | | | | | paper trail now, this patch is similar to one posted for one of the preliminary versions of a new armv6 port. I took them and made them more generic. Option not enabled by default since each board/port has to provide its own eputc, and possibly do other things as well... Notes: svn path=/head/; revision=261038
* Reduce the scope of the proctree_lock. If several processes causeKonstantin Belousov2013-09-131-7/+6
| | | | | | | | | | | | | | | | | | continuous calls to the uprintf(9), the proctree_lock could be shared-locked for indefinite amount of time, starving exclusive requests. Since proctree_lock is needed for fork() and exit(), this effectively stops the machine. While there, do the similar reduction for tprintf(9). Reported and tested by: pho Reviewed by: ed Sponsored by: The FreeBSD Foundation MFC after: 1 week Approved by: re (glebius) Notes: svn path=/head/; revision=255509
* Add a vtprintf. It is to tprintf what vprintf is to printf.Navdeep Parhar2013-09-071-5/+12
| | | | | | | Reviewed by: kib Notes: svn path=/head/; revision=255351
* Fix double vision syndrome (read: double output) when in theMarcel Moolenaar2011-10-161-13/+7
| | | | | | | debugger without a panic. Notes: svn path=/head/; revision=226435
* Set pca.p_bufr to NULL when we haven't allocated a buffer.Kenneth D. Merry2011-06-071-0/+3
| | | | | | | | | | | | | | | | | | Otherwise, p_bufr is set to garbage on the stack, and if that garbage happens to be non-NULL, and the TOLOG or TOCONS flag is set, putbuf() will get called and attempt to fill the non-existent buffer. This is really only relevant for tprintf() (and only when the priority is not -1), but set it in uprintf() and ttyprintf() for completeness. The next step, to avoid log buffer scrambling, would be to add the PRINTF_BUFR_SIZE code to tprintf(), but this should prevent panics. Submitted by: rmacklem Found by: pho Notes: svn path=/head/; revision=222804
* Fix apparent garbage in the message buffer.Kenneth D. Merry2011-05-311-33/+124
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | While we have had a fix in place (options PRINTF_BUFR_SIZE=128) to fix scrambled console output, the message buffer and syslog were still getting log messages one character at a time. While all of the characters still made it into the log (courtesy of atomic operations), they were often interleaved when there were multiple threads writing to the buffer at the same time. This fixes message buffer accesses to use buffering logic as well, so that strings that are less than PRINTF_BUFR_SIZE will be put into the message buffer atomically. So now dmesg output should look the same as console output. subr_msgbuf.c: Convert most message buffer calls to use a new spin lock instead of atomic variables in some places. Add a new routine, msgbuf_addstr(), that adds a NUL-terminated string to a message buffer. This takes a priority argument, which allows us to eliminate some races (at least in the the string at a time case) that are present in the implementation of msglogchar(). (dangling and lastpri are static variables, and are subject to races when multiple callers are present.) msgbuf_addstr() also allows the caller to request that carriage returns be stripped out of the string. This matches the behavior of msglogchar(), but in testing so far it doesn't appear that any newlines are being stripped out. So the carriage return removal functionality may be a candidate for removal later on if further analysis shows that it isn't necessary. subr_prf.c: Add a new msglogstr() routine that calls msgbuf_logstr(). Rename putcons() to putbuf(). This now handles buffered output to the message log as well as the console. Also, remove the logic in putcons() (now putbuf()) that added a carriage return before a newline. The console path was the only path that needed it, and cnputc() (called by cnputs()) already adds a carriage return. So this duplication resulted in kernel-generated console output lines ending in '\r''\r''\n'. Refactor putchar() to handle the new buffering scheme. Add buffering to log(). Change log_console() to use msglogstr() instead of msglogchar(). Don't add extra newlines by default in log_console(). Hide that behavior behind a tunable/sysctl (kern.log_console_add_linefeed) for those who would like the old behavior. The old behavior led to the insertion of extra newlines for log output for programs that print out a string, and then a trailing newline on a separate write. (This is visible with dmesg -a.) msgbuf.h: Add a prototype for msgbuf_addstr(). Add three new fields to struct msgbuf, msg_needsnl, msg_lastpri and msg_lock. The first two are needed for log message functionality previously handled by msglogchar(). (Which is still active if buffering isn't enabled.) Include sys/lock.h and sys/mutex.h for the new mutex. Reviewed by: gibbs Notes: svn path=/head/; revision=222537
* Use type-specific inline function imax() instead of deprecated macro MAX().Jung-uk Kim2010-07-121-1/+1
| | | | | | | Prodded by: bde Notes: svn path=/head/; revision=209949
* Implement optional 'precision' for numbers. Previously, it was parsed butJung-uk Kim2010-07-081-11/+14
| | | | | | | | ignored. Some third-party modules (e.g., APCICA) prefer this format over zero padding flag '0'. Notes: svn path=/head/; revision=209836
* Make /dev/klog and kern.msgbuf* MPSAFE.Ed Schouten2009-11-031-5/+16
| | | | | | | | | | | | | | | | | Normally msgbufp is locked using Giant. Switch it to use the msgbuf_lock. Instead of changing the tsleep() calls to msleep(), just convert it to condvar(9). In my opinion the locking around msgbuf_peekbytes() still remains questionable. It looks like locks are dropped while performing copies of multiple blocks to userspace, which may cause the msgbuf to be reset in the mean time. At least getting it underneath from Giant should make it a little easier for us to figure out how to solve that. Reminded by: rdivacky Notes: svn path=/head/; revision=198860
* Remove redundant code in printf() and vprintf().Ed Schouten2009-02-271-28/+1
| | | | | | | | | | | printf() and vprintf() are exactly the same, except the way arguments are passed. Just like we see in other pieces of code (i.e. libc's printf()), implement printf() using vprintf(). Submitted by: Christoph Mallon <christoph mallon gmx de> Notes: svn path=/head/; revision=189104
* Revert previous commit to subr_prf.c and make it more tidy.Ed Schouten2009-02-271-3/+5
| | | | | | | | | | As mentioned by bz and bde, the change I made wasn't the proper way to fix. Inspired by bde's patch, perform some small cleanups to uprintf(). Reviewed by: bz Notes: svn path=/head/; revision=189102
* Remove redundant assignment of `p'.Ed Schouten2009-02-261-1/+0
| | | | | | | | | | `p' is already initialized with `td->td_proc'. Because td is always curthread, it is safe to initialize it without any locks. Found by: LLVM's scan-build Notes: svn path=/head/; revision=189066
* Use NULL in preference to 0 for pointers.Warner Losh2009-02-031-1/+1
| | | | Notes: svn path=/head/; revision=188057
* Revert r185891.Ed Schouten2008-12-211-2/+10
| | | | | | | | | | | | | | | In r185891 I removed the newlines from messages written to /dev/console, because it made startup messages from rc-scripts harder to read. This, unfortunately, causes the kernel message that is printed after a non-terminated log message to be concatenated. This could be fixed, but on short term it's better to just revert the change. Reported by: Jaakko Heinonen <jh saunalahti fi> Notes: svn path=/head/; revision=186383
* Remove added newlines from logged messages written to /dev/console.Ed Schouten2008-12-101-10/+2
| | | | | | | | | | | | | | | | | | The /dev/console device node logs all strings that are written to it. When the string does not contain a trailing newline, it appends one. I can imagine this was useful a long time ago, but with our current rc-scripts, it generates a whole bunch of messages that look like: | Configuring syscons: | blanktime | . By not appending the newlines, the output of `dmesg -a' is now (almost?) exactly the same as what the user will see on the console device (syscons, uart). Notes: svn path=/head/; revision=185891
* Obey signedness flag in %z case.Xin LI2008-11-171-1/+1
| | | | | | | MFC after: 2 months Notes: svn path=/head/; revision=185036
* Integrate the new MPSAFE TTY layer to the FreeBSD operating system.Ed Schouten2008-08-201-10/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The last half year I've been working on a replacement TTY layer for the FreeBSD kernel. The new TTY layer was designed to improve the following: - Improved driver model: The old TTY layer has a driver model that is not abstract enough to make it friendly to use. A good example is the output path, where the device drivers directly access the output buffers. This means that an in-kernel PPP implementation must always convert network buffers into TTY buffers. If a PPP implementation would be built on top of the new TTY layer (still needs a hooks layer, though), it would allow the PPP implementation to directly hand the data to the TTY driver. - Improved hotplugging: With the old TTY layer, it isn't entirely safe to destroy TTY's from the system. This implementation has a two-step destructing design, where the driver first abandons the TTY. After all threads have left the TTY, the TTY layer calls a routine in the driver, which can be used to free resources (unit numbers, etc). The pts(4) driver also implements this feature, which means posix_openpt() will now return PTY's that are created on the fly. - Improved performance: One of the major improvements is the per-TTY mutex, which is expected to improve scalability when compared to the old Giant locking. Another change is the unbuffered copying to userspace, which is both used on TTY device nodes and PTY masters. Upgrading should be quite straightforward. Unlike previous versions, existing kernel configuration files do not need to be changed, except when they reference device drivers that are listed in UPDATING. Obtained from: //depot/projects/mpsafetty/... Approved by: philip (ex-mentor) Discussed: on the lists, at BSDCan, at the DevSummit Sponsored by: Snow B.V., the Netherlands dcons(4) fixed by: kan Notes: svn path=/head/; revision=181905
* Instead of doing comparisons using the pcpu area to see ifJulian Elischer2007-03-081-1/+1
| | | | | | | | | | a thread is an idle thread, just see if it has the IDLETD flag set. That flag will probably move to the pflags word as it's permenent and never chenges for the life of the system so it doesn't need locking. Notes: svn path=/head/; revision=167327
* Flushing the buffer is conditional on actually using the buffer. Oops.John Birrell2006-11-301-0/+4
| | | | Notes: svn path=/head/; revision=164764
* Turn console printf buffering into a kernel option and only onJohn Birrell2006-11-301-14/+23
| | | | | | | | | | | | | | | | | | | | by default for sun4v where it is absolutely required. This change moves the buffer from struct pcpu to the stack to avoid using the critical section which created a LOR in a couple of cases due to interaction with the tty code and kqueue. The LOR can't be fixed with the critical section and the pcpu buffer can't be used without the critical section. Putting the buffer on the stack was my initial solution, but it was pointed out that the stress on the stack might cause problems depending on the call path. We don't have a way of creating tests for those possible cases, so it's best to leave this as an option for the time being. In time we may get enough data to enable this option more generally. Notes: svn path=/head/; revision=164760
* Sweep kernel replacing suser(9) calls with priv(9) calls, assigningRobert Watson2006-11-061-1/+2
| | | | | | | | | | | | | | | | specific privilege names to a broad range of privileges. These may require some future tweaking. Sponsored by: nCircle Network Security, Inc. Obtained from: TrustedBSD Project Discussed on: arch@ Reviewed (at least in part) by: mlaier, jmg, pjd, bde, ceri, Alex Lyashkov <umka at sevcity dot net>, Skip Ford <skip dot ford at verizon dot net>, Antoine Brodin <antoine dot brodin at laposte dot net> Notes: svn path=/head/; revision=164033
* Add a cnputs() function to write a string to the console withJohn Birrell2006-11-011-17/+72
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | a lock to prevent interspersed strings written from different CPUs at the same time. To avoid putting a buffer on the stack or having to malloc one, space is incorporated in the per-cpu structure. The buffer size if 128 bytes; chosen because it's the next power of 2 size up from 80 characters. String writes to the console are buffered up the end of the line or until the buffer fills. Then the buffer is flushed to all console devices. Existing low level console output via cnputc() is unaffected by this change. ithread calls to log() are also unaffected to avoid blocking those threads. A minor change to the behaviour in a panic situation is that console output will still be buffered, but won't be written to a tty as before. This should prevent interspersed panic output as a number of CPUs panic before we end up single threaded running ddb. Reviewed by: scottl, jhb MFC after: 2 weeks Notes: svn path=/head/; revision=163858
* Declare security and security.bsd sysctl hierarchies in sysctl.h alongRobert Watson2006-09-171-2/+0
| | | | | | | | | | | with other commonly used sysctl name spaces, rather than declaring them all over the place. MFC after: 1 month Sponsored by: nCircle Network Security, Inc. Notes: svn path=/head/; revision=162383
* Simplify the pager support in DDB. Allowing different db commands toJohn Baldwin2006-07-121-5/+2
| | | | | | | | | | | | | | | | | | | install custom pager functions didn't actually happen in practice (they all just used the simple pager and passed in a local quit pointer). So, just hardcode the simple pager as the only pager and make it set a global db_pager_quit flag that db commands can check when the user hits 'q' (or a suitable variant) at the pager prompt. Also, now that it's easy to do so, enable paging by default for all ddb commands. Any command that wishes to honor the quit flag can do so by checking db_pager_quit. Note that the pager can also be effectively disabled by setting $lines to 0. Other fixes: - 'show idt' on i386 and pc98 now actually checks the quit flag and terminates early. - 'show intr' now actually checks the quit flag and terminates early. Notes: svn path=/head/; revision=160312
* Implement printf 'X' conversion for both libstand and kernel.Jung-uk Kim2006-03-091-10/+13
| | | | Notes: svn path=/head/; revision=156518
* Always print a newline char at the end of the line.Scott Long2006-02-251-1/+2
| | | | Notes: svn path=/head/; revision=156001
* Acquire Giant in uprintf() and tprintf() rather than asserting it. InRobert Watson2005-09-261-6/+11
| | | | | | | | | | | | | | the vast majority of cases, these functions are called without mutexes held, meaning that in all but two cases, there will be no ordering issues with doing this, and it will eliminate the need for changes in the caller. In two cases, mutexes are held, so Giant must be acquired before those mutexes such that uprintf() and tprintf() recurse Giant rather than generating a lock order reversal. Suggested by: bde Notes: svn path=/head/; revision=150560
* Correct an incorrect comment from the dawn of time: neither tprintf()Robert Watson2005-09-201-10/+2
| | | | | | | | | | | | | nor uprintf() is believed to perform tsleep() or msleep() as written, as ttycheckoutq() is called with '0' as its sleep argument. Remove recently added WITNESS warnings for sleep as the comment was incorrect. This should silence a warning from the nfs_timer() code. Discussed with: bde Notes: svn path=/head/; revision=150370
* Add GIANT_REQUIRED and WITNESS sleep warnings to uprintf() and tprintf(),Robert Watson2005-09-191-0/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | as they both interact with the tty code (!MPSAFE) and may sleep if the tty buffer is full (per comment). Modify all consumers of uprintf() and tprintf() to hold Giant around calls into these functions. In most cases, this means adding an acquisition of Giant immediately around the function. In some cases (nfs_timer()), it means acquiring Giant higher up in the callout. With these changes, UFS no longer panics on SMP when either blocks are exhausted or inodes are exhausted under load due to races in the tty code when running without Giant. NB: Some reduction in calls to uprintf() in the svr4 code is probably desirable. NB: In the case of nfs_timer(), calling uprintf() while holding a mutex, or even in a callout at all, is a bad idea, and will generate warnings and potential upset. This needs to be fixed, but was a problem before this change. NB: uprintf()/tprintf() sleeping is generally a bad ideas, as is having non-MPSAFE tty code. MFC after: 1 week Notes: svn path=/head/; revision=150335
* When padding with zero, do pad after prefixes rather than paddingXin LI2005-09-041-1/+5
| | | | | | | | | | | | | | | before prefixes. Use cases: printf("%05d", -42); --> "00-42" (should be "-0042") printf("%#05x", 12); --> "000xc" (should be "0x00c") Submitted by: Oliver Fromme PR: kern/85520 MFC After: 1 week Notes: svn path=/head/; revision=149784
* If we ignore an unknown % sequence, we must stop interpreting thePoul-Henning Kamp2005-09-031-2/+9
| | | | | | | | | | | remaining % arguments because the varargs are now out of sync and there is a risk that we might for instance dereference an integer in a %s argument. Sponsored by: Napatech.com Notes: svn path=/head/; revision=149756
* Make "show msgbuf" use the pager instead of blasting the whole thing out.Doug White2005-06-061-2/+5
| | | | | | | MFC after: 3 days Notes: svn path=/head/; revision=147064
* Constify hexdump() harder.Poul-Henning Kamp2005-04-061-2/+2
| | | | Notes: svn path=/head/; revision=144706
* In stange circumstances we may end up being the last reference to aPoul-Henning Kamp2005-03-171-4/+1
| | | | | | | | | | | | | | session in tprintf(). SESSRELE() needs to properly dispose of the sessions mutex. Add sessrele() which does the proper cleanup and have SESSRELE() call it. Use SESSRELE also in pgdelete(). Found by: Coverity (ID:526) Notes: svn path=/head/; revision=143740
* Update for the KDB framework:Marcel Moolenaar2004-07-101-3/+2
| | | | | | | o Check kdb_active instead of db_active and do so unconditionally. Notes: svn path=/head/; revision=131931
* Clean up and wash struct iovec and struct uio handling.Poul-Henning Kamp2004-07-101-12/+5
| | | | | | | | | | | | | | | Add copyiniov() which copies a struct iovec array in from userland into a malloc'ed struct iovec. Caller frees. Change uiofromiov() to malloc the uio (caller frees) and name it copyinuio() which is more appropriate. Add cloneuio() which returns a malloc'ed copy. Caller frees. Use them throughout. Notes: svn path=/head/; revision=131897
* Add a sysctl/tunable, "kern.always_console_output", that lets you setBrian Feldman2004-06-181-3/+12
| | | | | | | | | | output to permanently (not ephemerally) go to the console. It is also sent to any other console specified by TIOCCONS as normal. While I'm here, document the kern.log_console_output sysctl. Notes: svn path=/head/; revision=130700
* Remove advertising clause from University of California Regent's license,Warner Losh2004-04-051-4/+0
| | | | | | | | | per letter dated July 22, 1999. Approved by: core Notes: svn path=/head/; revision=127911
* Add support for 'h' and 'hh' modifiers for printf(9).Nate Lawson2004-02-191-2/+21
| | | | | | | | Submitted by: Bruno Ducrot <ducrot AT poupinou.org> Reviewed by: bde Notes: svn path=/head/; revision=125985
* Re-arrange and consolidate some random debugging stuffScott Long2003-12-071-0/+53
| | | | Notes: svn path=/head/; revision=123215
* Revert stuff which accidentally ended up in the previous commit.Poul-Henning Kamp2003-07-221-20/+0
| | | | Notes: svn path=/head/; revision=117879