Skip to content

fix(beep): bundle fallback chime for Linux distros without freedesktop sounds#1535

Merged
tdewey-rpi merged 3 commits into
raspberrypi:mainfrom
4RH1T3CT0R7:dev/4rh1t3ct0r/fix-linux-beep-fallback
Mar 6, 2026
Merged

fix(beep): bundle fallback chime for Linux distros without freedesktop sounds#1535
tdewey-rpi merged 3 commits into
raspberrypi:mainfrom
4RH1T3CT0R7:dev/4rh1t3ct0r/fix-linux-beep-fallback

Conversation

@4RH1T3CT0R7

@4RH1T3CT0R7 4RH1T3CT0R7 commented Mar 3, 2026

Copy link
Copy Markdown
Contributor
  • Expand system sound file search paths to cover Ubuntu (Yaru), KDE (Ocean), and GNOME legacy themes
  • Bundle a small (26KB) WAV chime as last-resort fallback for distros with no system sounds at all
  • Extract the bundled chime to a PID-namespaced temp file with restrictive permissions (security: rpi-imager runs as root)
  • Clean up temp file automatically on application exit via std::atexit()

Root Cause

On Linux distros that don't ship freedesktop sound theme files (e.g. Arch), findSoundFile() returns nullptr because only two paths were checked:

  • /usr/share/sounds/freedesktop/stereo/complete.oga
  • /usr/share/sounds/freedesktop/stereo/bell.oga

This caused isBeepAvailable() to return false (unless canberra-gtk-play or beep was installed), and the beep() function to fail with "Failed to open sound file." even when pw-play or aplay was available.

The fix adds three more distro-specific paths, and when none exist, extracts a bundled WAV chime from Qt resources to a temp file. This enables the existing pw-play/aplay/pactl fallback chain to work on any Linux system.

Security considerations

Since rpi-imager runs as root via pkexec, temp file handling is security-sensitive:

  • PID in filename prevents symlink attacks and multi-instance collisions
  • QFile::remove() before copy() prevents following pre-existing symlinks
  • ReadOwner | WriteOwner permissions restricts access to root only
  • std::atexit() cleanup removes the temp file on exit

Closes #1449

Comment thread src/linux/platformquirks_linux.cpp Outdated
@tdewey-rpi

Copy link
Copy Markdown
Collaborator

What's the copyright story on the chime.wav? Are you able to certify it's your own product and you're able to assign usage rights to the project?

@4RH1T3CT0R7

4RH1T3CT0R7 commented Mar 5, 2026

Copy link
Copy Markdown
Contributor Author

Good catch, thanks! I initially assumed the chime was from @0xDE57's repo (https://github.com/0xDE57/raspberry-chime, CC0 1.0), but after your comment I double-checked and it turned out to be a different file entirely

Replaced it now with 314A.wav from that repo - properly CC0-licensed, 88KB, root note at 314Hz (a nice pi reference)

@tdewey-rpi

Copy link
Copy Markdown
Collaborator

@0xDE57

Confirming we're now in a place to accept this. Thanks for the contributions both!

…p sounds

On Linux distros that don't ship freedesktop sound theme files (e.g. Arch),
the "Play sound when finished" feature fails because the hardcoded paths
/usr/share/sounds/freedesktop/stereo/{complete,bell}.oga don't exist.

This adds:
- More system sound search paths (Ubuntu Yaru, KDE Ocean, GNOME legacy)
- A bundled 26KB WAV chime as last-resort fallback, extracted to a temp
  file so existing playback commands (pw-play, aplay, pactl) can use it
- PID-based temp filename and restrictive permissions for security
  (rpi-imager runs as root via pkexec)
- Automatic cleanup of the temp file on application exit

The bundled chime is a synthetically generated 880Hz sine wave (0.3s).

Closes raspberrypi#1449
PID allocation is predictable, making symlink attacks easier.
Use QUuid::createUuid() for an unpredictable temp filename.
Use 314A.wav (314Hz root note, "pi" themed) from
https://github.com/0xDE57/raspberry-chime, licensed under CC0 1.0.

Original contribution by @0xDE57 in issue raspberrypi#1449.
@tdewey-rpi tdewey-rpi force-pushed the dev/4rh1t3ct0r/fix-linux-beep-fallback branch from 2a4797f to 63596b7 Compare March 6, 2026 11:33
@tdewey-rpi tdewey-rpi merged commit 9e9576a into raspberrypi:main Mar 6, 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.

[BUG]: No Sound with "Play sound when finished"

2 participants