FreeBSD kernel kern code
subr_prf.c File Reference
#include <sys/cdefs.h>
#include "opt_ddb.h"
#include "opt_printf.h"
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/lock.h>
#include <sys/kdb.h>
#include <sys/mutex.h>
#include <sys/sx.h>
#include <sys/kernel.h>
#include <sys/msgbuf.h>
#include <sys/malloc.h>
#include <sys/priv.h>
#include <sys/proc.h>
#include <sys/stddef.h>
#include <sys/sysctl.h>
#include <sys/tty.h>
#include <sys/syslog.h>
#include <sys/cons.h>
#include <sys/uio.h>
#include <sys/ctype.h>
#include <machine/stdarg.h>
Include dependency graph for subr_prf.c:

Go to the source code of this file.

Data Structures

struct  putchar_arg
 
struct  snprintf_arg
 

Macros

#define TOCONS   0x01
 
#define TOTTY   0x02
 
#define TOLOG   0x04
 
#define MAXNBUF   (sizeof(intmax_t) * NBBY + 1)
 
#define CONSCHUNK   128
 
#define PCHAR(c)   {int cc=(c); if (func) (*func)(cc,arg); else *d++ = cc; retval++; }
 

Functions

 __FBSDID ("$BSDSUniX$")
 
static void msglogchar (int c, int pri)
 
static void msglogstr (char *str, int pri, int filter_cr)
 
static void putchar (int ch, void *arg)
 
static char * ksprintn (char *nbuf, uintmax_t num, int base, int *len, int upper)
 
static void snprintf_func (int ch, void *arg)
 
 TUNABLE_INT ("kern.log_console_output",&log_console_output)
 
 SYSCTL_INT (_kern, OID_AUTO, log_console_output, CTLFLAG_RW,&log_console_output, 0,"Duplicate console output to the syslog.")
 
 TUNABLE_INT ("kern.log_console_add_linefeed",&log_console_add_linefeed)
 
 SYSCTL_INT (_kern, OID_AUTO, log_console_add_linefeed, CTLFLAG_RW,&log_console_add_linefeed, 0,"log_console() adds extra newlines.")
 
 TUNABLE_INT ("kern.always_console_output",&always_console_output)
 
 SYSCTL_INT (_kern, OID_AUTO, always_console_output, CTLFLAG_RW,&always_console_output, 0,"Always output to console despite TIOCCONS.")
 
void tablefull (const char *tab)
 
int uprintf (const char *fmt,...)
 
void tprintf (struct proc *p, int pri, const char *fmt,...)
 
int ttyprintf (struct tty *tp, const char *fmt,...)
 
static int _vprintf (int level, int flags, const char *fmt, va_list ap)
 
void log (int level, const char *fmt,...)
 
void log_console (struct uio *uio)
 
int printf (const char *fmt,...)
 
int vprintf (const char *fmt, va_list ap)
 
static void putbuf (int c, struct putchar_arg *ap)
 
int sprintf (char *buf, const char *cfmt,...)
 
int vsprintf (char *buf, const char *cfmt, va_list ap)
 
int snprintf (char *str, size_t size, const char *format,...)
 
int vsnprintf (char *str, size_t size, const char *format, va_list ap)
 
int vsnrprintf (char *str, size_t size, int radix, const char *format, va_list ap)
 
int kvprintf (char const *fmt, void(*func)(int, void *), void *arg, int radix, va_list ap)
 
void msgbufinit (void *ptr, int size)
 
 SYSCTL_INT (_security_bsd, OID_AUTO, unprivileged_read_msgbuf, CTLFLAG_RW,&unprivileged_read_msgbuf, 0,"Unprivileged processes may read the kernel message buffer")
 
static int sysctl_kern_msgbuf (SYSCTL_HANDLER_ARGS)
 
 SYSCTL_PROC (_kern, OID_AUTO, msgbuf, CTLTYPE_STRING|CTLFLAG_RD|CTLFLAG_MPSAFE, NULL, 0, sysctl_kern_msgbuf,"A","Contents of kernel message buffer")
 
static int sysctl_kern_msgbuf_clear (SYSCTL_HANDLER_ARGS)
 
 SYSCTL_PROC (_kern, OID_AUTO, msgbuf_clear, CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_SECURE|CTLFLAG_MPSAFE,&msgbuf_clearflag, 0, sysctl_kern_msgbuf_clear,"I","Clear kernel message buffer")
 
void hexdump (const void *ptr, int length, const char *hdr, int flags)
 

Variables

int log_open
 
static int msgbufmapped
 
int msgbuftrigger
 
static int log_console_output = 1
 
static int log_console_add_linefeed = 0
 
static int always_console_output = 0
 
static int unprivileged_read_msgbuf = 1
 
static int msgbuf_clearflag
 

Macro Definition Documentation

#define CONSCHUNK   128

Definition at line 300 of file subr_prf.c.

Referenced by log_console().

#define MAXNBUF   (sizeof(intmax_t) * NBBY + 1)

Definition at line 77 of file subr_prf.c.

Referenced by kvprintf(), and msglogchar().

#define PCHAR (   c)    {int cc=(c); if (func) (*func)(cc,arg); else *d++ = cc; retval++; }

Referenced by kvprintf().

#define TOCONS   0x01

Definition at line 72 of file subr_prf.c.

Referenced by _vprintf(), log(), putbuf(), putchar(), and vprintf().

#define TOLOG   0x04

Definition at line 74 of file subr_prf.c.

Referenced by _vprintf(), log(), putbuf(), putchar(), tprintf(), and vprintf().

#define TOTTY   0x02

Definition at line 73 of file subr_prf.c.

Referenced by putchar(), tprintf(), ttyprintf(), and uprintf().

Function Documentation

__FBSDID ( "$BSDSUniX$"  )
static int _vprintf ( int  level,
int  flags,
const char *  fmt,
va_list  ap 
)
static

Definition at line 245 of file subr_prf.c.

References cnputs(), putchar_arg::flags, kvprintf(), level, msglogstr(), putchar_arg::n_bufr, putchar_arg::p_bufr, putchar_arg::p_next, putchar_arg::pri, putchar(), putchar_arg::remain, TOCONS, TOLOG, and putchar_arg::tty.

Referenced by log(), and vprintf().

Here is the call graph for this function:

Here is the caller graph for this function:

void hexdump ( const void *  ptr,
int  length,
const char *  hdr,
int  flags 
)

Definition at line 1073 of file subr_prf.c.

References printf().

Here is the call graph for this function:

static char * ksprintn ( char *  nbuf,
uintmax_t  num,
int  base,
int *  len,
int  upper 
)
static

Definition at line 572 of file subr_prf.c.

References nbuf.

Referenced by kvprintf(), and msglogchar().

Here is the caller graph for this function:

int kvprintf ( char const *  fmt,
void(*)(int, void *)  func,
void *  arg,
int  radix,
va_list  ap 
)

Definition at line 614 of file subr_prf.c.

References ksprintn(), MAXNBUF, nbuf, PCHAR, qflag, and stop.

Referenced by _vprintf(), sbuf_vprintf(), sprintf(), tprintf(), ttyprintf(), uprintf(), vsnprintf(), vsnrprintf(), and vsprintf().

Here is the call graph for this function:

Here is the caller graph for this function:

void log ( int  level,
const char *  fmt,
  ... 
)
void log_console ( struct uio *  uio)

Definition at line 303 of file subr_prf.c.

References cloneuio(), CONSCHUNK, free(), log_console_add_linefeed, log_console_output, malloc(), msgbuftrigger, msglogstr(), putchar_arg::pri, and uiomove().

Referenced by ttyconsdev_write().

Here is the call graph for this function:

Here is the caller graph for this function:

void msgbufinit ( void *  ptr,
int  size 
)

Definition at line 973 of file subr_prf.c.

References msgbuf_copy(), msgbuf_reinit(), and msgbufmapped.

Here is the call graph for this function:

static void msglogchar ( int  c,
int  pri 
)
static

Definition at line 932 of file subr_prf.c.

References ksprintn(), MAXNBUF, msgbuf_addchar(), msgbufmapped, and nbuf.

Referenced by putbuf().

Here is the call graph for this function:

Here is the caller graph for this function:

static void msglogstr ( char *  str,
int  pri,
int  filter_cr 
)
static

Definition at line 964 of file subr_prf.c.

References msgbuf_addstr(), and msgbufmapped.

Referenced by _vprintf(), log_console(), and putbuf().

Here is the call graph for this function:

Here is the caller graph for this function:

int printf ( const char *  fmt,
  ... 
)

Definition at line 367 of file subr_prf.c.

References vprintf().

Referenced by _isitmyx(), _mtx_lock_spin_failed(), acl_posix1e_mode_to_entry(), acl_posix1e_mode_to_perm(), adopt(), aio_daemon(), blist_create(), blst_meta_free(), brelse(), bus_print_child_footer(), bus_print_child_header(), calcru1(), cf_get_method(), chgproccnt(), chgptscnt(), chgsbsize(), clock_ct_to_ts(), clock_ts_to_ct(), clone_create(), cluster_rbuild(), cnadd(), config_intrhook_establish(), cpu_tick_calibrate(), cpufreq_curr_sysctl(), cpufreq_levels_sysctl(), destroy_devl(), devclass_alloc_unit(), device_attach(), device_print_prettyname(), device_probe(), device_probe_child(), device_set_devclass(), devstat_add_entry(), disk_err(), domain_add(), dump_write(), elf_obj_lookup(), encode_long(), encode_timeval(), et_register(), exec_gzip_imgact(), exit1(), fail_point_eval_nontrivial(), falloc_noinstall(), firmware_get(), firmware_modevent(), firmware_mountroot(), firmware_register(), fork1(), fork_exit(), getnewbuf_scan(), getnewvnode(), graph_add_edge(), graph_remove_edge(), gzclose(), hexdump(), hhook_vnet_uninit(), init_dynamic_kenv(), init_hwpmc(), inittimecounter(), inittodr(), insert_brand_entry(), issignal(), ithread_execute_handlers(), kdb_backtrace(), kdb_backtrace_thread(), kdb_enter(), kdb_init(), kdb_panic(), kdb_reboot(), kdb_reenter(), kdb_trap(), kern_kldunload(), kern_ptrace(), kern_reboot(), kern_vfs_bio_buffer_alloc(), khelp_modevent(), khelp_new_hhook_registered(), knlist_destroy(), kproc_shutdown(), kqueue_add_filteropts(), kthread_shutdown(), ktr_tracepoint(), lf_activate_lock(), lf_advlockasync(), lf_alloc_lock(), lf_findoverlap(), lf_free_lock(), link_elf_ctf_get(), link_elf_error(), link_elf_link_preload(), link_elf_lookup_symbol(), link_elf_preload_parse_symbols(), linker_addmodules(), linker_file_register_modules(), linker_hints_lookup(), linker_load_dependencies(), linker_load_file(), linker_preload(), loadimage(), lockmgr_printinfo(), logopen(), logtimeout(), lookup(), m_print(), m_pulldown(), make_device(), malloc(), malloc_uninit(), mbp_alloc_page(), mbp_destroy(), mbp_get(), mbp_get_keep(), mi_startup(), module_register(), module_register_init(), msgbuf_reinit(), mtx_pool_create(), panic(), parse_dir_ask(), parse_dir_ask_printenv(), parse_dir_md(), parse_dir_onfail(), parse_directive(), parse_mount(), physio(), pipespace_new(), pmc_soft_ev_register(), power_profile_set_state(), prep_cdevsw(), print_caddr_t(), print_ct(), print_uptime(), print_version(), printf_uuid(), propagate_priority(), register_posix_clock(), relocate_file(), relookup(), res_find(), resettodr(), resource_list_print_type(), root_print_child(), runq_print(), sched_sync(), sdt_probe_stub(), setrunnable(), settime(), shminit(), shutdown_halt(), shutdown_panic(), shutdown_reset(), softclock_call_cc(), stack_print(), stack_print_ddb(), stack_print_short(), start_init(), sys_ioctl(), sysctl_add_oid(), sysctl_register_oid(), sysctl_remove_oid_locked(), sysctl_unregister_oid(), TAILQ_HEAD(), taskqueue_start_threads(), tc_init(), tdq_print(), tdq_setup(), ttcompatgetflags(), tty_ioctl_compat(), tvtohz(), uifree(), userret(), vaccess_acl_posix1e(), vfs_filteropt(), vfs_mountroot_devfs(), vfs_mountroot_parse(), vfs_mountroot_shuffle(), vfs_mountroot_wait(), vfs_register(), vfs_sysctl(), vfs_unmountall(), vm_hold_free_pages(), vn_printf(), vnlru_proc(), vntblinit(), vop_nostrategy(), vop_strategy_pre(), witness_checkorder(), witness_get(), witness_lock_list_get(), witness_thread_exit(), witness_unlock(), and witness_warn().

Here is the call graph for this function:

static void putbuf ( int  c,
struct putchar_arg ap 
)
static

Definition at line 393 of file subr_prf.c.

References always_console_output, cnputc(), cnputs(), putchar_arg::flags, msgbuf_addstr(), msglogchar(), msglogstr(), putchar_arg::n_bufr, putchar_arg::p_bufr, putchar_arg::p_next, panicstr, putchar_arg::pri, putchar_arg::remain, TOCONS, and TOLOG.

Referenced by putchar().

Here is the call graph for this function:

Here is the caller graph for this function:

static void putchar ( int  ch,
void *  arg 
)
static

Definition at line 450 of file subr_prf.c.

References cnputc(), putchar_arg::flags, kdb_active, panicstr, putbuf(), TOCONS, TOLOG, TOTTY, putchar_arg::tty, and tty_putchar().

Referenced by _vprintf(), tprintf(), ttyprintf(), and uprintf().

Here is the call graph for this function:

Here is the caller graph for this function:

static void snprintf_func ( int  ch,
void *  arg 
)
static

Definition at line 555 of file subr_prf.c.

References snprintf_arg::remain, and snprintf_arg::str.

Referenced by vsnprintf(), and vsnrprintf().

Here is the caller graph for this function:

int sprintf ( char *  buf,
const char *  cfmt,
  ... 
)

Definition at line 480 of file subr_prf.c.

References kvprintf().

Referenced by linker_find_file_by_name(), make_dev_physpath_alias(), msgbuf_addstr(), setenv(), setenv_static(), sysctl_kern_timecounter_choice(), and termcn_cnregister().

Here is the call graph for this function:

Here is the caller graph for this function:

SYSCTL_INT ( _kern  ,
OID_AUTO  ,
log_console_output  ,
CTLFLAG_RW  ,
log_console_output,
,
"Duplicate console output to the syslog."   
)
SYSCTL_INT ( _kern  ,
OID_AUTO  ,
log_console_add_linefeed  ,
CTLFLAG_RW  ,
log_console_add_linefeed,
,
"log_console() adds extra newlines."   
)
SYSCTL_INT ( _kern  ,
OID_AUTO  ,
always_console_output  ,
CTLFLAG_RW  ,
always_console_output,
,
"Always output to console despite TIOCCONS."   
)
SYSCTL_INT ( _security_bsd  ,
OID_AUTO  ,
unprivileged_read_msgbuf  ,
CTLFLAG_RW  ,
unprivileged_read_msgbuf,
,
"Unprivileged processes may read the kernel message buffer"   
)
static int sysctl_kern_msgbuf ( SYSCTL_HANDLER_ARGS  )
static

Definition at line 995 of file subr_prf.c.

References buf, msgbuf_lock, msgbuf_peekbytes(), priv_check(), and sysctl_handle_opaque().

Here is the call graph for this function:

static int sysctl_kern_msgbuf_clear ( SYSCTL_HANDLER_ARGS  )
static

Definition at line 1031 of file subr_prf.c.

References msgbuf_clear(), msgbuf_lock, and sysctl_handle_int().

Here is the call graph for this function:

SYSCTL_PROC ( _kern  ,
OID_AUTO  ,
msgbuf  ,
CTLTYPE_STRING|CTLFLAG_RD|  CTLFLAG_MPSAFE,
NULL  ,
,
sysctl_kern_msgbuf  ,
"A"  ,
"Contents of kernel message buffer"   
)
SYSCTL_PROC ( _kern  ,
OID_AUTO  ,
msgbuf_clear  ,
CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_SECURE|  CTLFLAG_MPSAFE,
msgbuf_clearflag,
,
sysctl_kern_msgbuf_clear  ,
"I"  ,
"Clear kernel message buffer"   
)
void tablefull ( const char *  tab)

Definition at line 127 of file subr_prf.c.

References log().

Here is the call graph for this function:

void tprintf ( struct proc *  p,
int  pri,
const char *  fmt,
  ... 
)
int ttyprintf ( struct tty *  tp,
const char *  fmt,
  ... 
)

Definition at line 229 of file subr_prf.c.

References putchar_arg::flags, kvprintf(), putchar_arg::p_bufr, putchar(), TOTTY, and putchar_arg::tty.

Referenced by tty_info().

Here is the call graph for this function:

Here is the caller graph for this function:

TUNABLE_INT ( "kern.log_console_output"  ,
log_console_output 
)
TUNABLE_INT ( "kern.log_console_add_linefeed"  ,
log_console_add_linefeed 
)
TUNABLE_INT ( "kern.always_console_output"  ,
always_console_output 
)
int uprintf ( const char *  fmt,
  ... 
)

Definition at line 137 of file subr_prf.c.

References putchar_arg::flags, kvprintf(), putchar_arg::p_bufr, proctree_lock, putchar(), TOTTY, and putchar_arg::tty.

Referenced by do_execve(), and load_section().

Here is the call graph for this function:

Here is the caller graph for this function:

int vprintf ( const char *  fmt,
va_list  ap 
)

Definition at line 380 of file subr_prf.c.

References _vprintf(), msgbuftrigger, panicstr, TOCONS, and TOLOG.

Referenced by device_printf(), panic(), printf(), vn_printf(), and witness_warn().

Here is the call graph for this function:

Here is the caller graph for this function:

int vsnprintf ( char *  str,
size_t  size,
const char *  format,
va_list  ap 
)

Definition at line 524 of file subr_prf.c.

References kvprintf(), snprintf_arg::remain, snprintf_func(), and snprintf_arg::str.

Referenced by bus_describe_intr(), fail_point_init(), intr_event_create(), kproc_create(), kproc_kthread_add(), kthread_add(), panic(), snprintf(), taskqueue_start_threads(), vfs_mount_error(), and vfs_opterror().

Here is the call graph for this function:

Here is the caller graph for this function:

int vsnrprintf ( char *  str,
size_t  size,
int  radix,
const char *  format,
va_list  ap 
)

Definition at line 541 of file subr_prf.c.

References kvprintf(), snprintf_arg::remain, snprintf_func(), and snprintf_arg::str.

Referenced by prep_devname(), terminal_maketty(), and tty_makedev().

Here is the call graph for this function:

Here is the caller graph for this function:

int vsprintf ( char *  buf,
const char *  cfmt,
va_list  ap 
)

Definition at line 496 of file subr_prf.c.

References kvprintf().

Here is the call graph for this function:

Variable Documentation

int always_console_output = 0
static

Definition at line 118 of file subr_prf.c.

Referenced by putbuf().

int log_console_add_linefeed = 0
static

Definition at line 113 of file subr_prf.c.

Referenced by log_console().

int log_console_output = 1
static

Definition at line 105 of file subr_prf.c.

Referenced by log_console().

int log_open

Definition at line 94 of file subr_log.c.

Referenced by log(), logclose(), logopen(), and logtimeout().

int msgbuf_clearflag
static

Definition at line 1028 of file subr_prf.c.

int msgbufmapped
static

Definition at line 102 of file subr_prf.c.

Referenced by msgbufinit(), msglogchar(), and msglogstr().

int msgbuftrigger

Definition at line 103 of file subr_prf.c.

Referenced by log(), log_console(), logtimeout(), tprintf(), and vprintf().

int unprivileged_read_msgbuf = 1
static

Definition at line 988 of file subr_prf.c.