Example #1
0
static int
gp_port_usbscsi_open (GPPort *port)
{
    int result, i;
    const int max_tries = 5;
    const char *path = port->settings.usbscsi.path;

    port->pl->fd = open (path, O_RDWR);
    if (port->pl->fd == -1) {
        gp_port_set_error (port, _("Failed to open '%s' (%m)."), path);
        return GP_ERROR_IO;
    }

    result = gp_port_usbscsi_lock (port);
    for (i = 0; i < max_tries && result == GP_ERROR_IO_LOCK; i++) {
        GP_LOG_D ("Failed to get a lock, trying again...");
        sleep (1);
        result = gp_port_usbscsi_lock (port);
    }
    if (result != GP_OK) {
        close (port->pl->fd);
        port->pl->fd = -1;
    }
    return result;
}
Example #2
0
static int
gp_port_usbscsi_open (GPPort *port)
{
	int result, i;
	const int max_tries = 5;
	const char *path = port->settings.usbscsi.path;

	result = gp_port_usbscsi_lock (port, path);
	if (result != GP_OK) {
		for (i = 0; i < max_tries; i++) {
			result = gp_port_usbscsi_lock (port, path);
			if (result == GP_OK)
				break;
			gp_log (GP_LOG_DEBUG, "gphoto2-port-usbscsi",
				"Failed to get a lock, trying again...");
			sleep (1);
		}
		CHECK (result)
	}
	port->pl->fd = open (path, O_RDWR);
	if (port->pl->fd == -1) {
		gp_port_usbscsi_unlock (port, path);
		gp_port_set_error (port, _("Failed to open '%s' (%m)."), path);
		return GP_ERROR_IO;
	}

	return GP_OK;
}