sem_open can't open a name with directory
- From: "Xiong, Crystal" <crystal xiong intel com>
- To: phil-list redhat com
- Subject: sem_open can't open a name with directory
- Date: Tue, 28 Jan 2003 21:00:54 +0800
Title: Message
If define name as "/tmp/xxxx", and invoke sem_open(name, flag...), sem_open will failed with "No such file or directory".
Looked into the code sem_open.c, the reason is that the name ("/tmp/xxxx")will map to /dev/shm/sem.tmp/xxxx, but sem.tmp directory is not there, so there will be an error.
I think in sem_open.c, it maybe needs a check of whether name has more slash characters other than the leading slash character.
If it has, mkdir the related directory before rename operation (sem_open.c:234), such as the following:
tmpname = strrchr(finalname, '/'); // get the file name without directory
strncpy(pathname, finalname, strlen(finalname) - strlen(tmpname)); // get the directory path
mkdir(pathname, 0777)
To the POSIX std, it says the interpretation of slash characters other than the leading slash character in name is implementaion defined. I think it will be more friendly to
allow the user using a name with directory.
Thanks,
Crystal
------------------------------------------------------------------------------------------------
This is only my personal opinion.
Crystal Xiong
Intel China Software Lab