Skip to content

Store the device id with a rename when hard links are denied - #432

Merged
ffilippopoulos merged 1 commit into
masterfrom
agent/device-id-no-hardlinks
Oct 20, 2026
Merged

ffilippopoulos merged 1 commit into
masterfrom
agent/device-id-no-hardlinks

Conversation

@ffilippopoulos

Copy link
Copy Markdown
Member

The device id file is first created by hard-linking a temporary file into place, so that concurrent first starts agree on one id. When linking is not available the agent falls back to a rename, which does not detect a file created in the meantime. The fallback covered EPERM, ENOTSUP, EXDEV and ENOSYS.

The SELinux policy of Android apps denies hard links with EACCES (avc: denied { link } ... untrusted_app), so the agent in v0.4.0-RC3 fails to start on Android with cannot store the device id ...: link ...: permission denied.

  • EACCES now selects the rename fallback. The temporary file is created in the same directory just before, so a real permission problem still fails at the rename.
  • Other link errors, such as EIO, are still returned.
  • The link call is a variable (linkFile) so tests can replace it.

On Android every first creation takes the fallback. That is fine there: one agent process runs, and Mobile.start refuses a second start. On Linux and macOS hard links work and the fallback does not run in practice.

Tests:

  • The id is created and reused when linking fails with each of the five errors. Removing EACCES from the fallback fails it.
  • An unrelated link error is returned.

The device id file is created with a hard link so that concurrent first
starts agree on one id. A link that fails with EACCES, which is how the
SELinux policy of Android apps answers, now falls back to a rename like
the other errors that mean hard links are not available. Other link
errors are still returned.

The link call is a variable so tests can replace it.
@ffilippopoulos
ffilippopoulos marked this pull request as ready for review October 20, 2026 09:07
@ffilippopoulos
ffilippopoulos merged commit 63e1442 into master Oct 20, 2026
10 checks passed
@ffilippopoulos
ffilippopoulos deleted the agent/device-id-no-hardlinks branch October 20, 2026 09:07
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.

2 participants