pax_global_header00006660000000000000000000000064134202330420014503gustar00rootroot0000000000000052 comment=9c4e5b3b6b2868b5ef1f42409fde60f0e629d0c1 beep-1.4.3/000077500000000000000000000000001342023304200124235ustar00rootroot00000000000000beep-1.4.3/.gitignore000066400000000000000000000007361342023304200144210ustar00rootroot00000000000000# Files that should not be tracked by Git # The compiled executable /beep /*.clang /*.gcc # Built sources /beep-usage.c # Build intermediates *.dep *.clang-o *.gcc-o *.o *.i *.s *.lst *.gcc-lst /beep.1 # The compressed man page /beep.1.gz # Built stuff /html/ # Test results /tests/*.actual.output.new /tests/*.actual.output /tests/*.output.actual.new /tests/*.output.actual /tests/*.actual.new /tests/*.actual /tests/*.output.new /tests/*.output # Misc results *.strace beep-1.4.3/90-pcspkr-beep.rules000066400000000000000000000003361342023304200161420ustar00rootroot00000000000000# Give write access to the PC speaker to the "beep" group so group members can run "beep" ACTION=="add", SUBSYSTEM=="input", ATTRS{name}=="PC Speaker", ENV{DEVNAME}!="", RUN+="/usr/bin/setfacl -m g:beep:w '$env{DEVNAME}'" beep-1.4.3/CHANGELOG000066400000000000000000000061601342023304200136400ustar00rootroot000000000000001.4.3 ----- - Only use -fcf-protection CFLAGS_gcc if actually supported on this platform 1.4.2 ----- - Improved man page and --help output - Cleaned signal handlers of all function calls - Use beep driver infrastructure (console and evdev drivers) - Abort on unhandled command line parameters - Use nanosleep(2) instead of usleep(3) 1.4.1 ----- - Safer signal handlers (safe_error_exit() without global variables). - Reduce accepted range of input numbers. 5 minute beeps should still be enough. 1.4.0 ----- - Fix CVE-2018-1000532 External Control of File Name or Path vulnerability in --device option - Fix CVE-2018-0492 race condition that allows local privilege escalation - Make /dev/input/by-path/platform-pcspkr-event-spkr the default device to use as the system administrator can allow access to that without needing any priviledge escalation risks via setuid or sudo. - Adapt --help output, beep.1 man page, README.md, INSTALL.md to reflect the new device use. - Add basic suite of tests. - Constrained a few integers to avoid integer overflows. - Only issue fallback '\a' type beeps if that '\a' actually goes to a tty device which can actually beep - Stop promoting floating point frequencies which no Kernel API can even use 1.3 --- - 8 years have passed! - Integrated a bunch of Gerfried Fuchs' changes maintained for the debian version for years and years - Added him to the CREDITS, too. - Support for devfs, and alternate console devices. - Warnings about multiply-specified frequency - Debug mode 1.2.2 ----- - Man pages now gzip -9 for better compression - Table of frequencies added to man page - Fix for platforms with unsigned chars - On ioctl() errors, beep will now do a printf("\a") so that, at very least, youget a beep. :) 1.2.1 ----- - fixed segfault when handling long options 1.2.0 ----- - added -n/--new support - so beep FINALLY handles multiple beeps on a single command line. - -f now takes decimal frequencies, not just whole numbers. 1.0.2 ----- - Added more common -V option, as companion to -v and --version - README now addresses the question of multiple beeps, and composing music with beep. 1.0.1 ----- - Fixed some outdated comments in the source, and a typo in the man page. 1.0.0 ----- - added a SIGINT handler, so Ctrl-C no longer leaves the speaker wailing forever - added -v/--version and -h/--help support - updated man page - this release is changed from 0.8 to 1.0.0, it's worthy of it. Feature complete and no outstanding bugs that I know of. 0.6.1 ----- - changed man page to gzip format (instead of bzip2) - updated man page and README to explain ioctl problems 0.6 --- - added -D option. Both -d and -D set inter-repetition delay, but -D instructs beep to delay even after the last beep, where -d delays only between beeps, and terminates immediately after last beep. - incorporated Rick Franchuk's idea of stdin hooks - dear god -c is annoying. - added a man page 0.5 --- - changed over from manually parsing command line parms to getopt() - changed atoi() calls into sscanf() calls, to get more meaningful error handling 0.4 --- - first usable - initial options supported: -f, -l, -d, -r beep-1.4.3/COPYING000066400000000000000000000432541342023304200134660ustar00rootroot00000000000000 GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Lesser General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) year name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. beep-1.4.3/CREDITS000066400000000000000000000047061342023304200134520ustar00rootroot00000000000000 > I (Johnathan Nightingale) handled the original coding, distribution, > maintenance, etc. > > Peter Tirsek (peter at tirsek dot com) filled me in on where the magical > fairy number comes from (see beep.c). He also tracked down the relevant > kernel code that causes the ioctl()s to die under certain conditions > (see the README or man page sections on ioctl). He is truly a wonderful > person. > > Andreas Hochsteger (e9625392 at student dot tuwien dot ac dot at) contributed > several useful little patches, and was my inspiration for the -d/-D > distinction. He's also thrown pointers my way about code packaging, which > are appreciated. > > Rick Franchuk (rickf at transpect dot net) came up with the idea of the -s and > -c stdin hooks. Since most people will be using beep to tell them when a new > line pops up in log, or mail, or what-have-you, this was quite clever of him > and though I really did mean to do it anyhow, he sent me the patch before I had > bothered to write it, so he gets the credit. :) > > Serge Winitzki (winitzki at erebus.phys.cwru.edu) suggested having beep take > floats for frequency, instead of int's. > > The guys at freshmeat.net really deserve a big ol whack of credit too, for > running a very cool site in general, and for running one so successfully that > my little 4k program generated literally hundreds of emails in reply. It gives > one a great sense of community to see such an overwhelming response. > > In particular, fryguy[at]freshmeat (Ryan Weaver) rocks supremely, for packaging > beep in RPM format, and maintaining said package until he decides not to. I > really did mean to make a spec for it myself, but hey, when freshmeat offers to > maintain your packages, you'd have to have a *real* good reason to say no. > > Most of all - and I write this nearly 10 years later, so I have the benefit of > history on my side here - I would like to thank Gerfried Fuchs, who has tirelessly > maintained beep in debian, along with a stack of patches, years after I stopped > hacking on it in earnest. He is amazingly dedicated, and has a new son whom we > would all be fortunate to have follow in his father's footsteps. Thanks to terom on Hacker News, Andrew Ayer, Richard Kettlewall, rain-1 on github, Jakub Wilk, and Benjamin Grange for their help with fixing CVE-2018-0492, CVE-2018-1000532, and the help fixing the fixes. Thanks to Hanno Böck for the report on possible integer overflows. Thanks to Stefan Helmert for the sig_atomic_t. beep-1.4.3/DEVELOPMENT.md000066400000000000000000000062421342023304200145330ustar00rootroot00000000000000beep development notes ====================== This file contains a number of notes, links and remarks which can be useful if you need to change `beep`. Testing ======= If you want to run the tests only for the executables compiled with clang, run $ make check COMPILERS=clang APIs ==== evdev API --------- The Linux kernel implements the input device event API in `drivers/input/misc/pcspkr.c` with `include/uapi/linux/input-event-codes.h` defining `EV_SND` as `0x12` and `SND_TONE` as 0x02. `include/uapi/linux/input.h` defines `EVIOCGSND(len)`, and there is documentation about `EV_SND` to be found in `Documentation/input/event-codes.rst` and `Documentation/input/input-programming.rst`. Console API ----------- The Linux kernel implements the console API in `drivers/tty/vt/vt_ioctl.c` with `include/uapi/linux/kd.h` defining `KIOCSOUND` to be `0x4B2F`. Fallback TTY '\a' API --------------------- If you print a '\a' (BEL) character to a TTY device stdout, that can sound some type of beep. Not with the desired frequency or duration or sequence, but at least there is a beep. Raspberry Pi ------------ The Raspberry Pi has no PC speaker hardware, but a few GPIO pins with PWM capability which root can access from userspace. Non-PC systems -------------- Non-PC systems like e.g. the Raspberry Pi and similar systems do not have PC beeper hardware, they have GPIO pins some of which are attached to PWM hardware which can be set to produce beeps. So if one properly attaches a loudspeaker or piezo buzzer to such a PWM pin (with a bunch more electrial components like capacitors, resistors, transistors where required), one has the hardware to produce beeps. This leaves one to sort out the software side of it, which gets us back to the issue that only root is allowed to touch the GPIO pins, but `beep` should also run as a non-root user without the potential for setuid or sudo facilitated security holes. Options: * Leave beeps to the root user only who can access the GPIO pins. * Add a priviledge `beep-daemon` to handle the beeping, and have a non-priviledge `beep` contact the beep daemon in some manner to do the actual beeping. * Use `AF_UNIX`/`SOCK_SEQPACKET` socket for some kind of to be agreed upon data structure for beeps. The `beep-daemon` or (better) someone like systemd who manages a `beep-daemon` can set up user and group access to the `AF_UNIX` socket. * Implementing a userspace input device driver ("uinput") compatible with the `EV_SND`/`SND_TONE` interface used by `/dev/input/by-path/platform-pcspkr-event-spkr`. Then the permission setup happens through `udev` rules, and `beep` can just work as normal (except it needs to find out the device name). As `libevdev` only allows one to create new uinput devices mimicking existing devices, we need to go directly to the kernel uinput API here to create a specifically pcspkr-like uinput device. TODO list --------- Post-1.4.0: * TODO: Go through all github.com forks of johnath/beep * TODO: Read up on signal(2). * TODO: Implement the uinput based beep-daemon for Raspberry Pi. beep-1.4.3/GNUmakefile000066400000000000000000000232201342023304200144740ustar00rootroot00000000000000######################################################################## # Installation directories ######################################################################## # We use GNU makefile conventions for directory names with one notable # exception: prefix is not /usr/local in order to keep the default # installation location for beep. PACKAGE_TARNAME = beep PACKAGE_VERSION = 1.4.3 DESTDIR= prefix=/usr exec_prefix=$(prefix) bindir=$(exec_prefix)/bin sbindir=$(exec_prefix)/sbin datarootdir=$(prefix)/share mandir=$(datarootdir)/man man1dir=$(mandir)/man1 docdir=$(datarootdir)/doc pkgdocdir=$(docdir)/$(PACKAGE_TARNAME) ######################################################################## # Tools ######################################################################## pathsearch = $(firstword $(wildcard $(addsuffix /$(1),$(subst :, ,$(PATH))))) # Avoid running GNU make builtin rules by mistake CC = false GZIP = $(call pathsearch,gzip) INSTALL = $(call pathsearch,install) PANDOC = $(call pathsearch,pandoc) SED = $(call pathsearch,sed) SLOCCOUNT = $(call pathsearch,sloccount) ######################################################################## # This needs to be the first rule ######################################################################## .PHONY: all all: all-local ######################################################################## # Variables to add to later ######################################################################## pkgdoc_DATA = ALL_PROGRAMS = bin_PROGRAMS = sbin_PROGRAMS = CLEANFILES = HTML_DATA = man1_DATA = pkgdoc_DATA = ######################################################################## # Define compilers and their flags ######################################################################## # We want accidental invocations of rules with $(CC) to fail CC = false # CPPFLAGS common to all compilers CPPFLAGS_COMMON = CPPFLAGS_COMMON += -DPACKAGE_TARNAME='"$(PACKAGE_TARNAME)"' CPPFLAGS_COMMON += -DPACKAGE_VERSION='"$(PACKAGE_VERSION)"' COMPILER_gcc = gcc LINKER_gcc = gcc CPPFLAGS_gcc = CFLAGS_gcc += -Wall -Wextra CFLAGS_gcc += -std=gnu99 -pedantic CFLAGS_gcc += -Werror CFLAGS_gcc += -O -gstabs CFLAGS_gcc += -Wa,-adhlns=$(@:-o=-lst) CFLAGS_gcc += -Werror=format-security CFLAGS_gcc += -Wp,-D_FORTIFY_SOURCE=2 CFLAGS_gcc += -Wp,-D_GLIBCXX_ASSERTIONS CFLAGS_gcc += -fstack-protector-strong CFLAGS_gcc += -fasynchronous-unwind-tables CFLAGS_gcc += -fstack-clash-protection ifeq (yes,$(shell if $(COMPILER_gcc) -fcf-protection -E -o null.o -c - < /dev/null > /dev/null 2>&1; then echo yes; else echo no; fi)) CFLAGS_gcc += -fcf-protection endif CFLAGS_gcc += -save-temps=obj LDFLAGS_gcc = LIBS_gcc = ifneq ($(call pathsearch,$(COMPILER_gcc)),) ifneq ($(COMPILER_gcc)),no) COMPILERS += gcc endif endif COMPILER_clang = clang LINKER_clang = clang CPPFLAGS_clang = CFLAGS_clang += -Wall -Wextra CFLAGS_clang += -Weverything CFLAGS_clang += -Wno-padded CFLAGS_clang += -std=gnu99 -pedantic CFLAGS_clang += -Werror CFLAGS_clang += -fsanitize=undefined CFLAGS_clang += -O -g LDFLAGS_clang = LIBS_clang = ifneq ($(call pathsearch,$(COMPILER_clang)),) ifneq ($(COMPILER_clang),no) COMPILERS += clang endif endif ######################################################################## # Detect libraries ######################################################################## ######################################################################## # Define executables and their flags ######################################################################## bin_PROGRAMS += beep beep_OBJS = beep_OBJS += beep.o beep_OBJS += beep-library.o beep_OBJS += beep-log.o beep_OBJS += beep-usage.o beep_OBJS += beep-drivers.o beep_OBJS += beep-driver-console.o beep_OBJS += beep-driver-evdev.o # beep_OBJS += beep-driver-noop.o beep_LIBS = beep-log.clang-o : CFLAGS_clang += -Wno-format-nonliteral # sbin_PROGRAMS += beep-foo # beep_foo_OBJS = # beep_foo_OBJS += beep.o # beep_foo_OBJS += beep-log.o # beep_foo_LIBS = # beep_foo_LIBS += -lm ######################################################################## # Built sources ######################################################################## CLEANFILES += beep-usage.c beep-usage.c: beep-usage.txt echo '/* Auto-generated from beep-usage.txt. Modify that file instead. */' > $@ echo '#include "beep-usage.h"' >> $@ echo 'char beep_usage[] =' >> $@ set -e; IFS=""; while read line; do \ echo " \"$${line}\\n\"" >> $@; \ done < $< echo ' ;' >> $@ ######################################################################## # Compile and Link rules including automatic dependency generation ######################################################################## # CALL: LINK_RULE define LINK_RULE ALL_PROGRAMS += $(2).$(1) $(2).$(1): $(patsubst %.o,%.$(1)-o,$($(3)_OBJS)) @: echo "LINK_RULE $$@: $$^" $(LINKER_$(1)) $(CFLAGS) $(CFLAGS_$(1)) $(LDFLAGS) $(LDFLAGS_$(1)) -o $$@ $$^ $($(3)_LIBS) $(LIBS_$(1)) $(LIBS) -include $$(patsubst %.o,%.$(1)-o.dep,$($(3)_OBJS)) endef # CALL: PER_COMPILER define PER_COMPILER $(foreach exec,$(bin_PROGRAMS) $(sbin_PROGRAMS),$(eval $(call LINK_RULE,$(1),$(exec),$(subst -,_,$(exec))))) %.$(1)-o: %.c $$(COMPILER_$(1)) $$(CPPFLAGS) $$(CPPFLAGS_COMMON) $$(CPPFLAGS_$(1)) $$(CFLAGS_COMMON) $$(CFLAGS) $$(CFLAGS_$(1)) -o $$@ -c $$< %.$(1)-o.dep: %.c $$(COMPILER_$(1)) $$(CPPFLAGS) $$(CPPFLAGS_COMMON) $$(CPPFLAGS_$(1)) $$(CFLAGS_COMMON) $$(CFLAGS) $$(CFLAGS_$(1)) -MM -MT "$$*.$(1)-o $$@ " $$< > $$@.tmp mv -f $$@.tmp $$@ endef $(foreach compiler,$(COMPILERS),$(eval $(call PER_COMPILER,$(compiler)))) # For each executable, take the first from COMPILERS to use %: $(firstword $(foreach comp,$(COMPILERS),%.$(comp))) cp -f $< $@ ######################################################################## # Generate doc and similar files ######################################################################## man1_DATA += beep.1.gz CLEANFILES += beep.1.gz CLEANFILES += beep.1 %.1: %.1.in $(SED) -e "s|[@]pkgdocdir@|$(pkgdocdir)|g" < $< > $@.tmp mv -f $@.tmp $@ %.1.gz: %.1 $(GZIP) --best -c < $< > $@ HTML_DATA += html/README.html HTML_DATA += html/INSTALL.html HTML_DATA += html/DEVELOPMENT.html HTML_DATA += html/PACKAGING.html HTML_DATA += html/PERMISSIONS.html .PHONY: html html: $(HTML_DATA) @mkdir -p html cp -f pandoc.css html/ html/%.html: %.md @mkdir -p html @if test -f $(PANDOC); then \ echo PANDOC $< -o $@; \ $(PANDOC) --from gfm --to html --standalone -M pagetitle="$$($(SED) -n 1p $<)" -M title="" -c pandoc.css $< -o $@; \ else \ echo "You need to install pandoc to generate the HTML files."; \ exit 1; \ fi pkgdoc_DATA += CHANGELOG pkgdoc_DATA += COPYING pkgdoc_DATA += CREDITS pkgdoc_DATA += README.md pkgdoc_DATA += PERMISSIONS.md ######################################################################## # Generic targets ######################################################################## .PHONY: all-local all-local: $(bin_PROGRAMS) $(sbin_PROGRAMS) $(ALL_PROGRAMS) $(man1_DATA) SLOC_SOURCES = SLOC_SOURCES += beep*.[ch] SLOC_SOURCES += gen-freq-table SLOC_SOURCES += tests/run-tests SLOC_SOURCES += tests/*.sh SLOC_SOURCES += GNUmakefile .PHONY: sloccount sloccount: @if test -e $(SLOCCOUNT); then \ $(SLOCCOUNT) --details $(SLOC_SOURCES); \ $(SLOCCOUNT) $(SLOC_SOURCES); \ else \ echo "sloccount not found"; \ fi SPLINT = splint SPLINT_FLAGS += -standard # SPLINT_FLAGS += -checks # SPLINT_FLAGS += -strict SPLINT_FLAGS += +posixstrictlib SPLINT_FLAGS += +gnuextensions SPLINT_FLAGS += -preproc SPLINT_FLAGS += -syntax SPLINT_FLAGS += -D__signed__=signed SPLINT_FLAGS += $(CPPFLAGS_COMMON) .PHONY: lint lint: $(SPLINT) $(SPLINT_FLAGS) beep*.c beep*.h .PHONY: check-targets check-targets: $(TARGETS) $(CHECK_TARGETS) .PHONY: check check: beep $(ALL_PROGRAMS) env PACKAGE_VERSION="${PACKAGE_VERSION}" \ /bin/bash tests/run-tests tests $(foreach compiler,$(COMPILERS),beep.$(compiler)) .PHONY: clean clean: rm -f $(bin_PROGRAMS) $(sbin_PROGRAMS) rm -f $(CLEANFILES) rm -f $(foreach comp,$(COMPILERS),*.$(comp) *.$(comp)-o) rm -f *.dep rm -f *.lst *.gcc-lst rm -f tests/*.new tests/*.output.actual rm -rf html rm -f *.o *.i *.s .PHONY: doc doc: $(pkgdoc_DATA) .PHONY: install install: all ifneq (,$(bin_PROGRAMS)) $(INSTALL) -m 0755 -d $(DESTDIR)$(bindir) $(INSTALL) -m 0755 -p $(bin_PROGRAMS) $(DESTDIR)$(bindir)/ endif ifneq (,$(sbin_PROGRAMS)) $(INSTALL) -m 0755 -d $(DESTDIR)$(sbindir) $(INSTALL) -m 0755 -p $(sbin_PROGRAMS) $(DESTDIR)$(sbindir)/ endif ifneq (,$(man1_DATA)) $(INSTALL) -m 0755 -d $(DESTDIR)$(man1dir) $(INSTALL) -m 0644 -p $(man1_DATA) $(DESTDIR)$(man1dir)/ endif ifneq (,$(pkgdoc_DATA)) $(INSTALL) -m 0755 -d $(DESTDIR)$(pkgdocdir) $(INSTALL) -m 0644 -p $(pkgdoc_DATA) $(DESTDIR)$(pkgdocdir)/ endif .PHONY: uninstall uninstall: for f in $(bin_PROGRAMS); do rm -f "$(DESTDIR)$(bindir)/$$f"; done for f in $(sbin_PROGRAMS); do rm -f "$(DESTDIR)$(sbindir)/$$f"; done for f in $(man1_DATA); do rm -f "$(DESTDIR)$(man1dir)/$$f"; done for f in $(pkgdoc_DATA); do rm -f "$(DESTDIR)$(pkgdocdir)/$$f"; done ######################################################################## # Development helpers ######################################################################## # List all references to documentation in the git repo .PHONY: refs refs: git grep -E '((http|https)://[a-zA-Z0-9\._/-]+|([A-Z]+\.md)|([a-zA-Z][a-zA-Z0-9_-]+\([0-9]+\)))' # List all TODOs and FIXMEs in the git repo .PHONY: todo todo: git grep -E '(TODO|FIXME):' ######################################################################## # End of GNUmakefile ######################################################################## beep-1.4.3/INSTALL.md000066400000000000000000000070001342023304200140500ustar00rootroot00000000000000Installing beep =============== This document describes how to install `beep` from sources and how to set up the system afterwards. If you are using `beep` as shipped in a distribution package, the package should have done most of those steps for you. The one exception should be adding users to the `beep` group. Compile and Install =================== The easy way is $ make $ make install By default, it'll put the executable `beep` in `/usr/bin`. If you don't like this, change the common variables as appropriate: $ make prefix=$HOME/.local $ make prefix=$HOME/.local install or $ make $ make DESTDIR=$PWD/__installroot install For the complete list of those variables, see the top of `GNUmakefile`. System configuration ==================== * Add a line alias platform:pcspkr pcspkr to a file like e.g. `/etc/modprobe.d/pcspkr-beep.conf`. After udev rule setup, run `modprobe pcspkr.ko` to load the driver without a reboot, creating the `/dev/input/by-path/platform-pcspkr-event-spkr` evdev device with the desired permissions. Device permission setup to allow non-root users to beep ======================================================= If you want to give all users in the `wheel` group write access to the input event device `/dev/input/by-path/platform-pcspkr-event-spkr`, add a `udev` rule like this to `/etc/udev/rules.d/90-pcspkr-beep.rules`: # Give write access to the PC speaker to "wheel" group so they can run "beep" ACTION=="add", SUBSYSTEM=="input", ATTRS{name}=="PC Speaker", ENV{DEVNAME}!="", RUN+="/usr/bin/setfacl -m g:wheel:w '$env{DEVNAME}'" For non-`wheel` users, set up a new system group `beep`: [root@host ~]# groupadd -r beep [root@host ~]# Add a `udev` rule to `/etc/udev/rules.d/90-pcspkr-beep.rules` which allows the `beep` group write access to the input event device `/dev/input/by-path/platform-pcspkr-event-spkr`: # Give write access to the PC speaker to "beep" group so they can run "beep" ACTION=="add", SUBSYSTEM=="input", ATTRS{name}=="PC Speaker", ENV{DEVNAME}!="", RUN+="/usr/bin/setfacl -m g:beep:w '$env{DEVNAME}'" You might have to unload and reload the `pcspkr.ko´ module to re-add the device so that the new rule is invoked: [root@host ~]# modprobe -r pcspkr; sleep 2; modprobe pcspkr [root@host ~]# Check that the device has the desired permissions with [root@host ~]# ls -lH /dev/input/by-path/platform-pcspkr-event-spkr crw-rw----+ 1 root input 13, 84 29. Dez 07:35 /dev/input/by-path/platform-pcspkr-event-spkr [root@host ~]# getfacl /dev/input/by-path/platform-pcspkr-event-spkr getfacl: Removing leading '/' from absolute path names # file: dev/input/by-path/platform-pcspkr-event-spkr # owner: root # group: input user::rw- group::rw- group:beep:-w- group:wheel:-w- mask::rw- other::--- [root@host ~]# Now add the users who are allowed to use beep to the `beep` group: [root@host ~]# usermod jane -a -G beep [root@host ~]# After having user `jane` log out (and after killing user `jane`'s running `tmux` instances, killing `system --user` sessions for user `jane`, or just plain rebooting), user `jane` can log back in and check whether she now a `beep` group member: [jane@host ~]$ id uid=1000(jane) gid=1000(jane) groups=1000(jane),10(wheel),942(beep) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 [jane@host ~]$ ./beep -f 220 -n -f 275 -n -f 330 -n -f 440 -n -f 550 -n -f 660 -n -f 880 [jane@host ~]$ beep-1.4.3/PACKAGING.md000066400000000000000000000131201342023304200142260ustar00rootroot00000000000000Packaging beep for Linux distributions ====================================== This file contains a number of ideas and suggestions which might come in helpful in case you are packaging `beep` for a Linux distribution. Building and installing ----------------------- The building and installing during a package build can be achieved with make make DESTDIR=/path/to/package-root install If you want to replace the compiler flags, run `make` like e.g. make CFLAGS_gcc="-O -gstabs,foo" CFLAGS_clang="" You can also keep `beep`'s default flags and just add your own with `CFLAGS`. The same principle applies for `CPPFLAGS`, `LDFLAGS`, and `LIBS`. If the system you are building on has both `gcc` and `clang`, the `beep` buildsystem will compile with both by default and choose the first one from its COMPILERS make variable, which you can override from the command line. make COMPILERS="clang gcc" Or you can specifically disable one of the compilers to only build one variant: make COMPILER_gcc=no If you need to set any of the `*dir` variables like `mandir` on the `make` command line, please set them both for the build step (`make`) and the install step (`make install`). For example, you might want to make pkgdocdir='$(docdir)/$(PACKAGE_TARNAME)-$(PACKAGE_VERSION)' make pkgdocdir='$(docdir)/$(PACKAGE_TARNAME)-$(PACKAGE_VERSION)' DESTDIR=/path/to/package-root install Files to install for beep ------------------------- ### User facing files * `/usr/bin/beep` The `beep` executable. * `/usr/share/man/man1/beep1.gz` Man page for the `beep` executable. ### Documentation files * `/usr/share/doc/beep/README.md` * `/usr/share/doc/beep/PERMISSIONS.md` Change or replace this file as necessary for your distribution to give package users and system administrators the information they need to successfully set up device permissions. * `/usr/share/doc/beep/CHANGELOG` * `/usr/share/doc/beep/COPYING` * `/usr/share/doc/beep/CREDITS` The files `INSTALL.md`, `DEVELOPMENT.md`, `PACKAGING.md` are not useful for binary packages. They make most sense for source trees. ### System setup including permissions * `/etc/modprobe.d/pcspkr-beep.conf` When the system administrator uncomments the `alias` line, this tells the system to load the `pcspkr.ko` kernel module. Without `pcspkr.ko`, there will be no sound from the PC speaker at all. Use, change, replace as is fitting for your distribution. If you want to use the default permission setup with a `beep` group and the system administrator adding users to the `beep` group, install and do the following: * `/etc/udev/rules.d/90-pcspkr-beep.rules` Sets up write access to the PC speaker device for group `beep` or whatever else the system administrator has set it up to do. Requires the `pcspkr.ko` kernel module to be loaded. Use, change, replace as is fitting for your distribution. * Upon installing the package, a `beep` user group needs to be created with something like # getent group beep >/dev/null || groupadd -r beep inside the package installation scripts. * `/usr/share/doc/beep/PERMISSIONS.md` This describes to system administrators how to add users to the `beep` group and to users how to check they actually are members of the `beep` group. Use, change, replace as is fitting for your distribution. All files installed into `/etc` are config files which the system administrator may change and expect to not be overwritten with package updates. Architectures ============= PC platforms ------------ `beep` was written for the x86 platform, and works on both 32bit and 64bit x86 platforms. Non-PC platforms implementing the `EV_SND`/`SND_TONE` interface --------------------------------------------------------------- From a cursory glance through the Linux kernel source code, there appear to be a number of devices implementing the same `EV_SND`/`SND_TONE` evdev interface `pcspkr.ko` implements, like e.g. `m68kspkr` or `sparcspkr`. It would be interesting to know on which non-PC platforms `beep` actually makes sense. The S/390 e.g. probably does not belong to the systems where beeper hardware is to be expected. Platforms without `pcspkr.ko` or other `EV_SND`/`SND_TONE` devices ------------------------------------------------------------------ For platforms *without* a PC speaker, packaging beep only makes sense if there is both hardware support for beeping, and software support for that hardware. At this time, `beep` provides no software support for any of those platforms. Packages ======== This is a list of links to distribution packages: * [archlinux](https://www.archlinux.org/) https://www.archlinux.org/packages/extra/x86_64/beep/ https://git.archlinux.org/svntogit/packages.git/tree/trunk?h=packages/beep * [Debian](https://www.debian.org/) https://sources.debian.org/src/beep/ * [Fedora](https://getfedora.org/) https://src.fedoraproject.org/rpms/beep * [Gentoo](https://www.gentoo.org/) https://packages.gentoo.org/packages/app-misc/beep https://gitweb.gentoo.org/repo/gentoo.git/tree/app-misc/beep * [OpenWRT](https://openwrt.org/) https://github.com/openwrt/packages/tree/master/utils/beep * [openSUSE](https://www.opensuse.org/) https://software.opensuse.org/package/beep https://build.opensuse.org/package/show/home%3AChristianMauderer%3Aopensuse-installations/beep * [Raspbian](https://www.raspbian.org/) Sources: See Debian. * [Ubuntu](https://www.ubuntu.com/) http://packages.ubuntu.com/src:beep Sources: See Debian. beep-1.4.3/PERMISSIONS.md000066400000000000000000000016441342023304200145650ustar00rootroot00000000000000Permission setup for beep ========================= The way to regulate permissions to the speaker device suggested by the `beep` package is to have the system administrator add all users who should be able to run beep to the `beep` group. Add user to `beep` group ------------------------ To add user `jane` to the `beep` group, the system administrator has to run a command like # usermod jane -a -G beep After having user `jane` log out (and after killing user `jane`'s running `tmux` instances, killing `system --user` sessions for user `jane`, or just plain rebooting), user `jane` can log back in and check whether she now a `beep` group member: [jane@host ~]$ id uid=1000(jane) gid=1000(jane) groups=1000(jane),10(wheel),942(beep) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 [jane@host ~]$ ./beep -f 220 -n -f 275 -n -f 330 -n -f 440 -n -f 550 -n -f 660 -n -f 880 [jane@host ~]$ beep-1.4.3/README.md000066400000000000000000000116541342023304200137110ustar00rootroot00000000000000beep - beep the PC loudspeaker on Linux ======================================= `beep` allows you to have the PC speaker issue beeps and beep patterns with given frequencies, durations, and spacing. Beginning in 2019, this version of beep can be found at [github.com/spkr-beep/beep/](https://github.com/spkr-beep/beep/). Please report bugs and other problems at [github.com/spkr-beep/beep/issues](https://github.com/spkr-beep/beep/issues). This version of`beep` is based on Johnathan Nightingales' original `beep` from [github.com/johnath/beep/](https://github.com/johnath/beep/) and [johnath.com/beep/](http://johnath.com/beep/) which was maintained from around 2000 to around 2013. What beep does -------------- * Parse the command line arguments * Find a suitable device file and API to use on it. * Set up signal handlers to silence the beeping in case beep is interrupted or killed before it has a chance to silence the PC speaker again. * Depending on the command line arguments, either * beep in the frequencies, sequencing and timing given on the command line until the sequence has finished. * when used in a pipe, beep for every character or line passing through the pipe until said pipe is finished. How beep works internally ========================= The evdev API ------------- The evdev API uses `write(2)` to write `EV_SND`/`SND_TONE` input_event data to the `/dev/input/by-path/platform-pcspkr-event-spkr` device file. The system administrator can set up normal file permissions on the device file to allow beeping access for certain users and groups. See `INSTALL.md` for more detailed elaborations. The console API --------------- In order to be allowed to run the `KIOCSOUND` `ioctl(2)` of the classical console API, the Linux kernel insists you must either be root or own the current TTY (e.g. non-root user logged in on `/dev/tty4`). The history of beep =================== In late 2018, while trying to come up with a fix for CVE-2018-1000532 for the Fedora package, Hans Ulrich Niedermann had to find find out exactly how `beep` works, and found out that the API to use in this day and age (the evdev API) was not even in available `beep`'s default configuration, or documented with the proper device name. So a few bits in the code had to be changed, a lot of documentation had to be changed, and eventually the changes had accumulated to so much that the result could not really be called `beep-1.3` any more. However, with the last repository activity in early 2013, Jonathan's github beep repository had been basically unmaintained for almost 6 years, so Hans Ulrich created https://github.com/spkr-beep/beep/ as a new home for beep. All contributors are welcome there, old and new. This following part has been taken from the original `README` by original `beep` author Johnathan Nightingale where he tells how `beep` came about. > 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: > > `johnath@johnath.com` > 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 > > > 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 > beep > 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-1.4.3/beep-driver-console.c000066400000000000000000000074251342023304200164430ustar00rootroot00000000000000/* beep-driver-evdev.c - implement the beep console driver * Copyright (C) 2000-2010 Johnathan Nightingale * Copyright (C) 2010-2013 Gerfried Fuchs * Copyright (C) 2019 Hans Ulrich Niedermann * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include #include #include #include #include "beep-driver-console.h" #include "beep-library.h" #include "beep-log.h" /* Use PIT_TICK_RATE value from the kernel. */ #ifndef CLOCK_TICK_RATE #define CLOCK_TICK_RATE 1193182UL #endif static int open_checked_device(const char *const device_name) { const int fd = open_checked_char_device(device_name); if (fd == -1) { return -1; } if (-1 == ioctl(fd, KIOCSOUND, 0)) { log_verbose("console: %d does not implement KIOCSOUND API", fd); return -1; } return fd; } static bool driver_detect(beep_driver *driver, const char *console_device) { if (console_device) { log_verbose("console driver_detect %p %s", (void *)driver, console_device); } else { log_verbose("console driver_detect %p %p", (void *)driver, (const void *)console_device); } if (console_device) { const int fd = open_checked_device(console_device); if (fd >= 0) { driver->device_fd = fd; driver->device_name = console_device; return true; } } else { static const char *const console_device_list[] = { "/dev/tty0", "/dev/vc/0", }; for (size_t i=0; i<(sizeof(console_device_list)/sizeof(console_device_list[0])); ++i) { const char *const device_name = console_device_list[i]; const int fd = open_checked_device(device_name); if (-1 != fd) { driver->device_fd = fd; driver->device_name = device_name; return true; } } } return false; } static void driver_init(beep_driver *driver) { log_verbose("console driver_init %p", (void *)driver); } static void driver_fini(beep_driver *driver) { log_verbose("console driver_fini %p", (void *)driver); close(driver->device_fd); driver->device_fd = -1; } static void driver_begin_tone(beep_driver *driver, const uint16_t freq) { log_verbose("console driver_begin_tone %p %u", (void *)driver, freq); const uintptr_t argp = ((freq != 0) ? (CLOCK_TICK_RATE/freq) : freq) & 0xffff; if (-1 == ioctl(driver->device_fd, KIOCSOUND, argp)) { /* If we cannot use the sound API, we cannot silence the sound either */ safe_error_exit("ioctl KIOCSOUND"); } } static void driver_end_tone(beep_driver *driver) { log_verbose("console driver_end_tone %p", (void *)driver); if (-1 == ioctl(driver->device_fd, KIOCSOUND, 0)) { safe_error_exit("ioctl KIOCSOUND"); } } beep_driver console_driver = { "console", NULL, driver_detect, driver_init, driver_fini, driver_begin_tone, driver_end_tone, 0, NULL }; /* * Local Variables: * c-basic-offset: 4 * indent-tabs-mode: nil * End: */ beep-1.4.3/beep-driver-console.h000066400000000000000000000020661342023304200164440ustar00rootroot00000000000000/* beep-driver-console.h - interface to the beep console driver * Copyright (C) 2019 Hans Ulrich Niedermann * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef BEEP_DRIVER_CONSOLE_H #define BEEP_DRIVER_CONSOLE_H #include "beep-driver.h" extern beep_driver console_driver; #endif /* BEEP_DRIVER_CONSOLE_H */ /* * Local Variables: * c-basic-offset: 4 * indent-tabs-mode: nil * End: */ beep-1.4.3/beep-driver-evdev.c000066400000000000000000000072241342023304200161070ustar00rootroot00000000000000/* beep-driver-evdev.c - implement the beep evdev driver * Copyright (C) 2000-2010 Johnathan Nightingale * Copyright (C) 2010-2013 Gerfried Fuchs * Copyright (C) 2019 Hans Ulrich Niedermann * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include #include #include #include #include #include #include #include #include "beep-driver-evdev.h" #include "beep-library.h" #include "beep-log.h" static int open_checked_device(const char *const device_name) { const int fd = open_checked_char_device(device_name); if (fd == -1) { return -1; } if (-1 == ioctl(fd, EVIOCGSND(0))) { log_verbose("evdev: %d does not implement EV_SND API", fd); return -1; } return fd; } static bool driver_detect(beep_driver *driver, const char *console_device) { if (console_device) { log_verbose("evdev driver_detect %p %s", (void *)driver, console_device); } else { log_verbose("evdev driver_detect %p %p", (void *)driver, (const void *)console_device); } if (console_device) { const int fd = open_checked_device(console_device); if (fd >= 0) { driver->device_fd = fd; driver->device_name = console_device; return true; } } else { static const char *const default_name = "/dev/input/by-path/platform-pcspkr-event-spkr"; const int fd = open_checked_device(default_name); if (fd >= 0) { driver->device_fd = fd; driver->device_name = default_name; return true; } } return false; } static void driver_init(beep_driver *driver) { log_verbose("evdev driver_init %p", (void *)driver); } static void driver_fini(beep_driver *driver) { log_verbose("evdev driver_fini %p", (void *)driver); close(driver->device_fd); driver->device_fd = -1; } static void driver_begin_tone(beep_driver *driver, const uint16_t freq) { log_verbose("evdev driver_begin_tone %p %u", (void *)driver, freq); struct input_event e; bzero(&e, sizeof(e)); e.type = EV_SND; e.code = SND_TONE; e.value = freq; if (sizeof(e) != write(driver->device_fd, &e, sizeof(e))) { /* If we cannot use the sound API, we cannot silence the sound either */ safe_error_exit("write EV_SND"); } } static void driver_end_tone(beep_driver *driver) { log_verbose("evdev driver_end_tone %p", (void *)driver); struct input_event e; bzero(&e, sizeof(e)); e.type = EV_SND; e.code = SND_TONE; e.value = 0; if (sizeof(e) != write(driver->device_fd, &e, sizeof(e))) { safe_error_exit("write EV_SND"); } } beep_driver evdev_driver = { "evdev", NULL, driver_detect, driver_init, driver_fini, driver_begin_tone, driver_end_tone, 0, NULL }; /* * Local Variables: * c-basic-offset: 4 * indent-tabs-mode: nil * End: */ beep-1.4.3/beep-driver-evdev.h000066400000000000000000000020511342023304200161050ustar00rootroot00000000000000/* beep-driver-evdev.h - interface to the beep evdev driver * Copyright (C) 2019 Hans Ulrich Niedermann * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef BEEP_DRIVER_EVDEV_H #define BEEP_DRIVER_EVDEV_H #include "beep-driver.h" extern beep_driver evdev_driver; #endif /* BEEP_DRIVER_EVDEV_H */ /* * Local Variables: * c-basic-offset: 4 * indent-tabs-mode: nil * End: */ beep-1.4.3/beep-driver-noop.c000066400000000000000000000037331342023304200157520ustar00rootroot00000000000000/* beep-driver-noop.c - implement the beep noop driver * Copyright (C) 2019 Hans Ulrich Niedermann * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include #include "beep-driver-noop.h" #include "beep-log.h" static bool driver_detect(beep_driver *driver, const char *const console_device) { if (console_device) { log_verbose("noop driver_detect %p %s", (void *)driver, console_device); } else { log_verbose("noop driver_detect %p %p", (void *)driver, (const void *)console_device); } return false; } static void driver_init(beep_driver *driver) { log_verbose("noop driver_init %p", (void *)driver); } static void driver_fini(beep_driver *driver) { log_verbose("noop driver_fini %p", (void *)driver); } static void driver_begin_tone(beep_driver *driver, const uint16_t freq) { log_verbose("noop driver_begin_tone %p %u", (void *)driver, freq); } static void driver_end_tone(beep_driver *driver) { log_verbose("noop driver_end_tone %p", (void *)driver); } beep_driver noop_driver = { "noop", NULL, driver_detect, driver_init, driver_fini, driver_begin_tone, driver_end_tone, 0, NULL }; /* * Local Variables: * c-basic-offset: 4 * indent-tabs-mode: nil * End: */ beep-1.4.3/beep-driver-noop.h000066400000000000000000000020441342023304200157510ustar00rootroot00000000000000/* beep-driver-noop.h - interface to the beep noop driver * Copyright (C) 2019 Hans Ulrich Niedermann * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef BEEP_DRIVER_NOOP_H #define BEEP_DRIVER_NOOP_H #include "beep-driver.h" extern beep_driver noop_driver; #endif /* BEEP_DRIVER_NOOP_H */ /* * Local Variables: * c-basic-offset: 4 * indent-tabs-mode: nil * End: */ beep-1.4.3/beep-driver.h000066400000000000000000000037301342023304200150030ustar00rootroot00000000000000/* beep-driver.h - the interface all beep drivers implement * Copyright (C) 2019 Hans Ulrich Niedermann * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef BEEP_DRIVER_H #define BEEP_DRIVER_H #include #include typedef struct _beep_driver beep_driver; typedef bool (*beep_driver_detect_func) (beep_driver *driver, const char *console_device); typedef void (*beep_driver_init_func) (beep_driver *driver); typedef void (*beep_driver_fini_func) (beep_driver *driver); typedef void (*beep_driver_begin_tone_func) (beep_driver *driver, const uint16_t freq); typedef void (*beep_driver_end_tone_func) (beep_driver *driver); struct _beep_driver { char *name; beep_driver *next; beep_driver_detect_func detect; beep_driver_init_func init; beep_driver_fini_func fini; beep_driver_begin_tone_func begin_tone; beep_driver_end_tone_func end_tone; /* As long as all drivers need these data items, we do not need to * hide them in the driver implementation. */ int device_fd; const char *device_name; }; #endif /* BEEP_DRIVER_H */ /* * Local Variables: * c-basic-offset: 4 * indent-tabs-mode: nil * End: */ beep-1.4.3/beep-drivers.c000066400000000000000000000036561342023304200151700ustar00rootroot00000000000000/* beep-drivers.h - interface to the beep driver infrastructure * Copyright (C) 2019 Hans Ulrich Niedermann * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include #include "beep-drivers.h" #include "beep-log.h" static beep_driver *first_driver = NULL; void beep_drivers_register(beep_driver *driver) { log_verbose("beep_drivers_register %p (%s)", (void *) driver, driver->name); if (first_driver) { driver->next = first_driver; first_driver = driver; } else { driver->next = NULL; first_driver = driver; } } beep_driver *beep_drivers_detect(const char *const console_device) { for (beep_driver *driver = first_driver; driver; driver=driver->next) { if (driver->detect(driver, console_device)) { return driver; } } return NULL; } void beep_drivers_init(beep_driver *driver) { driver->init(driver); } void beep_drivers_fini(beep_driver *driver) { driver->fini(driver); } void beep_drivers_begin_tone(beep_driver *driver, const uint16_t freq) { driver->begin_tone(driver, freq); } void beep_drivers_end_tone(beep_driver *driver) { driver->end_tone(driver); } /* * Local Variables: * c-basic-offset: 4 * indent-tabs-mode: nil * End: */ beep-1.4.3/beep-drivers.h000066400000000000000000000027621342023304200151720ustar00rootroot00000000000000/* beep-drivers.c - implement the beep driver infrastructure * Copyright (C) 2019 Hans Ulrich Niedermann * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef BEEP_DRIVERS_H #define BEEP_DRIVERS_H #include "beep-driver.h" void beep_drivers_register(beep_driver *driver) __attribute__(( nonnull(1) )); beep_driver *beep_drivers_detect(const char *const console_device); void beep_drivers_init(beep_driver *driver) __attribute__(( nonnull(1) )); void beep_drivers_fini(beep_driver *driver) __attribute__(( nonnull(1) )); void beep_drivers_begin_tone(beep_driver *driver, const uint16_t freq) __attribute__(( nonnull(1) )); void beep_drivers_end_tone(beep_driver *driver) __attribute__(( nonnull(1) )); #endif /* BEEP_DRIVERS_H */ /* * Local Variables: * c-basic-offset: 4 * indent-tabs-mode: nil * End: */ beep-1.4.3/beep-library.c000066400000000000000000000060071342023304200151470ustar00rootroot00000000000000/* beep-library.c - library of miscellaneous functions * Copyright (C) 2019 Hans Ulrich Niedermann * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include #include #include #include #include #include #include #include #include "beep-library.h" #include "beep-log.h" int open_checked_char_device(const char *const device_name) { struct stat sb; if (-1 == stat(device_name, &sb)) { log_verbose("b-lib: could not stat(2) %s: %s", device_name, strerror(errno)); return -1; } if (!S_ISCHR(sb.st_mode)) { log_verbose("b-lib: %s is not a character device", device_name); return -1; } const int fd = open(device_name, O_WRONLY); if (fd == -1) { log_verbose("b-lib: could not open(2) %s: %s", device_name, strerror(errno)); return -1; } log_verbose("b-lib: opened %s as %d", device_name, fd); if (-1 == fstat(fd, &sb)) { log_verbose("b-lib: could not fstat(2) %d: %s", fd, strerror(errno)); return -1; } if (!S_ISCHR(sb.st_mode)) { log_verbose("b-lib: %d is not a character device", fd); return -1; } return fd; } /* We do not know for certain whether perror does strange things with * global variables or malloc/free inside its code. */ void safe_error_exit(const char *const msg) { const int saved_errno = errno; char strerr_buf[128]; const int ret = strerror_r(saved_errno, strerr_buf, sizeof(strerr_buf)); if (ret != 0) { if (write(STDERR_FILENO, "strerror_r error\n", 0+0+0+0+strlen("strerror_r error\n"))) { /* ignore al write errors */ } _exit(EXIT_FAILURE); } const size_t msglen = strlen(msg); const size_t errlen = strlen(strerr_buf); if (write(STDERR_FILENO, msg, msglen)) { /* ignore al write errors */ } if (write(STDERR_FILENO, ": ", 2)) { /* ignore al write errors */ } if (write(STDERR_FILENO, strerr_buf, errlen)) { /* ignore al write errors */ } if (write(STDERR_FILENO, "\n", 1)) { /* ignore al write errors */ } _exit(EXIT_FAILURE); } /* * Local Variables: * c-basic-offset: 4 * indent-tabs-mode: nil * End: */ beep-1.4.3/beep-library.h000066400000000000000000000022401342023304200151470ustar00rootroot00000000000000/* beep-library.h - library of miscellaneous macros and functions * Copyright (C) 2019 Hans Ulrich Niedermann * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef BEEP_LIBRARY_H #define BEEP_LIBRARY_H int open_checked_char_device(const char *const device_name) __attribute__(( nonnull(1) )); void safe_error_exit(const char *const msg) __attribute__(( nonnull(1), noreturn )); #endif /* BEEP_LIBRARY_H */ /* * Local Variables: * c-basic-offset: 4 * indent-tabs-mode: nil * End: */ beep-1.4.3/beep-log.c000066400000000000000000000102071342023304200142610ustar00rootroot00000000000000/* beep-log.c - implement logging and message output * Copyright (C) 2018-2019 Hans Ulrich Niedermann * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include #include #include #include "beep-log.h" int log_level = 0; const char *progname = "beep-log"; /** beep-log internal function to actually print a message */ static void log_internal_vf(const char *levelstr, const char *const format, va_list args) __attribute__ ((nonnull (1,2))); static void log_internal_vf(const char *levelstr, const char *const format, va_list args) { fprintf(stdout, "%s: %s: ", progname, levelstr); vfprintf(stdout, format, args); fputc('\n', stdout); } void log_output(const char *const format, ...) { va_list args; va_start(args, format); vfprintf(stdout, format, args); va_end(args); } void log_error(const char *const format, ...) { va_list args; va_start(args, format); log_internal_vf("Error", format, args); va_end(args); } void log_warning(const char *const format, ...) { va_list args; va_start(args, format); log_internal_vf("Warning", format, args); va_end(args); } void log_verbose(const char *const format, ...) { va_list args; if (log_level > 0) { va_start(args, format); log_internal_vf("Verbose", format, args); va_end(args); } } /** Log a range of data */ void log_data(const void *const buf, const size_t start_ofs, const size_t size) { if (log_level <= 1) { return; } const unsigned char *const ucbuf = buf; static const char hexchar[] = "0123456789abcdef"; char linebuf[80] = "0000 __ __ __ __ __ __ __ __-__ __ __ __ __ __ __ __ ........-........"; for (size_t line_ofs=0, remaining=size; line_ofs>12) & 0xf]; linebuf[1] = hexchar[(line_ofs>> 8) & 0xf]; linebuf[2] = hexchar[(line_ofs>> 4) & 0xf]; linebuf[3] = hexchar[(line_ofs>> 0) & 0xf]; const size_t line_cols = (remaining<16)? remaining : 16; for (size_t col_ofs=0; col_ofs> 4) & 0x0f]; const char hex_lo = hexchar[(ch >> 0) & 0x0f]; linebuf[6+3*col_ofs+0] = hex_hi; linebuf[6+3*col_ofs+1] = hex_lo; linebuf[6+3*16+1+col_ofs+(col_ofs/8)] = ((0x20 <= ch) && (ch <= 0x7f)) ? (char)ch : '.'; } for (size_t col_ofs=line_cols; col_ofs<16; ++col_ofs) { linebuf[6+3*col_ofs+0] = ' '; linebuf[6+3*col_ofs+1] = ' '; linebuf[6+3*16+1+col_ofs+(col_ofs/8)] = ' '; } if (line_cols <= 8) { linebuf[6+3*8-1] = ' '; linebuf[6+3*16+1+8] = ' '; } fprintf(stdout, "%s: %s: %s\n", progname, "Data", linebuf); } } void log_init(const int argc, char *const argv[]) { /* if argv[0] is "./foo/bar/beep", set progname to "beep" */ if (argc >= 1) { const char *last_slash = strrchr(argv[0], '/'); if (last_slash) { const char *post_last_slash = last_slash+1; if (post_last_slash) { progname = post_last_slash; } } else { progname = argv[0]; } } } /* * Local Variables: * c-basic-offset: 4 * indent-tabs-mode: nil * End: */ beep-1.4.3/beep-log.h000066400000000000000000000043411342023304200142700ustar00rootroot00000000000000/* beep-log.h - interface to logging and message output * Copyright (C) 2018-2019 Hans Ulrich Niedermann * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef BEEP_LOG_H #define BEEP_LOG_H /** Currently active log level. * * Default is 0. Values greater than 0 are for verbose output. */ extern int log_level; /** Program name to use in log messages. * * Set this first thing in main(). Either just set it to some constant * string, or run log_init() to set this up from the non-path part of * argv[0]. */ extern const char *progname; /** Write a standard message */ void log_output(const char *const format, ...) __attribute__ ((nonnull (1))) __attribute__ ((format (printf, 1, 2))); /** Log an error message */ void log_error(const char *const format, ...) __attribute__ ((nonnull (1))) __attribute__ ((format (printf, 1, 2))); /** Log a warning message */ void log_warning(const char *const format, ...) __attribute__ ((nonnull (1))) __attribute__ ((format (printf, 1, 2))); /** Log a verbose message */ void log_verbose(const char *const format, ...) __attribute__ ((nonnull (1))) __attribute__ ((format (printf, 1, 2))); /** Log a range of data */ void log_data(const void *const buf, const size_t start_ofs, const size_t size) __attribute__ ((nonnull (1))); /** Initialize the log message prefix from the non-path part of argv[0]. */ void log_init(const int argc, char *const argv[]) __attribute__ ((nonnull (2))); #endif /* BEEP_LOG_H */ /* * Local Variables: * c-basic-offset: 4 * indent-tabs-mode: nil * End: */ beep-1.4.3/beep-usage.h000066400000000000000000000016401342023304200146120ustar00rootroot00000000000000/* beep-usage.h - interface to beep usage message string * Copyright (C) 2018-2019 Hans Ulrich Niedermann * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef BEEP_USAGE_H #define BEEP_USAGE_H extern char beep_usage[]; #endif /* BEEP_USAGE_H */ beep-1.4.3/beep-usage.txt000066400000000000000000000027141342023304200152050ustar00rootroot00000000000000Usage: beep [--verbose|--debug] [-e DEVICE] [-f FREQ_Hz] [-l LEN_ms] [-r REPS] [<-d|-D> DELAY_ms] [-s] [-c] beep [OPTIONS] [-n|--new TONE_OPTS...] beep [-h|--help] beep [-v|-V|--version] Beep the PC speaker in a number of ways. Options: Information options: -h, --help print this usage information and exit -V, -v, --version print program version information and exit Global options: -e, --device=DEVICE set the device to output the beeps to (see beep(1) man page) --debug, --verbose make program output more verbose Tone options: -f FREQ_Hz frequency of the tone in Hertz (Hz) -l LENGTH_ms length of the tone in milliseconds (ms) -d DELAY_ms delay between repetitions of the tone *without* delay after last repetition of the tone -D DELAY_ms delay between repetitions of the tone *with* delay after last repetition of the tone -r REPS number of repetitions of the last tone -n, --new start a new tone -s read text from stdin and write it through to stdout, beeping the last defined tone for every newline in the text, until EOF in stdin -c like -s, but beep for every character in the text Exit status: 0 if OK non-0 if any problems occured More documentation is available in the beep(1) man page via: man 1 beep beep-1.4.3/beep.1.in000066400000000000000000000240671342023304200140360ustar00rootroot00000000000000.\" The beep(1) man page .\" .\" This man page has been rewritten adhering to the following .\" documentation: man(7), man-pages(7), tbl(1) .\" .TH BEEP 1 "2019\-01\-11" "Linux" "User commands" .\" .\" ==================================================================== .\" .SH NAME beep \- beep the pc speaker any number of ways .\" .\" ==================================================================== .\" .SH SYNOPSIS .B beep .RB [\| GLOBALS \|] .RB [\| \-f .IR FREQ \|] .RB [\| \-l .IR LEN \|] .RB [\| \-r .IR REPEATS \|] .RB [\|< \-d|\-D > .IR DELAY \|] .RB [\| \-s \|] .RB [\| \-c \|] .br .B beep .RB [\| GLOBALS \|] .RI <\| TONE_OPTIONS \|> .RB [\| \-n|\-\-new \|] .RI <\| TONE_OPTIONS \|> .br .B beep .RI <\| \-h | \-\-help \|> .br .B beep .RI <\| \-v | \-V | \-\-version \|> .\" .\" ==================================================================== .\" .SH DESCRIPTION .PP \fBbeep\fR allows the user to control the PC speaker with precision, allowing different sounds to indicate different events. While \fBbeep\fR can be run quite happily on the command line, \fBbeep\fR's intended use is within shell/perl scripts, notifying the user when something interesting occurs. Of course, it has no notion of what \fIIS\fR interesting, but it is good at the notifying part. .PP All options have default values, meaning that just typing '\fBbeep\fR' will work. If an option is specified more than once on the command line, subsequent options override their predecessors. So '\fBbeep\fR \-f 200 \-f 300' will beep at 300Hz. .PP All durations are given in a unit of milliseconds, frequencies as Hertz, and the number of repeats is a dimensionless number. .\" .\" ==================================================================== .\" .SH OPTIONS .SS "Global options" .TP .BI \-e\ DEVICE \fR, \ \fB\-\-device= DEVICE Explicitly set the device \fBbeep\fR shall use to generate beep tones. When not given a device explicitly, \fBbeep\fR runs through an internal list of devices until one appears to work. .TP .BR \-\-debug ,\ \-\-verbose Make the \fBbeep\fR program more verbose. .SS "Tone options" .TP .BI \-f\ FREQ Beep with a tone frequency of \fIFREQ\fR Hz, where 0 < \fIFREQ\fR < 20000. As a general ballpark, the regular terminal beep is around 750Hz. For backwards compatibility, you can give \fIFREQ\fR as a floating point number, but \fBbeep\fR will round that to integer values as the kernel APIs expect them. .TP .BI \-l\ LEN Beep for a tone length of \fILEN\fR milliseconds. .TP .BI \-r\ REPEATS Repeat the tone including delays \fIREPEATS\fR times (defaults to 1). .TP .BI \-d\ DELAY\fR\ |\ \-D\ DELAY Specify a delay of \fIDELAY\fR milliseconds between repetitions. Small letter \fB\-d\fR specifies that this delay should only occur \fIbetween\fR beeps, that is, it should \fInot\fR occur after the last repetition. Capital letter \fB\-D\fR specifies that the delay should occur after every repetition, \fIincluding\fR the last one. Normally, \fB\-d\fR is what you want, but if, for example, you are stringing several \fBbeep\fR commands together to play the star wars anthem, you may want control over every delay. .TP .BR \-n ,\ \-\-new The \fB\-\-new\fR option allows you to chain multiple beeps together on a single command line. Each time the \fB\-\-new\FR is used, \fBbeep\fR starts treating all further arguments as though they were for a new beep. So for example: \fBbeep\fR \-f 1000 \-n \-f 2000 \-n \-f 1500 would produce a sequence of three beeps, the first with a frequency of 1000Hz (and otherwise default values), then a second beep with a frequency of 2000Hz (again, with things like delay and reps being set to their defaults), then a third beep, at 1500Hz. This is different from specifying a \fB\-r\fR value, since \fB\-r\fR repeats the same beep multiple times, whereas \fB\-\-new\fR allows you to specify different beeps. After a \fB\-\-new\fR, the new beep is created with all the default values, and any of these can be specified without altering values for preceding (or later) beeps. See the \fBEXAMPLES\fR section if this managed to confuse you. .TP .BR \-s ,\ \-c Both the \fB\-s\fR and the \fB\-c\fR option put \fBbeep\fR into input processing mode. \fB\-s\fR tells \fBbeep\fR to read from \fIstdin\fR, and beep after each newline. \fB\-c\fR tells \fBbeep\fR to beep after every character. In both cases, the \fBbeep\fR will also echo the input back out to stdout, which makes it easy to slip \fBbeep\fR into a text processing pipeline. See the \fBEXAMPLES\fR section. .SS "Other Actions" .BR \-h ,\ \-\-help Display \fBbeep\fR usage info and exit. .TP .BR \-v ,\ \-V ,\ \-\-version Display \fBbeep\fR version information and exit. .\" .\" ==================================================================== .\" .SH EXIT STATUS .PP When successful, .B beep returns with exit code 0. .PP Any non\-0 exit means .B beep has encountered an error and has bailed out. .\" .\" ==================================================================== .\" .SH FILES The device files .B beep uses by default are the following: .\" /dev/input/by\-path/platform\-pcspkr\-event\-spkr /dev/tty0 /dev/vc/0 .\" .\" ==================================================================== .\" .SH NOTES .SS "Devices and Permissions" .PP When you run \fBbeep\fR without explicitly giving a device to use, \fBbeep\fR tries opening the following devices in sequence until one succeeds: .IP "\fB/dev/input/by\-path/platform\-pcspkr\-event\-spkr\fR" 4 Uses the evdev API, and system administrator can allow access to any set of users and groups using the normal file permissions. .IP "\fB/dev/tty0\fR" 4 Uses the console API, and the kernel insists you are root or own the TTY. .IP "\fB/dev/vc/0\fR" 4 Uses the console API, and the kernel insists you are root or own the TTY. .PP .B beep does not support running as setuid root or via .BR "sudo" "(1)" . .PP For non\-root uses, the system administrator can set up a .BR udev "(7)" rule to allow write access to .B /dev/input/by\-path/platform\-pcspkr\-event\-spkr for certain users and/or user groups. For details, see the .B beep .B @pkgdocdir@/PERMISSIONS.md file. .\" .SS "APIs" .IP "evdev" 4 Uses the input event device driver, which means running .BR "write" "(2)" on .BR /dev/input/by\-path/platform\-pcspkr\-event\-spkr . .IP "console" 4 Uses the ancient console API, which means running the .B "KIOCSOUND" .BR "ioctl" "(2)" on a tty device like .BR /dev/tty0\ or\ /dev/vc/0. .\" .SS "Concurrent Invocations" Concurrent invocations of .B beep are not supported. There is only one tone generator in the PC hardware, and we do not manage access to that shared resource in any way. So if a first .B "beep \-f 1000 \-l 10000" process starts a long 10 second beep with 1000Hz, and 2 seconds later a second quick .B "beep \-f 2050 \-l 100" with 2050Hz comes in, you will hear that 2050Hz beep for 100ms, and then silence as the quick beep silences the tone generator. Now you will not hear that the first .B "beep" process is still running after having waited for the first 2100ms of 10000ms. You will also not that the first .B "beep" process will silence the already silent speaker 7900ms later, i.e. 10000ms after the first .B "beep" started. .\" .SS "Sound Volume" .PP The PC speaker hardware has no way to explicitly set the volume of a beep. .PP If you have a .IR "standalone PC" , however, chances are you have a piezo beeper connected to the mainboard. If you prioritize a loud beep over a certain frequency beep, you can choose to beep at a frequency close to the resonance frequency of the piezo beeper. Typical piezo beepers have a resonance frequency around 2000Hz, so you can test frequencies around that range. The author's piezo beeper is the loudest at about 2050Hz. .PP If you have a .IR "PC laptop" , chances are that your laptop will not have a piezo beeper hardware inside and that it will route the output of the pcspkr circuit to the laptop's internal speakers via the sound card mixer. In that case, you can and/or must change the mixer level for the beeper using a sound card mixer application. .\" .SS "Frequency Table" .PP This frequency table might come in hand for translating musical notes to frequencies. The frequencies are rounded to integer numbers as the kernel driver only works with integers. The column for .B "octave 4" is the octave of middle C. .\" This table was generated by the gen-freq-table script and .\" inserted into this man page manually. .TS center box; Cb | Cb s s s Cb | Cb Cb Cb Cb - | - - - - C | N N N N. note octave name 3 4 5 6 C 131 262 523 1047 C# 139 277 554 1109 D 147 294 587 1175 D# 156 311 622 1245 E 165 330 659 1319 F 175 349 698 1397 F# 185 370 740 1480 G 196 392 784 1568 G# 208 415 831 1661 A 220 440 880 1760 A# 233 466 932 1865 B 247 494 988 1976 C 262 523 1047 2093 .TE .\" .\" ==================================================================== .\" .SH BUGS Report bugs to .UR https://github.com/spkr\-beep/beep/issues .UE . .\" .\" ==================================================================== .\" .SH EXAMPLES .PP At its simplest (yet still effective) \fBbeep\fR .\" .PP A more interesting standalone setup \fBbeep\fR \-f 300.7 \-r 2 \-d 100 \-l 400 .\" .PP As part of a log watching pipeline tail \-f /var/log/xferlog | grep 'passwd' | \fBbeep\fR \-f 1000 \-r 5 \-s .\" .PP When using \-c mode, I recommend using a short \-D, and a shorter \-l, so that the beeps do not blur together. Something like this will get you a cheesy 1970's style beep\-as\-you\-type\-each\-letter effect cat file | \fBbeep\fR \-c \-f 400 \-D 50 \-l 10 .\" .PP A highly contrived example of \-n/\-\-new usage \fBbeep\fR \-f 1000 \-r 2 \-n \-r 5 \-l 10 \-\-new will produce first two 1000Hz beeps, then 5 beeps at the default tone, but only 10ms long each, followed by a third beep using all the default settings (since none are specified). .\" .PP See also the \fBFREQUENCY TABLE\fR below. .\" .\" ==================================================================== .\" .SH SEE ALSO .\" .BR fixme (1), .\" .BR andme (1), .BR @pkgdocdir@/README.md , .BR @pkgdocdir@/INSTALL.md , .BR @pkgdocdir@/PERMISSIONS.md , .UR "https://github.com/spkr\-beep/beep" .UE beep-1.4.3/beep.c000066400000000000000000000405231342023304200135060ustar00rootroot00000000000000/* beep - beep the pc speaker any number of ways * Copyright (C) 2000-2010 Johnathan Nightingale * Copyright (C) 2010-2013 Gerfried Fuchs * Copyright (C) 2013-2018 Hans Ulrich Niedermann * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * */ /* * For more documentation on beep, see the beep-usage.txt and * beep.1.in files. */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "beep-drivers.h" #include "beep-drivers.h" #include "beep-driver-console.h" #include "beep-driver-evdev.h" #include "beep-driver-noop.h" #include "beep-library.h" #include "beep-log.h" #include "beep-usage.h" static const char version_message[] = PACKAGE_TARNAME " " PACKAGE_VERSION "\n" "Copyright (C) 2002-2016 Johnathan Nightingale\n" "Copyright (C) 2013-2018 Hans Ulrich Niedermann\n" "Use and Distribution subject to GPL.\n" "For information: http://www.gnu.org/copyleft/.\n"; typedef enum { END_DELAY_NO = 0, END_DELAY_YES = 1, } end_delay_E; typedef enum { STDIN_BEEP_NONE = 0, STDIN_BEEP_LINE = 1, STDIN_BEEP_CHAR = 2, } stdin_beep_E; typedef struct _beep_parms_T beep_parms_T; /* Meaningful Defaults */ #define DEFAULT_FREQ 440 /* Middle A */ #define DEFAULT_LENGTH 200 /* milliseconds */ #define DEFAULT_REPS 1 #define DEFAULT_DELAY 100 /* milliseconds */ #define DEFAULT_END_DELAY END_DELAY_NO #define DEFAULT_STDIN_BEEP STDIN_BEEP_NONE struct _beep_parms_T { unsigned int freq; /* tone frequency (Hz) */ unsigned int length; /* tone length (ms) */ unsigned int reps; /* # of repetitions */ unsigned int delay; /* delay between reps (ms) */ end_delay_E end_delay; /* do we delay after last rep? */ stdin_beep_E stdin_beep; /* are we using stdin triggers? We have three options: - just beep and terminate (default) - beep after a line of input - beep after a character of input In the latter two cases, pass the text back out again, so that beep can be tucked appropriately into a text- processing pipe. */ beep_parms_T *next; /* in case -n/--new is used. */ }; /* Global. Set to true by the signal handlers, read only by the main * thread. */ static volatile sig_atomic_t global_abort = false; /* If we get interrupted, it would be nice to not leave the speaker * beeping in perpetuity. * * Everything called from this signal handler must be thread-safe, * signal-safe, reentrant including all API functions. Otherwise, we * get another CVE-2018-0492. * * So we make certain we keep to using the following API calls: * * * close(2): safe * * _exit(2): safe (which exit(3) is NOT) * * bzero(3): MT-safe * * memset(3): MT-safe * * write(2): safe * * strerror_r(3): MT-safe * * strlen(3): MT-safe */ void handle_signal(int unused_signum); void handle_signal(int unused_signum __attribute__(( unused ))) { global_abort = true; } /* print usage and leave exit code up to the caller */ static void print_usage(void) { fputs(beep_usage, stdout); } /* print usage and exit */ static void usage_bail(void) __attribute__(( noreturn )); static void usage_bail(void) { print_usage(); exit(EXIT_FAILURE); } /* Global. Written by parse_command_line(), read by main() initialization. */ static char *param_device_name = NULL; /* Parse the command line. argv should be untampered, as passed to main. * Beep parameters returned in result, subsequent parameters in argv will over- * ride previous ones. * * Currently valid parameters: * "-f " * "-l " * "-r " * "-d " * "-D " (similar to -d, but delay after last repetition as well) * "-s" (beep after each line of input from stdin, echo line to stdout) * "-c" (beep after each char of input from stdin, echo char to stdout) * "--verbose/--debug" * "-h/--help" * "-v/-V/--version" * "-n/--new" * * March 29, 2002 - Daniel Eisenbud points out that ch should be int, not char, * for correctness on platforms with unsigned chars. */ static void parse_command_line(const int argc, char *const argv[], beep_parms_T *result) { int ch; static const struct option opt_list[] = { {"help", no_argument, NULL, 'h'}, {"version", no_argument, NULL, 'V'}, {"new", no_argument, NULL, 'n'}, {"verbose", no_argument, NULL, 'X'}, {"debug", no_argument, NULL, 'X'}, {"device", required_argument, NULL, 'e'}, {NULL, 0, NULL, 0 } }; while ((ch = getopt_long(argc, argv, "f:l:r:d:D:schvVne:", opt_list, NULL)) != EOF) { /* handle parsed numbers for various arguments */ int argval_i = -1; unsigned int argval_u = ~0U; float argval_f = -1.0f; switch (ch) { case 'f': /* freq */ if (sscanf(optarg, "%f", &argval_f) != 1) { usage_bail(); } if ((0.0f > argval_f) || (argval_f > 20000.0f)) { usage_bail(); } argval_i = (int) (argval_f + 0.5f); argval_u = (unsigned int) argval_i; if (result->freq != 0) { log_warning("multiple -f values given, only last one is used."); } result->freq = argval_u; break; case 'l' : /* length */ if (sscanf(optarg, "%u", &argval_u) != 1) { usage_bail(); } if (argval_u > 300000U) { usage_bail(); } result->length = argval_u; break; case 'r' : /* repetitions */ if (sscanf(optarg, "%u", &argval_u) != 1) { usage_bail(); } if (argval_u > 300000U) { usage_bail(); } result->reps = argval_u; break; case 'd' : /* delay between reps - WITHOUT delay after last beep*/ if (sscanf(optarg, "%u", &argval_u) != 1) { usage_bail(); } if (argval_u > 300000U) { usage_bail(); } result->delay = argval_u; result->end_delay = END_DELAY_NO; break; case 'D' : /* delay between reps - WITH delay after last beep */ if (sscanf(optarg, "%u", &argval_u) != 1) { usage_bail(); } if (argval_u > 300000U) { usage_bail(); } result->delay = argval_u; result->end_delay = END_DELAY_YES; break; case 's' : result->stdin_beep = STDIN_BEEP_LINE; break; case 'c' : result->stdin_beep = STDIN_BEEP_CHAR; break; case 'v' : case 'V' : /* also --version */ fputs(version_message, stdout); exit(EXIT_SUCCESS); /* break; unreachable */ case 'n' : /* also --new - create another beep */ if (result->freq == 0) { result->freq = DEFAULT_FREQ; } result->next = (beep_parms_T *)malloc(sizeof(beep_parms_T)); result->next->freq = 0; result->next->length = DEFAULT_LENGTH; result->next->reps = DEFAULT_REPS; result->next->delay = DEFAULT_DELAY; result->next->end_delay = DEFAULT_END_DELAY; result->next->stdin_beep = DEFAULT_STDIN_BEEP; result->next->next = NULL; result = result->next; /* yes, I meant to do that. */ break; case 'X' : /* --debug / --verbose */ if (log_level < 999) { /* just limit to some finite value */ log_level++; } break; case 'e' : /* also --device */ if (param_device_name) { log_error("You cannot give the --device parameter more than once."); exit(EXIT_FAILURE); } param_device_name = optarg; break; case 'h': /* also --help */ print_usage(); exit(EXIT_SUCCESS); /* break; unreachable */ default: usage_bail(); /* break; unreachable */ } } if (optind < argc) { log_error("non-option arguments left on command line"); usage_bail(); } if (result->freq == 0) { result->freq = DEFAULT_FREQ; } } static int sleep_ms(beep_driver *driver, unsigned int milliseconds) { const time_t seconds = milliseconds / 1000U; const long nanoseconds = (milliseconds % 1000UL) * 1000UL * 1000UL; const struct timespec request = { seconds, nanoseconds }; const int retcode = nanosleep(&request, NULL); if (global_abort) { beep_drivers_end_tone(driver); beep_drivers_fini(driver); exit(EXIT_FAILURE); } return retcode; } static void play_beep(beep_driver *driver, beep_parms_T parms) { log_verbose("%d times %d ms beeps (%d ms delay between, " "%d ms delay after) @ %d Hz", parms.reps, parms.length, parms.delay, parms.end_delay, parms.freq); /* repeat the beep */ for (unsigned int i = 0; (!global_abort) && (i < parms.reps); i++) { beep_drivers_begin_tone(driver, parms.freq & 0xffff); sleep_ms(driver, parms.length); beep_drivers_end_tone(driver); if ((parms.end_delay == END_DELAY_YES) || ((i+1) < parms.reps)) { sleep_ms(driver, parms.delay); } } } /* If stdout is a TTY, print a bell character to stdout as a fallback. */ static void fallback_beep(void) { /* Printing '\a' can only beep if we print it to a tty */ if (isatty(STDOUT_FILENO)) { fputc('\a', stdout); } } int main(const int argc, char *const argv[]) { log_init(argc, argv); /* Bail out if running setuid or setgid. * * It is near impossible to make beep setuid-safe: * * * We open files for writing, and may even write to them. * * * Checking the device file with realpath leaks information. * * So we refuse running setuid or setgid. */ if ((getuid() != geteuid()) || (getgid() != getegid())) { log_error("Running setuid or setgid, " "which is not supported for security reasons."); log_error("Set up permissions for the pcspkr evdev device file instead."); exit(EXIT_FAILURE); } /* Bail out if running under sudo. * * For the reasoning, see the setuid comment above. */ if (getenv("SUDO_COMMAND") || getenv("SUDO_USER") || getenv("SUDO_UID") || getenv("SUDO_GID")) { log_error("Running under sudo, " "which is not supported for security reasons."); log_error("Set up permissions for the pcspkr evdev device file instead."); exit(EXIT_FAILURE); } /* Parse command line */ beep_parms_T *parms = (beep_parms_T *)malloc(sizeof(beep_parms_T)); if (NULL == parms) { perror("malloc"); exit(EXIT_FAILURE); } parms->freq = 0; parms->length = DEFAULT_LENGTH; parms->reps = DEFAULT_REPS; parms->delay = DEFAULT_DELAY; parms->end_delay = DEFAULT_END_DELAY; parms->stdin_beep = DEFAULT_STDIN_BEEP; parms->next = NULL; parse_command_line(argc, argv, parms); /* Register drivers. If we do that after parse_command_line, we may * have set the logging verbosity. If we do that before * parse_command_line, parse_command_line might use some driver * functions. Not sure yet which option we prefer. */ /* beep_drivers_register(&noop_driver); */ beep_drivers_register(&console_driver); beep_drivers_register(&evdev_driver); beep_driver *driver = NULL; if (param_device_name) { driver = beep_drivers_detect(param_device_name); if (!driver) { const int saved_errno = errno; log_error("Could not open %s for writing: %s", param_device_name, strerror(saved_errno)); exit(EXIT_FAILURE); } } else { driver = beep_drivers_detect(NULL); if (!driver) { log_error("Could not open any device"); /* Output the only beep we can, in an effort to fall back on usefulness */ fallback_beep(); exit(EXIT_FAILURE); } } log_verbose("beep: using driver %p (name=%s, fd=%d, dev=%s)", (void *)driver, driver->name, driver->device_fd, driver->device_name); /* At this time, we know what API to use on which device, and we do * not have to fall back onto printing '\a' any more. */ /* Memory barrier. All globals have been set up, so we make sure the * values are actually written to memory. Only then do we install * the signal handlers. * * TBD: Use C11 atomic_signal_fence() instead of "__asm__ volatile"? */ __asm__ volatile ("" : : : "memory"); /* After all the initialization has happened and the global * variables used to communicate with the signal handlers have * actually been set up properly, we can finally install the signal * handlers. As we do not start making any noises, there is no need * to install the signal handlers any earlier. */ signal(SIGINT, handle_signal); signal(SIGTERM, handle_signal); /* this outermost while loop handles the possibility that -n/--new has been used, i.e. that we have multiple beeps specified. Each iteration will play, then free() one parms instance. */ while ((!global_abort) && parms) { beep_parms_T *next = parms->next; if (parms->stdin_beep != STDIN_BEEP_NONE) { /* In this case, beep is probably part of a pipe, in which case POSIX says stdin and out should be fuly buffered. This however means very laggy performance with beep just twiddling it's thumbs until a buffer fills. Thus, kill the buffering. In some situations, this too won't be enough, namely if we're in the middle of a long pipe, and the processes feeding us stdin are buffered, we'll have to wait for them, not much to be done about that. */ setvbuf(stdin, NULL, _IONBF, 0); setvbuf(stdout, NULL, _IONBF, 0); char sin[4096]; while ((!global_abort) && (fgets(sin, 4096, stdin))) { if (parms->stdin_beep == STDIN_BEEP_CHAR) { for (char *ptr=sin; (!global_abort) && (*ptr); ptr++) { putchar(*ptr); fflush(stdout); play_beep(driver, *parms); } } else { /* STDIN_BEEP_LINE */ fputs(sin, stdout); play_beep(driver, *parms); } } } else { play_beep(driver, *parms); } /* Junk each parms struct after playing it */ free(parms); parms = next; } beep_drivers_end_tone(driver); beep_drivers_fini(driver); if (global_abort) { return EXIT_FAILURE; } else { return EXIT_SUCCESS; } } /* * Local Variables: * c-basic-offset: 4 * indent-tabs-mode: nil * End: */ beep-1.4.3/gen-freq-table000066400000000000000000000027521342023304200151450ustar00rootroot00000000000000#!/usr/bin/env python3 # # gen-freq-table - calculate and print the frequency table for use in beep(1) man page # Copyright (C) 2018-2019 Hans Ulrich Niedermann # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. import math n_list = range(-9, 3+1) octave_list = range(3, 6+1) freqs = [ [ (440*(2**(i-4))*math.exp(math.log(2)*n/12)) for i in octave_list ] for n in n_list ] notes = [ "C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B", "C" ] print("""\ .TS center box; Cb | Cb s s s Cb | Cb Cb Cb Cb - | - - - - C | N N N N. note octave """, end="") print("name\t", end="") for octave in octave_list: print("%d\t" % octave, end="") print() for (note, freqline) in zip(notes,freqs): print("%s\t" % note, end="") for f in freqline: print("%d\t" % int(round(f)), end="") print() print("""\ .TE """, end="") beep-1.4.3/pandoc.css000066400000000000000000000113271342023304200144050ustar00rootroot00000000000000/* Source: https://gist.github.com/killercup/5917178 * * Quoting the original author of this file, "killercup" from * : * * > Thanks for your interest! Gist doesn't send notifications for * > comments, if you want to get in touch with me, tweet/mail/IM me. * > * > @durka, feel free to assume its * > public domain || CC0 || MIT || Apache 2.0 :) * > I'm not sure I came up with all of it myself (like that * > _font-face trick or the usage of content with attr), but what * > I did copy should be (commonly) known patterns. * */ /* * I add this to html files generated with pandoc. */ html { font-size: 100%; overflow-y: scroll; -webkit-text-size-adjust: 100%; -ms-text-size-adjust: 100%; } body { color: #444; font-family: Georgia, Palatino, 'Palatino Linotype', Times, 'Times New Roman', serif; font-size: 12px; line-height: 1.7; padding: 1em; margin: auto; max-width: 42em; background: #fefefe; } a { color: #0645ad; text-decoration: none; } a:visited { color: #0b0080; } a:hover { color: #06e; } a:active { color: #faa700; } a:focus { outline: thin dotted; } *::-moz-selection { background: rgba(255, 255, 0, 0.3); color: #000; } *::selection { background: rgba(255, 255, 0, 0.3); color: #000; } a::-moz-selection { background: rgba(255, 255, 0, 0.3); color: #0645ad; } a::selection { background: rgba(255, 255, 0, 0.3); color: #0645ad; } p { margin: 1em 0; } img { max-width: 100%; } h1, h2, h3, h4, h5, h6 { color: #111; line-height: 125%; margin-top: 2em; font-weight: normal; } h4, h5, h6 { font-weight: bold; } h1 { font-size: 2.5em; } h2 { font-size: 2em; } h3 { font-size: 1.5em; } h4 { font-size: 1.2em; } h5 { font-size: 1em; } h6 { font-size: 0.9em; } blockquote { color: #666666; margin: 0; padding-left: 3em; border-left: 0.5em #EEE solid; } hr { display: block; height: 2px; border: 0; border-top: 1px solid #aaa; border-bottom: 1px solid #eee; margin: 1em 0; padding: 0; } pre, code, kbd, samp { color: #000; font-family: monospace, monospace; _font-family: 'courier new', monospace; font-size: 0.98em; } pre { white-space: pre; white-space: pre-wrap; word-wrap: break-word; } b, strong { font-weight: bold; } dfn { font-style: italic; } ins { background: #ff9; color: #000; text-decoration: none; } mark { background: #ff0; color: #000; font-style: italic; font-weight: bold; } sub, sup { font-size: 75%; line-height: 0; position: relative; vertical-align: baseline; } sup { top: -0.5em; } sub { bottom: -0.25em; } ul, ol { margin: 1em 0; padding: 0 0 0 2em; } li p:last-child { margin-bottom: 0; } ul ul, ol ol { margin: .3em 0; } dl { margin-bottom: 1em; } dt { font-weight: bold; margin-bottom: .8em; } dd { margin: 0 0 .8em 2em; } dd:last-child { margin-bottom: 0; } img { border: 0; -ms-interpolation-mode: bicubic; vertical-align: middle; } figure { display: block; text-align: center; margin: 1em 0; } figure img { border: none; margin: 0 auto; } figcaption { font-size: 0.8em; font-style: italic; margin: 0 0 .8em; } table { margin-bottom: 2em; border-bottom: 1px solid #ddd; border-right: 1px solid #ddd; border-spacing: 0; border-collapse: collapse; } table th { padding: .2em 1em; background-color: #eee; border-top: 1px solid #ddd; border-left: 1px solid #ddd; } table td { padding: .2em 1em; border-top: 1px solid #ddd; border-left: 1px solid #ddd; vertical-align: top; } .author { font-size: 1.2em; text-align: center; } @media only screen and (min-width: 480px) { body { font-size: 14px; } } @media only screen and (min-width: 768px) { body { font-size: 16px; } } @media print { * { background: transparent !important; color: black !important; filter: none !important; -ms-filter: none !important; } body { font-size: 12pt; max-width: 100%; } a, a:visited { text-decoration: underline; } hr { height: 1px; border: 0; border-bottom: 1px solid black; } a[href]:after { content: " (" attr(href) ")"; } abbr[title]:after { content: " (" attr(title) ")"; } .ir a:after, a[href^="javascript:"]:after, a[href^="#"]:after { content: ""; } pre, blockquote { border: 1px solid #999; padding-right: 1em; page-break-inside: avoid; } tr, img { page-break-inside: avoid; } img { max-width: 100% !important; } @page :left { margin: 15mm 20mm 15mm 10mm; } @page :right { margin: 15mm 10mm 15mm 20mm; } p, h2, h3 { orphans: 3; widows: 3; } h2, h3 { page-break-after: avoid; } } beep-1.4.3/pcspkr-beep.conf000066400000000000000000000001701342023304200155030ustar00rootroot00000000000000# Uncomment the following line to have the pcspkr.ko driver # load automatically on boot # alias platform:pcspkr pcspkr beep-1.4.3/tests/000077500000000000000000000000001342023304200135655ustar00rootroot00000000000000beep-1.4.3/tests/00-nothing.expected.0000066400000000000000000000000251342023304200173260ustar00rootroot00000000000000BEEP=BEEP_EXECUTABLE beep-1.4.3/tests/00-nothing.sh000077500000000000000000000000371342023304200160070ustar00rootroot00000000000000#!/bin/sh echo "BEEP=${BEEP}" beep-1.4.3/tests/01-nothing.sh000077500000000000000000000001221342023304200160030ustar00rootroot00000000000000#!/bin/sh # If we produce this output, this test will fail : echo "BEEP=${BEEP}" beep-1.4.3/tests/02-second-device-name.expected.0000066400000000000000000000001251342023304200213110ustar00rootroot00000000000000BEEP_EXECUTABLE: Error: You cannot give the --device parameter more than once. Error beep-1.4.3/tests/02-second-device-name.sh000077500000000000000000000001121342023304200177630ustar00rootroot00000000000000if ${BEEP} -e /dev/tty0 -e /dev/tty1; then : else echo "Error" fi beep-1.4.3/tests/03-cmdline-unhandled-option.expected.0000066400000000000000000000000741342023304200225500ustar00rootroot00000000000000BEEP_EXECUTABLE: unrecognized option '--blubb' Error: Good. beep-1.4.3/tests/03-cmdline-unhandled-option.sh000077500000000000000000000001571342023304200212300ustar00rootroot00000000000000if ${BEEP} --blubb > /dev/null; then echo "beep should not have succeeded" else echo "Error: Good." fi beep-1.4.3/tests/04-cmdline-unhandled-non-option.sh000077500000000000000000000002501342023304200220130ustar00rootroot00000000000000if ${BEEP} blubb > /dev/null; then echo "beep should have exited with non-0, but exited with 0" else : "The unhandled non-option argument has been detected" fi beep-1.4.3/tests/05-cmdline-help.bash000077500000000000000000000001721342023304200172120ustar00rootroot00000000000000${BEEP} --help | sed 1q if test "x${PIPESTATUS[*]}" = "x0 0"; then : else echo "Error exit, should not happen" fi beep-1.4.3/tests/05-cmdline-help.expected.0000066400000000000000000000000071342023304200202260ustar00rootroot00000000000000Usage: beep-1.4.3/tests/05-cmdline-version.bash000077500000000000000000000001751342023304200177520ustar00rootroot00000000000000${BEEP} --version | sed 1q if test "x${PIPESTATUS[*]}" = "x0 0"; then : else echo "Error exit, should not happen" fi beep-1.4.3/tests/05-cmdline-version.expected.0000066400000000000000000000000251342023304200207630ustar00rootroot00000000000000beep PACKAGE_VERSION beep-1.4.3/tests/10-beep-default.sh000077500000000000000000000000101342023304200166660ustar00rootroot00000000000000${BEEP} beep-1.4.3/tests/11-beep-f-880Hz.sh000077500000000000000000000000171342023304200163160ustar00rootroot00000000000000${BEEP} -f 880 beep-1.4.3/tests/20-beep-default.sh000077500000000000000000000000231342023304200166730ustar00rootroot00000000000000${BEEP} -f "$FREQ" beep-1.4.3/tests/20-beep-device-dev-evdev-pcspkr.sh000077500000000000000000000001041342023304200216710ustar00rootroot00000000000000${BEEP} -f "$FREQ" -e /dev/input/by-path/platform-pcspkr-event-spkr beep-1.4.3/tests/21-beep-device-dev-console.expected.0000066400000000000000000000001311342023304200222450ustar00rootroot00000000000000BEEP_EXECUTABLE: Error: Could not open /dev/console for writing: Permission denied Error beep-1.4.3/tests/21-beep-device-dev-console.expected.1000066400000000000000000000000001342023304200222410ustar00rootroot00000000000000beep-1.4.3/tests/21-beep-device-dev-console.sh000077500000000000000000000001131342023304200207230ustar00rootroot00000000000000if ${BEEP} -f "$FREQ" -e /dev/console; then : else echo "Error" fi beep-1.4.3/tests/30-beep-device-dev-tty0.expected.0000066400000000000000000000001261342023304200215070ustar00rootroot00000000000000BEEP_EXECUTABLE: Error: Could not open /dev/tty0 for writing: Permission denied Error beep-1.4.3/tests/30-beep-device-dev-tty0.expected.1000066400000000000000000000000001342023304200214770ustar00rootroot00000000000000beep-1.4.3/tests/30-beep-device-dev-tty0.sh000077500000000000000000000001101342023304200201560ustar00rootroot00000000000000if ${BEEP} -f "$FREQ" -e /dev/tty0; then : else echo "Error" fi beep-1.4.3/tests/31-beep-device-dev-tty4.expected.0000066400000000000000000000001251342023304200215130ustar00rootroot00000000000000BEEP_EXECUTABLE: Error: console device '/dev/tty4' does not support either API Error beep-1.4.3/tests/31-beep-device-dev-tty4.expected.1000066400000000000000000000000001342023304200215040ustar00rootroot00000000000000beep-1.4.3/tests/31-beep-device-dev-tty4.expected.2000066400000000000000000000001261342023304200215160ustar00rootroot00000000000000BEEP_EXECUTABLE: Error: Could not open /dev/tty4 for writing: Permission denied Error beep-1.4.3/tests/31-beep-device-dev-tty4.expected.3000066400000000000000000000001341342023304200215160ustar00rootroot00000000000000BEEP_EXECUTABLE: Error: Could not open /dev/tty4 for writing: Operation not permitted Error beep-1.4.3/tests/31-beep-device-dev-tty4.sh000077500000000000000000000001101342023304200201630ustar00rootroot00000000000000if ${BEEP} -f "$FREQ" -e /dev/tty4; then : else echo "Error" fi beep-1.4.3/tests/33-beep-device-dev-tty63.expected.0000066400000000000000000000001271342023304200216040ustar00rootroot00000000000000BEEP_EXECUTABLE: Error: Could not open /dev/tty63 for writing: Permission denied Error beep-1.4.3/tests/33-beep-device-dev-tty63.expected.1000066400000000000000000000000001342023304200215730ustar00rootroot00000000000000beep-1.4.3/tests/33-beep-device-dev-tty63.sh000077500000000000000000000001111342023304200202530ustar00rootroot00000000000000if ${BEEP} -f "$FREQ" -e /dev/tty63; then : else echo "Error" fi beep-1.4.3/tests/34-beep-device-dev-ttyXX.expected.0000066400000000000000000000001371342023304200217150ustar00rootroot00000000000000BEEP_EXECUTABLE: Error: Could not open /dev/ttyXX for writing: No such file or directory Error beep-1.4.3/tests/34-beep-device-dev-ttyXX.sh000077500000000000000000000001111342023304200203630ustar00rootroot00000000000000if ${BEEP} -f "$FREQ" -e /dev/ttyXX; then : else echo "Error" fi beep-1.4.3/tests/35-beep-device-dev-tty99.expected.0000066400000000000000000000001371342023304200216200ustar00rootroot00000000000000BEEP_EXECUTABLE: Error: Could not open /dev/tty99 for writing: No such file or directory Error beep-1.4.3/tests/35-beep-device-dev-tty99.sh000077500000000000000000000001111342023304200202660ustar00rootroot00000000000000if ${BEEP} -f "$FREQ" -e /dev/tty99; then : else echo "Error" fi beep-1.4.3/tests/36-beep-device-dev-ttyX.expected.0000066400000000000000000000001361342023304200215660ustar00rootroot00000000000000BEEP_EXECUTABLE: Error: Could not open /dev/ttyX for writing: No such file or directory Error beep-1.4.3/tests/36-beep-device-dev-ttyX.sh000077500000000000000000000001101342023304200202340ustar00rootroot00000000000000if ${BEEP} -f "$FREQ" -e /dev/ttyX; then : else echo "Error" fi beep-1.4.3/tests/37-beep-device-dev-ttyS1.expected.0000066400000000000000000000001271342023304200216430ustar00rootroot00000000000000BEEP_EXECUTABLE: Error: Could not open /dev/ttyS1 for writing: Permission denied Error beep-1.4.3/tests/37-beep-device-dev-ttyS1.expected.1000066400000000000000000000001301342023304200216360ustar00rootroot00000000000000BEEP_EXECUTABLE: Error: Could not open /dev/ttyS1 for writing: Input/output error Error beep-1.4.3/tests/37-beep-device-dev-ttyS1.sh000077500000000000000000000001111342023304200203120ustar00rootroot00000000000000if ${BEEP} -f "$FREQ" -e /dev/ttyS1; then : else echo "Error" fi beep-1.4.3/tests/38-beep-device-dev-tty999.expected.0000066400000000000000000000001401342023304200217060ustar00rootroot00000000000000BEEP_EXECUTABLE: Error: Could not open /dev/tty999 for writing: No such file or directory Error beep-1.4.3/tests/38-beep-device-dev-tty999.sh000077500000000000000000000001121342023304200203630ustar00rootroot00000000000000if ${BEEP} -f "$FREQ" -e /dev/tty999; then : else echo "Error" fi beep-1.4.3/tests/40-beep-device-dev-vc-0.expected.0000066400000000000000000000001361342023304200213560ustar00rootroot00000000000000BEEP_EXECUTABLE: Error: Could not open /dev/vc/0 for writing: No such file or directory Error beep-1.4.3/tests/40-beep-device-dev-vc-0.sh000077500000000000000000000001101342023304200200240ustar00rootroot00000000000000if ${BEEP} -f "$FREQ" -e /dev/vc/0; then : else echo "Error" fi beep-1.4.3/tests/50-long-len-and-signal-SIGINT.expected.0000066400000000000000000000000331342023304200224050ustar00rootroot00000000000000Signal has aborted beep: 1 beep-1.4.3/tests/50-long-len-and-signal-SIGINT.sh000077500000000000000000000005521342023304200210710ustar00rootroot00000000000000ts_begin="$(date +%s)" ${BEEP} -f "$FREQ" -l 10000 & pid="$!" sleep 0.2 kill -s INT "$pid" wait "$pid" retcode="$?" ts_end="$(date +%s)" ts_delta="$(expr "$ts_end" - "$ts_begin")" # echo "ts_delta=$ts_delta" if test "$ts_delta" -le 2; then echo "Signal has aborted beep: ${retcode}" else echo "Signal has apparently NOT aborted beep: ${retcode}" fi beep-1.4.3/tests/50-long-len-and-signal-SIGTERM.expected.0000066400000000000000000000000331342023304200225220ustar00rootroot00000000000000Signal has aborted beep: 1 beep-1.4.3/tests/50-long-len-and-signal-SIGTERM.sh000077500000000000000000000005531342023304200212070ustar00rootroot00000000000000ts_begin="$(date +%s)" ${BEEP} -f "$FREQ" -l 10000 & pid="$!" sleep 0.2 kill -s TERM "$pid" wait "$pid" retcode="$?" ts_end="$(date +%s)" ts_delta="$(expr "$ts_end" - "$ts_begin")" # echo "ts_delta=$ts_delta" if test "$ts_delta" -le 2; then echo "Signal has aborted beep: ${retcode}" else echo "Signal has apparently NOT aborted beep: ${retcode}" fi beep-1.4.3/tests/51-long-delay-and-signal-SIGINT.expected.0000066400000000000000000000000331342023304200227260ustar00rootroot00000000000000Signal has aborted beep: 1 beep-1.4.3/tests/51-long-delay-and-signal-SIGINT.sh000077500000000000000000000005521342023304200214120ustar00rootroot00000000000000ts_begin="$(date +%s)" ${BEEP} -f "$FREQ" -D 10000 & pid="$!" sleep 0.2 kill -s INT "$pid" wait "$pid" retcode="$?" ts_end="$(date +%s)" ts_delta="$(expr "$ts_end" - "$ts_begin")" # echo "ts_delta=$ts_delta" if test "$ts_delta" -le 2; then echo "Signal has aborted beep: ${retcode}" else echo "Signal has apparently NOT aborted beep: ${retcode}" fi beep-1.4.3/tests/README.md000066400000000000000000000065151342023304200150530ustar00rootroot00000000000000The beep testsuite ================== Deficiencies ------------ * Quick hack. * Does not test whether actual sound output happened. The different frequency might help a human detect a different melody, but that is no replacement for a properly automatted test. Devices ======= [root@host ~]# echo blubb > /dev/input/blubb [user@host ~]$ ls -lR /dev/tty0 /dev/vc/0 /dev/input/ ls: cannot access '/dev/vc/0': No such file or directory crw--w----+ 1 root tty 4, 0 27. Dez 17:55 /dev/tty0 /dev/input/: total 4 -rw-r--r--. 1 root root 6 28. Dez 01:55 blubb drwxr-xr-x. 2 root root 140 27. Dez 17:55 by-id drwxr-xr-x. 2 root root 180 27. Dez 19:19 by-path crw-rw----. 1 root input 13, 64 27. Dez 17:55 event0 crw-rw----. 1 root input 13, 65 27. Dez 17:55 event1 crw-rw----. 1 root input 13, 74 27. Dez 17:55 event10 crw-rw----. 1 root input 13, 75 27. Dez 17:55 event11 crw-rw----. 1 root input 13, 76 27. Dez 17:55 event12 crw-rw----. 1 root input 13, 77 27. Dez 17:55 event13 crw-rw----. 1 root input 13, 78 27. Dez 17:55 event14 crw-rw----. 1 root input 13, 79 27. Dez 17:55 event15 crw-rw----. 1 root input 13, 80 27. Dez 17:55 event16 crw-rw----. 1 root input 13, 81 27. Dez 17:55 event17 crw-rw----. 1 root input 13, 82 27. Dez 17:55 event18 crw-rw----. 1 root input 13, 83 27. Dez 17:55 event19 crw-rw----. 1 root input 13, 66 27. Dez 17:55 event2 crw-rw----. 1 root input 13, 84 27. Dez 17:55 event20 crw-rw----. 1 root input 13, 85 27. Dez 19:19 event21 crw-rw----. 1 root input 13, 67 27. Dez 17:55 event3 crw-rw----. 1 root input 13, 68 27. Dez 17:55 event4 crw-rw----. 1 root input 13, 69 27. Dez 17:55 event5 crw-rw----. 1 root input 13, 70 27. Dez 17:55 event6 crw-rw----. 1 root input 13, 71 27. Dez 17:55 event7 crw-rw----. 1 root input 13, 72 27. Dez 17:55 event8 crw-rw----. 1 root input 13, 73 27. Dez 17:55 event9 crw-rw----. 1 root input 13, 63 27. Dez 17:55 mice crw-rw----. 1 root input 13, 32 27. Dez 17:55 mouse0 /dev/input/by-id: total 0 lrwxrwxrwx. 1 root root 9 27. Dez 17:55 usb-B16_b_02_USB-PS_2_Optical_Mouse-event-mouse -> ../event3 lrwxrwxrwx. 1 root root 9 27. Dez 17:55 usb-B16_b_02_USB-PS_2_Optical_Mouse-mouse -> ../mouse0 lrwxrwxrwx. 1 root root 9 27. Dez 17:55 usb-Burr-Brown_from_TI_USB_Audio_CODEC-event-if03 -> ../event2 lrwxrwxrwx. 1 root root 9 27. Dez 17:55 usb-Microsoft_Natural®_Ergonomic_Keyboard_4000-event-kbd -> ../event4 lrwxrwxrwx. 1 root root 9 27. Dez 17:55 usb-Microsoft_Natural®_Ergonomic_Keyboard_4000-if01-event-kbd -> ../event5 /dev/input/by-path: total 0 lrwxrwxrwx. 1 root root 9 27. Dez 17:55 pci-0000:00:10.1-usb-0:1:1.3-event -> ../event2 lrwxrwxrwx. 1 root root 9 27. Dez 17:55 pci-0000:00:12.2-usb-0:2.3:1.0-event-mouse -> ../event3 lrwxrwxrwx. 1 root root 9 27. Dez 17:55 pci-0000:00:12.2-usb-0:2.3:1.0-mouse -> ../mouse0 lrwxrwxrwx. 1 root root 9 27. Dez 17:55 pci-0000:00:12.2-usb-0:2.4:1.0-event-kbd -> ../event4 lrwxrwxrwx. 1 root root 9 27. Dez 17:55 pci-0000:00:12.2-usb-0:2.4:1.1-event-kbd -> ../event5 lrwxrwxrwx. 1 root root 10 27. Dez 17:55 platform-eeepc-wmi-event -> ../event20 lrwxrwxrwx. 1 root root 10 27. Dez 19:19 platform-pcspkr-event-spkr -> ../event21 [user@host ~]$ beep-1.4.3/tests/run-tests000066400000000000000000000067551342023304200154710ustar00rootroot00000000000000#!/bin/bash # # run-tests - run a given series of test cases for beep # Copyright (C) 2018-2019 Hans Ulrich Niedermann # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. CMP=cmp DIFF=diff SED=sed SHELL=sh # TODO: If we have more tone generating tests, find a well-known # melody without repeating notes and play that melody so that a # human can hear when the melody has holes. FREQS=(440 494 554 587 659 740 831 880 988 1109 1175 1319 1480 1661 1760) : set -e : set -x test_dir="$1" shift pass=0 fail=0 if test -t 1; then hilite="$(tput setaf 3)" normal="$(tput sgr0)" green="$(tput setaf 2)" red="$(tput setaf 1)$(tput bold)" else hilite="" normal="" green="" red="" fi passmsg="${green}PASS${normal}" failmsg="${red}FAIL${normal}" canonicalize_output() { ${SED} -e "s|${BEEP}|BEEP_EXECUTABLE|g" -e "s|^${BEEP##*/}:|BEEP_EXECUTABLE:|g" -e "s|$(echo "${PACKAGE_VERSION}" | ${SED} 's/\./\\./g')|PACKAGE_VERSION|g" } success_beeps() { if test -e "beep"; then ./beep -f 220 -l 100 -n -f 275 -l 100 -n -f 330 -l 100 -n -f 440 -l 100 -n -f 550 -l 100 -n -f 660 -l 100 -n -f 880 fi } : set -x for executable; do export BEEP="$PWD/$executable" freq_idx=0 for test in $(ls -1 tests/*.{bash,sh}); do export FREQ="${FREQS[${freq_idx}]}" base="$(basename $(basename "$test" .bash) .sh)" dir="$(dirname "$test")" actual="${dir}/${executable}--${base}.actual" printf "${hilite}%-13s${normal} ${hilite}%-32s${normal} " "${executable}" "${base}" if "${test}" > "${actual}.new" 2>&1; then canonicalize_output < "${actual}.new" > "${actual}" expects_output=false for file in "${dir}/${base}.expected".[0-9]; do if test -f "$file"; then expects_output=true break fi done if "${expects_output}"; then expect_fail="true" for expected in "${dir}/${base}.expected".[0-9]; do if ${CMP} --quiet "${expected}" "${actual}"; then pass="$(expr "${pass}" + 1)" echo "${passmsg}${expected/#*expected}" expect_fail="false" break fi done if "$expect_fail"; then fail="$(expr "${fail}" + 1)" echo "${failmsg}" for expected in "${dir}/${base}.expected".[0-9]; do ${DIFF} -u "${expected}" "${actual}" done fi else if test -s "${actual}"; then fail="$(expr "${fail}" + 1)" echo "${failmsg}" cat "${actual}" else pass="$(expr "${pass}" + 1)" echo "${passmsg}" fi fi else canonicalize_output < "${actual}.new" > "${actual}" fail="$(expr "${fail}" + 1)" echo "${failmsg}" cat "${actual}" fi freq_idx="$(expr "$freq_idx" + 1)" if test "$freq_idx" -ge "${#FREQS[@]}"; then freq_idx=0 fi sleep 0.35 || sleep 1 done done echo "${pass} passed, ${fail} failed, $(expr "${pass}" + "${fail}") total." if test "${fail}" -gt 0; then \ exit 1 else success_beeps exit 0 fi