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>
22 #include <sys/types.h>
25 #include <zephyr/zephyr.h>
33 extern char *strsave();
35 void dcm_com_err_hook(whoami, code, fmt, pvar)
42 fputs(whoami, stderr);
46 fputs(error_message(code), stderr);
49 _doprnt(fmt, pvar, stderr);
61 com_err(whoami, errno, "%s: exiting", s);
63 com_err(whoami, errno, "exiting");
68 void scream(argc, argv, hint)
73 leave("Programmer botch");
82 sprintf(buf, "%d", i);
89 return("/tmp/tkt_dcm");
93 int maybe_lock_update(dir, host, service, exclusive)
94 char *dir, *host, *service;
100 sprintf(lock, "%s/dcm/locks/%s.%s", dir, host, service);
101 if ((fd = open(lock, O_TRUNC | O_CREAT, 0)) < 0)
102 com_err(whoami, errno, ": maybe_lock_update: opening %s", lock);
103 else if (flock(fd, (exclusive ? LOCK_EX : LOCK_SH) | LOCK_NB) != 0) {
104 if (errno != EWOULDBLOCK)
105 com_err(whoami, errno, ": maybe_lock_update: flock");
106 else if (dbg & DBG_VERBOSE)
107 com_err(whoami, 0, "%s already locked\n", lock);
110 } else if (dbg & DBG_VERBOSE)
111 com_err(whoami, 0, "%s now locked\n", lock);