Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core/service: try to query for new main process's starttime #32961

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

YHNdnzj
Copy link
Member

@YHNdnzj YHNdnzj commented May 21, 2024

Currently, when service_set_main_pidref() is called without specifying start_timestamp, exec_status_start() always uses dual_timestamp_now(). This is not ideal, though, as when the main pid changes halfway due to e.g. sd_notify + MAINPID=, it's definitely spurious.

@YHNdnzj YHNdnzj added the pid1 label May 21, 2024
@github-actions github-actions bot added the please-review PR is ready for (re-)review by a maintainer label May 21, 2024
@YHNdnzj YHNdnzj added ci-fails/needs-rework 🔥 Please rework this, the CI noticed an issue with the PR and removed please-review PR is ready for (re-)review by a maintainer labels May 21, 2024
Copy link

Important

An -rc1 tag has been created and a release is being prepared, so please note that PRs introducing new features and APIs will be held back until the new version has been released.

@github-actions github-actions bot added util-lib tests please-review PR is ready for (re-)review by a maintainer and removed ci-fails/needs-rework 🔥 Please rework this, the CI noticed an issue with the PR labels May 21, 2024
@bluca
Copy link
Member

bluca commented May 21, 2024

Is this due to recent changes? Or is it something that was always there?

@YHNdnzj
Copy link
Member Author

YHNdnzj commented May 21, 2024

Is this due to recent changes? Or is it something that was always there?

I think this was never done correctly, so it's OK to target v257.

Copy link
Member

@bluca bluca left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds like a bug though, and it's for metrics purpose only, so should be fine to merge already

src/test/test-process-util.c Outdated Show resolved Hide resolved
src/test/test-process-util.c Outdated Show resolved Hide resolved
src/core/service.c Outdated Show resolved Hide resolved
@poettering
Copy link
Member

so i presume the process start_time is actually the fork() time, right, and not updated at execve() time, right?

assuming that this is the case, code looks roughly ok, but the clock confusion needs to be fixed.

@poettering poettering added reviewed/needs-rework 🔨 PR has been reviewed and needs another round of reworks and removed please-review PR is ready for (re-)review by a maintainer labels May 22, 2024
@YHNdnzj
Copy link
Member Author

YHNdnzj commented May 22, 2024

so i presume the process start_time is actually the fork() time, right, and not updated at execve() time, right?

According to this piece of comment, yes.

(I didn't check yesterday, partly because I was tired, but also because I think exec() time is still better than now().)

Currently, when service_set_main_pidref() is called
without specifying start_timestamp, exec_status_start()
always uses dual_timestamp_now(). This is not ideal,
though, as when the main pid changes halfway due to
e.g. sd_notify + MAINPID=, it's definitely spurious.
@github-actions github-actions bot added please-review PR is ready for (re-)review by a maintainer and removed reviewed/needs-rework 🔨 PR has been reviewed and needs another round of reworks labels May 22, 2024
@poettering
Copy link
Member

so i presume the process start_time is actually the fork() time, right, and not updated at execve() time, right?

According to this piece of comment, yes.

(I didn't check yesterday, partly because I was tired, but also because I think exec() time is still better than now().)

well, if it was the exec() time, then it should probably be placed in the "handoff" timestamp.

@poettering
Copy link
Member

So i given the inaccuracy of jiffies I think we should take more care not to override any timestamps if we forked off the process ourselves. In particular as deriving the realtime timestamp from the boottime timestamp is a bit icky, and we should really avoid doing that if we don#t really have to.

@poettering poettering removed the please-review PR is ready for (re-)review by a maintainer label May 22, 2024
@poettering poettering added the reviewed/needs-rework 🔨 PR has been reviewed and needs another round of reworks label May 22, 2024
@poettering
Copy link
Member

Sounds like a bug though, and it's for metrics purpose only, so should be fine to merge already

dunno, i disagree, i don#t see the implications of this at all. Let's not hurry this. I am pretty sure this should be 257 material.

@YHNdnzj
Copy link
Member Author

YHNdnzj commented May 22, 2024

So i given the inaccuracy of jiffies I think we should take more care not to override any timestamps if we forked off the process ourselves. In particular as deriving the realtime timestamp from the boottime timestamp is a bit icky, and we should really avoid doing that if we don#t really have to.

We don't? If the main process is forked off by us, we always pass in start_timestamp (see service_enter_start)

@YHNdnzj YHNdnzj added please-review PR is ready for (re-)review by a maintainer and removed reviewed/needs-rework 🔨 PR has been reviewed and needs another round of reworks labels May 22, 2024
@poettering
Copy link
Member

So, this does redefine what the start timestamp actually means. previously it meant: timestamp when the main process become the main process. with this pr applied it means timestampt when the process that is currently the main process started. Which are two distinct definitions.

I think the latter does make some sense in that it is less confusing to users probably. hence i think we probably should make the change, but really, such as change is v257 material i am sure.

@poettering
Copy link
Member

So i given the inaccuracy of jiffies I think we should take more care not to override any timestamps if we forked off the process ourselves. In particular as deriving the realtime timestamp from the boottime timestamp is a bit icky, and we should really avoid doing that if we don#t really have to.

We don't? If the main process is forked off by us, we always pass in start_timestamp (see service_enter_start)

ah, sorry, i misread the func, i though it would update the tstamp always, but it only does it when the pid changes. hence, indeed we should be good.

@YHNdnzj YHNdnzj added this to the v257 milestone May 22, 2024
@bluca
Copy link
Member

bluca commented May 22, 2024

So i given the inaccuracy of jiffies I think we should take more care not to override any timestamps if we forked off the process ourselves. In particular as deriving the realtime timestamp from the boottime timestamp is a bit icky, and we should really avoid doing that if we don#t really have to.

We don't? If the main process is forked off by us, we always pass in start_timestamp (see service_enter_start)

ah, sorry, i misread the func, i though it would update the tstamp always, but it only does it when the pid changes. hence, indeed we should be good.

Yeah this is only in a particular case where we know it's wrong. Given it's only in that case, and it's only for display purpose (eg, our behaviour is not affected), it's fine for me to either take it immediately or postpone, don't mind either way.

@YHNdnzj
Copy link
Member Author

YHNdnzj commented May 22, 2024

I have no strong opinion on which release this should target, either.

@poettering poettering added good-to-merge/after-next-release and removed please-review PR is ready for (re-)review by a maintainer labels May 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

None yet

4 participants