summaryrefslogtreecommitdiffstats
path: root/sys/kern/subr_log.c (follow)
Commit message (Collapse)AuthorAgeFilesLines
* Unlock sendsyslog(2). Console output still requires kernel lock to bemvs2021-03-181-39/+56
| | | | | | | | held but this path is only followed while `syslogf' socket is not set. New `syslogf_rwlock' used to protect `syslogf' access. ok bluhm@
* Early daemons like dhcpleased(8), slaacd(8), unwind(8), resolvd(8)bluhm2021-03-091-28/+154
| | | | | | | | | | | | | are started before syslogd(8). This resulted in ugly sendsyslog(2) dropped logs and the real message was lost. Create a temporary stash for log messages within the kernel. It has a limited size of 100 messages, and each message is truncated to 8192 bytes. When the stash is exhausted, the well-known dropped message is generated with a counter. After syslogd(8) has setup everything, it sends a debug line through libc to flush the kernel stash. Then syslogd receives all messages from the kernel before the usual logs. OK deraadt@ visa@
* Simplify sleep_setup API to two operations in preparation for splittingmpi2021-02-081-5/+3
| | | | | | | | | | | | the SCHED_LOCK(). Putting a thread on a sleep queue is reduce to the following: sleep_setup(); /* check condition or release lock */ sleep_finish(); Previous version ok cheloha@, jmatthew@, ok claudio@
* Fix boot-time crash on sparc64visa2021-01-081-4/+15
| | | | | | | | | | | | On sparc64, initmsgbuf() is invoked before curcpu() is usable on the boot processor. Consequently, it is unsafe to use mutexes during the message buffer initialization. Avoid such use by skipping log_mtx when appending a newline from initmsgbuf(). Use mbp instead of msgbufp as the buffer argument to the putchar routine for consistency. Bug reported and fix suggested by miod@
* Refactor klist insertion and removalvisa2020-12-251-3/+3
| | | | | | | | | | | | Rename klist_{insert,remove}() to klist_{insert,remove}_locked(). These functions assume that the caller has locked the klist. The current state of locking remains intact because the kernel lock is still used with all klists. Add new functions klist_insert() and klist_remove() that lock the klist internally. This allows some code simplification. OK mpi@
* Serialize msgbuf access with a mutex.visa2020-10-251-28/+62
| | | | | | | | | | | | | | | | | | This introduces a system-wide mutex that serializes msgbuf operations. The mutex controls access to all modifiable fields of struct msgbuf. It also covers logsoftc.sc_state. To avoid adding extra lock order constraints that would affect use of printf(9), the code does not take new locks when the log mutex is held. The code assumes that there is at most one thread using logread(). This keeps the logic simple. If there was more than one reader, logread() might return the same data to different readers. Also, log wakeup might not be reliable with multiple threads. Tested in snaps for two weeks. OK mpi@
* Fix kn_data returned by filt_logread().visa2020-08-181-16/+21
| | | | | | | | | Take into account the circular nature of the message buffer when computing the number of available bytes. Move the computation into a separate function and use it with the kevent(2) and ioctl(2) interfaces. OK mpi@
* Remove an unnecessary field from struct msgbuf.visa2020-08-181-2/+1
| | | | OK mvs@
* Abstract the head of knote lists. This allows extending the lists,visa2020-04-071-3/+3
| | | | | | for example, with locking assertions. OK mpi@, anton@
* Replace field f_isfd with field f_flags in struct filterops to allowvisa2020-02-201-2/+2
| | | | | | adding more filter properties without cluttering the struct. OK mpi@, anton@
* Convert infinite sleeps to tsleep_nsec(9).mpi2020-01-111-3/+2
| | | | ok bluhm@
* Unify handling of ioctls FIOSETOWN/SIOCSPGRP/TIOCSPGRP andvisa2020-01-081-5/+5
| | | | | | | | | | | | FIOGETOWN/SIOCGPGRP/TIOCGPGRP. Do this by determining the meaning of the ID parameter inside the sigio code. Also add cases for FIOSETOWN and FIOGETOWN where there have been TIOCSPGRP and TIOCGPGRP before. These changes allow removing the ID translation from sys_fcntl() and sys_ioctl(). Idea from NetBSD OK mpi@, claudio@
* Change /dev/log to use pgsigio(9) and sigio_init(9) like it was done forclaudio2020-01-021-11/+9
| | | | | bpf(4) and tun(4) instead of using hand rolled code using csignal(). OK visa@
* Use C99 designated initializers with struct filterops. In addition,visa2019-12-311-3/+7
| | | | | | make the structs const so that the data are put in .rodata. OK mpi@, deraadt@, anton@, bluhm@
* The console buffer is allocated during startup. initconsbuf() isbluhm2019-12-241-9/+4
| | | | | | | only called from main(). There allocation must not fail, so better use M_WAITOK and remove error handling. As it is not a temporary buffer, M_TTYS is more appropriate. OK deraadt@ mpi@
* Make log tick interval independent of hz and reduce the frequencyvisa2019-10-241-4/+4
| | | | | | so that the timeout would not be scheduled on every tick. Discussed with and OK mpi@
* Work around locking issues in logwakeup(). Instead of actually waking upvisa2019-06-201-1/+41
| | | | | | | | | | | waiters, just set a flag in logwakeup(). The flag is later noted through periodic polling. This lets the wakeup code run with sufficient locking. logwakeup() is a very tricky place to take locks because the function can be called in many different contexts. By not requiring locks in the routine helps to keep printf(9) as usable as possible. OK mpi@
* dosendsyslog() must only pass ktrgenio(9) userspace buffers that it canguenther2019-06-171-15/+8
| | | | | | | | use copyin() on. While here: just put the struct iovec for ktrace on the stack instead of mallocing and freeing it. problem debugged by patrick@ ok deraadt@ mpi@
* Use FNONBLOCK instead of SS_NBIO to check/indicate that the I/O modempi2018-07-301-2/+4
| | | | | | | | | | | | | for sockets is non-blocking. This allows us to G/C SS_NBIO. Having to keep the two flags in sync in a mp-safe way is complicated. This change introduce a behavior change in sosplice(), it can now always block. However this should not matter much due to the socket lock being taken beforhand. ok bluhm@, benno@, visa@
* Remove almost unused `flags' argument of suser().mpi2018-02-191-2/+2
| | | | | | | The account flag `ASU' will no longer be set but that makes suser() mpsafe since it no longer mess with a per-process field. No objection from millert@, ok tedu@, bluhm@
* Print the pid of the most recent program that failed to send a logmpi2017-10-171-6/+10
| | | | | | | | | via sendsyslog(2) along with the corresponding errno. Help when troubleshooting which program is triggering an error, like an overflow. ok bluhm@
* sendsyslog should take a const char * everywhere.espie2017-09-251-2/+2
| | | | okay bluhm@, deraadt@
* Kernel sendsyslog(2), libc syslog(3), and syslogd(8) restrict andbluhm2017-08-081-3/+3
| | | | | | truncate the length of a syslog message to 8192 bytes. Use one global define LOG_MAXLINE for all of them. OK deraadt@ millert@
* Both syslog(3) and syslogd(8) truncate the message at 8192 bytes.bluhm2017-07-181-1/+4
| | | | | Do the same in sendsyslog(2) and document the behavior. reported by Ilja Van Sprundel; OK millert@ deraadt@
* Reorder FREF() and FRELE() in a way that the the global variablebluhm2017-03-271-7/+9
| | | | | | | syslogf always points to a file object with increased reference count. This makes the implementation independent from the fact whether changing the reference counter may sleep. pointed out by Mateusz Guzik; OK deraadt@
* There was a race in dosendsyslog() which resulted in a crash.bluhm2017-03-241-7/+10
| | | | | | | | | | sosend(syslogf->f_data, ...) could be called with a NULL pointer. syslogf was not NULL, f_data was NULL and f_count was 1. The file structure is ref counted, but the global variable syslogf is not protected. So it may change during sleep and dosendsyslog() possibly used a different socket at each access. Solution is to access syslogf only once, use a local copy, and do the ref counting there. OK millert@ deraadt@
* As klog dropped message has no ifdef small kernel, sendsyslogbluhm2016-06-231-9/+6
| | | | | | should not have it either. While there bring some variables in sync between both functions. OK deraadt@
* It is annoying that the dmesg buffer can overflow and loose messagesbluhm2016-06-231-1/+15
| | | | | | | undetected during debugging. To make clear what happens, count the dropped bytes and write message buffer full to syslogd. This also helps to have a reliable log system. OK deraadt@ millert@ tedu@
* As logging to dmesg with msgbuf_putchar() can happen in any interruptbluhm2016-06-081-15/+21
| | | | | | | handler, every access to msg buf counters should be protected by splhigh(). This is already done in some places, make it consistenly everywhere. OK mpi@ deraadt@
* sys_osendsyslog can go away; we have transitioned to the new version withderaadt2016-05-311-16/+1
| | | | | a flags argument ok guenther sthen
* All msg buf counters are long, so lmin(9) should be used for them.bluhm2016-05-191-2/+2
| | | | OK deraadt@ natano@
* Kill trailing whitespaces.bluhm2016-05-181-4/+4
|
* Use constty and cn_devvp for checking wether to use cnwrite(). Thatbluhm2016-05-181-23/+21
| | | | | | makes console redirection with senssyslog(2) and LOG_CONS work again. Also merge the two if else if else blocks into one. OK deraadt@
* Allow sendsyslog(2) with LOG_CONS even when /dev/console has notbluhm2016-05-171-5/+29
| | | | | | | been opened during init(8). Only log with cnwrite() if cn_devvp exists, otherwise use cnputc() as fallback. While there move extern declarations to dev/cons.h. input and OK deraadt@
* Backout the previous fix for the sendsyslog(2) with LOG_CONS solution.bluhm2016-05-171-2/+2
| | | | | | | Permanently holding /dev/console open in the kernel works only until init(8) calls revoke(2). After that the console device vnode cannot be used anymore. It still resulted in a hanging init(8) if it tried to syslog(3) something. With the backout also dmesg -s works again.
* If sendsyslog(2) is called with LOG_CONS before syslogd(8) has beenbluhm2016-05-101-2/+2
| | | | | | | | started and before init(8) has opened the console, the kernel could crash as the console device has not been initialized. Open /dev/console in the kernel before starting init(8) and keep it open. This way sendsyslog(2) can be called early in the system. OK beck@ deraadt@
* Rename the system call sendsyslog2 to sendsyslog. Keep the old onebluhm2016-03-211-7/+7
| | | | | | as osendsyslog for a while. The three argument variant is the only one that will stay. input kettenis@; OK deraadt@
* Convert to uiomove(); from Martin Natano, thanks!stefan2016-01-131-6/+7
| | | | ok deraadt@
* In sendsyslogd(2) strip off syslog priority when logging to console.bluhm2016-01-071-4/+32
| | | | OK deraadt@ millert@
* The pointer buf is a user space string which was directly passedbluhm2016-01-011-31/+32
| | | | | | | | | | to tputchar() and could crash the kernel. Better use cnwrite() in sendsyslog2() for writing to console. It takes a struct uio which does the copyin() automatically. In addition cnwrite() outputs to the real console or to a redirected one, whichever is appropriate. One drawback is that the syslog priority cannot be stripped off easily. OK deraadt@
* remove stale lint annotationstedu2015-12-051-6/+1
|
* Add sendsyslog2(), which accepts the syslog/openlog "logopt" flagderaadt2015-11-241-7/+40
| | | | | | | LOG_CONS. If syslogd is not accepting messages, direct them to the console. This allows us to remove the direct /dev/console opening code from the bowels of libc. Of course, that forgotten code was exposed by pledge. ok kettenis millert beck
* The must be no space after the syslog priority in the sendsyslog(2)bluhm2015-09-111-2/+2
| | | | | dropped message error log. OK benno@
* To make logging to local syslog reliable, log a message about failedbluhm2015-09-021-4/+40
| | | | | | log atempts. sendsyslog(2) is a good place to detect and report the problem. OK deraadt@
* Pass a thread pointer instead of its file descriptor table to getsock(9).mpi2015-05-061-2/+2
| | | | | | Diff from Vitaliy Makkoveev. Manpage tweak and ok millert@
* Remove some includes include-what-you-use claims don'tjsg2015-03-141-2/+1
| | | | | | | have any direct symbols used. Tested for indirect use by compiling amd64/i386/sparc64 kernels. ok tedu@ deraadt@
* First step towards making uiomove() take a size_t size argument:miod2015-02-101-2/+2
| | | | | | | - rename uiomove() to uiomovei() and update all its users. - introduce uiomove(), which is similar to uiomovei() but with a size_t. - rewrite uiomovei() as an uiomove() wrapper. ok kettenis@
* Many architectures call initmsgbuf() really really early, before uvm iskettenis2015-01-131-1/+7
| | | | | | | | | initialized. Calling malloc(9) at that point is not a good idea. So initialize consbuf later. Fixes dmesg -s on sparc64 (and probably a few other architectures). ok miod@, deraadt@
* Add dmesg -s support, to view the output of rc(8) system startup messages.mpf2015-01-131-7/+13
| | | | | Help and feedback by Theo and Miod. OK deraadt@, manpage-ok jmc@
* yet more mallocarray() changes.doug2014-12-131-2/+3
| | | | ok tedu@ deraadt@