From nobody Fri Mar 11 09:51:49 2022 X-Original-To: current@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id B51E51A0B614 for ; Fri, 11 Mar 2022 09:51:56 +0000 (UTC) (envelope-from Alexander@leidinger.net) Received: from mailgate.Leidinger.net (bastille.leidinger.net [89.238.82.207]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature ECDSA (P-256) client-digest SHA256) (Client CN "mailgate.leidinger.net", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4KFLn63k1Xz4bJb for ; Fri, 11 Mar 2022 09:51:54 +0000 (UTC) (envelope-from Alexander@leidinger.net) Received: from outgoing.leidinger.net (p5b165562.dip0.t-ipconnect.de [91.22.85.98]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-256) client-signature ECDSA (P-256)) (Client CN "outgoing.leidinger.net", Issuer "R3" (verified OK)) by mailgate.Leidinger.net (Postfix) with ESMTPSA id 388D22CDDF for ; Fri, 11 Mar 2022 10:51:52 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=leidinger.net; s=outgoing-alex; t=1646992312; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type; bh=jzsovUao9oRYI/6WrsW8+jaPw+pbqKPxCZ2NnS7PDbI=; b=Rd7syq4l9r3jcBzPPI/bfzJdtjrP59C9InfO98fhwAY4ZwX2P/umgf0Kr9lSAN65IWKA7a nOGehGejZ4keakzlBK+rTsHY6lYXjd4BhLTf6XML9Jzbf5UNDi/CA7tKsOvvx7n+i1o56r 4FArzFJaNrMPyNQXcpb1IU1qjSbceitpIDliKcuIXkpn8pcmMKMQyjIRwv6qLDlyhyZP4Y 4L0ogaYtHlQw8HYAgEGGjM4XJLzW0NKmj63NsO07v1GOAVHF79slTwEk6GD+GqKhcygW88 DejZB6wWLm7i2PZ1rthLeUlMlze9uIf8uET0VJji6Ht5m1hJV6KjDfO0meF7zA== Received: from webmail.leidinger.net (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-256) server-digest SHA256) (Client did not present a certificate) by outgoing.leidinger.net (Postfix) with ESMTPS id E0DB6A11B for ; Fri, 11 Mar 2022 10:51:49 +0100 (CET) Date: Fri, 11 Mar 2022 10:51:49 +0100 Message-ID: <20220311105149.Horde.uO0yyQjwC3xmwZvuZWV1ADl@webmail.leidinger.net> From: Alexander Leidinger To: current@freebsd.org Subject: What are the in-kernel functions to print human readable timestamps (bintime)? Accept-Language: de,en Content-Type: multipart/signed; boundary="=_YHArA4YOh1lxGoFmGL8x-nN"; protocol="application/pgp-signature"; micalg=pgp-sha256 List-Id: Discussions about the use of FreeBSD-current List-Archive: https://lists.freebsd.org/archives/freebsd-current List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-current@freebsd.org MIME-Version: 1.0 X-Rspamd-Queue-Id: 4KFLn63k1Xz4bJb X-Spamd-Bar: ----- Authentication-Results: mx1.freebsd.org; dkim=pass header.d=leidinger.net header.s=outgoing-alex header.b=Rd7syq4l; dmarc=pass (policy=quarantine) header.from=leidinger.net; spf=pass (mx1.freebsd.org: domain of Alexander@leidinger.net designates 89.238.82.207 as permitted sender) smtp.mailfrom=Alexander@leidinger.net X-Spamd-Result: default: False [-5.10 / 15.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; R_DKIM_ALLOW(-0.20)[leidinger.net:s=outgoing-alex]; NEURAL_HAM_MEDIUM(-1.00)[-0.998]; FROM_HAS_DN(0.00)[]; R_SPF_ALLOW(-0.20)[+mx:c]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.20)[multipart/signed,text/plain]; PREVIOUSLY_DELIVERED(0.00)[current@freebsd.org]; TO_DN_NONE(0.00)[]; RCPT_COUNT_ONE(0.00)[1]; NEURAL_HAM_LONG(-1.00)[-1.000]; RCVD_COUNT_THREE(0.00)[3]; MID_RHS_MATCH_FROMTLD(0.00)[]; DKIM_TRACE(0.00)[leidinger.net:+]; DMARC_POLICY_ALLOW(-0.50)[leidinger.net,quarantine]; NEURAL_HAM_SHORT(-1.00)[-0.999]; MLMMJ_DEST(0.00)[current]; SIGNED_PGP(-2.00)[]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+,1:+,2:~]; SUBJECT_ENDS_QUESTION(1.00)[]; ASN(0.00)[asn:34240, ipnet:89.238.64.0/18, country:DE]; RCVD_TLS_ALL(0.00)[]; RECEIVED_SPAMHAUS_PBL(0.00)[91.22.85.98:received] X-ThisMailContainsUnwantedMimeParts: N 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 #include #include +#include #include #include #include @@ -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--