From 048ce0876f5421f70a6d348479bdeacdd8472bed Mon Sep 17 00:00:00 2001 From: Eugene Grosbein Date: Wed, 22 Jun 2022 01:29:08 +0700 Subject: [PATCH] adjkerntz(8): detect extra jailed invokation to keep logs clean It may happen that "adjkerntz -a" called from jailed root crontab. In that case it spams logs with a line: sysctl(set: "machdep.wall_cmos_clock"): Operation not permitted Be silent in that case. MFC after: 1 month --- sbin/adjkerntz/adjkerntz.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/sbin/adjkerntz/adjkerntz.c b/sbin/adjkerntz/adjkerntz.c index e6cadcf7f189..2fde545ebf32 100644 --- a/sbin/adjkerntz/adjkerntz.c +++ b/sbin/adjkerntz/adjkerntz.c @@ -46,6 +46,7 @@ __FBSDID("$FreeBSD$"); * with Garrett Wollman and Bruce Evans fixes. * */ +#include #include #include #include @@ -159,6 +160,12 @@ again: len = sizeof(kern_offset); if (sysctlbyname("machdep.adjkerntz", &kern_offset, &len, NULL, 0) == -1) { + if (errno == EPERM && !init && geteuid() == 0) + /* + * Surplus call from jailed root crontab. + * Avoid spamming logs. + */ + return 1; syslog(LOG_ERR, "sysctl(\"machdep.adjkerntz\"): %m"); return 1; }