Re: /proc/beep

From: Neil Brown (neilb_at_cse.unsw.edu.au)
Date: 09/11/03

  • Next message: richard.brunner_at_amd.com: "RE: [PATCH] 2.6 workaround for Athlon/Opteron prefetch errata"
    To: Frank Cusack <fcusack@fcusack.com>
    Date:	Thu, 11 Sep 2003 14:42:21 +1000
    
    

    On Wednesday September 10, fcusack@fcusack.com wrote:
    > /proc/beep is a kernel tweak that sends beep "signals" to a userspace
    > process reading the /proc/beep file. There are one or two of these
    > modules you can find on the Internet. In order to support them the
    > kernel needs to export kd_mksound.
    >
    > Would a /proc/beep module be accepted into the main tree? From the
    > ones I've found, I can understand why they might not be accepted. But
    > I'm willing to do the [small amount of] work required to get one looking
    > like other kernel modules.
    >
    > If not, could at least kd_mksound be exported by default anyway? This
    > would allow homegrown /proc/beep's to not require any kernel mods.

    The equivalent can be done with the "input layer" in 2.6.
    Open /dev/input/uinput and register yourself as a beep handler, and
    you get the beeps instead of the speaker.

    The following code does this (but doesn't claim to be well written,
    portable, reliable, secure, or anything else).

    It requires you do be runnig 'esd' and to have loaded some sample into
    esd. The sample is played instead of any beep.

    NeilBrown

    /*
     * A user event handler that notices bells and
     * echos something
     */

    #include <linux/input.h>
    #include <linux/uinput.h>
    #include <fcntl.h>
    #include <stdio.h>

    main(int argc, char *argv[])
    {
            char *dev = "/dev/input/user";
            int fd;
            int esd,id;
            struct input_event ev;
            struct uinput_user_dev dv;
            if (argc >= 2)
                    dev = argv[1];

            
            fd = open(dev, O_RDWR, 0);
            if (!fd) {
                    perror(dev);
                    exit(1);
            }
            memset(&dv, 0, sizeof(dv));
            strcpy(dv.name, "Quiet Bell");
            dv.id.bustype = 0;
            dv.id.vendor = 0;
            dv.id.product = 0;
            dv.id.version = 1;

            if (write(fd, &dv, sizeof(dv)) != sizeof(dv)) {
                    perror("Write device name");
                    exit(1);
            }
            if (ioctl(fd, UI_SET_EVBIT, EV_SND)) {
                    perror("Cannot request snd event");
                    exit(1);
            }
            if (ioctl(fd, UI_SET_SNDBIT, 0)) {
                    perror("Cannot request Click");
                    exit(1);
            }
            if (ioctl(fd, UI_SET_SNDBIT, 1)) {
                    perror("Cannot request Bell");
                    exit(1);
            }
            if (ioctl(fd, UI_SET_SNDBIT, 2)) {
                    perror("Cannot request Tone");
                    exit(1);
            }

            if (ioctl(fd, UI_DEV_CREATE, NULL)) {
                    perror("Create uinput dev");
                    exit(1);
            }

            if (argc > 2) {
                    esd = esd_open_sound(NULL);
                    id = esd_sample_getid(esd, argv[2]);
            }

            while (read(fd, &ev, sizeof(ev)) == sizeof(ev)) {
                    if (argc <= 2)
                            printf("%d %d %d\n", ev.type, ev.code, ev.value);
                    else if (ev.type == 18 && ev.code == 2 && ev.value > 0)
                            esd_sample_play(esd, id);
            }
            exit(0);
    }
    -
    To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
    the body of a message to majordomo@vger.kernel.org
    More majordomo info at http://vger.kernel.org/majordomo-info.html
    Please read the FAQ at http://www.tux.org/lkml/


  • Next message: richard.brunner_at_amd.com: "RE: [PATCH] 2.6 workaround for Athlon/Opteron prefetch errata"

    Relevant Pages

    • Re: NUMA mempolicy /proc code in mainline shouldnt have been merged
      ... > understand what features the kernel needs to offer. ... Could we just do the numa_maps in the right way now and do a code cleanup ... user interface / system interface separation)? ... send the line "unsubscribe linux-kernel" in ...
      (Linux-Kernel)
    • Re: [RFC][PATCH] Runtime switching of the idle function [take 2]
      ... At no point do you appear to explain _why_ the kernel needs this feature? ... The use of yield() could be problematic - its semantics are rather ... send the line "unsubscribe linux-kernel" in ...
      (Linux-Kernel)
    • Re: Linux 2.6.9-rc1
      ... >>protected under a write lock. ... > Why this new exported symbol? ... Because other code that is not yet in the kernel needs it (like ... send the line "unsubscribe linux-kernel" in ...
      (Linux-Kernel)