7 * Utility functions used by the DCM.
9 * (c) Copyright 1987, 1988 by the Massachusetts Institute of Technology.
10 * For copying and distribution information, please see the file
15 static char *rcsid_utils_c = "$Header$";
18 #include <mit-copyright.h>
23 #include <sys/types.h>
27 #include <moira_site.h>
34 extern char *strsave();
36 void dcm_com_err_hook(whoami, code, fmt, pvar)
43 fputs(whoami, stderr);
47 fputs(error_message(code), stderr);
50 _doprnt(fmt, pvar, stderr);
62 com_err(whoami, errno, "%s: exiting", s);
64 com_err(whoami, errno, "exiting");
69 void scream(argc, argv, hint)
74 leave("Programmer botch");
83 sprintf(buf, "%d", i);
90 return("/tmp/tkt_dcm");
94 int maybe_lock_update(host, service, exclusive)
101 sprintf(lock, "%s/%s.%s", LOCK_DIR, host, service);
102 if ((fd = open(lock, O_TRUNC | O_CREAT, 0)) < 0)
103 com_err(whoami, errno, ": maybe_lock_update: opening %s", lock);
104 else if (flock(fd, (exclusive ? LOCK_EX : LOCK_SH) | LOCK_NB) != 0) {
105 if (errno != EWOULDBLOCK)
106 com_err(whoami, errno, ": maybe_lock_update: flock");
107 else if (dbg & DBG_VERBOSE)
108 com_err(whoami, 0, "%s already locked\n", lock);
111 } else if (dbg & DBG_VERBOSE)
112 com_err(whoami, 0, "%s now locked\n", lock);
117 int mr_query_with_retry(name, argc, argv, proc, hint)
126 for (tries = 0; tries < DEADLOCK_TRIES; tries++) {
127 status = mr_query(name, argc, argv, proc, hint);
128 if (status != MR_DEADLOCK)
130 sleep(DEADLOCK_WAIT);