Runtime: Support Console.beep on Linux (Fedora/RHEL)

Created on 6 Dec 2017  ยท  22Comments  ยท  Source: dotnet/runtime

@chiddekel commented on Tue Dec 05 2017

Run on OS: Fedora 27
Kernel Linux: 4.13.16-302.fc27.x86_64

Step zero: yum install beep
First, runsudo modprobe pcspkr and then beep should work.

Additional uncomment the /etc/modprobe.d/beep.conf line at:
# alias platform:pcspkr pcspkr
to
alias platform:pcspkr pcspkr
For automatic load pcspkr module

Run application beep e.g - /usr/bin/beep -f 2000 -l 1000
The beep in this case equal to n = 2000 Hz and duration 1000 ms

This is tiny, small C source includes, of beep application.
https://goo.gl/E3kfPy

The portion of this code can be re-write to C# and use in Console.beep implementation for Linux platform.

area-System.Console enhancement up-for-grabs

Most helpful comment

No, that is not how this repo / product operates.

@richlander or @leecow can comment further.

All 22 comments

For clarification, Console.Beep() works fine on Unix. It's Console.Beep(int, int) that throws PlatformNotSupportedException, due to lack of a good cross-platform mechanism for implementing it and it's relative value.

The implementation of platform Linux, Darwin, NT is simple if else statement or case switch.
The code run after e.g If (platform == Linux) { } and the detect it is restricted only by this way:

The sounds are caused by the BIOS (Basic Input/Output System) by the OS (Operating System), by the DE (Desktop Environment).

You're welcome to submit a PR to be evaluated. I do not believe this is something folks at Microsoft will invest in any time soon.

In short - it's not hard to implement.
All pice is in place.

Linux Developer or distro maintainer of eg, Fedora, Debian etc, etc
Must check two-step:

  1. Is module pcspkr un-blacklist
  2. Is PC Speaker, PC Beep, or Beep unmute for example by alsa.

Source code for /usr/bin/beep is at http://security.debian.org/debian-security/pool/updates/main/b/beep/beep_1.3.orig.tar.gz.

Question for corefx folks:

Is shelling out to /usr/bin/beep acceptable or would you prefer that ๐Ÿ‘‡ is re-implemented.

< Deleted screenshot of GPL licensed code >

@stephentoub thoughts? I'd prefer to port the code, as long as it's the same for all distro, since shelling out is not free (is another dependency, and is clumsy)

I'd prefer to port the code, as long as it's the same for all distro, since shelling out is not free (is another dependency, and is clumsy)

I agree. However:
a) What's the license on that code? Porting something GPL for example would not be acceptable.
b) How much code is it? The snippet shown above is calling methods (e.g. do_beep) where the src isn't shown.

It seems like an implementation should be possible, at least on Linux, with relatively little code, but if the cited source is GPL or a similar license, someone who's not looked at the code will need to provide the implementation.

Hi,

has anybody start the work on this?

@paule96 I don't think so, you are welcome to offer a PR but note the comment above that it must be a clean implementation without consulting code under GPL or similar license.

I will try my best maybe :) But I don't have any know how about programming nativ stuff on Linux ๐Ÿ˜„ have anybody a good starting tutorial for this stuff? ๐Ÿ†˜

On unix you open the console /dev/tty0, /dev/vc/0, /dev/console and write to it. However, as far as I know this requires root permissions. So writing directly to it will be a problem.

beep usually has its user id set to root.

But root for sound "sounds" wrong. ๐Ÿคทโ€โ™€๏ธ
I have googled and found a sound function in C. (https://www.programmingsimplified.com/c/dos.h/sound) But I don't have any know how about C. So I don't know if this is the right way....

The function you have found is using dos.h, that doesn't seem like right place to look.

Link was unavailable - here is re paste Debian git repo. http://git.deb.at/w/pkg/beep.git

here is re paste Debian git repo

That code is GPL.

Yes code is GPL - re writed code based on beep Debian source code ๐Ÿ‘†- should be include the rule of interoperable in copyright law, adding part code of framework or library under GPL licence.

should be include the rule of interoperable in copyright law adding portion of code under GPL licence.

Sorry, I'm not quite understanding, but we _cannot_ base code in this repo on anything that is GPL.

You can, new portion of code will be under GPL licence, and licence can be add to this specific portion of code, so will be include only to beep re-implementation.

No, that is not how this repo / product operates.

@richlander or @leecow can comment further.

Just sharing what I know about this beeping/linux terminal stuff, in case you find it useful:

  • This would likely make sense to work only when the user is at the console, either gui or text mode, is that right? Or should it work always even if you would connect through ssh and issue Beep...
  • Generally you can beep by issuing some ioctls on a virtual terminal. In case of ssh or serial port there is no current vt, in case of text mode there is, in case of graphical mode there is, but only the xserver/wayland compositor is really connected to it.
  • /dev/tty won't work for graphical sessions or remote, /dev/ttyn would in case of gui but not sure how to check which to open (the correct one has ownership set to current user), /dev/tty0 is the currently active vt but it is root only, and /dev/console does not even have to be the vt.
  • The pc speaker also registers as input device but I am not really sure how much it matters. Although generally you may be able to get access to these from non remote without root. But finding the correct one means probably checking in sysfs or udev. I am not sure what is or is not acceptable.
    In summary, to me it seems at least tricky.

Just saw this issue. I don't think I saw it originally. I am closing this given how old this issue is, and the fact that the primary code being considered is GPL.

Anyone should feel to open a new issue if they have a new proposal for tackling this topic.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

nalywa picture nalywa  ยท  3Comments

GitAntoinee picture GitAntoinee  ยท  3Comments

jzabroski picture jzabroski  ยท  3Comments

omariom picture omariom  ยท  3Comments

chunseoklee picture chunseoklee  ยท  3Comments