* [PATCH] qga: do not attempt running hwclock(8) on BSD
@ 2026-10-14 11:20 Roman Bogorodskiy
2026-10-14 20:12 ` Brad Smith
0 siblings, 1 reply; 3+ messages in thread
From: Roman Bogorodskiy @ 2026-10-14 11:20 UTC (permalink / raw)
To: qemu-devel; +Cc: Roman Bogorodskiy, Michael Roth, Kostiantyn Kostiuk
Currently, qmp_guest_set_time() sets system time using
the settimeofday(2) system call and then runs the hwclock(8)
util to set hardware time.
BSDs do not ship hwclock(8), so current implementation
always fails while trying to run it.
Update the code not to run it on BSD. The settimeofday(2)
call sets both system and hardware time on these systems.
For example, on FreeBSD settimeofday() calls settime()
which calls resettodr() [1] which updates RTC clock [2].
It is similar on OpenBSD and NetBSD, though implementations
differ a bit.
Additional detail: on FreeBSD RTC clock setting can be
disabled with the `machdep.disable_rtc_set` sysctl.
As we cannot do anything about it, do not handle that
case separately.
BSD systems do not provide a common utility equivalent
to hwclock -s, so report an unsupported operation when
no time is supplied.
1: https://cgit.freebsd.org/src/tree/sys/kern/kern_time.c
2: https://cgit.freebsd.org/src/tree/sys/kern/subr_rtc.c
Signed-off-by: Roman Bogorodskiy <bogorodskiy@gmail.com>
---
qga/commands-posix.c | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/qga/commands-posix.c b/qga/commands-posix.c
index 837e285b6d..f3d18e6dcd 100644
--- a/qga/commands-posix.c
+++ b/qga/commands-posix.c
@@ -322,6 +322,20 @@ void qmp_guest_set_time(bool has_time, int64_t time_ns, Error **errp)
}
}
+#if defined(CONFIG_BSD)
+ /*
+ * BSDs (FreeBSD, OpenBSD, NetBSD) do not have the hwclock(8) tool.
+ * These systems update hardware clock when settimeofday() sets
+ * system time, so no additional actions are needed.
+ * Setting system time from RTC is not supported.
+ */
+ if (!has_time) {
+ error_setg(errp, "Setting system time from RTC is not supported");
+ }
+
+ return;
+#endif
+
/* Now, if user has passed a time to set and the system time is set, we
* just need to synchronize the hardware clock. However, if no time was
* passed, user is requesting the opposite: set the system time from the
--
2.55.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] qga: do not attempt running hwclock(8) on BSD
2026-10-14 11:20 [PATCH] qga: do not attempt running hwclock(8) on BSD Roman Bogorodskiy
@ 2026-10-14 20:12 ` Brad Smith
2026-10-15 14:29 ` Roman Bogorodskiy
0 siblings, 1 reply; 3+ messages in thread
From: Brad Smith @ 2026-10-14 20:12 UTC (permalink / raw)
To: Roman Bogorodskiy, qemu-devel; +Cc: Michael Roth, Kostiantyn Kostiuk
On 2026-10-14 7:20 a.m., Roman Bogorodskiy wrote:
> Currently, qmp_guest_set_time() sets system time using
> the settimeofday(2) system call and then runs the hwclock(8)
> util to set hardware time.
>
> BSDs do not ship hwclock(8), so current implementation
> always fails while trying to run it.
>
> Update the code not to run it on BSD. The settimeofday(2)
> call sets both system and hardware time on these systems.
> For example, on FreeBSD settimeofday() calls settime()
> which calls resettodr() [1] which updates RTC clock [2].
> It is similar on OpenBSD and NetBSD, though implementations
> differ a bit.
>
> Additional detail: on FreeBSD RTC clock setting can be
> disabled with the `machdep.disable_rtc_set` sysctl.
> As we cannot do anything about it, do not handle that
> case separately.
>
> BSD systems do not provide a common utility equivalent
> to hwclock -s, so report an unsupported operation when
> no time is supplied.
>
> 1: https://cgit.freebsd.org/src/tree/sys/kern/kern_time.c
> 2: https://cgit.freebsd.org/src/tree/sys/kern/subr_rtc.c
>
> Signed-off-by: Roman Bogorodskiy <bogorodskiy@gmail.com>
> ---
> qga/commands-posix.c | 14 ++++++++++++++
> 1 file changed, 14 insertions(+)
>
> diff --git a/qga/commands-posix.c b/qga/commands-posix.c
> index 837e285b6d..f3d18e6dcd 100644
> --- a/qga/commands-posix.c
> +++ b/qga/commands-posix.c
> @@ -322,6 +322,20 @@ void qmp_guest_set_time(bool has_time, int64_t time_ns, Error **errp)
> }
> }
>
> +#if defined(CONFIG_BSD)
> + /*
> + * BSDs (FreeBSD, OpenBSD, NetBSD) do not have the hwclock(8) tool.
> + * These systems update hardware clock when settimeofday() sets
> + * system time, so no additional actions are needed.
> + * Setting system time from RTC is not supported.
> + */
> + if (!has_time) {
> + error_setg(errp, "Setting system time from RTC is not supported");
> + }
> +
> + return;
> +#endif
> +
> /* Now, if user has passed a time to set and the system time is set, we
> * just need to synchronize the hardware clock. However, if no time was
> * passed, user is requesting the opposite: set the system time from the
The command is Linux specific so it shouldn't be checking CONFIG_BSD. It
should be
using something like #ifndef CONFIG_LINUX.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] qga: do not attempt running hwclock(8) on BSD
2026-10-14 20:12 ` Brad Smith
@ 2026-10-15 14:29 ` Roman Bogorodskiy
0 siblings, 0 replies; 3+ messages in thread
From: Roman Bogorodskiy @ 2026-10-15 14:29 UTC (permalink / raw)
To: Brad Smith; +Cc: qemu-devel, Michael Roth, Kostiantyn Kostiuk
Brad Smith wrote:
> On 2026-10-14 7:20 a.m., Roman Bogorodskiy wrote:
> > Currently, qmp_guest_set_time() sets system time using
> > the settimeofday(2) system call and then runs the hwclock(8)
> > util to set hardware time.
> >
> > BSDs do not ship hwclock(8), so current implementation
> > always fails while trying to run it.
> >
> > Update the code not to run it on BSD. The settimeofday(2)
> > call sets both system and hardware time on these systems.
> > For example, on FreeBSD settimeofday() calls settime()
> > which calls resettodr() [1] which updates RTC clock [2].
> > It is similar on OpenBSD and NetBSD, though implementations
> > differ a bit.
> >
> > Additional detail: on FreeBSD RTC clock setting can be
> > disabled with the `machdep.disable_rtc_set` sysctl.
> > As we cannot do anything about it, do not handle that
> > case separately.
> >
> > BSD systems do not provide a common utility equivalent
> > to hwclock -s, so report an unsupported operation when
> > no time is supplied.
> >
> > 1: https://cgit.freebsd.org/src/tree/sys/kern/kern_time.c
> > 2: https://cgit.freebsd.org/src/tree/sys/kern/subr_rtc.c
> >
> > Signed-off-by: Roman Bogorodskiy <bogorodskiy@gmail.com>
> > ---
> > qga/commands-posix.c | 14 ++++++++++++++
> > 1 file changed, 14 insertions(+)
> >
> > diff --git a/qga/commands-posix.c b/qga/commands-posix.c
> > index 837e285b6d..f3d18e6dcd 100644
> > --- a/qga/commands-posix.c
> > +++ b/qga/commands-posix.c
> > @@ -322,6 +322,20 @@ void qmp_guest_set_time(bool has_time, int64_t time_ns, Error **errp)
> > }
> > }
> > +#if defined(CONFIG_BSD)
> > + /*
> > + * BSDs (FreeBSD, OpenBSD, NetBSD) do not have the hwclock(8) tool.
> > + * These systems update hardware clock when settimeofday() sets
> > + * system time, so no additional actions are needed.
> > + * Setting system time from RTC is not supported.
> > + */
> > + if (!has_time) {
> > + error_setg(errp, "Setting system time from RTC is not supported");
> > + }
> > +
> > + return;
> > +#endif
> > +
> > /* Now, if user has passed a time to set and the system time is set, we
> > * just need to synchronize the hardware clock. However, if no time was
> > * passed, user is requesting the opposite: set the system time from the
>
> The command is Linux specific so it shouldn't be checking CONFIG_BSD. It
> should be
> using something like #ifndef CONFIG_LINUX.
>
Updated in v2. Actually, I have started with that, but later changed to
CONFIG_BSD check because I tried to avoid testing this change on
Solaris. Anyway, just tried this change on OpenIndiana and it works as
expected.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-10-15 14:30 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-14 11:20 [PATCH] qga: do not attempt running hwclock(8) on BSD Roman Bogorodskiy
2026-10-14 20:12 ` Brad Smith
2026-10-15 14:29 ` Roman Bogorodskiy
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.