#include <sys/ioctl.h>
#include <sys/types.h>
#include <linux/kd.h>
+#include <linux/input.h>
/* I don't know where this number comes from, I admit that freely. A
wonderful human named Raine M. Ekman used it in a program that played
struct beep_parms_t *next; /* in case -n/--new is used. */
} beep_parms_t;
+enum { BEEP_TYPE_CONSOLE, BEEP_TYPE_EVDEV };
+
/* Momma taught me never to use globals, but we need something the signal
handlers can get at.*/
int console_fd = -1;
+int console_type = BEEP_TYPE_CONSOLE;
+char *console_device = NULL;
+
+
+void do_beep(int freq) {
+ if (console_type == BEEP_TYPE_CONSOLE) {
+ if(ioctl(console_fd, KIOCSOUND, freq != 0
+ ? (int)(CLOCK_TICK_RATE/freq)
+ : freq) < 0) {
+ printf("\a"); /* Output the only beep we can, in an effort to fall back on usefulness */
+ perror("ioctl");
+ }
+ } else {
+ /* BEEP_TYPE_EVDEV */
+ struct input_event e;
+
+ e.type = EV_SND;
+ e.code = SND_TONE;
+ e.value = freq;
+
+ write(console_fd, &e, sizeof(struct input_event));
+ }
+}
+
/* If we get interrupted, it would be nice to not leave the speaker beeping in
perpetuity. */
void handle_signal(int signum) {
+
+ if(console_device)
+ free(console_device);
+
switch(signum) {
case SIGINT:
if(console_fd >= 0) {
/* Kill the sound, quit gracefully */
- ioctl(console_fd, KIOCSOUND, 0);
+ do_beep(0);
close(console_fd);
exit(signum);
} else {
/* print usage and exit */
void usage_bail(const char *executable_name) {
printf("Usage:\n%s [-f freq] [-l length] [-r reps] [-d delay] "
- "[-D delay] [-s] [-c]\n",
+ "[-D delay] [-s] [-c] [-e device]\n",
executable_name);
printf("%s [Options...] [-n] [--new] [Options...] ... \n", executable_name);
printf("%s [-h] [--help]\n", executable_name);
void parse_command_line(int argc, char **argv, beep_parms_t *result) {
int c;
- struct option opt_list[6] = {{"help", 0, NULL, 'h'},
+ struct option opt_list[7] = {{"help", 0, NULL, 'h'},
{"version", 0, NULL, 'V'},
{"new", 0, NULL, 'n'},
{"verbose", 0, NULL, 'X'},
{"debug", 0, NULL, 'X'},
+ {"device", 1, NULL, 'e'},
{0,0,0,0}};
- while((c = getopt_long(argc, argv, "f:l:r:d:D:schvVn", opt_list, NULL))
+ while((c = getopt_long(argc, argv, "f:l:r:d:D:schvVne:", opt_list, NULL))
!= EOF) {
int argval = -1; /* handle parsed numbers for various arguments */
float argfreq = -1;
case 'X' : /* --debug / --verbose */
result->verbose = 1;
break;
+ case 'e' : /* also --device */
+ console_device = strdup(optarg);
+ break;
case 'h' : /* notice that this is also --help */
default :
usage_bail(argv[0]);
}
}
+ if (result->freq == 0)
+ result->freq = DEFAULT_FREQ;
}
void play_beep(beep_parms_t parms) {
parms.reps, parms.length, parms.delay, parms.end_delay, parms.freq);
/* try to snag the console */
- if((console_fd = open("/dev/tty0", O_WRONLY)) == -1) {
- if((console_fd = open("/dev/vc/0", O_WRONLY)) == -1) {
- fprintf(stderr, "Could not open /dev/tty0 or /dev/vc/0 for writing.\n");
- printf("\a"); /* Output the only beep we can, in an effort to fall back on usefulness */
- perror("open");
- exit(1);
- }
+ if(console_device)
+ console_fd = open(console_device, O_WRONLY);
+ else
+ if((console_fd = open("/dev/input/event0", O_WRONLY)) == -1)
+ if((console_fd = open("/dev/tty0", O_WRONLY)) == -1)
+ console_fd = open("/dev/vc/0", O_WRONLY);
+
+ if(console_fd == -1) {
+ fprintf(stderr, "Could not open %s for writing\n",
+ console_device != NULL ? console_device : "/dev/tty0 or /dev/vc/0");
+ printf("\a"); /* Output the only beep we can, in an effort to fall back on usefulness */
+ perror("open");
+ exit(1);
}
+
+ if (ioctl(console_fd, EVIOCGSND(0)) != -1)
+ console_type = BEEP_TYPE_EVDEV;
+ else
+ console_type = BEEP_TYPE_CONSOLE;
/* Beep */
for (i = 0; i < parms.reps; i++) { /* start beep */
- if(ioctl(console_fd, KIOCSOUND, (int)(CLOCK_TICK_RATE/parms.freq)) < 0) {
- printf("\a"); /* Output the only beep we can, in an effort to fall back on usefulness */
- perror("ioctl");
- }
+ do_beep(parms.freq);
/* Look ma, I'm not ansi C compatible! */
usleep(1000*parms.length); /* wait... */
- ioctl(console_fd, KIOCSOUND, 0); /* stop beep */
+ do_beep(0);
if(parms.end_delay || (i+1 < parms.reps))
usleep(1000*parms.delay); /* wait... */
} /* repeat. */
parms = next;
}
+ if(console_device)
+ free(console_device);
+
return EXIT_SUCCESS;
}
---- beep.1.orig 2005-10-18 19:44:09.000000000 +0200
-+++ beep.1 2005-10-18 19:55:39.000000000 +0200
+--- beep.1.orig 2006-02-14 00:21:35.000000000 +0100
++++ beep.1 2006-02-14 00:25:37.000000000 +0100
@@ -1,9 +1,9 @@
-.TH BEEP 1 "March 2002"
-+.TH BEEP 1 "October 2005"
++.TH BEEP 1 "February 2006"
.SH NAME
beep \- beep the pc speaker any number of ways
.SH SYNOPSIS
.B beep
-[\-f N] [\-l N] [\-r N] [\-d N] [\-D N] [\-s] [\-c]
-+[\-\-verbose | \-\-debug] [\-f N] [\-l N] [\-r N] [\-d N] [\-D N] [\-s] [\-c]
++[\-\-verbose | \-\-debug] [\-e device | \-\-device device] [\-f N] [\-l N] [\-r N] [\-d N] [\-D N] [\-s] [\-c]
.HP
.B beep
[ OPTIONS ] [-n] [--new] [ OPTIONS ]
-@@ -20,6 +20,12 @@
+@@ -20,6 +20,15 @@
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.
.SH OPTIONS
.TP
+beep:
+
+[DEBUG] 5 times 200 ms beeps (100 delay between, 0 delay after) @ 1000.00 Hz
++.TP
++\fB\-e\fR device, \fB\-\-device\fR device
++use device as event device. If the switch isn't used, /dev/input/event0, /dev/tty0 and /dev/vc/0 are tried in turn.
+.TP
\fB\-f\fR N
beep at N Hz, where 0 < N < 20000. As a general ballpark, the regular terminal beep is around 750Hz. N is not, incidentally, restricted to whole numbers.
.TP
-@@ -59,7 +65,8 @@
+@@ -59,7 +68,9 @@
.TP
As part of a log-watching pipeline
-tail -f /var/log/xferlog | grep 'passwd' | \fBbeep\fR -f 1000 -r 5 -s
+tail -f /var/log/xferlog | grep --line-buffered 'passwd' | \\
++.br
+\fBbeep\fR -f 1000 -r 5 -s
.TP
When using -c mode, I recommend using a short -D, and a shorter -l, so that the beeps don't blur together. Something like this will get you a cheesy 1970's style beep-as-you-type-each-letter effect
+beep (1.2.2-17) unstable; urgency=low
+
+ * Added additional debconf translations:
+ - Portuguese by Miguel Figueiredo (closes: #344676)
+ * Updated debconf translation:
+ - Vietnamese by Clytie Siddall (closes: #343851)
+ * Fixed breakage raised with --verbose patch (closes: #335027)
+ * Added udev generation (closes: #350220)
+ * Applied patch from Alessandro Zummo for evdev and general device node
+ support (closes: #350214)
+
+ -- Gerfried Fuchs <alfie@debian.org> Tue, 14 Feb 2006 01:27:06 +0100
+
beep (1.2.2-16) unstable; urgency=low
* The "update for the masses" release.
controlled completely through command line options. It's not supposed to be
complex, and it isn't - but it makes system monitoring (or whatever else it
gets hacked into) much more informative.
+
+Package: beep-udeb
+Architecture: any
+Section: debian-installer
+Depends: ${shlibs:Depends}
+Description: advanced pc-speaker beeper
+ beep does what you'd expect: it beeps. However, it offers various
+ additional features, such as the ability to control pitch, duration,
+ and repetitions.
+ .
+ beep-udeb is a minimal package used by debian-installer.
--- /dev/null
+# Portuguese translation for beep's debconf messages.
+# 2005, Miguel Figueiredo <elmig@debianpt.org>
+#
+# 2005-12-24 - Initial translation
+#
+msgid ""
+msgstr ""
+"Project-Id-Version: beep 1.2.2-16\n"
+"Report-Msgid-Bugs-To: beep@packages.debian.org\n"
+"POT-Creation-Date: 2005-06-14 00:09+0200\n"
+"PO-Revision-Date: 2005-12-24 15:08+0000\n"
+"Last-Translator: Miguel Figueiredo <elmig@debianpt.org>\n"
+"Language-Team: Portuguese <traduz@debianpt.org>\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+
+#. Type: select
+#. Choices
+#: ../templates:3
+msgid ""
+"suid root for all, suid root with only group audio executable, not suid at "
+"all"
+msgstr ""
+"suid root para todos, suid root apenas com o grupo audio executável, sem suid"
+
+#. Type: select
+#. Description
+#: ../templates:5
+msgid "How do you want to handle suid root for the beep program?"
+msgstr "Como deseja lidar com o suid root para o programa beep?"
+
+#. Type: select
+#. Description
+#: ../templates:5
+msgid ""
+"beep must be run as root since it needs to access the speaker hardware. "
+"There are several posibilities to make the program usable: Either only for "
+"root (no suid bit at all), executable only by users of the group audio, or "
+"usable for all."
+msgstr ""
+"O beep tem de ser executado como root já que necessita de acesso ao "
+"hardware do altifalante. Existem várias possibilidades de tornar o "
+"programa utilizável: Quer apenas para o root (sem o bit suid), executável "
+"apenas para utilizadores do grupo audio, ou utilizável para todos."
+
+#. Type: select
+#. Description
+#: ../templates:5
+msgid ""
+"Since each program set as suid root can be a security risk this is not done "
+"by default. However, the program is quite small (~150 lines of code), so it "
+"is fairly easy to verify the safety of the code yourself, if you don't trust "
+"my judgement."
+msgstr ""
+"Já que cada programa como suid root pode ser um risco de segurança isto "
+"não é feito por omissão. No entanto, o programa é bastante pequeno (~150 "
+"linhas de código), por isso é bastante fácil verificar por si mesmo a "
+"segurança do código, se não acreditar no meu julgamento."
-# Vietnamese translation for beep.
+# Vietnamese translation for Beep.
# Copyright © 2005 Free Software Foundation, Inc.
# Clytie Siddall <clytie@riverland.net.au>, 2005.
#
msgid ""
msgstr ""
-"Project-Id-Version: beep 1.2.2-15\n"
+"Project-Id-Version: beep 1.2.2\n"
"Report-Msgid-Bugs-To: beep@packages.debian.org\n"
"POT-Creation-Date: 2005-06-14 00:09+0200\n"
-"PO-Revision-Date: 2005-06-12 18:01+0930\n"
+"PO-Revision-Date: 2005-12-30 12:48+0100\n"
"Last-Translator: Clytie Siddall <clytie@riverland.net.au>\n"
"Language-Team: Vietnamese <gnomevi-list@lists.sourceforge.net>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=1; plural=0\n"
+"X-Generator: LocFactoryEditor 1.5.1b\n"
#. Type: select
#. Choices
"suid root for all, suid root with only group audio executable, not suid at "
"all"
msgstr ""
-"«suid root» cho tất cả, «suid root» chỉ với tập tin có thể chạy âm thanh "
-"nhóm, không có «suid root»"
+"« suid root » cho tất cả, « suid root » chỉ với tập tin có thể chạy âm thanh "
+"nhóm, không có « suid root »"
#. Type: select
#. Description
#: ../templates:5
-#, fuzzy
msgid "How do you want to handle suid root for the beep program?"
-msgstr "Bạn có muốn quản lý «suid root» cho chương trình beep như thế nào?"
+msgstr "Bạn có muốn quản lý « suid root » cho chương trình beep như thế nào?"
#. Type: select
#. Description
"root (no suid bit at all), executable only by users of the group audio, or "
"usable for all."
msgstr ""
-"Trình beep phải chạy là người chủ (root) vì nó cần phải truy cập phần cứng "
-"loa. Vì vậy, bạn cần chọn mức độ truy cập thích hợp:\n"
+"Trình beep phải chạy với tư cách người chủ (root) vì nó cần phải truy cập "
+"phần cứng loa. Vì vậy, bạn cần chọn mức độ truy cập thích hợp:\n"
"• chỉ cho phép người chủ truy cập trình này (không có bit suid)\n"
-"• chỉ cho phép người dùng trong nhóm audio chạy trình này\n"
+"• chỉ cho phép người dùng trong nhóm « audio » (âm thanh) chạy trình này\n"
"• cho phép mọi người truy cập trình này."
#. Type: select
#. Description
#: ../templates:5
-#, fuzzy
msgid ""
"Since each program set as suid root can be a security risk this is not done "
"by default. However, the program is quite small (~150 lines of code), so it "
#!/usr/bin/make -f
# debian/rules file for beep
-PACKAGE = beep
-TMP = $(CURDIR)/debian/$(PACKAGE)
+PKG1 = beep
+TMP1 = $(CURDIR)/debian/$(PKG1)
+PKG2 = beep-udeb
+TMP2 = $(CURDIR)/debian/$(PKG2)
+
+VERSION = $(shell dpkg-parsechangelog | grep "^Version:" | cut -d" " -f 2)
+ARCH = $(shell dpkg-architecture -qDEB_HOST_ARCH)
FLAGS = -g -Wall
INSTALL = install
clean:
$(checkdir)
$(checkroot)
- -rm -rf $(TMP) debian/substvars debian/files build-stamp
+ -rm -rf $(TMP1) $(TMP2) debian/substvars debian/files build-stamp
-$(MAKE) clean
install: build
$(checkdir)
$(checkroot)
- -rm -rf $(TMP) debian/substvars
- $(INSTALL_DIR) $(TMP)
- cd $(TMP) && $(INSTALL_DIR) usr/bin usr/share/man/man1 \
- usr/share/doc/$(PACKAGE)
- $(MAKE) install INSTALL_DIR=$(TMP)/usr/bin \
- MAN_DIR=$(TMP)/usr/share/man/man1
+ -rm -rf $(TMP1) $(TMP2) debian/substvars
+ $(INSTALL_DIR) $(TMP1)
+ cd $(TMP1) && $(INSTALL_DIR) usr/bin usr/share/man/man1 \
+ usr/share/doc/$(PKG1)
+ $(MAKE) install INSTALL_DIR=$(TMP1)/usr/bin \
+ MAN_DIR=$(TMP1)/usr/share/man/man1
-test "$(STRIP)" = "true" && \
strip --remove-section=.comment --remove-section=.note \
- --strip-unneeded $(TMP)/usr/bin/beep
- gunzip $(TMP)/usr/share/man/man1/beep.1.gz
- cd $(TMP)/usr/share/man/man1 && patch beep.1 $(TMP)/../beep.1.diff
- -rm -f $(TMP)/usr/share/man/man1/beep.1.orig
- gzip --best $(TMP)/usr/share/man/man1/beep.1
- chown root:audio $(TMP)/usr/bin/beep
- $(INSTALL_FILE) CREDITS README $(TMP)/usr/share/doc/$(PACKAGE)
- $(INSTALL_FILE) CHANGELOG $(TMP)/usr/share/doc/$(PACKAGE)/changelog
- cd $(TMP)/usr/share/doc/$(PACKAGE) && gzip -9 changelog README
+ --strip-unneeded $(TMP1)/usr/bin/beep
+ gunzip $(TMP1)/usr/share/man/man1/beep.1.gz
+ cd $(TMP1)/usr/share/man/man1 && patch beep.1 $(TMP1)/../beep.1.diff
+ -rm -f $(TMP1)/usr/share/man/man1/beep.1.orig
+ gzip --best $(TMP1)/usr/share/man/man1/beep.1
+ chown root:audio $(TMP1)/usr/bin/beep
+ $(INSTALL_FILE) CREDITS README $(TMP1)/usr/share/doc/$(PKG1)
+ $(INSTALL_FILE) CHANGELOG $(TMP1)/usr/share/doc/$(PKG1)/changelog
+ cd $(TMP1)/usr/share/doc/$(PKG1) && gzip -9 changelog README
+ $(INSTALL_DIR) $(TMP2)/usr/bin
+ $(INSTALL_PROGRAM) beep $(TMP2)/usr/bin
# Build architecture-independent files here.
binary-arch: build install
$(checkdir)
$(checkroot)
- $(INSTALL_DIR) $(TMP)/DEBIAN
+ $(INSTALL_DIR) $(TMP1)/DEBIAN $(TMP2)/DEBIAN
$(INSTALL_FILE) debian/README.Debian debian/copyright \
- $(TMP)/usr/share/doc/$(PACKAGE)
+ $(TMP1)/usr/share/doc/$(PKG1)
$(INSTALL_FILE) debian/changelog \
- $(TMP)/usr/share/doc/$(PACKAGE)/changelog.Debian
- gzip -9 $(TMP)/usr/share/doc/$(PACKAGE)/changelog.Debian
+ $(TMP1)/usr/share/doc/$(PKG1)/changelog.Debian
+ gzip -9 $(TMP1)/usr/share/doc/$(PKG1)/changelog.Debian
$(INSTALL_SCRIPT) debian/postinst debian/postrm debian/config \
- $(TMP)/DEBIAN
- po2debconf debian/templates > $(TMP)/DEBIAN/templates
- dpkg-shlibdeps -Tdebian/substvars -dDepends $(TMP)/usr/bin/beep
- dpkg-gencontrol -ldebian/changelog -isp -Tdebian/substvars -p$(PACKAGE) \
- -P$(TMP)
- cd $(TMP) && find * -type f ! -regex '^DEBIAN/.*' -print0 | \
+ $(TMP1)/DEBIAN
+ po2debconf debian/templates > $(TMP1)/DEBIAN/templates
+ dpkg-shlibdeps -Tdebian/substvars -dDepends $(TMP1)/usr/bin/beep
+ dpkg-gencontrol -ldebian/changelog -isp -Tdebian/substvars -p$(PKG1) \
+ -P$(TMP1)
+ cd $(TMP1) && find * -type f ! -regex '^DEBIAN/.*' -print0 | \
xargs -r0 md5sum > DEBIAN/md5sums
- dpkg --build $(TMP) ..
+ dpkg --build $(TMP1) ..
+ dpkg-gencontrol -ldebian/changelog -isp -Tdebian/substvars -p$(PKG2) \
+ -P$(TMP2) -n$(PKG2)_$(VERSION)_$(ARCH).udeb
+ dpkg --build $(TMP2) ../$(PKG2)_$(VERSION)_$(ARCH).udeb
binary: binary-arch