tags 466855 +patch
thanks

Hi all,

Il giorno sab, 23/02/2008 alle 15.05 +0100, Julien BLACHE ha scritto:
> Giuseppe Sacco <[EMAIL PROTECTED]> wrote:
> 
> Hi,
> 
> > [snapscan] add_usb_device(libusb:001:002)
> > [snapscan] add_usb_device: Detected (kind of) an USB device
> > [snapscan] snapscani_usb_open(libusb:001:002)
> > [snapscan] snapscani_usb_open: Can't get semaphore
> > [snapscan] add_usb_device: error opening device libusb:001:002: Invalid 
> > argument
> 
> Oliver, this happens on PowerPC with SANE 1.0.19. Any idea about
> what's going on here ?

I think I found the problem, while I do not have any solution right now.
The semaphore implementation used on linux/powerpc is not the pthread
one, so the semaphore creation is done via 

static int snapscani_mutex_open(snapscan_mutex_t* sem_id, const char* dev)
{
    *sem_id = semget( ftok(dev,0x12), 1, IPC_CREAT | 0660 );
    if (*sem_id != -1)
    {
        semop(*sem_id, &sem_signal, 1);
        return 1;
    }
    return 0;
}

This is a problem when dev is not a pathname. In my case
dev="libusb:001:003" and this means ftok() returns -1, so that even
semget() will return an error (Permission denied).

Accourding to the ftok(3) manual page, the first argument "must refer to
an existing, accessible file". So, probably, we have to find a way to
get a pathname like /dev/bus/usb/001/003 from libusb, or create a faked
one.

The following patch make the program working in this peculiar case. I
don't know if this is a general solution, or if this might create new
bugs.

static int snapscani_mutex_open(snapscan_mutex_t* sem_id, const char* dev)
{
    char x[24];
    /* dev="libusb:001:003"
            01234567890123 */
    if (strncmp(dev, "libusb:", 7) == 0) {
       strcpy(x, "/dev/bus/usb/");
       strncat(x, &dev[7], 3);
       strcat(x, "/");
       strncat(x, &dev[11], 3);
       dev=x;
    }

    *sem_id = semget( ftok(dev,0x12), 1, IPC_CREAT | 0660 );
    if (*sem_id != -1)
    {
        semop(*sem_id, &sem_signal, 1);
        return 1;
    }
    return 0;
}

Bye,
Giuseppe




-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]

Reply via email to