File: totals.c

package info (click to toggle)
dcc 1.2.74-2
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 3,552 kB
  • ctags: 4,041
  • sloc: ansic: 41,034; perl: 2,310; sh: 2,186; makefile: 224
file content (99 lines) | stat: -rw-r--r-- 2,118 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/* Distributed Checksum Clearinghouse
 *
 * count work
 *
 * Copyright (c) 2005 by Rhyolite Software
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND RHYOLITE SOFTWARE DISCLAIMS ALL
 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL RHYOLITE SOFTWARE
 * BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES
 * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
 * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
 * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
 * SOFTWARE.
 *
 * Rhyolite Software DCC 1.2.74-1.2 $Revision$
 */


#include "cmn_defs.h"
#include <signal.h>


TOTALS totals;

static void totals_msg_signal(int);
static void *totals_msg_thread(void *);



static void
totals_msg_signal(int ign UATTRIB)
{
	time_t now;

	signal(SIGUSR1, totals_msg_signal);
	now = time(0);
	totals_msg();
	totals.msg_next = now + 24*60*60;
}



static void *
totals_msg_thread(void *ign UATTRIB)
{
	time_t now, next;
	struct tm tm;
	int secs;

	totals.msg_prev = time(0);
	for (;;) {
		now = time(0);
		next = totals.msg_next;
		if (!next) {
			dcc_localtime(now, &tm);
			tm.tm_sec = 0;
			tm.tm_min = 0;
			tm.tm_hour = 0;
			++tm.tm_mday;
			next = mktime(&tm);
			if (next == -1) {
				dcc_error_msg("mktime() failed");
				next = now + 60*60;
			}
		}
		secs = next - now;
		do {
			secs = sleep(secs);
		} while (secs > 0);

		if (time(0) >= totals.msg_next)
			totals_msg();
	}
}



void
totals_init(void)
{
	pthread_t msg_tid;
	int i;

	signal(SIGUSR1, totals_msg_signal);

	i = pthread_create(&msg_tid, 0, totals_msg_thread, 0);
	if (i)
		dcc_logbad(EX_SOFTWARE, "pthread_create(totals msg): %s",
			   ERROR_STR1(i));
	i = pthread_detach(msg_tid);
	if (i)
		dcc_logbad(EX_SOFTWARE, "pthread_detach(totals msg): %s",
			   ERROR_STR1(i));
}