tech-userlevel archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
sem_open(2) and ENAMETOOLONG
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256
The sem_open(2) function call reports an error for a too long name and
sets errno:
[ENAMETOOLONG] The name argument is too long.
I noted in the kernel that the limit is SEM_MAX_NAMELEN:
do_ksem_open(struct lwp *l, const char *semname, int oflag, mode_t mode,
unsigned int value, intptr_t *idp, copyout_t docopyout)
{
char name[SEM_MAX_NAMELEN + 1];
proc_t *p = l->l_proc;
ksem_t *ksnew = NULL, *ks;
file_t *fp;
intptr_t id;
int fd, error;
error = copyinstr(semname, name, sizeof(name), NULL);
if (error) {
return error;
}
-- sys/kern/uipc_sem.c
The limit is held privately in the kernel:
sys/kern/uipc_sem.c:#define SEM_MAX_NAMELEN 14
I read in the POSIX resources that the limit is defined by PATH_MAX or
its variation:
ENAMETOOLONG
The length of the name argument exceeds {PATH_MAX} or a pathname
component is longer than {NAME_MAX}.
-- https://man-k.org/man/posix/3P/sem_open?r=1&q=sem_open
[ENAMETOOLONG]
The length of the name argument exceeds {_POSIX_PATH_MAX} on
systems that do not support the XSI option [XSI] [Option Start] or
exceeds {_XOPEN_PATH_MAX} on XSI systems, [Option End] or has a
pathname component that is longer than {_POSIX_NAME_MAX} on systems
that do not support the XSI option [XSI] [Option Start] or longer
than {_XOPEN_NAME_MAX} on XSI systems. [Option End]
--
http://pubs.opengroup.org/onlinepubs/9699919799/functions/sem_open.html
Is our code compliant? If so, could we export SEM_MAX_NAMELEN to
userland header.
MacOSX defines SEM_NAME_LEN as 31.
https://developer.apple.com/library/ios/documentation/System/Conceptual/
ManPages_iPhoneOS/man2/sem_open.2.html
Additionally I noted that SEM_VALUE_MAX is defined at least twice in
the code-base, in <semaphore.h> and sys/kern/uipc_sem.c (thankfully
with the same value: ~0U).
FreeBSD seems to respect the PATH_MAX property of the name argument:
sem_t *
_sem_open(const char *name, int flags, ...)
{
char path[PATH_MAX];
/***/
--
https://github.com/freebsd/freebsd/blob/af3e10e5a78d3af8cef6088748978c6c
612757f0/lib/libc/gen/sem_new.c#L158
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2
iQIcBAEBCAAGBQJXG51vAAoJEEuzCOmwLnZsCkYP/2WO36+5+ST5UJqUn5eNbkyf
OKWjLuIJ4pcFyIkKDz3+QrEtfcsPftpEQ1XYG/v5mt41cNYebJYwdYS8na/GUs3B
fcBPNKGMKaEDyo+aVMZKvZyKKtHN9lRuLyPyTQtbiczM18piorSV6XrY7w6E/wwQ
IuAff3k2qsAG2jDZ6mGDiQALbjL5A3dGpmTOJ14tKwKd3GtaKwolkR87nhlb/lBD
J6FRNa3jv3N7vqD5u4Jhb5sX9gVH/rjlB0fvsz09lQpS3l1X39eKkuvNnsuF5OQv
No1lngOv0S2v/pAlMOnIqJCascLP+nGY77cMA7wC5M92zN80gT8rkbrCKC5ps2Ks
MQSAuaPkpWKQv8NgslizZmTvLt1DOzkix/E4myyCgkrK0X9VHYYL1UmJin4n0ne9
b1Y6YL102qxgF3dgf6QXq+B6h5JCKaSg2qvtHx+jFmfR4JzLciZZDlZgdgZ56md3
K1cVamllP7/7gYF8p7h7C96ZRQg0sUjiSqtEbjltC3uBN4Xnf4iwWhFX9oRclWVh
sLeg1L7EAJNjONGIOXHH+s8YeKQSyOrlfh0PDkHwh281P/Sj+KSSXIoGNWRbbEfJ
7M5ralQMr+IiVKVMpjPkxoLdnUEXt0p39G/Kx5Vpe6kV8A7D+7kw3GZMs/Rxr0NK
pFTZtP8UkLrx4NFK+aFs
=nAqN
-----END PGP SIGNATURE-----
Home |
Main Index |
Thread Index |
Old Index