Commit ba79469c authored by Per Cederqvist's avatar Per Cederqvist

Renamed sync_output_header to foutput_header, and clean up the

time handling.  This is more preparation for bug 1616.
* src/server/simple-cache.c (sync_output_header): Renamed to
foutput_header and moved to ram-output.c.  All callers updated.
* src/server/ramkomd.c (current_time): Moved to server-time.c.
(main): Use set_initial_time instead of calling gettimeofday and
accessing current_time directly.
* src/server/ram-output.c, src/server/ram-output.h
(foutput_header): Renamed from sync_output_header.  Use
output_format instead of a hardcoding it to 2.
* src/server/dbck.c (main): Call set_initial_time().
* src/server/dbck-cache.c (sync_output_header): Use foutput_header
to output a format 2 header.
* src/server/server-time.c: New file.
(current_time): Moved here from ramkomd.c.
* src/server/server-time.c, src/server/server-time.h
(set_time): Moved here from connections.c.
(set_initial_time): New function.
* src/server/connections.c (set_ time): Moved to server-time.c.
* src/server/Makefile.am (GENOBJS): Added server-time.c.
(DBCK): Ditto.
parent d7498aeb
2006-10-18 Per Cederqvist <ceder@lysator.liu.se>
Renamed sync_output_header to foutput_header, and clean up the
time handling. This is more preparation for bug 1616.
* src/server/simple-cache.c (sync_output_header): Renamed to
foutput_header and moved to ram-output.c. All callers updated.
* src/server/ramkomd.c (current_time): Moved to server-time.c.
(main): Use set_initial_time instead of calling gettimeofday and
accessing current_time directly.
* src/server/ram-output.c, src/server/ram-output.h
(foutput_header): Renamed from sync_output_header. Use
output_format instead of a hardcoding it to 2.
* src/server/dbck.c (main): Call set_initial_time().
* src/server/dbck-cache.c (sync_output_header): Use foutput_header
to output a format 2 header.
* src/server/server-time.c: New file.
(current_time): Moved here from ramkomd.c.
* src/server/server-time.c, src/server/server-time.h
(set_time): Moved here from connections.c.
(set_initial_time): New function.
* src/server/connections.c (set_ time): Moved to server-time.c.
* src/server/Makefile.am (GENOBJS): Added server-time.c.
(DBCK): Ditto.
2006-10-17 Per Cederqvist <ceder@lysator.liu.se>
Added functions wrapper functions around a few stdio functions,
......
......@@ -140,7 +140,7 @@ GENOBJS = connections.c log.c $(ATOMS) \
send-async.c server-config.c text-garb.c \
isc-parse.c memory.c $(PROTA) \
internal-connections.c rfc931.c isc-malloc.c \
conf-file.c local-to-global.c
conf-file.c local-to-global.c server-time.c
# Files for lyskomd.
......@@ -155,7 +155,7 @@ GETOPT = getopt.c getopt1.c
NODIST_DBCK = version-info.c
DBCK = dbck.c dbck-cache.c ram-smalloc.c ram-parse.c server-config.c \
ram-io.c ram-output.c memory.c conf-file.c $(GETOPT) \
local-to-global.c lockdb.h lockdb.c
local-to-global.c lockdb.h lockdb.c server-time.c
# Files for encrypt (a program to transform the database from unencrypted
# apasswords to encrypted). No longer supported.
......
......@@ -185,31 +185,6 @@ queue_remove(Connection *c)
update_stat(STAT_RUN_QUEUE, -1);
}
void
set_time(void)
{
struct timeval last_time;
static int limiter = 0;
last_time = current_time;
if (gettimeofday(&current_time, NULL) < 0)
{
if (limiter < 50)
{
kom_log("WARNING: gettimeofday failed: %s\n", strerror(errno));
if (++limiter == 50)
kom_log("WARNING: will not log the above message again.\n");
}
}
if (timeval_less(current_time, last_time))
{
kom_log("WARNING: Time moved backward at least %g seconds.\n",
timeval_diff_d(last_time, current_time));
/* FIXME (bug 62): Should we take more decisive action here? */
}
}
static void
logout_client(Connection *cp)
{
......
......@@ -561,8 +561,7 @@ sync_output_header(FILE* fp, const char *state, int oformat)
fprintf(fp, "%s:%05ld\n", state, (long)oformat);
break;
case 2:
fprintf(fp, "%s:%05ld\n", state, (long)oformat);
fprintf(fp, "%020lu\n", (unsigned long)time(NULL));
foutput_header(fp, state, 1);
break;
default:
restart_kom("sync_output_header(): Unknown output format %d",
......
......@@ -83,6 +83,7 @@
#include "linkansi.h"
#include "eintr.h"
#include "kom-memory.h"
#include "server-time.h"
#define OPT_PERS_PRESENTATION_CONF 1
......@@ -1436,6 +1437,8 @@ main (int argc,
int need_rw = 0;
int have_lock = 0;
set_initial_time();
link_ansi();
#ifdef TRACED_ALLOCATIONS
......
......@@ -49,6 +49,7 @@
#include "lyskomd.h"
#include "log.h"
#include "local-to-global.h"
#include "server-time.h"
/* Forward declarations. */
static void foutput_aux_item_list(FILE *, const Aux_item_list *);
......@@ -74,6 +75,14 @@ static void foutput_array_nodata(FILE *fp);
static int output_format = 2;
void
foutput_header(FILE* fp, const char *state, int include_timestamp)
{
fprintf(fp, "%s:%05d\n", state, output_format); /* DIRTY-FLAG and VERSION*/
if (include_timestamp)
fprintf(fp, "%020lu\n", (unsigned long)current_time.tv_sec);
}
void
set_output_format(int fmt)
{
......
......@@ -33,6 +33,9 @@
* Written by ceder 1990-07-13. Rewritten 1990-08-31.
*/
extern void
foutput_header(FILE *fp, const char *state, int include_timestamp);
extern void
foutput_info(FILE *fp,
Info *info);
......
......@@ -118,8 +118,6 @@
typedef int rlim_t;
#endif
struct timeval current_time = { 0, 0 };
#ifndef NDEBUG
int buglevel = 0;
......@@ -596,8 +594,7 @@ main (int argc,
link_ansi();
if (gettimeofday(&current_time, NULL) < 0)
restart_kom("gettimeofday failed: %s\n", strerror(errno));
set_initial_time();
#ifdef TRACED_ALLOCATIONS
/* We must do this before we allocate any memory... */
......
/*
* The current time is kept in a global variable.
* Copyright (C) 1999, 2003 Lysator Academic Computer Association.
*
* This file is part of the LysKOM server.
*
* LysKOM is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 1, or (at your option)
* any later version.
*
* LysKOM is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License
* along with LysKOM; see the file COPYING. If not, write to
* Lysator, c/o ISY, Linkoping University, S-581 83 Linkoping, SWEDEN,
* or the Free Software Foundation, Inc., 675 Mass Ave, Cambridge,
* MA 02139, USA.
*
* Please report bugs at http://bugzilla.lysator.liu.se/.
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <stddef.h>
#include <errno.h>
#include <string.h>
#include "timewrap.h"
#include "misc-types.h"
#include "timeval-util.h"
#include "server-time.h"
#include "log.h"
#include "lyskomd.h"
struct timeval current_time = { 0, 0 };
void
set_initial_time(void)
{
if (gettimeofday(&current_time, NULL) < 0)
restart_kom("gettimeofday failed: %s\n", strerror(errno));
}
void
set_time(void)
{
struct timeval last_time;
static int limiter = 0;
last_time = current_time;
if (gettimeofday(&current_time, NULL) < 0)
{
if (limiter < 50)
{
kom_log("WARNING: gettimeofday failed: %s\n", strerror(errno));
if (++limiter == 50)
kom_log("WARNING: will not log the above message again.\n");
}
}
if (timeval_less(current_time, last_time))
{
kom_log("WARNING: Time moved backward at least %g seconds.\n",
timeval_diff_d(last_time, current_time));
/* FIXME (bug 62): Should we take more decisive action here? */
}
}
......@@ -23,4 +23,7 @@
* Please report bugs at http://bugzilla.lysator.liu.se/.
*/
void set_time(void);
void set_initial_time(void);
extern struct timeval current_time;
......@@ -1778,13 +1778,6 @@ get_version(const char *fn)
return version;
}
static void
sync_output_header(FILE* fp, const char *state, int include_timestamp)
{
fprintf(fp, "%s:%05ld\n", state, 2L); /* DIRTY-FLAG and VERSION*/
if (include_timestamp)
fprintf(fp, "%020lu\n", (unsigned long)current_time.tv_sec);
}
static void
pre_sync(void)
......@@ -1950,7 +1943,7 @@ pre_sync(void)
sync_output_header(file_b, "DIRTY", 1);
foutput_header(file_b, "DIRTY", 1);
fprintf(file_b, "#C %d\n", highest_conf_no);
fprintf(file_b, "#T %ld\n", highest_text_no);
fprintf(file_b, "I");
......@@ -2399,7 +2392,7 @@ save_one_text(void)
return;
}
sync_output_header(file_b, "CLEAN", 0);
foutput_header(file_b, "CLEAN", 0);
if ( ferror(file_b) != 0 )
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment