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>
29 #include <moira_site.h>
36 extern char *strsave();
38 void dcm_com_err_hook(whoami, code, fmt, pvar)
45 fputs(whoami, stderr);
49 fputs(error_message(code), stderr);
52 _doprnt(fmt, pvar, stderr);
64 com_err(whoami, errno, "%s: exiting", s);
66 com_err(whoami, errno, "exiting");
71 void scream(argc, argv, hint)
76 leave("Programmer botch");
85 sprintf(buf, "%d", i);
92 return("/tmp/tkt_dcm");
96 int maybe_lock_update(host, service, exclusive)
104 sprintf(lock, "%s/%s.%s", LOCK_DIR, host, service);
105 fl.l_type = exclusive ? F_WRLCK : F_RDLCK;
106 fl.l_whence = fl.l_start = fl.l_len = 0;
107 if ((fd = open(lock, O_TRUNC | O_CREAT | O_RDWR, 0)) < 0)
108 com_err(whoami, errno, ": maybe_lock_update: opening %s", lock);
109 else if (fcntl(fd, F_SETLK, &fl) != 0) {
111 com_err(whoami, errno, ": maybe_lock_update: flock");
112 else if (dbg & DBG_VERBOSE)
113 com_err(whoami, 0, "%s already locked\n", lock);
116 } else if (dbg & DBG_VERBOSE)
117 com_err(whoami, 0, "%s now locked\n", lock);