Little Palm fixes
[MonkeyD.git] / src / clock.c
blob4205ead5e428d8fbff9abb503fa564ead330fa29
1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 /* Monkey HTTP Daemon
4 * ------------------
5 * Copyright (C) 2001-2010, Eduardo Silva P. <edsiper@gmail.com>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Library General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 /* clock.c */
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <pthread.h>
27 #include <time.h>
28 #include <unistd.h>
30 #include "memory.h"
31 #include "clock.h"
33 void mk_clock_log_set_time()
35 time_t utime;
37 if (!log_current_time.data) {
38 log_current_time.data = mk_mem_malloc_z(30);
39 log_current_time.len = 28;
42 if ((utime = time(NULL)) == -1) {
43 return;
46 log_current_utime = utime;
47 strftime(log_current_time.data, 30, "[%d/%b/%G %T %z]",
48 (struct tm *) localtime((time_t *) & utime));
51 void mk_clock_header_set_time()
53 int n, len = 32;
54 time_t date;
55 struct tm *gmt_tm;
57 if (!header_current_time.data) {
58 header_current_time.data = mk_mem_malloc_z(len);
59 header_current_time.len = len - 1;
62 date = time(NULL);
63 gmt_tm = (struct tm *) gmtime(&date);
64 n = strftime(header_current_time.data, len, GMT_DATEFORMAT, gmt_tm);
67 void *mk_clock_worker_init(void *args)
69 /* Time when monkey was started */
70 monkey_init_time = time(NULL);
72 while (1) {
73 mk_clock_log_set_time();
74 mk_clock_header_set_time();
75 sleep(1);