Skip to content

Add some utilities for PATH searching.#2405

Open
3405691582 wants to merge 1 commit intogoogle:mainfrom
3405691582:488432653_1
Open

Add some utilities for PATH searching.#2405
3405691582 wants to merge 1 commit intogoogle:mainfrom
3405691582:488432653_1

Conversation

@3405691582
Copy link
Copy Markdown
Collaborator

A lot of our tooling relies on executing binaries found on the host system. The subprocess library ends up calling execvpe on Linux, which means that PATH resolution happens for the executable.

Two issues present themselves. Firstly, execvpe is a Linuxism -- it is not in the SUS; our tentative non-Linux (macOS) implementation calles execve instead.

Secondly and more importantly, if the executable that we expect to be able to run is not in PATH, then we will fail to exec it, even if the actual executable is installed; this can happen on some distributions where nonprivileged users are configured by default to not have executables where root privileges are required in PATH.

Therefore, we need to be able to perform PATH resolution ourselves, so that we can do things like test if a binary truly isn't available or whether it merely isn't in the current PATH.

We add a reminder for ourselves too that while the usual colon-separated PATH splitting makes perfect sense for SUS systems, it is not the case on platforms like Windows -- if in the future we want to go down that direction.

(Also, perhaps we should just migrate to using posix_spawn, but that's not important right now.)

Bug: 488432653

@3405691582 3405691582 requested a review from Databean April 15, 2026 19:11
Copy link
Copy Markdown
Member

@Databean Databean left a comment

Choose a reason for hiding this comment

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

I'm not sure we can use posix_spawn because we do a bunch of work between the fork and exec steps, though some of that is also linux-specific.

Definitely regret the change to use execvpe over execve, which came in aosp/1584808, and would prefer to use execve again though I don't know how much other fallout it would cause.

Comment thread base/cvd/cuttlefish/common/libs/utils/files_test.cpp Outdated
Comment thread base/cvd/cuttlefish/common/libs/utils/files_test.cpp Outdated
@Databean Databean added the kokoro:run Run e2e tests. label Apr 16, 2026
@GoogleCuttlefishTesterBot GoogleCuttlefishTesterBot removed the kokoro:run Run e2e tests. label Apr 16, 2026
@3405691582 3405691582 added the kokoro:run Run e2e tests. label Apr 16, 2026
@3405691582 3405691582 enabled auto-merge April 16, 2026 19:36
@GoogleCuttlefishTesterBot GoogleCuttlefishTesterBot removed the kokoro:run Run e2e tests. label Apr 16, 2026
@3405691582 3405691582 added the kokoro:force-run Trigger a presubmit build unconditionally. label Apr 16, 2026
@GoogleCuttlefishTesterBot GoogleCuttlefishTesterBot removed the kokoro:force-run Trigger a presubmit build unconditionally. label Apr 16, 2026
A lot of our tooling relies on executing binaries found on the host
system. The subprocess library ends up calling execvpe on Linux, which
means that PATH resolution happens for the executable.

Two issues present themselves. Firstly, execvpe is a Linuxism -- it is
not in the SUS; our tentative non-Linux (macOS) implementation calles
execve instead.

Secondly and more importantly, if the executable that we expect to be
able to run is not in PATH, then we will fail to exec it, even if the
actual executable is installed; this can happen on some distributions
where nonprivileged users are configured by default to not have
executables where root privileges are required in PATH.

Therefore, we need to be able to perform PATH resolution ourselves, so
that we can do things like test if a binary truly isn't available or
whether it merely isn't in the current PATH.

We add a reminder for ourselves too that while the usual colon-separated
PATH splitting makes perfect sense for SUS systems, it is not the case
on platforms like Windows -- if in the future we want to go down that
direction.

(Also, perhaps we should just migrate to using posix_spawn, but that's
not important right now.)

Bug: 488432653
@3405691582 3405691582 added the kokoro:force-run Trigger a presubmit build unconditionally. label Apr 16, 2026
@GoogleCuttlefishTesterBot GoogleCuttlefishTesterBot removed the kokoro:force-run Trigger a presubmit build unconditionally. label Apr 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants