Hi!
I am trying to create a userspace driver with module uinput and I am
getting into trouble when I terminate the program that creates the
device. After a while the machine will crash ...
The object is to create a joystick device, and I might be missing some
important bits of documentation. So far I am not writing any data to the
interface, but js_demo will find it and open it, showing the expected
number of axis. The name of the interface looks like random though,
which worries me and gets me to suspect that something is wrong
Any idea why the machine is crashing or has a pointer to some example I
could study? As long as I just let the program run, there is no
problem ... Only on termination.
This is what I have gotten so far in the uinput department:
--8<-------------------------------------------------
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <signal.h>
#include <linux/input.h>
#include <linux/uinput.h>
int create_uinput() {
int fd = -1;
fd = open ("/dev/uinput", O_RDWR);
if (fd <= 0)
{
fprintf (stderr,"could not open uinput device\n");
exit(EXIT_FAILURE);
}
memset (&uinp, 0, sizeof (struct uinput_user_dev));
strncpy (uinp.name, "NoJoy!", 7); // FIXME!
uinp.id.version = 4;
uinp.id.bustype = BUS_USB;
ioctl (fd, UI_SET_EVBIT, EV_ABS);
ioctl (fd, UI_SET_EVBIT, EV_KEY);
ioctl (fd, UI_SET_ABSBIT, ABS_X);
ioctl (fd, UI_SET_ABSBIT, ABS_Y);
ioctl (fd, UI_SET_ABSBIT, ABS_Z);
ioctl (fd, UI_SET_ABSBIT, ABS_THROTTLE);
ioctl (fd, UI_SET_KEYBIT, BTN_TOP);
ioctl (fd, UI_SET_KEYBIT, BTN_TOP2);
ioctl (fd, UI_SET_KEYBIT, BTN_BASE);
ioctl (fd, UI_SET_KEYBIT, BTN_BASE2);
ioctl (fd, UI_SET_KEYBIT, BTN_BASE3);
ioctl (fd, UI_SET_KEYBIT, BTN_BASE4);
// Create device
write (fd, &uinp, sizeof (uinp));
if (ioctl (fd, UI_DEV_CREATE))
{
fprintf (stderr,"could not create uinput device.\n");
exit(EXIT_FAILURE);
}
sigset(SIGINT,destroy_uinput);
sigset(SIGTERM,destroy_uinput);
return fd;
}
void destroy_uinput()
{
fprintf(stderr,"NoJoy says: BYE!\n");
if(uinp_fd > 0)
{
ioctl (uinp_fd, UI_DEV_DESTROY);
close (uinp_fd);
}
exit(0);
}
-- _______________________________________________ Linux-audio-dev mailing list Linux-audio-dev@email-addr-hidden http://lists.linuxaudio.org/mailman/listinfo.cgi/linux-audio-devReceived on Thu Sep 27 16:15:07 2007
This archive was generated by hypermail 2.1.8 : Thu Sep 27 2007 - 16:15:07 EEST