LCOV - code coverage report
Current view: top level - timesync - timesyncd-conf.c (source / functions) Hit Total Coverage
Test: main_coverage.info Lines: 30 58 51.7 %
Date: 2019-08-22 15:41:25 Functions: 2 4 50.0 %

          Line data    Source code
       1             : /* SPDX-License-Identifier: LGPL-2.1+ */
       2             : 
       3             : #include "alloc-util.h"
       4             : #include "def.h"
       5             : #include "dns-domain.h"
       6             : #include "extract-word.h"
       7             : #include "string-util.h"
       8             : #include "timesyncd-conf.h"
       9             : #include "timesyncd-manager.h"
      10             : #include "timesyncd-server.h"
      11             : 
      12           4 : int manager_parse_server_string(Manager *m, ServerType type, const char *string) {
      13             :         ServerName *first;
      14             :         int r;
      15             : 
      16           4 :         assert(m);
      17           4 :         assert(string);
      18             : 
      19           4 :         first = type == SERVER_FALLBACK ? m->fallback_servers : m->system_servers;
      20             : 
      21           4 :         if (type == SERVER_FALLBACK)
      22           2 :                  m->have_fallbacks = true;
      23             : 
      24          16 :         for (;;) {
      25          20 :                 _cleanup_free_ char *word = NULL;
      26          20 :                 bool found = false;
      27             :                 ServerName *n;
      28             : 
      29          20 :                 r = extract_first_word(&string, &word, NULL, 0);
      30          20 :                 if (r < 0)
      31           0 :                         return log_error_errno(r, "Failed to parse timesyncd server syntax \"%s\": %m", string);
      32          20 :                 if (r == 0)
      33           4 :                         break;
      34             : 
      35          16 :                 r = dns_name_is_valid_or_address(word);
      36          16 :                 if (r < 0)
      37           0 :                         return log_error_errno(r, "Failed to check validity of NTP server name or address '%s': %m", word);
      38          16 :                 if (r == 0) {
      39           6 :                         log_error("Invalid NTP server name or address, ignoring: %s", word);
      40           6 :                         continue;
      41             :                 }
      42             : 
      43             :                 /* Filter out duplicates */
      44          20 :                 LIST_FOREACH(names, n, first)
      45          12 :                         if (streq_ptr(n->string, word)) {
      46           2 :                                 found = true;
      47           2 :                                 break;
      48             :                         }
      49             : 
      50          10 :                 if (found)
      51           2 :                         continue;
      52             : 
      53           8 :                 r = server_name_new(m, NULL, type, word);
      54           8 :                 if (r < 0)
      55           0 :                         return r;
      56             :         }
      57             : 
      58           4 :         return 0;
      59             : }
      60             : 
      61           1 : int manager_parse_fallback_string(Manager *m, const char *string) {
      62           1 :         if (m->have_fallbacks)
      63           1 :                 return 0;
      64             : 
      65           0 :         return manager_parse_server_string(m, SERVER_FALLBACK, string);
      66             : }
      67             : 
      68           0 : int config_parse_servers(
      69             :                 const char *unit,
      70             :                 const char *filename,
      71             :                 unsigned line,
      72             :                 const char *section,
      73             :                 unsigned section_line,
      74             :                 const char *lvalue,
      75             :                 int ltype,
      76             :                 const char *rvalue,
      77             :                 void *data,
      78             :                 void *userdata) {
      79             : 
      80           0 :         Manager *m = userdata;
      81             :         int r;
      82             : 
      83           0 :         assert(filename);
      84           0 :         assert(lvalue);
      85           0 :         assert(rvalue);
      86             : 
      87           0 :         if (isempty(rvalue))
      88           0 :                 manager_flush_server_names(m, ltype);
      89             :         else {
      90           0 :                 r = manager_parse_server_string(m, ltype, rvalue);
      91           0 :                 if (r < 0) {
      92           0 :                         log_syntax(unit, LOG_ERR, filename, line, r, "Failed to parse NTP server string '%s'. Ignoring.", rvalue);
      93           0 :                         return 0;
      94             :                 }
      95             :         }
      96             : 
      97           0 :         return 0;
      98             : }
      99             : 
     100           0 : int manager_parse_config_file(Manager *m) {
     101             :         int r;
     102             : 
     103           0 :         assert(m);
     104             : 
     105           0 :         r = config_parse_many_nulstr(PKGSYSCONFDIR "/timesyncd.conf",
     106             :                                      CONF_PATHS_NULSTR("systemd/timesyncd.conf.d"),
     107             :                                      "Time\0",
     108             :                                      config_item_perf_lookup, timesyncd_gperf_lookup,
     109             :                                      CONFIG_PARSE_WARN, m);
     110           0 :         if (r < 0)
     111           0 :                 return r;
     112             : 
     113           0 :         if (m->poll_interval_min_usec < 16 * USEC_PER_SEC) {
     114           0 :                 log_warning("Invalid PollIntervalMinSec=. Using default value.");
     115           0 :                 m->poll_interval_min_usec = NTP_POLL_INTERVAL_MIN_USEC;
     116             :         }
     117             : 
     118           0 :         if (m->poll_interval_max_usec < m->poll_interval_min_usec) {
     119           0 :                 log_warning("PollIntervalMaxSec= is smaller than PollIntervalMinSec=. Using default value.");
     120           0 :                 m->poll_interval_max_usec = MAX(NTP_POLL_INTERVAL_MAX_USEC, m->poll_interval_min_usec * 32);
     121             :         }
     122             : 
     123           0 :         return r;
     124             : }

Generated by: LCOV version 1.14