tech-kern archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: Strange semaphore behavior, sem_init() fails with errno 4294967295 (-1)



> In each thread, my software does a fork() followed by an execve().
> If I remove this fork(), I'm unable to reproduce this bug.

I have a fuzzy memory that fork() may do something to semaphores...?

> int
> sem_init(sem_t *sem, int pshared, unsigned int value)
> {
>     intptr_t    semid;
>     int error;
> 
>     if (_ksem_init(value, &semid) == -1)
>         return (-1);
> 
>     if ((error = sem_alloc(value, semid, sem)) != 0) {
>         _ksem_destroy(semid);
>         errno = error;
>         return (-1);
>     }
> 
>     return (0);
> }

> As errno contains an error, I suppose that sem_alloc() returns this
> error, but sem_alloc() can only return ENOSPC or EINVAL...

If _ksem_init is, as the name seems to imply, a kernel call, could it
maybe be setting errno?

What is your basis for saying that sem_alloc can generate only ENOSPC
and EINVAL?  Reading the source, or looking at documentation, or what?
In particular, if it's documentation, don't trust it too much; I've
seen documentation lie far too often.

Also, don't forget that successful calls normally don't touch errno,
though I _think_ that doesn't matter here....

/~\ The ASCII				  Mouse
\ / Ribbon Campaign
 X  Against HTML		mouse%rodents-montreal.org@localhost
/ \ Email!	     7D C8 61 52 5D E7 2D 39  4E F1 31 3E E8 B3 27 4B


Home | Main Index | Thread Index | Old Index