- for (i = 0;;) {
- /* attempt to create lock file */
- if (lockit (&lkinfo) == 0) {
- /* if successful, turn on timer and return */
- timerON (lkinfo.curlock, fd);
- return fd;
- } else {
- /*
- * Abort locking, if we fail to lock after 5 attempts
- * and are never able to stat the lock file.
- */
- if (stat (lkinfo.curlock, &st) == -1) {
- if (i++ > 5)
- return -1;
- sleep (5);
- } else {
- i = 0;
- time (&curtime);
-
- /* check for stale lockfile, else sleep */
- if (curtime > st.st_ctime + RSECS)
- unlink (lkinfo.curlock);
- else
- sleep (5);
- }
+ {
+ int i;
+ for (i = 0;;) {
+ /* attempt to create lock file */
+ if (lockit(&lkinfo) == 0) {
+ /* if successful, turn on timer and return */
+ timerON(lkinfo.curlock, fd);
+ return fd;
+ } else {
+ /*
+ ** Abort locking, if we fail to lock after 5
+ ** attempts and are never able to stat the
+ ** lock file.
+ */
+ struct stat st;
+ if (stat(lkinfo.curlock, &st) == -1) {
+ if (i++ > 5)
+ return -1;
+ sleep(1);
+ } else {
+ time_t curtime;
+ i = 0;
+ time(&curtime);
+
+ /*
+ ** check for stale lockfile,
+ ** else sleep
+ */
+ if (curtime > st.st_ctime + RSECS)
+ unlink(lkinfo.curlock);
+ else
+ sleep(1);
+ }
+ lockname(file, &lkinfo, 1);
+ }
+ }