[4884] in Kerberos

home help back first fref pref prev next nref lref last post

fcntl and file locking

daemon@ATHENA.MIT.EDU (Jim Ertle)
Tue Mar 28 18:29:40 1995

To: kerberos@MIT.EDU
Date: Tue, 28 Mar 1995 20:59:19 GMT
From: ertle@bajoran.emba.uvm.edu (Jim Ertle)


Hi!
   I'm trying to compile/run kerberos5 at our site, and I'm having
some difficulty with file locking ( in kinit, which locks with
fcc_maybe/fcc_init ).  Extracted from the code, the lock procedure
still doesn't work - it gets an error of EINVAL, which implies an
invalid argument was passed in.

   I'm on a Sun4 running SunOS 4.1.3, and the man pages seem to say
that the following should work.  It doesn't, of course.

   Is there an answer to my dilemma?



/********************   START PROG   ***********************/
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <fcntl.h>


int main()
{

  int fd;
  struct flock sf;

  sf.l_type = F_WRLCK;
  sf.l_whence = 0;
  sf.l_start = 0;
  sf.l_len = 0;

  if (-1 == (fd = open("/tmp/test.ertle",O_CREAT|O_RDWR, 0666)))
    {
      perror("Opening /tmp/test.ertle ");
      exit(2);
    }
  if (-1 == (fcntl(fd,(int) F_SETLKW,&sf)))
    {
      perror("Locking /tmp/test.ertle ");
      exit(1);
    }
  unlink("/tmp/test.ertle");
}
/********************   END PROG   ***********************/

-- 
James A. Ertle                       |If you argue for your faults, 
ertle@emba.uvm.edu                   |sure enough, they're yours.
UVM's EMBA Computer Facility         |            - Richard Bach
Burlington, Vt. USA                  |

home help back first fref pref prev next nref lref last post