According to man page sem_getvalue() may return -1 on error and possibly set errno to EINVAL when the given semaphore is not valid. This seems to be inconsistent with the current glibc implementation which always return 0 (see comment on missing argument check at [1]). Should we simply drop the reference to -1 return value and ERRORS from man page? [1] https://sourceware.org/git/?p=glibc.git;a=blob;f=nptl/sem_getvalue.c;h=d33993d7ac2f4ac9c3ed550985e63ee47d54baa3;hb=HEAD
This is tricky. POSIX allows for EINVAL, and portable applications may care about it. It's true that glibc doesn't check for a valid semaphore, but maybe one day it might. In the source file that you refer to there is this comment: /* XXX Check for valid SEM parameter. */ Admittedly, that comment has been there for a very long time, and nothing so far changed though. I opted to add a sentence: EINVAL sem is not a valid semaphore. (The glibc implementation currently does not check whether sem is valid.) Closing this report now.
Ok Michael, it makes sense! Thanks for looking at it.