]> andersk Git - moira.git/blob - dcm/utils.c
Don't log a critical error if the user ^Cs a DCM build. Just print a
[moira.git] / dcm / utils.c
1 /*
2  *      $Source$
3  *      $Author$
4  *      $Header$
5  *
6  * 
7  *      Utility functions used by the DCM.
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>.
12  */
13
14 #ifndef lint
15 static char *rcsid_utils_c = "$Header$";
16 #endif lint
17
18 #include <mit-copyright.h>
19 #include <stdio.h>
20 #include <string.h>
21 #include <errno.h>
22 #include <varargs.h>
23 #include <sys/types.h>
24 #include <sys/time.h>
25 #include <sys/file.h>
26 #include <sys/stat.h>
27 #include <fcntl.h>
28 #include <moira.h>
29 #include <moira_site.h>
30 #include "dcm.h"
31
32
33 int dbg = 0;
34 int log_flags;
35
36 extern char *strsave();
37
38 void dcm_com_err_hook(whoami, code, fmt, pvar)
39         char *whoami;
40         int code;
41         char *fmt;
42         caddr_t pvar;
43 {
44         if (whoami) {
45                 fputs(whoami, stderr);
46                 fputs(": ", stderr);
47         }
48         if (code) {
49                 fputs(error_message(code), stderr);
50         }
51         if (fmt) {
52                 _doprnt(fmt, pvar, stderr);
53         }
54         putc('\n', stderr);
55         fflush(stderr);
56 }
57                 
58 void leave(s)
59 char *s;
60 {
61     extern int errno;
62
63     if (*s)
64       com_err(whoami, errno, "%s: exiting", s);
65     else
66       com_err(whoami, errno, "exiting");
67
68     exit(errno);
69 }
70
71 void scream(argc, argv, hint)
72 int argc;
73 char **argv;
74 int hint;
75 {
76     leave("Programmer botch");
77 }
78
79
80 char *itoa(i)
81 int i;
82 {
83     char buf[20];
84
85     sprintf(buf, "%d", i);
86     return(strsave(buf));
87 }
88
89
90 char *tkt_string()
91 {
92     return("/tmp/tkt_dcm");
93 }
94
95
96 int maybe_lock_update(host, service, exclusive)
97 char *host, *service;
98 int exclusive;
99 {
100     char lock[BUFSIZ];
101     int fd;
102     flock_t fl;
103
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) {
110         if (errno != EAGAIN) 
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);
114         close(fd);
115         return -1;
116     } else if (dbg & DBG_VERBOSE) 
117       com_err(whoami, 0, "%s now locked\n", lock);
118     return fd;
119 }
This page took 0.320337 seconds and 5 git commands to generate.