[systemd-devel] hint to know the state of the service using function
Cristian Rodríguez
crrodriguez at opensuse.org
Fri Aug 23 17:41:52 UTC 2024
On Fri, Aug 23, 2024 at 11:51 AM Rajmohan. R <Rajmohan.R at kpit.com> wrote:
> Hi,
> Below is the change related to logging of the units (service) while
> changing the state [in]active_[exit/enter].
>
> I did not get any hint from source code, to know the state change using
> function, without querying the target system through CLI.
> Could someone from the forum help in providing a hint on how to get the
> state of the services without querying through CLI.
>
> Instead of below changes, is there any alternative modification i can do
> to know the state of the service.
>
> diff --git a/src/core/unit.c b/src/core/unit.c
> index c406bb7ab2..e6ad9b3fbf 100644
> --- a/src/core/unit.c
> +++ b/src/core/unit.c
> @@ -2497,15 +2497,31 @@ void unit_notify(Unit *u, UnitActiveState os,
> UnitActiveState ns, UnitNotifyFlag
> if (!MANAGER_IS_RELOADING(m)) {
> dual_timestamp_get(&u->state_change_timestamp);
>
> - if (UNIT_IS_INACTIVE_OR_FAILED(os) &&
> !UNIT_IS_INACTIVE_OR_FAILED(ns))
> + if (UNIT_IS_INACTIVE_OR_FAILED(os) &&
> !UNIT_IS_INACTIVE_OR_FAILED(ns)) {
> u->inactive_exit_timestamp =
> u->state_change_timestamp;
> - else if (!UNIT_IS_INACTIVE_OR_FAILED(os) &&
> UNIT_IS_INACTIVE_OR_FAILED(ns))
> + log_warning("sd: u=%s, inactive_exit="USEC_FMT,
> + u->id,
> u->inactive_exit_timestamp.monotonic);
>
>
A patch that does this may be acceptable if you file a PR and use the debug
level.. using the warning level for this does not fly..
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/systemd-devel/attachments/20240823/12c2fcf1/attachment.htm>
More information about the systemd-devel
mailing list