Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LOCK_EX not available on solaris #2

Closed
GoogleCodeExporter opened this issue May 7, 2015 · 2 comments
Closed

LOCK_EX not available on solaris #2

GoogleCodeExporter opened this issue May 7, 2015 · 2 comments

Comments

@GoogleCodeExporter
Copy link

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.

Original issue reported on code.google.com by FISHMAN...@gmail.com on 9 Dec 2010 at 12:00

@GoogleCodeExporter
Copy link
Author

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.

Original comment by j...@unixpapa.com on 5 Oct 2011 at 4:16

  • Changed state: Accepted

@GoogleCodeExporter
Copy link
Author

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.

Original comment by j...@unixpapa.com on 6 Oct 2011 at 2:32

  • Changed state: Fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant