4 ms·
Can't one just sudo echo -e "\7” anyway? Or if you're trying to do something fancier there is snd-pcsp which lets use use the piezo as a normal ALSA devi
by Y_Y 9y ago
Can't one just
sudo echo -e "\7”
anyway? Or if you're trying to do something fancier there is snd-pcsp which lets use use the piezo as a normal ALSA device (quality may vary). Not that many modern machines even include such a useful device.
- dblotsky 9y agoNitpick: on my machine, that's: sudo echo -e "\07"
- FreeFull 9y agoSimply displaying a character doesn't need sudo at all anyway, so just echo -e "\07"
- laumars 9y ago`sudo` isn't there for displaying the character, it's there for ioctl to have permissions to play the beep on remote terminals[1]. I think some terminal emulators (eg Konsole) will just read char 7 and play a system defined WAV or other workaround but your more classic terminals (eg xterm) would potentially have difficulties calling the system bell. [1] for reference: Xorg terminals are also classed as remote terminals (eg check the TTY column in `w` to see how Linux assigns pseudo-tty's to terminal emulators inside X).
- FreeFull 9y agoEven in that case, you'd have to run the terminal as root. Running echo as root won't do anything. X11 also has beep functionality built in, which is what I'd expect xterm to use.
- laumars 9y ago> Even in that case, you'd have to run the terminal as root. Running echo as root won't do anything. To be honest that was my assumption as well but I didn't test that theory so was only reporting on the rationale of the GPs post > X11 also has beep functionality built in, which is what I'd expect xterm to use X11 runs as root though (that said Xorg may not anymore now as there were talks about patching Linux so it didn't have to be) so Xorg could easily still use the standard ioctl bell (that's possibly all Xorg is doing behind the scenes in fact?) But as I said earlier, some GUI terminal emulators avoid ioctl entirely and play a WAV tone instead.
- jwilk 9y ago"echo -e" is not portable, and neither are any escape sequences for echo. The portable way to print ASCII BEL is: printf '\a'
- Retr0spectrum 9y agoWhy would that need root? Is it not up to your terminal emulator to interpret the \7 and trigger the actual beep?
- rnhmjoj 9y agoSee the "A note about ioctl" section of the README: https://github.com/johnath/beep https://github.com/johnath/beep
- DCoder 9y agoThat section says: > there's only one file opening, and while there is a potential race condition there, it's with /dev/console. If someone can exploit this race by replacing /dev/console, you've got bigger problems. :) However, by reading the source one can see that you can now tell beep where it should direct its output (-e, which is not documented anywhere), so the note above is no longer accurate. I would guess that this is the crux of the problem – the patch that fixes the security issue basically changes "open the output device once for each beep" to "open the output device on startup", greatly reducing the number of races. (It also zeroes out the buffer that's being written to certain output devices, but I have no idea if that is also to patch this security hole or to proactively prevent uninitialized bytes from leaking.)
- jwilk 9y agoBut echo doesn't do any ioctls. The only thing it does is writing bytes on stdout.
- scbrg 9y agoI guess the whole point of setuid is that no, you can't always "just sudo" :-)
- gall0ws 9y agoYes, it tries to do fancy things with ioctl().
- DCoder 9y agoIf you're connected to a remote server, `echo` will annoy you and your cat, but `beep` will annoy the server administrator :)
- exikyut 9y agoI have long wished servers had functioning speakers. And that virtio-beep existed. I wonder what would happen if I pushed to get the support into KVM and the kernel. Best case scenario, the videos accompanying the too-bemused-to-really-be-angry bug reports would be legendary.
- ape4 9y agoor #include <curses.h> main() { beep(); } In fairness, the beep command does more https://linux.die.net/man/1/beep https://linux.die.net/man/1/beep