]> granicus.if.org Git - vnstat/commitdiff
fix interfaces having the possibility of staying marked as disabled after coming...
authorTeemu Toivola <git@humdi.net>
Tue, 25 Jun 2019 19:37:18 +0000 (22:37 +0300)
committerTeemu Toivola <git@humdi.net>
Tue, 25 Jun 2019 19:37:18 +0000 (22:37 +0300)
CHANGES
src/daemon.c
src/dbsql.c
tests/dbsql_tests.c

diff --git a/CHANGES b/CHANGES
index 571dfc83e2e0ad02dd7baa805d4fd3e05b30b620..78952c02193dcf77161fbf2c42f2bbcf2659c3d7 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -8,6 +8,9 @@
      if the used systemd version supported ProtectSystem=strict but didn't
      support StateDirectory (issue seen at least with systemd 232 in Debian 9)
    - Debian and Red Hat init.d example files had wrong path for the pid file
+   - Interfaces could end up staying marked as 'disabled' in the database even
+     after becoming back active and monitored, only the shown status was wrong
+     without resulting in any data loss
  - New
    - Automatic interface selection when the Interface configuration setting
      is left empty (new default)
index 92c371f05ebcdbf89d20d54fce52f9e593fa2fc9..b9f1f1254b1226deedfc07f0bc3f6e75a522d3ee 100644 (file)
@@ -636,12 +636,6 @@ void flushcachetodisk(DSTATE *s)
                        }
                }
 
-               /* update interface timestamp in database */
-               if (!db_setupdated(iterator->interface, iterator->updated)) {
-                       handledatabaseerror(s);
-                       break;
-               }
-
                if (!iterator->active && !logcount) {
                        /* throw away if interface hasn't seen any data and is disabled */
                        if (!iterator->currx && !iterator->curtx) {
@@ -657,12 +651,18 @@ void flushcachetodisk(DSTATE *s)
                                        break;
                                }
                        }
+               }
 
-                       /* update interface activity status in database if changed */
-                       if (!db_setactive(iterator->interface, iterator->active)) {
-                               handledatabaseerror(s);
-                               break;
-                       }
+               /* update interface timestamp in database */
+               if (!db_setupdated(iterator->interface, iterator->updated)) {
+                       handledatabaseerror(s);
+                       break;
+               }
+
+               /* update interface activity status in database */
+               if (!db_setactive(iterator->interface, iterator->active)) {
+                       handledatabaseerror(s);
+                       break;
                }
 
                iterator = iterator->next;
index ede57e0eaeab81741c9d757378d688c0e15e7e2f..97957d5cb3a1691e496965cd092db0c981c6f6e8 100644 (file)
@@ -807,17 +807,6 @@ int db_addtraffic_dated(const char *iface, const uint64_t rx, const uint64_t tx,
                }
        }
 
-       /* change updated only if more recent than previous when timestamp provided */
-       if (timestamp > 0) {
-               sqlite3_snprintf(1024, sql, "update interface set active=1, updated=datetime(%s, 'localtime') where id=%" PRId64 " and updated < datetime(%s, 'localtime')", nowdate, (int64_t)ifaceid, nowdate);
-       } else {
-               sqlite3_snprintf(1024, sql, "update interface set active=1, updated=datetime(%s, 'localtime') where id=%" PRId64 "", nowdate, (int64_t)ifaceid);
-       }
-       if (!db_exec(sql)) {
-               /* no transaction rollback needed here as failure of the first step results in no transaction being active */
-               return 0;
-       }
-
        /* total */
        if (rx > 0 || tx > 0) {
                sqlite3_snprintf(1024, sql, "update interface set rxtotal=rxtotal+%" PRIu64 ", txtotal=txtotal+%" PRIu64 " where id=%" PRId64 "", rx, tx, (int64_t)ifaceid);
index fac72baeccf6a59bdc6b82f9f88bba2170f76510..1211409d7498b218417c8700f2f39ae69436e513 100644 (file)
@@ -178,7 +178,7 @@ START_TEST(db_addtraffic_can_add_traffic_and_interfaces)
 }
 END_TEST
 
-START_TEST(db_addtraffic_dated_does_not_turn_back_time)
+START_TEST(db_addtraffic_dated_does_not_touch_updated_time)
 {
        int ret;
        interfaceinfo info;
@@ -212,7 +212,7 @@ START_TEST(db_addtraffic_dated_does_not_turn_back_time)
        ck_assert_int_eq(ret, 1);
        ck_assert_int_eq(info.rxtotal, 3);
        ck_assert_int_eq(info.txtotal, 3);
-       ck_assert_int_eq(info.updated, 2100000000);
+       ck_assert_int_lt(info.updated, 2100000000);
 
        ret = db_addtraffic_dated("eth0", 1, 1, 1000);
        ck_assert_int_eq(ret, 1);
@@ -220,7 +220,7 @@ START_TEST(db_addtraffic_dated_does_not_turn_back_time)
        ck_assert_int_eq(ret, 1);
        ck_assert_int_eq(info.rxtotal, 4);
        ck_assert_int_eq(info.txtotal, 4);
-       ck_assert_int_eq(info.updated, 2100000000);
+       ck_assert_int_lt(info.updated, 2100000000);
 
        ret = db_addtraffic("eth0", 1, 1);
        ck_assert_int_eq(ret, 1);
@@ -2198,7 +2198,7 @@ void add_dbsql_tests(Suite *s)
        tcase_add_test(tc_dbsql, db_setinfo_can_not_update_nonexisting_name);
        tcase_add_test(tc_dbsql, db_addtraffic_with_no_traffic_does_nothing);
        tcase_add_test(tc_dbsql, db_addtraffic_can_add_traffic_and_interfaces);
-       tcase_add_test(tc_dbsql, db_addtraffic_dated_does_not_turn_back_time);
+       tcase_add_test(tc_dbsql, db_addtraffic_dated_does_not_touch_updated_time);
        tcase_add_test(tc_dbsql, db_getinterfacecount_counts_interfaces);
        tcase_add_test(tc_dbsql, db_getinterfacecountbyname_counts_interfaces);
        tcase_add_test(tc_dbsql, db_setactive_fails_with_no_open_db);