Operating System - HP-UX
1756584 Members
3103 Online
108848 Solutions
New Discussion юеВ

Re: pstat_getpathname releases fcntl lock?

 
Randy Proctor
New Member

pstat_getpathname releases fcntl lock?

When I call pstat_getpathname, the fcntl lock I had on the file descriptor is released. Can anyone confirm this behavior and/or point me toward something I am doing wrong?

Example output of the program follows. The "waiting" pid should not say "got lock" until the holding pid says "releasing lock". Commenting out the call to pstat_getpathname fixes this behavior.

6869: got lock on 3
6869: sleeping...
6868: waiting for lock on 3...
6869: calling pstat_getpathname
6868: got lock on 3

Code:

#define _PSTAT64
#include
#include
#include
#include
#include
#include

int main(int argc, char *argv[])
{
struct flock lock;
pid_t pid;
int result;
int fd;

pid = fork();

fd = open("/tmp/locktest",O_RDWR|O_CREAT,0666);
if (fd == -1) return EXIT_FAILURE;

printf("%5d: waiting for lock on %d...\n",getpid(),fd);
lock.l_type = F_WRLCK;
lock.l_start = 0;
lock.l_len = 0;
lock.l_whence = SEEK_SET;
do {
errno = 0;
result = fcntl(fd,F_SETLKW,&lock);
} while (result == -1 && errno == EINTR);
if (result == -1) return EXIT_FAILURE;

printf("%5d: got lock on %d\n",getpid(),fd);

printf("%5d: sleeping...\n",getpid());
sleep(1);

printf("%5d: calling pstat_getpathname\n",getpid());
{
char filename[PATH_MAX];
struct pst_fileinfo2 psf;
pstat_getfile2(&psf,sizeof(psf),0,fd,getpid());
pstat_getpathname(filename,sizeof(filename),&psf.psf_fid);
}

printf("%5d: sleeping...\n",getpid());
sleep(2);

printf("%5d: releasing lock on %d\n",getpid(),fd);
close(fd);

if (pid != 0) waitpid(pid,NULL,0);

return EXIT_SUCCESS;
}
4 REPLIES 4
Randy Proctor
New Member

Re: pstat_getpathname releases fcntl lock?

Sorry, forgot to add: reproduced on 11.23 and 11.31 Itanium, 32 and 64 bit.
James R. Ferguson
Acclaimed Contributor

Re: pstat_getpathname releases fcntl lock?

Hi Randy:

And exactly what release is this running on? Do:

# uname -a

Regards!

...JRF...
Randy Proctor
New Member

Re: pstat_getpathname releases fcntl lock?

And also 11.11 PA-RISC 32 bit.
Dennis Handly
Acclaimed Contributor

Re: pstat_getpathname releases fcntl lock?

>Can anyone confirm this behavior and/or point me toward something I am doing wrong?

Questions of this technical nature are going to have to go to the Response Center.

How are you synchronizing your parent/child access to that file? I would expect you should create it before you fork.

There doesn't seem to be anything obviously wrong with your program.