aboutsummaryrefslogtreecommitdiff
path: root/sys/kern/subr_prf.c
diff options
context:
space:
mode:
authorKonstantin Belousov <kib@FreeBSD.org>2016-07-21 16:34:56 +0000
committerKonstantin Belousov <kib@FreeBSD.org>2016-07-21 16:34:56 +0000
commit9837947b07a67c89a1ae88ca883df5e0b142b618 (patch)
tree99028bdec5601f45dbfbd4586b77a286cff58778 /sys/kern/subr_prf.c
parent303c356245bb3e7efab29e776b941d733a8f77bc (diff)
downloadsrc-9837947b07a67c89a1ae88ca883df5e0b142b618.tar.gz
src-9837947b07a67c89a1ae88ca883df5e0b142b618.zip
Provide counter_warning(9) KPI which allows to issue limited number of
warnings for some kernel events, mostly intended for the use of obsoleted or otherwise undersired interfaces. This is an abstracted and race-expelled code from compat pty driver. Requested and reviewed by: jhb Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D7270
Notes
Notes: svn path=/head/; revision=303151
Diffstat (limited to 'sys/kern/subr_prf.c')
-rw-r--r--sys/kern/subr_prf.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/sys/kern/subr_prf.c b/sys/kern/subr_prf.c
index 5bcf39b9400b..5f9796e7d876 100644
--- a/sys/kern/subr_prf.c
+++ b/sys/kern/subr_prf.c
@@ -1196,3 +1196,22 @@ sbuf_hexdump(struct sbuf *sb, const void *ptr, int length, const char *hdr,
}
}
+void
+counted_warning(unsigned *counter, const char *msg)
+{
+ struct thread *td;
+ unsigned c;
+
+ for (;;) {
+ c = *counter;
+ if (c == 0)
+ break;
+ if (atomic_cmpset_int(counter, c, c - 1)) {
+ td = curthread;
+ log(LOG_INFO, "pid %d (%s) %s%s\n",
+ td->td_proc->p_pid, td->td_name, msg,
+ c > 1 ? "" : " - not logging anymore");
+ break;
+ }
+ }
+}