aboutsummaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
authorNils Gillmann <ng0@n0.is>2018-11-13 11:42:15 +0000
committerNils Gillmann <ng0@n0.is>2018-11-13 11:42:15 +0000
commit9d1e77b9331acb9bd8b6c99aa942f62b9759e650 (patch)
tree85475b117fff75b563a6f9512d3ead476a830f7d /src/util
parente8a1a082555f98af40f98fd3a20ccd803ad478f8 (diff)
parent98288a7b26344294a3668101b9c2b502dfc19e12 (diff)
downloadgnunet-9d1e77b9331acb9bd8b6c99aa942f62b9759e650.tar.gz
gnunet-9d1e77b9331acb9bd8b6c99aa942f62b9759e650.zip
Merge branch 'master' of gnunet.org:gnunet
Diffstat (limited to 'src/util')
-rw-r--r--src/util/configuration.c35
-rw-r--r--src/util/disk.c51
-rw-r--r--src/util/gnunet-service-resolver.c18
-rw-r--r--src/util/service.c10
4 files changed, 82 insertions, 32 deletions
diff --git a/src/util/configuration.c b/src/util/configuration.c
index 312e0acd3..197c664db 100644
--- a/src/util/configuration.c
+++ b/src/util/configuration.c
@@ -138,6 +138,41 @@ GNUNET_CONFIGURATION_destroy (struct GNUNET_CONFIGURATION_Handle *cfg)
138 138
139 139
140/** 140/**
141 * Parse a configuration file @a filename and run the function
142 * @a cb with the resulting configuration object. Then free the
143 * configuration object and return the status value from @a cb.
144 *
145 * @param filename configuration to parse, NULL for "default"
146 * @param cb function to run
147 * @param cb_cls closure for @a cb
148 * @return #GNUNET_SYSERR if parsing the configuration failed,
149 * otherwise return value from @a cb.
150 */
151int
152GNUNET_CONFIGURATION_parse_and_run (const char *filename,
153 GNUNET_CONFIGURATION_Callback cb,
154 void *cb_cls)
155{
156 struct GNUNET_CONFIGURATION_Handle *cfg;
157 int ret;
158
159 cfg = GNUNET_CONFIGURATION_create ();
160 if (GNUNET_OK !=
161 GNUNET_CONFIGURATION_load (cfg,
162 filename))
163 {
164 GNUNET_break (0);
165 GNUNET_CONFIGURATION_destroy (cfg);
166 return GNUNET_SYSERR;
167 }
168 ret = cb (cb_cls,
169 cfg);
170 GNUNET_CONFIGURATION_destroy (cfg);
171 return ret;
172}
173
174
175/**
141 * De-serializes configuration 176 * De-serializes configuration
142 * 177 *
143 * @param cfg configuration to update 178 * @param cfg configuration to update
diff --git a/src/util/disk.c b/src/util/disk.c
index e0227be70..dc38d1137 100644
--- a/src/util/disk.c
+++ b/src/util/disk.c
@@ -2668,28 +2668,19 @@ GNUNET_DISK_internal_file_handle_ (const struct GNUNET_DISK_FileHandle *fh,
2668 2668
2669 2669
2670/** 2670/**
2671 * Remove the directory given under @a option in 2671 * Helper function for #GNUNET_DISK_purge_cfg_dir.
2672 * section [PATHS] in configuration under @a cfg_filename
2673 * 2672 *
2674 * @param cfg_filename configuration file to parse 2673 * @param cls a `const char *` with the option to purge
2675 * @param option option with the dir name to purge 2674 * @param cfg our configuration
2675 * @return #GNUNET_OK on success
2676 */ 2676 */
2677void 2677static int
2678GNUNET_DISK_purge_cfg_dir (const char *cfg_filename, 2678purge_cfg_dir (void *cls,
2679 const char *option) 2679 const struct GNUNET_CONFIGURATION_Handle *cfg)
2680{ 2680{
2681 struct GNUNET_CONFIGURATION_Handle *cfg; 2681 const char *option = cls;
2682 char *tmpname; 2682 char *tmpname;
2683 2683
2684 cfg = GNUNET_CONFIGURATION_create ();
2685 if (GNUNET_OK !=
2686 GNUNET_CONFIGURATION_load (cfg,
2687 cfg_filename))
2688 {
2689 GNUNET_break (0);
2690 GNUNET_CONFIGURATION_destroy (cfg);
2691 return;
2692 }
2693 if (GNUNET_OK != 2684 if (GNUNET_OK !=
2694 GNUNET_CONFIGURATION_get_value_filename (cfg, 2685 GNUNET_CONFIGURATION_get_value_filename (cfg,
2695 "PATHS", 2686 "PATHS",
@@ -2699,10 +2690,8 @@ GNUNET_DISK_purge_cfg_dir (const char *cfg_filename,
2699 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, 2690 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
2700 "PATHS", 2691 "PATHS",
2701 option); 2692 option);
2702 GNUNET_CONFIGURATION_destroy (cfg); 2693 return GNUNET_NO;
2703 return;
2704 } 2694 }
2705 GNUNET_CONFIGURATION_destroy (cfg);
2706 if (GNUNET_SYSERR == 2695 if (GNUNET_SYSERR ==
2707 GNUNET_DISK_directory_remove (tmpname)) 2696 GNUNET_DISK_directory_remove (tmpname))
2708 { 2697 {
@@ -2710,11 +2699,29 @@ GNUNET_DISK_purge_cfg_dir (const char *cfg_filename,
2710 "remove", 2699 "remove",
2711 tmpname); 2700 tmpname);
2712 GNUNET_free (tmpname); 2701 GNUNET_free (tmpname);
2713 return; 2702 return GNUNET_OK;
2714 } 2703 }
2715 GNUNET_free (tmpname); 2704 GNUNET_free (tmpname);
2705 return GNUNET_OK;
2716} 2706}
2717 2707
2718 2708
2709/**
2710 * Remove the directory given under @a option in
2711 * section [PATHS] in configuration under @a cfg_filename
2712 *
2713 * @param cfg_filename configuration file to parse
2714 * @param option option with the dir name to purge
2715 */
2716void
2717GNUNET_DISK_purge_cfg_dir (const char *cfg_filename,
2718 const char *option)
2719{
2720 GNUNET_break (GNUNET_OK ==
2721 GNUNET_CONFIGURATION_parse_and_run (cfg_filename,
2722 &purge_cfg_dir,
2723 (void *) option));
2724}
2725
2719 2726
2720/* end of disk.c */ 2727/* end of disk.c */
diff --git a/src/util/gnunet-service-resolver.c b/src/util/gnunet-service-resolver.c
index d907bd8d9..3b871ce33 100644
--- a/src/util/gnunet-service-resolver.c
+++ b/src/util/gnunet-service-resolver.c
@@ -364,7 +364,7 @@ lookup_dns_servers (char ***server_addrs)
364 GNUNET_DISK_file_close (fh); 364 GNUNET_DISK_file_close (fh);
365 return -1; 365 return -1;
366 } 366 }
367 if (bytes_read > SIZE_MAX) 367 if ((size_t) bytes_read > SIZE_MAX)
368 { 368 {
369 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 369 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
370 "/etc/resolv.conf file too large to mmap. " 370 "/etc/resolv.conf file too large to mmap. "
@@ -379,7 +379,7 @@ lookup_dns_servers (char ***server_addrs)
379 *server_addrs = NULL; 379 *server_addrs = NULL;
380 read_offset = 0; 380 read_offset = 0;
381 num_dns_servers = 0; 381 num_dns_servers = 0;
382 while (read_offset < bytes_read) 382 while (read_offset < (size_t) bytes_read)
383 { 383 {
384 const char *newline; 384 const char *newline;
385 size_t line_len; 385 size_t line_len;
@@ -648,11 +648,16 @@ try_cache (const char *hostname,
648 struct ResolveCache *pos; 648 struct ResolveCache *pos;
649 struct ResolveCache *next; 649 struct ResolveCache *next;
650 int found; 650 int found;
651 int in_hosts;
651 652
653 in_hosts = GNUNET_NO;
652 for (pos = hosts_head; NULL != pos; pos = pos->next) 654 for (pos = hosts_head; NULL != pos; pos = pos->next)
653 if (0 == strcmp (pos->hostname, 655 if (0 == strcmp (pos->hostname,
654 hostname)) 656 hostname))
657 {
658 in_hosts = GNUNET_YES;
655 break; 659 break;
660 }
656 if (NULL == pos) 661 if (NULL == pos)
657 { 662 {
658 next = cache_head; 663 next = cache_head;
@@ -673,7 +678,8 @@ try_cache (const char *hostname,
673 hostname); 678 hostname);
674 return GNUNET_NO; 679 return GNUNET_NO;
675 } 680 }
676 if (cache_head != pos) 681 if ( (GNUNET_NO == in_hosts) &&
682 (cache_head != pos) )
677 { 683 {
678 /* move result to head to achieve LRU for cache eviction */ 684 /* move result to head to achieve LRU for cache eviction */
679 GNUNET_CONTAINER_DLL_remove (cache_head, 685 GNUNET_CONTAINER_DLL_remove (cache_head,
@@ -1313,7 +1319,7 @@ extract_hosts (const char *line,
1313 if (NULL != c) 1319 if (NULL != c)
1314 line_len = c - line; 1320 line_len = c - line;
1315 /* ignore leading whitespace */ 1321 /* ignore leading whitespace */
1316 while ( (0 > line_len) && 1322 while ( (0 < line_len) &&
1317 isspace ((unsigned char) *line) ) 1323 isspace ((unsigned char) *line) )
1318 { 1324 {
1319 line++; 1325 line++;
@@ -1382,7 +1388,7 @@ load_etc_hosts (void)
1382 GNUNET_DISK_file_close (fh); 1388 GNUNET_DISK_file_close (fh);
1383 return; 1389 return;
1384 } 1390 }
1385 if (bytes_read > SIZE_MAX) 1391 if ((size_t) bytes_read > SIZE_MAX)
1386 { 1392 {
1387 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1393 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1388 "/etc/hosts file too large to mmap. " 1394 "/etc/hosts file too large to mmap. "
@@ -1395,7 +1401,7 @@ load_etc_hosts (void)
1395 GNUNET_DISK_MAP_TYPE_READ, 1401 GNUNET_DISK_MAP_TYPE_READ,
1396 (size_t) bytes_read); 1402 (size_t) bytes_read);
1397 read_offset = 0; 1403 read_offset = 0;
1398 while (read_offset < bytes_read) 1404 while (read_offset < (size_t) bytes_read)
1399 { 1405 {
1400 const char *newline; 1406 const char *newline;
1401 size_t line_len; 1407 size_t line_len;
diff --git a/src/util/service.c b/src/util/service.c
index ea34abc6c..b61168570 100644
--- a/src/util/service.c
+++ b/src/util/service.c
@@ -1815,8 +1815,9 @@ GNUNET_SERVICE_run_ (int argc,
1815 opt_cfg_filename = GNUNET_strdup (cfg_filename); 1815 opt_cfg_filename = GNUNET_strdup (cfg_filename);
1816 if (GNUNET_YES == GNUNET_DISK_file_test (opt_cfg_filename)) 1816 if (GNUNET_YES == GNUNET_DISK_file_test (opt_cfg_filename))
1817 { 1817 {
1818 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load (cfg, 1818 if (GNUNET_SYSERR ==
1819 opt_cfg_filename)) 1819 GNUNET_CONFIGURATION_load (cfg,
1820 opt_cfg_filename))
1820 { 1821 {
1821 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1822 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1822 _("Malformed configuration file `%s', exit ...\n"), 1823 _("Malformed configuration file `%s', exit ...\n"),
@@ -1826,8 +1827,9 @@ GNUNET_SERVICE_run_ (int argc,
1826 } 1827 }
1827 else 1828 else
1828 { 1829 {
1829 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load (cfg, 1830 if (GNUNET_SYSERR ==
1830 NULL)) 1831 GNUNET_CONFIGURATION_load (cfg,
1832 NULL))
1831 { 1833 {
1832 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1834 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1833 _("Malformed configuration, exit ...\n")); 1835 _("Malformed configuration, exit ...\n"));