]> andersk Git - moira.git/blame - dcm/utils.c
install startdcm correctly
[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>
21#include <varargs.h>
22#include <sys/types.h>
23#include <sys/time.h>
24#include <sys/file.h>
25#include <zephyr/zephyr.h>
26#include <sms.h>
27#include "dcm.h"
28
29
30int dbg = 0;
31int log_flags;
32
33extern char *strsave();
34
35void dcm_com_err_hook(whoami, code, fmt, pvar)
36 char *whoami;
37 int code;
38 char *fmt;
39 caddr_t pvar;
40{
41 if (whoami) {
42 fputs(whoami, stderr);
43 fputs(": ", stderr);
44 }
45 if (code) {
46 fputs(error_message(code), stderr);
47 }
48 if (fmt) {
49 _doprnt(fmt, pvar, stderr);
50 }
51 putc('\n', stderr);
52 fflush(stderr);
53}
54
55void leave(s)
56char *s;
57{
58 extern int errno;
59
60 if (*s)
61 com_err(whoami, errno, "%s: exiting", s);
62 else
63 com_err(whoami, errno, "exiting");
64
65 exit(errno);
66}
67
68void scream(argc, argv, hint)
69int argc;
70char **argv;
71int hint;
72{
73 leave("Programmer botch");
74}
75
76
77char *itoa(i)
78int i;
79{
80 char buf[20];
81
82 sprintf(buf, "%d", i);
83 return(strsave(buf));
84}
85
86
87char *tkt_string()
88{
89 return("/tmp/tkt_dcm");
90}
91
92
93int maybe_lock_update(dir, host, service, exclusive)
94char *dir, *host, *service;
95int exclusive;
96{
97 char lock[BUFSIZ];
98 int fd;
99
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);
108 close(fd);
109 return -1;
110 } else if (dbg & DBG_VERBOSE)
111 com_err(whoami, 0, "%s now locked\n", lock);
112 return fd;
113}
114
This page took 0.06207 seconds and 5 git commands to generate.