Support POSIX file locking.
authorJohn Carr <jfc@mit.edu>
Sun, 23 Feb 1992 12:29:25 +0000 (12:29 +0000)
committerJohn Carr <jfc@mit.edu>
Sun, 23 Feb 1992 12:29:25 +0000 (12:29 +0000)
Use fstat() instead of stat().

git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@2245 dc483132-0cff-0310-8789-dd5450dbe970

src/slave/kprop.c

index 70a3f2c0903b7f89dd2a5788ca742fd6a7bd4660..04472f7c2bb2b8d70a374d70c1ecb2da64c8938c 100644 (file)
@@ -176,7 +176,7 @@ void get_tickets()
 {
        char   my_host_name[MAXHOSTNAMELEN];
        char   buf[BUFSIZ];
-       char   *cp, *strcpy(), *krb_get_phost();
+       char   *cp;
        struct hostent *hp;
        krb5_address **my_addresses;
        krb5_error_code retval;
@@ -408,18 +408,33 @@ open_database(data_fn, size)
        struct stat     stbuf, stbuf_ok;
        char            *data_ok_fn;
        static char ok[] = ".dump_ok";
-       
+
        if ((fd = open(data_fn, O_RDONLY)) < 0) {
-               com_err(progname, 0, "While trying to open %s",
+               com_err(progname, errno, "while trying to open %s",
                        data_fn);
                exit(1);
        }
-       if (flock(fd, LOCK_SH | LOCK_NB)) {
-               com_err(progname, errno, "while trying to flock %s",
-                       data_fn);
+       
+#ifdef POSIX_FILE_LOCKS
+       if (lockf(fd, LOCK_SH | LOCK_NB, 0) < 0) {
+               if (errno == EWOULDBLOCK || errno == EAGAIN)
+                       com_err(progname, 0, "database locked");
+               else
+                       com_err(progname, errno, "while trying to flock %s",
+                               data_fn);
+               exit(1);
+       }
+#else
+       if (flock(fd, LOCK_SH | LOCK_NB) < 0) {
+               if (errno == EWOULDBLOCK || errno == EAGAIN)
+                       com_err(progname, 0, "database locked");
+               else
+                       com_err(progname, errno, "while trying to flock %s",
+                               data_fn);
                exit(1);
        }
-       if (stat(data_fn, &stbuf)) {
+#endif
+       if (fstat(fd, &stbuf)) {
                com_err(progname, errno, "while trying to stat %s",
                        data_fn);
                exit(1);