Coder Social home page Coder Social logo

beep's Introduction

Intro
-----

I just got so tired of being limited to printf("\a"); when I wanted a terminal
beep.  This program isn't supposed to be anything stupendous, it's just
supposed to get the job done.  Its intended purpose in life is to live inside
shell/perl scripts, and allow a little more granularity than you get with the
default terminal bell.  Maybe I'm the only one who thinks this is useful. :)

If for any reason you decide you need to, contact me:

[email protected]
http://johnath.com/

And beep can generally be found at:

http://johnath.com/beep/

For installation instructions, see INSTALL.
For copying and (non-)warranty information, see COPYING.
For usage information, check the man page.

There is a github repository of this code at: git://github.com/johnath/beep.git

A note about ioctl
------------------

As noted in the man page, some users are running into a situation where beep 
dies with a complaint from ioctl().  The reason for this, as Peter Tirsek was
nice enough to point out to me, stems from how the kernel handles beep's 
attempt to poke at (for non-programmers: ioctl is a sort of catch-all function
that lets you poke at things that have no other predefined poking-at mechanism)
the tty, which is how it beeps.  The short story is, the kernel checks that 
either:

- you are the superuser
- you own the current tty

What this means is that root can always make beep work (to the best of my 
knowledge!), and that any local user can make beep work, BUT a non-root remote
user cannot use beep in it's natural state.  What's worse, an xterm, or other
x-session counts, as far as the kernel is concerned, as 'remote', so beep 
won't work from a non-priviledged xterm either.  I had originally chalked this
up to a bug, but there's actually nothing I can do about it, and it really is 
a Good Thing that the kernel does things this way.  There is also a solution.

By default beep is not installed with the suid bit set, because that would 
just be zany.  On the other hand, if you do make it suid root, all your 
problems with beep bailing on ioctl calls will magically vanish, which is 
pleasant, and the only reason not to is that any suid program is a potential 
security hole.  Conveniently, beep is very short, so auditing it is pretty 
straightforward.

Decide for yourself, of course, but it looks safe to me - there's only one 
buffer and fgets doesn't let it overflow, 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.  :)

So the quick solution is beep is not beeping when you want it to is:

$ su
Password:
# chmod 4755 /usr/bin/beep

(or wherever you put it)

The one snag is that this will give any little nitwit the ability to run beep 
successfully - make sure this is what you want.  If it isn't, a slightly more 
complex fix would be something like:

# chgrp beep /usr/bin/beep
# chmod 4750 /usr/bin/beep

and then add only beep-worthy users to the 'beep' group.

Playing Songs
-------------

A surprising number of people have sent in requests, or even patches, to help
beep play multiple, different sounds off a single invocation.  I had always
thought that if people wanted a more complex melody, they would just do 
something like:

$ cat << EOF > song.sh
#!/bin/sh
beep <first beep's options>
beep <second beep's options>
etc...
EOF

Nevertheless, because of repeated and vociferous demand, version 1.2 (and 
presumably all later versions) include the -n/--new switch which allows you to
use one command line to create multiple beeps.  Check the man page for 
details.  I have also had a couple people suggest that I encourage the 
development of such shell scripts/command lines, even collect the particularly
melodious ones.  Certainly if anyone feels like sending some to me, I will put
them somewhere visible, or even include them as a sample.  I think Dvorak's New
World Symphony, 4th Movement, for example, would make a lovely shell script.
I also wouldn't mind a rendition of BNL's If I had a million dollars.  But by
all means, be creative.

All files copyright (C) Johnathan Nightingale, 2002.
All files distributed under the GNU general public license.








beep's People

Contributors

chrisyco avatar johnath avatar lafrech avatar rhonda avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

beep's Issues

Option for typewriter effect when typing within terminal?

I've seen quite a few extravagant typewriting sound emulators using ALSA/Pulse for output, but seemingly bloated in my opinion with high resource usage, rather than using simple PC speaker beep. (eg. bucklespring program, but useless for vision impaired as the sounds are emitted upon press and release, more of a cosmetic feature rather than useful feature.)

Is there any method of providing the beep command the option for emulating a typewriter while typing within terminals?

If I'm not mistaken, the process is relatively simple, detect a keyscan press, play beep. I'm pretty sure the code is almost there using "beep -c -f 750 -D 20 -l 5", just needs to detect a keyscan press.

beep fails, but exits 0 (unless strace'd)

Not sure how to debug this yet, so I'm just providing some info that I'm guessing is at least bug worthy: the exit status should be non-zero, I believe (as you can see errors occur, via strace)

beep itself:

$ beep -v
beep-1.3
$ beep # exits 0, no sound

straced, changes exit status:

$ strace beep # exits 1, no sound
execve("/usr/bin/beep", ["beep"], [/* 85 vars */]) = 0
brk(NULL)                               = 0xa81000
fcntl(0, F_GETFD)                       = 0
fcntl(1, F_GETFD)                       = 0
fcntl(2, F_GETFD)                       = 0
access("/etc/suid-debug", F_OK)         = -1 ENOENT (No such file or directory)
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f32e0bad000
access("/etc/ld.so.preload", R_OK)      = -1 ENOENT (No such file or directory)
open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=120136, ...}) = 0
mmap(NULL, 120136, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f32e0b8f000
close(3)                                = 0
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
open("/lib/x86_64-linux-gnu/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\3\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0P\10\2\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0755, st_size=1697504, ...}) = 0
mmap(NULL, 3803552, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f32e05eb000
mprotect(0x7f32e0782000, 2097152, PROT_NONE) = 0
mmap(0x7f32e0982000, 24576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x197000) = 0x7f32e0982000
mmap(0x7f32e0988000, 14752, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7f32e0988000
close(3)                                = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f32e0b8e000
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f32e0b8d000
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f32e0b8c000
arch_prctl(ARCH_SET_FS, 0x7f32e0b8d700) = 0
mprotect(0x7f32e0982000, 16384, PROT_READ) = 0
mprotect(0x7f32e0baf000, 4096, PROT_READ) = 0
munmap(0x7f32e0b8f000, 120136)          = 0
brk(NULL)                               = 0xa81000
brk(0xaa2000)                           = 0xaa2000
rt_sigaction(SIGINT, {0x400f60, [INT], SA_RESTORER|SA_RESTART, 0x7f32e061e250}, {SIG_DFL, [], 0}, 8) = 0
rt_sigaction(SIGTERM, {0x400f60, [TERM], SA_RESTORER|SA_RESTART, 0x7f32e061e250}, {SIG_DFL, [], 0}, 8) = 0
open("/dev/tty0", O_WRONLY)             = -1 EACCES (Permission denied)
open("/dev/vc/0", O_WRONLY)             = -1 ENOENT (No such file or directory)
write(2, "Could not open /dev/tty0 or /dev"..., 50Could not open /dev/tty0 or /dev/vc/0 for writing
) = 50
fstat(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 4), ...}) = 0
write(2, "open: No such file or directory\n", 32open: No such file or directory
) = 32
write(1, "\7", 1)                       = 1
exit_group(1)                           = ?
+++ exited with 1 +++

Some more info, in case it's helpful:

$ echo -e '\a' # no sound

$ mpv /usr/share/sounds/freedesktop/stereo/bell.oga # SOUND! bell dings
Playing: /usr/share/sounds/freedesktop/stereo/bell.oga
 (+) Audio --aid=1 (vorbis)
AO: [pulse] 44100Hz stereo 2ch float


Exiting... (End of file)

Thank you

Thank you for making this command take a duration and a frequency as argument, I had fun making Albinoni's Adagio in a shell script, and a piano in awk (dvorak by default, with qwerty ready to switch in source) thanks to this.

Multiple calls to beep really cut it, no real need for -n indeed.

You can close this right away, there is no issues (only linux kernel limitations).

Kill the sound and quit gracefully on SIGTERM

When beep receives SIGTERM, it ends leaving the speaker beeping.

This can be an annoyance.

Here's a patch to add SIGTERM support just like SIGINT is managed.

Have a nice day.

Jérôme


*** beep.c 2010-08-03 15:57:27.000000000 +0200
--- beep.c.bak 2012-01-02 19:30:48.704000195 +0100


*** 127,132 ****
--- 127,133 ----

switch(signum) {
case SIGINT:
  • case SIGTERM:
    if(console_fd >= 0) {
    /* Kill the sound, quit gracefully */
    do_beep(0);

*** 321,326 ****
--- 322,328 ----
parms->next = NULL;

signal(SIGINT, handle_signal);

  • signal(SIGTERM, handle_signal);
    parse_command_line(argc, argv, parms);

/* this outermost while loop handles the possibility that -n/--new has been

Integer overflow in handling of -l (length) and -D (delay) parameter

beep contains integer overflows in the handling of the length and delay parameters.

To test compile beep with ubsan:
clang -fsanitize=undefined beep.c -o beep

And try:
./beep -l 2147483647
beep.c:299:16: runtime error: signed integer overflow: 1000 * 2147483647 cannot be represented in type 'int'

or
./beep -D 2147483647
beep.c:302:19: runtime error: signed integer overflow: 1000 * 2147483647 cannot be represented in type 'int'

The problem is that the value is multiplied by 1000. Integer overflows are undefined behavior and can thus lead to unpredictable outcome due to compiler optimizations.

This could be made safe by using unsigned variables. They could still overflow, but would "just" wrap around and lead to different values being used. Alternatively of course the inputs could be capped to values that can safely be multiplied within the size of an integer.

Incorporate sine for output

Currently it seems beep uses square waves for acoustics however, sines are softer and it would be nice to have beep output whatever it does already but as sines so for an ordinary command for example:

$ beep -f 1000 -n -f 2000 -n -f 1500

but for sines we add -t and for sine output
$beep -t sine -f 1000 -n -f 2000 -n -f 1500

it would be a refreshing change to have.

Support default audio device

Since hardware vendors decided for us that we don't like the system bell, it would be great to have a way to beep via the default audio device.

If you want to keep beet simple for systems with a real bell, maybe you would consider having a separate binary that uses the system bell. If for some reason some options won't work with the default audio, it will still be fine for me.

Volume of speaker seems to be different on different systems

Hi,

We'd like to use beep for a small project, but noticed that the speaker volume isn't always as loud as we like to have it. Do you know if it is at all possible to change the volume of the PC speaker, or influence the volume of the sound in any way (eg. increasing the amplitude of the sound) ?

The problem is that in a noisy environment (eg. datacenter) the sound from some systems is barely noticeable.

Thanks in advance.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.