Fixed possible double close of device in case of error.

Opening device in O_RDONLY mode, instead of O_RDWR.
This commit is contained in:
Sascha Hlusiak
2007-04-15 23:48:52 -04:00
parent 1640d08d16
commit 8cafcf33ec
2 changed files with 9 additions and 1 deletions

View File

@@ -96,6 +96,7 @@ jstkOpenDevice(JoystickDevPtr joystick)
xf86Msg(X_ERROR, "Joystick: hid_get_report_desc failed: %s\n",
strerror(errno));
close(joystick->fd);
joystick->fd = -1;
return -1;
}
@@ -103,6 +104,7 @@ jstkOpenDevice(JoystickDevPtr joystick)
xf86Msg(X_ERROR, "Joystick: ioctl USB_GET_REPORT_ID failed: %s\n",
strerror(errno));
close(joystick->fd);
joystick->fd = -1;
return -1;
}
@@ -115,6 +117,7 @@ jstkOpenDevice(JoystickDevPtr joystick)
hid_dispose_report_desc(rd);
free(bsddata);
close(joystick->fd);
joystick->fd = -1;
return -1;
}
@@ -182,6 +185,7 @@ jstkOpenDevice(JoystickDevPtr joystick)
xf86Msg(X_ERROR, "Joystick: Didn't find any usable axes.\n");
free(bsddata);
close(joystick->fd);
joystick->fd = -1;
return -1;
}

View File

@@ -65,7 +65,7 @@ jstkOpenDevice(JoystickDevPtr joystick)
unsigned char axes, buttons;
int driver_version;
if ((joystick->fd = open(joystick->device, O_RDWR | O_NDELAY, 0)) < 0) {
if ((joystick->fd = open(joystick->device, O_RDONLY | O_NDELAY, 0)) < 0) {
xf86Msg(X_ERROR, "Cannot open joystick '%s' (%s)\n", joystick->device,
strerror(errno));
return -1;
@@ -75,6 +75,7 @@ jstkOpenDevice(JoystickDevPtr joystick)
xf86Msg(X_ERROR, "Joystick: ioctl on '%s' failed: %s\n", joystick->device,
strerror(errno));
close(joystick->fd);
joystick->fd = -1;
return -1;
}
if ((driver_version >> 16) < 1) {
@@ -88,6 +89,7 @@ jstkOpenDevice(JoystickDevPtr joystick)
xf86Msg(X_ERROR, "Joystick: ioctl on '%s' failed: %s\n", joystick->device,
strerror(errno));
close(joystick->fd);
joystick->fd = -1;
return -1;
}
@@ -95,6 +97,7 @@ jstkOpenDevice(JoystickDevPtr joystick)
xf86Msg(X_ERROR, "Joystick: ioctl on '%s' failed: %s\n", joystick->device,
strerror(errno));
close(joystick->fd);
joystick->fd = -1;
return -1;
}
@@ -102,6 +105,7 @@ jstkOpenDevice(JoystickDevPtr joystick)
xf86Msg(X_ERROR, "Joystick: ioctl on '%s' failed: %s\n",
joystick->device, strerror(errno));
close(joystick->fd);
joystick->fd = -1;
return -1;
}