]> andersk Git - moira.git/blobdiff - dcm/utils.c
since the Oracle-based moirad never returns MR_DEADLOCK, we don't need
[moira.git] / dcm / utils.c
index 19f8b4e5792dba6eff09820df894aa1942d50f75..c0c4501beda326b55e10e8f485bfb1821347c797 100644 (file)
@@ -3,23 +3,30 @@
  *     $Author$
  *     $Header$
  *
- *     Copyright (C) 1987 by the Massachusetts Institute of Technology
  * 
  *     Utility functions used by the DCM.
+ *
+ *  (c) Copyright 1987, 1988 by the Massachusetts Institute of Technology.
+ *  For copying and distribution information, please see the file
+ *  <mit-copyright.h>.
  */
 
 #ifndef lint
 static char *rcsid_utils_c = "$Header$";
 #endif lint
 
+#include <mit-copyright.h>
 #include <stdio.h>
-#include <strings.h>
+#include <string.h>
+#include <errno.h>
 #include <varargs.h>
 #include <sys/types.h>
 #include <sys/time.h>
 #include <sys/file.h>
-#include <zephyr/zephyr.h>
-#include <sms.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <moira.h>
+#include <moira_site.h>
 #include "dcm.h"
 
 
@@ -86,18 +93,21 @@ char *tkt_string()
 }
 
 
-int maybe_lock_update(dir, host, service, exclusive)
-char *dir, *host, *service;
+int maybe_lock_update(host, service, exclusive)
+char *host, *service;
 int exclusive;
 {
     char lock[BUFSIZ];
     int fd;
+    flock_t fl;
 
-    sprintf(lock, "%s/dcm/locks/%s.%s", dir, host, service);
-    if ((fd = open(lock, O_TRUNC |  O_CREAT, 0)) < 0)
+    sprintf(lock, "%s/%s.%s", LOCK_DIR, host, service);
+    fl.l_type = exclusive ? F_WRLCK : F_RDLCK;
+    fl.l_whence = fl.l_start = fl.l_len = 0;
+    if ((fd = open(lock, O_TRUNC |  O_CREAT | O_RDWR, 0)) < 0)
       com_err(whoami, errno, ": maybe_lock_update: opening %s", lock);
-    else if (flock(fd, (exclusive ? LOCK_EX : LOCK_SH) | LOCK_NB) != 0) {
-       if (errno != EWOULDBLOCK
+    else if (fcntl(fd, F_SETLK, &fl) != 0) {
+       if (errno != EAGAIN
          com_err(whoami, errno, ": maybe_lock_update: flock");
        else if (dbg & DBG_VERBOSE)
          com_err(whoami, 0, "%s already locked\n", lock);
@@ -107,4 +117,3 @@ int exclusive;
       com_err(whoami, 0, "%s now locked\n", lock);
     return fd;
 }
-
This page took 0.044537 seconds and 4 git commands to generate.