Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 11 Mar 2022 10:49:42 +0100
From:      Alexander Leidinger <Alexander@leidinger.net>
To:        current@freebsd.org
Subject:   What are the in-kernel functions to format time?
Message-ID:  <20220311104942.Horde.BX4nDaPVTH6Lz85SCVNcopM@webmail.leidinger.net>

index | next in thread | raw e-mail

[-- Attachment #1 --]
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 <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) == 0)
                         sig |= 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.

-- 
http://www.Leidinger.net Alexander@Leidinger.net: PGP 0x8F31830F9F2772BF
http://www.FreeBSD.org    netchild@FreeBSD.org  : PGP 0x8F31830F9F2772BF

[-- Attachment #2 --]
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2

iQIzBAABCAAdFiEER9UlYXp1PSd08nWXEg2wmwP42IYFAmIrGzUACgkQEg2wmwP4
2IZJnBAAni6vGDfXQIPS9JR9+vD7Ib1tf03qCij/AxLtvmxPR0DmxeDGvXayJifn
0L264r6CJZU/n/UyDca4bf6JDBs08gcN8aQgQl0dH9jaKpNCGqqUrPsilfIssg9f
OuhRYiExwOfJuU7+omgt/a2tJjQG2r3iC2UyQFwuCMBxZF79tKosLsxfWN7wtW+a
OrqhSf/IecXYtR1paLJvEFV7++zr4hdvxcbYy9hHHZA4mvB9i5PfhocU2TDdwhX9
XOsBrtRz0sLxomtDG2nJaHvYt8nGzu7cGUbigKkUcV9Fcs8CW2/ZYzI9FvkVemm4
Cj6V9c6/sTx820iPtGZ/fmilR07UPpcXJqRI2GazRAE4OyJMtohBb2nI0EBloH/h
xWQD5Ph3Ps7O48gLxX9E1IvzTjy3DZSdcSyOBy5pd0Eg9wUIi8axHog0MLHAI9zj
vjjfXNaMqAU9D0GMQh2+IM3hygbHy3NgUJf6mwFjcwuPZM+mT3H/Ua/brCDCK60u
2Uzry5ry5ugIUCUqts1X/5uO5LIXWTUplSW9IP4uH/x5sAtorac7wu8PprsNX1DO
IwSilpml2bQ8JxBjSU9LNqsrLWVNS4hOe0Dj52O2u3gYwdASszGH+5EUPipbsUCr
vIg42XjIfsMToSAFM9C4ploxZMilV2WiDUoDphhmnLAKW/khUmI=
=P6mT
-----END PGP SIGNATURE-----
help

Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20220311104942.Horde.BX4nDaPVTH6Lz85SCVNcopM>