#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 <sms_app.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <moira.h>
+#include <moira_site.h>
#include "dcm.h"
{
char lock[BUFSIZ];
int fd;
+ flock_t fl;
sprintf(lock, "%s/%s.%s", LOCK_DIR, host, service);
- if ((fd = open(lock, O_TRUNC | O_CREAT, 0)) < 0)
+ 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);
com_err(whoami, 0, "%s now locked\n", lock);
return fd;
}
-
-
-int sms_query_with_retry(name, argc, argv, proc, hint)
-char *name;
-int argc;
-char **argv;
-int (*proc)();
-char *hint;
-{
- int status, tries;
-
- for (tries = 0; tries < DEADLOCK_TRIES; tries++) {
- status = sms_query(name, argc, argv, proc, hint);
- if (status != SMS_DEADLOCK)
- return(status);
- sleep(DEADLOCK_WAIT);
- }
- return(status);
-}