Re: Question about shm_open and sem_open

2015-12-10 Thread Ted Unangst
Jeunder Yu wrote: > > geteuid may be better. though i would hope the difference doesn't matter. > > The difference is very important for me. > > In my application, I am root and change to different uid, create semaphore > and share memory, make some hand sharking to client app with different uid.

Re: Question about shm_open and sem_open

2015-12-10 Thread Jeunder Yu
2015年11月20日 下午2:46於 "Ted Unangst" 寫道: > > 游俊德 wrote: > > Hello, > > > > I have a question about source code of shm_open and sem_open functions. > > > > int > > shm_open(const char *path, int flags, mode_t mode) > > { > >

Re: Question about shm_open and sem_open

2015-11-19 Thread Ted Unangst
游俊德 wrote: > Hello, > > I have a question about source code of shm_open and sem_open functions. > > int > shm_open(const char *path, int flags, mode_t mode) > { > (skipped) > > if (sb,st_uid != getuid()) { > close(fd

Question about shm_open and sem_open

2015-11-19 Thread 游俊德
Hello, I have a question about source code of shm_open and sem_open functions. int shm_open(const char *path, int flags, mode_t mode) { (skipped) if (sb,st_uid != getuid()) { close(fd); errno = EPERM; return -1

Re: sem_open value

2013-11-21 Thread Vadim Zhukov
2013/11/21 Ted Unangst : > Read the standard again and discovered some more missing features. > > 1. sem_open allows setting the value via a fourth argument. Fixed. > > 2. Multiple sem_open calls of the same path in the same process are > supposed to return the same pointer. Not

sem_open value

2013-11-20 Thread Ted Unangst
Read the standard again and discovered some more missing features. 1. sem_open allows setting the value via a fourth argument. Fixed. 2. Multiple sem_open calls of the same path in the same process are supposed to return the same pointer. Not the same semaphore, the same pointer. This is mind

Re: sem_open

2013-11-20 Thread Ted Unangst
On Wed, Nov 20, 2013 at 23:12, Stuart Henderson wrote: > On 2013/11/20 18:09, Ted Unangst wrote: >> On Wed, Nov 20, 2013 at 21:59, Stuart Henderson wrote: >> > graphics/ilmbase hangs during autoconf; it runs something close to this >> >> The diff I previously posted seems to fix this. At least, I c

Re: sem_open

2013-11-20 Thread Stuart Henderson
On 2013/11/20 18:09, Ted Unangst wrote: > On Wed, Nov 20, 2013 at 21:59, Stuart Henderson wrote: > > graphics/ilmbase hangs during autoconf; it runs something close to this > > The diff I previously posted seems to fix this. At least, I could > repro with a snapshot and now I can't reproduce after

Re: sem_open

2013-11-20 Thread Ted Unangst
tted one more bug, but it shouldn't affect i386 or amd64. The spinlock needs to be initialized in sem_open. > #include > int > main() > { > sem_t mysem; > > if (sem_init(&mysem, 1, 1) == 0) { > if (sem_wait(&mysem) == 0) { > sem_post(&mysem); > sem_destroy(&mysem); > } > } > }

sem_open

2013-11-20 Thread Stuart Henderson
graphics/ilmbase hangs during autoconf; it runs something close to this #include int main() { sem_t mysem; if (sem_init(&mysem, 1, 1) == 0) { if (sem_wait(&mysem) == 0) { sem_post(&mysem); sem_destroy(&mysem);

better sem_open internals

2013-11-20 Thread Ted Unangst
- sem_t sem = *semp; + sem_t sem; int r; - if (!semp || !*semp) { + if (!semp || !(sem = *semp)) { errno = EINVAL; return (-1); } @@ -316,7 +313,7 @@ sem_open(const char *name, int oflag, .. char sempath[SEM_PATH_SIZE];

sem_open goldilocks

2013-11-19 Thread Ted Unangst
/lib/librthread/rthread_sem.c,v retrieving revision 1.12 diff -u -p -r1.12 rthread_sem.c --- rthread_sem.c 20 Nov 2013 03:16:39 - 1.12 +++ rthread_sem.c 20 Nov 2013 03:32:36 - @@ -338,7 +338,17 @@ sem_open(const char *name, int oflag, .. errno = EPERM;

Re: sem_open

2013-10-25 Thread Vadim Zhukov
> This may or may not be a working implementation of sem_open. This is a bit improved version of Ted's diff: * Add support of shared=1 for sem_init() * Less memory leaks in error paths * More strong checks where applicable This is RFC/FYI status only, still under testing. -- zhuk@

Re: sem_open

2013-10-25 Thread Vadim Zhukov
2013/10/26 Ted Unangst : > This may or may not be a working implementation of sem_open. > > Using tricks similar to those used in shm_open, we create a semaphore > in a tmp file shared by mmap. This lets other processes share the > spinlock and counter. Our thrsleep and thrwakeup

Re: sem_open

2013-10-25 Thread Theo de Raadt
> On Sat, Oct 26, 2013 at 00:54, Vadim Zhukov wrote: > >> +/* SHA256_DIGEST_STRING_LENGTH includes nul */ > >> +/* "/tmp/" + sha256 + ".sem" */ > > > > Shouldn't this respect the TMPDIR envvar? > > No, it's an internal artifact of the implementation. And furthermore, making additional library fu

Re: sem_open

2013-10-25 Thread Ted Unangst
On Sat, Oct 26, 2013 at 00:54, Vadim Zhukov wrote: >> +/* SHA256_DIGEST_STRING_LENGTH includes nul */ >> +/* "/tmp/" + sha256 + ".sem" */ > > Shouldn't this respect the TMPDIR envvar? No, it's an internal artifact of the implementation.

Re: sem_open

2013-10-25 Thread Vadim Zhukov
2013/10/26 Ted Unangst : > This may or may not be a working implementation of sem_open. > > Using tricks similar to those used in shm_open, we create a semaphore > in a tmp file shared by mmap. This lets other processes share the > spinlock and counter. Our thrsleep and thrwakeup

sem_open

2013-10-25 Thread Ted Unangst
This may or may not be a working implementation of sem_open. Using tricks similar to those used in shm_open, we create a semaphore in a tmp file shared by mmap. This lets other processes share the spinlock and counter. Our thrsleep and thrwakeup syscalls don't really work between processes,