Date: Fri, 11 Mar 2022 10:51:49 +0100 From: Alexander Leidinger <Alexander@leidinger.net> To: current@freebsd.org Subject: What are the in-kernel functions to print human readable timestamps (bintime)? Message-ID: <20220311105149.Horde.uO0yyQjwC3xmwZvuZWV1ADl@webmail.leidinger.net>
next in thread | raw e-mail | index | archive | help
This message is in MIME format and has been PGP signed. --=_YHArA4YOh1lxGoFmGL8x-nN Content-Type: text/plain; charset=utf-8; format=flowed; DelSp=Yes Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Hi, I'm looking for a function to convert bintime to a human readable=20=20 format=20in the kernel... and what is the usual format we use? The use case for this is: if something throws a log from the kernel=20=20 about=20a signal, I want to know when it happened, or in terms of code=20= =20 see=20below (tabs are most probably messed up). Do we have some kind of policy in terms of kernel messages and=20=20 timestamps?=20Like "do not commit logging with timestamps"? I have the=20= =20 code=20below because I needed it at least once and think something like=20= =20 this=20(in a human readably shape) would be beneficial to have in the=20=20 tree. Code: ---snip--- diff=20--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 <sys/sysent.h> #include <sys/syslog.h> #include <sys/sysproto.h> +#include <sys/time.h> #include <sys/timers.h> #include <sys/unistd.h> #include <sys/wait.h> @@ -3440,14 +3441,18 @@ sigexit(struct thread *td, int sig) */ if (coredump(td) =3D=3D 0) sig |=3D WCOREFLAG; - if (kern_logsigexit) + if (kern_logsigexit) { + struct bintime now; + + getbintime(&now); 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. --=20 http://www.Leidinger.net=20Alexander@Leidinger.net: PGP 0x8F31830F9F2772BF http://www.FreeBSD.org netchild@FreeBSD.org : PGP 0x8F31830F9F2772BF --=_YHArA4YOh1lxGoFmGL8x-nN Content-Type: application/pgp-signature Content-Description: Digitale PGP-Signatur Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQIzBAABCAAdFiEER9UlYXp1PSd08nWXEg2wmwP42IYFAmIrG7QACgkQEg2wmwP4 2IZ/7A/+ODlQi5qYzhtss8qRThkoS851gcsLeMFGVmddBZ9SqGHzucmrQLC6T1o8 NmRefQeUUJrkTmm+Q8b2yk1KlBy2CQA2yBu2XWFgHVE/2mhytXJoMcR4QH/qEMSC Lu/wDthbF/WtKzYpjekrGRHtZfxfgfPTDH1WAEKP0oMhA3q8xRPy7UgT9qGEQV2I cykLXbHm+InqPpPwYlB6HqbZ+00KPugqUujK8K4qqSORg4pV/hkBo/Qse4s/dyLt LwrIv8Ve7s4ffZH86AeQFJcjjt3KsnEDd66/+LzYvof5SZ7x51hrkJ4gonwdAhTw xkzFJ8E0Gm98QGBecUFF0oy7Q9zLCAyn6nn0Bbr0+JONfNToADBN8WoVcVASLA+V qp6+qIgNdQOdxhKvkINl7NTt78R37CJBIM6HHDafibLZKvWqwwsPkS2KKqUX6d2H 3z/72OIn/nIzRF8hOgMpjEL1OKp8l6+W/hPv8bpGvGflmpw2BiU5VTnQ+JiJDupJ MS8QkL8hhdSpZWKuB6Y2nTfzRrf/gGG+CA3YLD9owDiqVbwDzChL7e28SF8sKc5O c7uWZqMta9zDHGwDAS8Gf4Js55ogOVGzUtphdH2uhcbocmVNks7ZmuUIEQPPseIj A9x6gdBTPW8G+FZyHmMMbxwLI6QG7BeRmsze/HNnze5Mk3V60IM= =CnUJ -----END PGP SIGNATURE----- --=_YHArA4YOh1lxGoFmGL8x-nN--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20220311105149.Horde.uO0yyQjwC3xmwZvuZWV1ADl>