]> andersk Git - moira.git/blame - dcm/utils.c
possible NULL reference
[moira.git] / dcm / utils.c
CommitLineData
846841f4 1/*
2 * $Source$
3 * $Author$
4 * $Header$
5 *
846841f4 6 *
7 * Utility functions used by the DCM.
0a5ff702 8 *
9 * (c) Copyright 1987, 1988 by the Massachusetts Institute of Technology.
10 * For copying and distribution information, please see the file
11 * <mit-copyright.h>.
846841f4 12 */
13
14#ifndef lint
15static char *rcsid_utils_c = "$Header$";
16#endif lint
17
0a5ff702 18#include <mit-copyright.h>
846841f4 19#include <stdio.h>
20#include <strings.h>
f5c191c8 21#include <errno.h>
846841f4 22#include <varargs.h>
23#include <sys/types.h>
24#include <sys/time.h>
25#include <sys/file.h>
2ce085d2 26#include <moira.h>
27#include <moira_site.h>
846841f4 28#include "dcm.h"
29
30
31int dbg = 0;
32int log_flags;
33
34extern char *strsave();
35
36void dcm_com_err_hook(whoami, code, fmt, pvar)
37 char *whoami;
38 int code;
39 char *fmt;
40 caddr_t pvar;
41{
42 if (whoami) {
43 fputs(whoami, stderr);
44 fputs(": ", stderr);
45 }
46 if (code) {
47 fputs(error_message(code), stderr);
48 }
49 if (fmt) {
50 _doprnt(fmt, pvar, stderr);
51 }
52 putc('\n', stderr);
53 fflush(stderr);
54}
55
56void leave(s)
57char *s;
58{
59 extern int errno;
60
61 if (*s)
62 com_err(whoami, errno, "%s: exiting", s);
63 else
64 com_err(whoami, errno, "exiting");
65
66 exit(errno);
67}
68
69void scream(argc, argv, hint)
70int argc;
71char **argv;
72int hint;
73{
74 leave("Programmer botch");
75}
76
77
78char *itoa(i)
79int i;
80{
81 char buf[20];
82
83 sprintf(buf, "%d", i);
84 return(strsave(buf));
85}
86
87
88char *tkt_string()
89{
90 return("/tmp/tkt_dcm");
91}
92
93
185f76ce 94int maybe_lock_update(host, service, exclusive)
95char *host, *service;
846841f4 96int exclusive;
97{
98 char lock[BUFSIZ];
99 int fd;
100
185f76ce 101 sprintf(lock, "%s/%s.%s", LOCK_DIR, host, service);
846841f4 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);
109 close(fd);
110 return -1;
111 } else if (dbg & DBG_VERBOSE)
112 com_err(whoami, 0, "%s now locked\n", lock);
113 return fd;
114}
115
753d180d 116
2ce085d2 117int mr_query_with_retry(name, argc, argv, proc, hint)
753d180d 118char *name;
119int argc;
120char **argv;
121int (*proc)();
122char *hint;
123{
124 int status, tries;
125
126 for (tries = 0; tries < DEADLOCK_TRIES; tries++) {
2ce085d2 127 status = mr_query(name, argc, argv, proc, hint);
128 if (status != MR_DEADLOCK)
753d180d 129 return(status);
130 sleep(DEADLOCK_WAIT);
131 }
132 return(status);
133}
This page took 0.086058 seconds and 5 git commands to generate.