Re: What are the in-kernel functions to format time?
On 3/11/22 12:20, Gary Jennejohn wrote: Do you mean the %zd? kvprintf() checks for a zflag and handles the argument as size_t or ssize_t, depending on whether the sign is positive or negative. Hi, Given that time is a 64-bit value, then probably "%llu", and (unsigned long long)bintime would do it, but then you need that cast. ./_types.h:typedef __int64_t __sbintime_t; I was tinking of a %XXX that divides the value somehow into something more readable, maybe suffixing "ns" or "ms" or "us" or something. --HPS
Re: What are the in-kernel functions to format time?
On Fri, 11 Mar 2022 11:01:03 +0100 Hans Petter Selasky wrote: > On 3/11/22 10:49, Alexander Leidinger wrote: > > Hi, > > > > I'm looking for a function to convert bintime to a human readable format > > > in the kernel... and what is the usual format we use? > > > > > > The use case for this is: if something throws a log from the kernel > about > > a signal, I want to know when it happened, or in terms of code see > below > > (tabs are most probably messed up). > > > > Do we have some kind of policy in terms of kernel messages and > > > timestamps? Like "do not commit logging with timestamps"? I have the > code > > below because I needed it at least once and think something like > this (in > > a human readably shape) would be beneficial to have in the tree. > > > > Hi, > > I think our kernel printer doesn't support this: > > sys/kern/subr_prf.c > Do you mean the %zd? kvprintf() checks for a zflag and handles the argument as size_t or ssize_t, depending on whether the sign is positive or negative. However, %n isn't supported. > If you need to extend the format, please check other OS'es too, like > OpenBSD, NetBSD and Linux, what they support, so there won't be any > obvious conflicts when moving code cross platforms! > -- Gary Jennejohn
Re: What are the in-kernel functions to format time?
On 3/11/22 10:49, Alexander Leidinger wrote: Hi, I'm looking for a function to convert bintime to a human readable format in the kernel... and what is the usual format we use? The use case for this is: if something throws a log from the kernel about a signal, I want to know when it happened, or in terms of code see below (tabs are most probably messed up). Do we have some kind of policy in terms of kernel messages and timestamps? Like "do not commit logging with timestamps"? I have the code below because I needed it at least once and think something like this (in a human readably shape) would be beneficial to have in the tree. Hi, I think our kernel printer doesn't support this: sys/kern/subr_prf.c If you need to extend the format, please check other OS'es too, like OpenBSD, NetBSD and Linux, what they support, so there won't be any obvious conflicts when moving code cross platforms! --HPS
What are the in-kernel functions to format time?
Hi, I'm looking for a function to convert bintime to a human readable format in the kernel... and what is the usual format we use? The use case for this is: if something throws a log from the kernel about a signal, I want to know when it happened, or in terms of code see below (tabs are most probably messed up). Do we have some kind of policy in terms of kernel messages and timestamps? Like "do not commit logging with timestamps"? I have the code below because I needed it at least once and think something like this (in a human readably shape) would be beneficial to have in the tree. Code: ---snip--- diff --git a/sys/kern/kern_sig.c b/sys/kern/kern_sig.c index 4a15bd45355..a83eebe0736 100644 --- a/sys/kern/kern_sig.c +++ b/sys/kern/kern_sig.c @@ -80,6 +80,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include @@ -3440,14 +3441,18 @@ sigexit(struct thread *td, int sig) */ if (coredump(td) == 0) sig |= WCOREFLAG; - if (kern_logsigexit) + if (kern_logsigexit) { + struct bintime now; + + getbintime(); log(LOG_INFO, - "pid %d (%s), jid %d, uid %d: exited on " - "signal %d%s\n", p->p_pid, p->p_comm, + "%zd: pid %d (%s), jid %d, uid %d: exited on " + "signal %d%s\n", now.sec, p->p_pid, p->p_comm, p->p_ucred->cr_prison->pr_id, td->td_ucred->cr_uid, sig &~ WCOREFLAG, sig & WCOREFLAG ? " (core dumped)" : ""); + } } else PROC_UNLOCK(p); exit1(td, 0, sig); ---snip--- Bye, Alexander. -- http://www.Leidinger.net alexan...@leidinger.net: PGP 0x8F31830F9F2772BF http://www.FreeBSD.orgnetch...@freebsd.org : PGP 0x8F31830F9F2772BF pgpiH30aWZMth.pgp Description: Digitale PGP-Signatur