Subject: Re: How to produce BEEP
To: None <netbsd-help@NetBSD.ORG>
From: Mike Long <mike.long@analog.com>
List: netbsd-help
Date: 10/16/1996 21:25:34
>Date: Wed, 16 Oct 1996 17:57:39 -0400
>From: Hacksaw <hacksaw@remote116.channel1.com>

>Ummm, did you try it?
>
>I compiled Mike's program. Nothing. Not when pointed at /dev/console,
>not when pointed at /dev/vt0 (my real console), not when pointed at
>/dev/vt7 (the vt in use by X). But beeping works, emacs and shells do
>it fine.

Obviously, I didn't try it. :-)

>Nope. I think the solutions =
>i386: compile a kernel with the "speaker" device added,
>All others: S**t Outta Luck?

A little UTSLing yielded ioctl(CONSOLE_X_BELL).  So, here's my second
try:

#include <unistd.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#define CONSOLE_X_BELL _IOW('t', 123, int[2])
void beep(void)
{
    int f = open("/dev/console", O_WRONLY | O_NOCTTY);
    int a[2] = { 2600, 500 }; /* pitch (Hz), duration (ms) */
    if (f >= 0) {
	ioctl(f, CONSOLE_X_BELL, a);
	close(f);
    }
}

YMMV on different ports.  It also probably won't work if you don't
have "options XSERVER" in your kernel config.  The binary needs to be
setuid root.
-- 
Mike Long <mike.long@analog.com>     <URL:http://www.shore.net/~mikel>
VLSI Design Engineer         finger mikel@shore.net for PGP public key
Analog Devices, CPD Division          CCBF225E7D3F7ECB2C8F7ABB15D9BE7B
Norwood, MA 02062 USA       (eq (opinion 'ADI) (opinion 'mike)) -> nil