Hi Tim,

On 24/05/16 10:24, Tim Ruehsen wrote:
> Hi Ander,
> 
> IMO, another possibility is to add a flag to 'struct hsts_store' that 
> indicates any change made. hsts_store_save() could be skipped if that flag is 
> not set.
> 
> At the same time the debug info has to be moved from main.c/save_hsts() to 
> hsts.c/hsts_store_save() OR hsts.c needs another function to return the value 
> of the flag, so that save_hsts() could check it.
> 

You mean something like the attached?

> WDYT ?

That could be an option. But I'm not sure we can skip the call to
hsts_store_save at all, because doing so would also mean not updating
the in-memory HSTS database, which might have been modified by other
wget processes.

We could also test whether there have been such changes (within
hsts_store_save), and then call hsts_store_dump only if affirmative. But
again, I don't think it pays off for the sole reason of removing a debug
message.

> 
> Tim
> 
From 5673896b0eca6a0707f8c0971002e7571f0dd9ba Mon Sep 17 00:00:00 2001
From: Ander Juaristi <[email protected]>
Date: Tue, 24 May 2016 11:14:38 +0200
Subject: [PATCH] Correct HSTS debug message

---
 src/hsts.c | 11 ++++++++++-
 src/main.c |  2 +-
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/src/hsts.c b/src/hsts.c
index d5e0bee..c04ee73 100644
--- a/src/hsts.c
+++ b/src/hsts.c
@@ -53,6 +53,7 @@ as that of the covered work.  */
 struct hsts_store {
   struct hash_table *table;
   time_t last_mtime;
+  bool changed;
 };
 
 struct hsts_kh {
@@ -423,7 +424,10 @@ hsts_store_entry (hsts_store_t store,
       if (entry && match == CONGRUENT_MATCH)
         {
           if (max_age == 0)
-            hsts_remove_entry (store, kh);
+            {
+              hsts_remove_entry (store, kh);
+              store->changed = true;
+            }
           else if (max_age > 0)
             {
               if (entry->max_age != max_age ||
@@ -436,6 +440,8 @@ hsts_store_entry (hsts_store_t store,
                     entry->created = t;
                   entry->max_age = max_age;
                   entry->include_subdomains = include_subdomains;
+
+                  store->changed = true;
                 }
             }
           /* we ignore negative max_ages */
@@ -450,6 +456,8 @@ hsts_store_entry (hsts_store_t store,
              happen we got a non-existent entry with max_age == 0.
           */
           result = hsts_add_entry (store, host, port, max_age, include_subdomains);
+          if (result)
+            store->changed = true;
         }
       /* we ignore new entries with max_age == 0 */
       xfree (kh->host);
@@ -470,6 +478,7 @@ hsts_store_open (const char *filename)
   store = xnew0 (struct hsts_store);
   store->table = hash_table_new (0, hsts_hash_func, hsts_cmp_func);
   store->last_mtime = 0;
+  store->changed = false;
 
   if (file_exists_p (filename))
     {
diff --git a/src/main.c b/src/main.c
index ed050a5..4189414 100644
--- a/src/main.c
+++ b/src/main.c
@@ -204,7 +204,7 @@ save_hsts (void)
     {
       char *filename = get_hsts_database ();
 
-      if (filename)
+      if (hsts_store->changed)
         DEBUGP (("Saving HSTS entries to %s\n", filename));
 
       hsts_store_save (hsts_store, filename);
-- 
2.1.4

Reply via email to