From 4fe40027ab84df2690aaa393494e6fd1279f0b2f Mon Sep 17 00:00:00 2001
From: Fabian Keil <fk@fabiankeil.de>
Date: Sun, 26 Dec 2010 15:30:28 +0000
Subject: [PATCH] Don't keep the client connection alive if any configuration
file changed since the time the connection came in.
This is closer to Privoxy's behaviour before keep-alive support
for client connection has been added and also less confusing in
general.
---
jcc.c | 7 +++++-
loaders.c | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++--
loaders.h | 6 +++--
3 files changed, 73 insertions(+), 5 deletions(-)
diff --git a/jcc.c b/jcc.c
index e1158188..acad412f 100644
--- a/jcc.c
+++ b/jcc.c
@@ -1,4 +1,4 @@
-const char jcc_rcs[] = "$Id: jcc.c,v 1.330 2010/09/14 07:16:07 fabiankeil Exp $";
+const char jcc_rcs[] = "$Id: jcc.c,v 1.331 2010/11/06 11:48:32 fabiankeil Exp $";
/*********************************************************************
*
* File : $Source: /cvsroot/ijbswa/current/jcc.c,v $
@@ -2515,6 +2515,11 @@ static void serve(struct client_state *csp)
}
}
+ if (continue_chatting && any_loaded_file_changed(csp->config->config_file_list))
+ {
+ continue_chatting = 0;
+ }
+
if (continue_chatting)
{
unsigned int client_timeout;
diff --git a/loaders.c b/loaders.c
index 1bc06872..d196f645 100644
--- a/loaders.c
+++ b/loaders.c
@@ -1,4 +1,4 @@
-const char loaders_rcs[] = "$Id: loaders.c,v 1.75 2010/05/26 23:01:47 ler762 Exp $";
+const char loaders_rcs[] = "$Id: loaders.c,v 1.76 2010/07/21 14:35:09 fabiankeil Exp $";
/*********************************************************************
*
* File : $Source: /cvsroot/ijbswa/current/loaders.c,v $
@@ -8,7 +8,7 @@ const char loaders_rcs[] = "$Id: loaders.c,v 1.75 2010/05/26 23:01:47 ler762 Exp
* the list of active loaders, and to automatically
* unload files that are no longer in use.
*
- * Copyright : Written by and Copyright (C) 2001-2009 the
+ * Copyright : Written by and Copyright (C) 2001-2010 the
* Privoxy team. http://www.privoxy.org/
*
* Based on the Internet Junkbuster originally written
@@ -1422,6 +1422,67 @@ int run_loader(struct client_state *csp)
}
+/*********************************************************************
+ *
+ * Function : file_has_been_modified
+ *
+ * Description : Helper function to check if a file has been changed
+ *
+ * Parameters :
+ * 1 : filename = The name of the file to check
+ * 2 : last_known_modification = The time of the last known
+ * modification
+ *
+ * Returns : TRUE if the file has been changed,
+ * FALSE otherwise.
+ *
+ *********************************************************************/
+static int file_has_been_modified(const char *filename, time_t last_know_modification)
+{
+ struct stat statbuf[1];
+
+ if (stat(filename, statbuf) < 0)
+ {
+ /* Error, probably file not found which counts as change. */
+ return 1;
+ }
+
+ return (last_know_modification != statbuf->st_mtime);
+}
+
+
+/*********************************************************************
+ *
+ * Function : any_loaded_file_changed
+ *
+ * Description : Helper function to check if any loaded file has been
+ * changed since the time it has been loaded.
+ *
+ * XXX: Should we cache the return value for x seconds?
+ *
+ * Parameters :
+ * 1 : files_to_check = List of files to check
+ *
+ * Returns : TRUE if any file has been changed,
+ * FALSE otherwise.
+ *
+ *********************************************************************/
+int any_loaded_file_changed(const struct file_list *files_to_check)
+{
+ const struct file_list *file_to_check = files_to_check;
+
+ while (file_to_check != NULL)
+ {
+ if (file_has_been_modified(file_to_check->filename, file_to_check->lastmodified))
+ {
+ log_error(LOG_LEVEL_INFO, "%s has been changed", file_to_check->filename);
+ return TRUE;
+ }
+ file_to_check = file_to_check->next;
+ }
+ return FALSE;
+}
+
/*
Local Variables:
diff --git a/loaders.h b/loaders.h
index a1dca78b..1951b1da 100644
--- a/loaders.h
+++ b/loaders.h
@@ -1,6 +1,6 @@
#ifndef LOADERS_H_INCLUDED
#define LOADERS_H_INCLUDED
-#define LOADERS_H_VERSION "$Id: loaders.h,v 1.24 2009/04/24 15:29:43 fabiankeil Exp $"
+#define LOADERS_H_VERSION "$Id: loaders.h,v 1.25 2009/05/16 13:27:20 fabiankeil Exp $"
/*********************************************************************
*
* File : $Source: /cvsroot/ijbswa/current/loaders.h,v $
@@ -10,7 +10,7 @@
* the list of active loaders, and to automatically
* unload files that are no longer in use.
*
- * Copyright : Written by and Copyright (C) 2001-2009 the
+ * Copyright : Written by and Copyright (C) 2001-2010 the
* Privoxy team. http://www.privoxy.org/
*
* Based on the Internet Junkbuster originally written
@@ -102,6 +102,8 @@ extern void add_loader(int (*loader)(struct client_state *),
struct configuration_spec * config);
extern int run_loader(struct client_state *csp);
+extern int any_loaded_file_changed(const struct file_list *files_to_check);
+
/* Revision control strings from this header and associated .c file */
extern const char loaders_rcs[];
extern const char loaders_h_rcs[];
--
2.50.1