Export to GitHub

pwauth - issue #2

LOCK_EX not available on solaris


Posted on Dec 9, 2010 by Grumpy Giraffe

What steps will reproduce the problem? 1. Enable SLEEP_LOCK 2. compile

What is the expected output? What do you see instead? gcc -g -c snooze.c snooze.c: In function snooze': snooze.c:51: error:LOCK_EX' undeclared (first use in this function) snooze.c:51: error: (Each undeclared identifier is reported only once snooze.c:51: error: for each function it appears in.) * Error code 1 make: Fatal error: Command failed for target `snooze.o'

What version of the product are you using? On what operating system? pwauth 2.3.8 SunOS 5.11 snv_151a i86pc i386 i86pc

Please provide any additional information below. It looks like the LOCK_EX macro isn't defined in Solaris, and there isn't an easy way to replace it. The code compiles just fine with SLEEP_LOCK disabled.

Comment #1

Posted on Oct 5, 2011 by Happy Wombat

Ugh. Solaris seems to have manual pages claiming it has flock() but they lie.

Probably I should rewrite this using fcntl() which is probably more portable.

Probably the function would change to something like:

snooze(int seconds) { int slfd; struct flock lock; lock.l_type= F_WRLCK; lock.l_whence= SEEK_SET; lock.l_start= 0; lock.l_len= 0;

/* Lock the sleep-lock file to serialize our sleeps */

if ((slfd= open(SLEEP_LOCK,O_CREAT|O_RDWR,0644)) >= 0)
    fcntl(slfd,F_SETLKW,&lock);

sleep(seconds);

/* Release sleep-lock file */
/*lock.l_type= F_UNLCK; fcntl(slfd,F_SETLK,&lock);*/
close(slfd);

}

But I haven't tested that at all.

Comment #2

Posted on Oct 6, 2011 by Happy Wombat

Version 2.3.10 has been modified to use fcntl() locking instead of flock() locking. Since fcntl() is a POSIX standard, I believe it should be more portable and should work on Solaris.

Status: Fixed

Labels:
Type-Defect Priority-Medium