aboutsummaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
Diffstat (limited to 'src/util')
-rw-r--r--src/util/common_logging.c209
-rw-r--r--src/util/crypto_random.c8
-rw-r--r--src/util/getopt.c4
-rw-r--r--src/util/os_network.c27
-rw-r--r--src/util/scheduler.c8
-rw-r--r--src/util/service.c12
-rw-r--r--src/util/strings.c4
-rw-r--r--src/util/test_bio.c2
-rw-r--r--src/util/test_common_logging_runtime_loglevels.c9
-rw-r--r--src/util/test_os_network.c7
10 files changed, 141 insertions, 149 deletions
diff --git a/src/util/common_logging.c b/src/util/common_logging.c
index ded410e3d..22901bf26 100644
--- a/src/util/common_logging.c
+++ b/src/util/common_logging.c
@@ -268,9 +268,9 @@ void
268GNUNET_abort () 268GNUNET_abort ()
269{ 269{
270#if WINDOWS 270#if WINDOWS
271 DebugBreak(); 271 DebugBreak ();
272#endif 272#endif
273 abort(); 273 abort ();
274} 274}
275 275
276 276
@@ -292,6 +292,7 @@ add_definition (char *component, char *file, char *function, int from_line,
292{ 292{
293 struct LogDef n; 293 struct LogDef n;
294 int r; 294 int r;
295
295 if (logdefs_size == logdefs_len) 296 if (logdefs_size == logdefs_len)
296 resize_logdefs (); 297 resize_logdefs ();
297 memset (&n, 0, sizeof (n)); 298 memset (&n, 0, sizeof (n));
@@ -299,27 +300,26 @@ add_definition (char *component, char *file, char *function, int from_line,
299 component = (char *) ".*"; 300 component = (char *) ".*";
300 r = regcomp (&n.component_regex, (const char *) component, REG_NOSUB); 301 r = regcomp (&n.component_regex, (const char *) component, REG_NOSUB);
301 if (r != 0) 302 if (r != 0)
302 { 303 {
303 return r; 304 return r;
304 } 305 }
305 if (strlen (file) == 0) 306 if (strlen (file) == 0)
306 file = (char *) ".*"; 307 file = (char *) ".*";
307 r = regcomp (&n.file_regex, (const char *) file, REG_NOSUB); 308 r = regcomp (&n.file_regex, (const char *) file, REG_NOSUB);
308 if (r != 0) 309 if (r != 0)
309 { 310 {
310 regfree (&n.component_regex); 311 regfree (&n.component_regex);
311 return r; 312 return r;
312 } 313 }
313 if ( (NULL == function) || 314 if ((NULL == function) || (strlen (function) == 0))
314 (strlen (function) == 0))
315 function = (char *) ".*"; 315 function = (char *) ".*";
316 r = regcomp (&n.function_regex, (const char *) function, REG_NOSUB); 316 r = regcomp (&n.function_regex, (const char *) function, REG_NOSUB);
317 if (r != 0) 317 if (r != 0)
318 { 318 {
319 regfree (&n.component_regex); 319 regfree (&n.component_regex);
320 regfree (&n.file_regex); 320 regfree (&n.file_regex);
321 return r; 321 return r;
322 } 322 }
323 n.from_line = from_line; 323 n.from_line = from_line;
324 n.to_line = to_line; 324 n.to_line = to_line;
325 n.level = level; 325 n.level = level;
@@ -364,16 +364,16 @@ GNUNET_get_log_call_status (int caller_level, const char *comp,
364 force_only = min_level >= 0; 364 force_only = min_level >= 0;
365 for (i = 0; i < logdefs_len; i++) 365 for (i = 0; i < logdefs_len; i++)
366 { 366 {
367 ld = &logdefs[i]; 367 ld = &logdefs[i];
368 if ((!force_only || ld->force) && 368 if ((!force_only || ld->force) &&
369 (line >= ld->from_line && line <= ld->to_line) && 369 (line >= ld->from_line && line <= ld->to_line) &&
370 (regexec (&ld->component_regex, comp, 0, NULL, 0) == 0) && 370 (regexec (&ld->component_regex, comp, 0, NULL, 0) == 0) &&
371 (regexec (&ld->file_regex, file, 0, NULL, 0) == 0) && 371 (regexec (&ld->file_regex, file, 0, NULL, 0) == 0) &&
372 (regexec (&ld->function_regex, function, 0, NULL, 0) == 0)) 372 (regexec (&ld->function_regex, function, 0, NULL, 0) == 0))
373 { 373 {
374 /* We're finished */ 374 /* We're finished */
375 return caller_level <= ld->level; 375 return caller_level <= ld->level;
376 } 376 }
377 } 377 }
378 /* No matches - use global level, if defined */ 378 /* No matches - use global level, if defined */
379 if (min_level >= 0) 379 if (min_level >= 0)
@@ -434,83 +434,83 @@ parse_definitions (const char *constname, int force)
434 to_line = INT_MAX; 434 to_line = INT_MAX;
435 for (p = def, state = 0, start = def; keep_looking; p++) 435 for (p = def, state = 0, start = def; keep_looking; p++)
436 { 436 {
437 switch (p[0]) 437 switch (p[0])
438 { 438 {
439 case ';': /* found a field separator */ 439 case ';': /* found a field separator */
440 p[0] = '\0'; 440 p[0] = '\0';
441 switch (state) 441 switch (state)
442 { 442 {
443 case 0: /* within a component name */ 443 case 0: /* within a component name */
444 comp = start; 444 comp = start;
445 break; 445 break;
446 case 1: /* within a file name */ 446 case 1: /* within a file name */
447 file = start; 447 file = start;
448 break; 448 break;
449 case 2: /* within a function name */ 449 case 2: /* within a function name */
450 /* after a file name there must be a function name */ 450 /* after a file name there must be a function name */
451 function = start; 451 function = start;
452 break; 452 break;
453 case 3: /* within a from-to line range */ 453 case 3: /* within a from-to line range */
454 if (strlen (start) > 0) 454 if (strlen (start) > 0)
455 { 455 {
456 errno = 0; 456 errno = 0;
457 from_line = strtol (start, &t, 10); 457 from_line = strtol (start, &t, 10);
458 if (errno != 0 || from_line < 0) 458 if (errno != 0 || from_line < 0)
459 { 459 {
460 free (def); 460 free (def);
461 return counter; 461 return counter;
462 } 462 }
463 if (t < p && t[0] == '-') 463 if (t < p && t[0] == '-')
464 { 464 {
465 errno = 0; 465 errno = 0;
466 start = t + 1; 466 start = t + 1;
467 to_line = strtol (start, &t, 10); 467 to_line = strtol (start, &t, 10);
468 if (errno != 0 || to_line < 0 || t != p) 468 if (errno != 0 || to_line < 0 || t != p)
469 { 469 {
470 free (def); 470 free (def);
471 return counter; 471 return counter;
472 } 472 }
473 } 473 }
474 else /* one number means "match this line only" */ 474 else /* one number means "match this line only" */
475 to_line = from_line; 475 to_line = from_line;
476 } 476 }
477 else /* default to 0-max */ 477 else /* default to 0-max */
478 { 478 {
479 from_line = 0; 479 from_line = 0;
480 to_line = INT_MAX; 480 to_line = INT_MAX;
481 } 481 }
482 break; 482 break;
483 } 483 }
484 start = p + 1; 484 start = p + 1;
485 state += 1; 485 state += 1;
486 break; 486 break;
487 case '\0': /* found EOL */ 487 case '\0': /* found EOL */
488 keep_looking = 0; 488 keep_looking = 0;
489 /* fall through to '/' */ 489 /* fall through to '/' */
490 case '/': /* found a definition separator */ 490 case '/': /* found a definition separator */
491 switch (state) 491 switch (state)
492 { 492 {
493 case 4: /* within a log level */ 493 case 4: /* within a log level */
494 p[0] = '\0'; 494 p[0] = '\0';
495 state = 0; 495 state = 0;
496 level = get_type ((const char *) start); 496 level = get_type ((const char *) start);
497 if (level == GNUNET_ERROR_TYPE_INVALID 497 if (level == GNUNET_ERROR_TYPE_INVALID ||
498 || level == GNUNET_ERROR_TYPE_UNSPECIFIED 498 level == GNUNET_ERROR_TYPE_UNSPECIFIED ||
499 || 0 != add_definition (comp, file, function, from_line, 499 0 != add_definition (comp, file, function, from_line, to_line,
500 to_line, level, force)) 500 level, force))
501 { 501 {
502 free (def); 502 free (def);
503 return counter; 503 return counter;
504 } 504 }
505 counter += 1; 505 counter += 1;
506 start = p + 1; 506 start = p + 1;
507 break; 507 break;
508 default: 508 default:
509 break; 509 break;
510 } 510 }
511 default: 511 default:
512 break; 512 break;
513 } 513 }
514 } 514 }
515 free (def); 515 free (def);
516 return counter; 516 return counter;
@@ -560,8 +560,7 @@ GNUNET_log_setup (const char *comp, const char *loglevel, const char *logfile)
560 component_nopid = GNUNET_strdup (comp); 560 component_nopid = GNUNET_strdup (comp);
561 561
562 env_logfile = getenv ("GNUNET_FORCE_LOGFILE"); 562 env_logfile = getenv ("GNUNET_FORCE_LOGFILE");
563 if ( (env_logfile != NULL) && 563 if ((env_logfile != NULL) && (strlen (env_logfile) > 0))
564 (strlen (env_logfile) > 0) )
565 logfile = env_logfile; 564 logfile = env_logfile;
566 565
567 if (logfile == NULL) 566 if (logfile == NULL)
diff --git a/src/util/crypto_random.c b/src/util/crypto_random.c
index a1485029e..ff20646f7 100644
--- a/src/util/crypto_random.c
+++ b/src/util/crypto_random.c
@@ -38,10 +38,10 @@
38/* The code is derived from glibc, obviously */ 38/* The code is derived from glibc, obviously */
39#if MINGW 39#if MINGW
40#ifdef RANDOM 40#ifdef RANDOM
41# undef RANDOM 41#undef RANDOM
42#endif 42#endif
43#ifdef SRANDOM 43#ifdef SRANDOM
44# undef SRANDOM 44#undef SRANDOM
45#endif 45#endif
46#define RANDOM() glibc_weak_rand32() 46#define RANDOM() glibc_weak_rand32()
47#define SRANDOM(s) glibc_weak_srand32(s) 47#define SRANDOM(s) glibc_weak_srand32(s)
@@ -57,6 +57,7 @@ int32_t
57glibc_weak_rand32 () 57glibc_weak_rand32 ()
58{ 58{
59 int32_t val = glibc_weak_rand32_state; 59 int32_t val = glibc_weak_rand32_state;
60
60 val = ((glibc_weak_rand32_state * 1103515245) + 12345) & 0x7fffffff; 61 val = ((glibc_weak_rand32_state * 1103515245) + 12345) & 0x7fffffff;
61 glibc_weak_rand32_state = val; 62 glibc_weak_rand32_state = val;
62 return val; 63 return val;
@@ -314,7 +315,8 @@ void __attribute__ ((constructor)) GNUNET_CRYPTO_random_init ()
314 gcry_set_progress_handler (&entropy_generator, NULL); 315 gcry_set_progress_handler (&entropy_generator, NULL);
315 atexit (&killfind); 316 atexit (&killfind);
316 GNUNET_CRYPTO_seed_weak_random (time (NULL) ^ 317 GNUNET_CRYPTO_seed_weak_random (time (NULL) ^
317 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX)); 318 GNUNET_CRYPTO_random_u32
319 (GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX));
318} 320}
319 321
320 322
diff --git a/src/util/getopt.c b/src/util/getopt.c
index 6c63cb339..08c133423 100644
--- a/src/util/getopt.c
+++ b/src/util/getopt.c
@@ -257,8 +257,8 @@ extern pid_t __libc_pid;
257/* Make sure the environment variable bash 2.0 puts in the environment 257/* Make sure the environment variable bash 2.0 puts in the environment
258 is valid for the getopt call we must make sure that the ARGV passed 258 is valid for the getopt call we must make sure that the ARGV passed
259 to getopt is that one passed to the process. */ 259 to getopt is that one passed to the process. */
260static void 260static void GNUNET_UNUSED
261 GNUNET_UNUSED store_args_and_env (int argc, char *const *argv) 261store_args_and_env (int argc, char *const *argv)
262{ 262{
263 /* XXX This is no good solution. We should rather copy the args so 263 /* XXX This is no good solution. We should rather copy the args so
264 * that we can compare them later. But we must not use malloc(3). */ 264 * that we can compare them later. But we must not use malloc(3). */
diff --git a/src/util/os_network.c b/src/util/os_network.c
index a4758496e..b25e9d00b 100644
--- a/src/util/os_network.c
+++ b/src/util/os_network.c
@@ -58,12 +58,13 @@ GNUNET_OS_network_interfaces_list (GNUNET_OS_NetworkInterfaceProcessor proc,
58 58
59 for (i = 0; i < results_count; i++) 59 for (i = 0; i < results_count; i++)
60 { 60 {
61 if (GNUNET_OK != proc (proc_cls, results[i].pretty_name, 61 if (GNUNET_OK !=
62 results[i].is_default, 62 proc (proc_cls, results[i].pretty_name, results[i].is_default,
63 &results[i].address, 63 &results[i].address,
64 results[i].flags & ENUMNICS3_MASK_OK ? &results[i].mask : NULL, 64 results[i].flags & ENUMNICS3_MASK_OK ? &results[i].mask : NULL,
65 results[i].flags & ENUMNICS3_BCAST_OK ? &results[i].broadcast : NULL, 65 results[i].
66 results[i].addr_size)) 66 flags & ENUMNICS3_BCAST_OK ? &results[i].broadcast : NULL,
67 results[i].addr_size))
67 break; 68 break;
68 } 69 }
69 EnumNICs3_free (results); 70 EnumNICs3_free (results);
@@ -92,10 +93,8 @@ GNUNET_OS_network_interfaces_list (GNUNET_OS_NetworkInterfaceProcessor proc,
92 if (GNUNET_OK != 93 if (GNUNET_OK !=
93 proc (proc_cls, ifa_ptr->ifa_name, 94 proc (proc_cls, ifa_ptr->ifa_name,
94 0 == strcmp (ifa_ptr->ifa_name, GNUNET_DEFAULT_INTERFACE), 95 0 == strcmp (ifa_ptr->ifa_name, GNUNET_DEFAULT_INTERFACE),
95 ifa_ptr->ifa_addr, 96 ifa_ptr->ifa_addr, ifa_ptr->ifa_broadaddr,
96 ifa_ptr->ifa_broadaddr, 97 ifa_ptr->ifa_netmask, alen))
97 ifa_ptr->ifa_netmask,
98 alen))
99 break; 98 break;
100 } 99 }
101 } 100 }
@@ -169,9 +168,7 @@ GNUNET_OS_network_interfaces_list (GNUNET_OS_NetworkInterfaceProcessor proc,
169 proc (proc_cls, ifc, 0 == strcmp (ifc, GNUNET_DEFAULT_INTERFACE), 168 proc (proc_cls, ifc, 0 == strcmp (ifc, GNUNET_DEFAULT_INTERFACE),
170 (const struct sockaddr *) &a4, 169 (const struct sockaddr *) &a4,
171 /* TODO broadcast and netmask */ 170 /* TODO broadcast and netmask */
172 NULL, 171 NULL, NULL, sizeof (a4)))
173 NULL,
174 sizeof (a4)))
175 break; 172 break;
176 continue; 173 continue;
177 } 174 }
@@ -188,9 +185,7 @@ GNUNET_OS_network_interfaces_list (GNUNET_OS_NetworkInterfaceProcessor proc,
188 proc (proc_cls, ifc, 0 == strcmp (ifc, GNUNET_DEFAULT_INTERFACE), 185 proc (proc_cls, ifc, 0 == strcmp (ifc, GNUNET_DEFAULT_INTERFACE),
189 (const struct sockaddr *) &a6, 186 (const struct sockaddr *) &a6,
190 /* TODO broadcast and netmask */ 187 /* TODO broadcast and netmask */
191 NULL, 188 NULL, NULL, sizeof (a6)))
192 NULL,
193 sizeof (a6)))
194 break; 189 break;
195 continue; 190 continue;
196 } 191 }
diff --git a/src/util/scheduler.c b/src/util/scheduler.c
index d4a11fc8a..1acc9a6d6 100644
--- a/src/util/scheduler.c
+++ b/src/util/scheduler.c
@@ -676,7 +676,7 @@ run_ready (struct GNUNET_NETWORK_FDSet *rs, struct GNUNET_NETWORK_FDSet *ws)
676 if (((tc.reason & GNUNET_SCHEDULER_REASON_WRITE_READY) != 0) && 676 if (((tc.reason & GNUNET_SCHEDULER_REASON_WRITE_READY) != 0) &&
677 (pos->write_fd != -1) && 677 (pos->write_fd != -1) &&
678 (!GNUNET_NETWORK_fdset_test_native (ws, pos->write_fd))) 678 (!GNUNET_NETWORK_fdset_test_native (ws, pos->write_fd)))
679 GNUNET_abort (); // added to ready in previous select loop! 679 GNUNET_abort (); // added to ready in previous select loop!
680#if DEBUG_TASKS 680#if DEBUG_TASKS
681 LOG (GNUNET_ERROR_TYPE_DEBUG, "Running task: %llu / %p\n", pos->id, 681 LOG (GNUNET_ERROR_TYPE_DEBUG, "Running task: %llu / %p\n", pos->id,
682 pos->callback_cls); 682 pos->callback_cls);
@@ -726,9 +726,9 @@ sighandler_shutdown ()
726 static char c; 726 static char c;
727 int old_errno = errno; /* backup errno */ 727 int old_errno = errno; /* backup errno */
728 728
729 if (getpid() != my_pid) 729 if (getpid () != my_pid)
730 exit(1); /* we have fork'ed since the signal handler was created, 730 exit (1); /* we have fork'ed since the signal handler was created,
731 ignore the signal, see https://gnunet.org/vfork discussion */ 731 * ignore the signal, see https://gnunet.org/vfork discussion */
732 GNUNET_DISK_file_write (GNUNET_DISK_pipe_handle 732 GNUNET_DISK_file_write (GNUNET_DISK_pipe_handle
733 (shutdown_pipe_handle, GNUNET_DISK_PIPE_END_WRITE), 733 (shutdown_pipe_handle, GNUNET_DISK_PIPE_END_WRITE),
734 &c, sizeof (c)); 734 &c, sizeof (c));
diff --git a/src/util/service.c b/src/util/service.c
index b5711972b..91fc460e2 100644
--- a/src/util/service.c
+++ b/src/util/service.c
@@ -1566,12 +1566,12 @@ GNUNET_SERVICE_run (int argc, char *const *argv, const char *serviceName,
1566 LOG (GNUNET_ERROR_TYPE_DEBUG, 1566 LOG (GNUNET_ERROR_TYPE_DEBUG,
1567 "Service `%s' runs with configuration from `%s'\n", serviceName, cfg_fn); 1567 "Service `%s' runs with configuration from `%s'\n", serviceName, cfg_fn);
1568#endif 1568#endif
1569 if ( (GNUNET_OK == 1569 if ((GNUNET_OK ==
1570 GNUNET_CONFIGURATION_get_value_number (sctx.cfg, "TESTING", "SKEW_OFFSET", 1570 GNUNET_CONFIGURATION_get_value_number (sctx.cfg, "TESTING",
1571 &skew_offset)) && 1571 "SKEW_OFFSET", &skew_offset)) &&
1572 (GNUNET_OK == 1572 (GNUNET_OK ==
1573 GNUNET_CONFIGURATION_get_value_number (sctx.cfg, "TESTING", 1573 GNUNET_CONFIGURATION_get_value_number (sctx.cfg, "TESTING",
1574 "SKEW_VARIANCE", &skew_variance)) ) 1574 "SKEW_VARIANCE", &skew_variance)))
1575 { 1575 {
1576 clock_offset = skew_offset - skew_variance; 1576 clock_offset = skew_offset - skew_variance;
1577 GNUNET_TIME_set_offset (clock_offset); 1577 GNUNET_TIME_set_offset (clock_offset);
diff --git a/src/util/strings.c b/src/util/strings.c
index 58a4847bc..2b5538b35 100644
--- a/src/util/strings.c
+++ b/src/util/strings.c
@@ -237,7 +237,7 @@ GNUNET_STRINGS_fancy_size_to_bytes (const char *fancy_size,
237 last = 0; 237 last = 0;
238 if (1 != sscanf (tok, "%llu", &last)) 238 if (1 != sscanf (tok, "%llu", &last))
239 { 239 {
240 GNUNET_free (in); 240 GNUNET_free (in);
241 return GNUNET_SYSERR; /* expected number */ 241 return GNUNET_SYSERR; /* expected number */
242 } 242 }
243 } 243 }
@@ -316,7 +316,7 @@ GNUNET_STRINGS_fancy_time_to_relative (const char *fancy_size,
316 last = 0; 316 last = 0;
317 if (1 != sscanf (tok, "%llu", &last)) 317 if (1 != sscanf (tok, "%llu", &last))
318 { 318 {
319 GNUNET_free (in); 319 GNUNET_free (in);
320 return GNUNET_SYSERR; /* expected number */ 320 return GNUNET_SYSERR; /* expected number */
321 } 321 }
322 } 322 }
diff --git a/src/util/test_bio.c b/src/util/test_bio.c
index 19f78b6b7..9b18258fb 100644
--- a/src/util/test_bio.c
+++ b/src/util/test_bio.c
@@ -195,7 +195,7 @@ test_bigmeta_rw ()
195static int 195static int
196test_directory_r () 196test_directory_r ()
197{ 197{
198#if LINUX 198#if LINUX
199 char *msg; 199 char *msg;
200 char readResult[200]; 200 char readResult[200];
201 struct GNUNET_BIO_ReadHandle *fileR; 201 struct GNUNET_BIO_ReadHandle *fileR;
diff --git a/src/util/test_common_logging_runtime_loglevels.c b/src/util/test_common_logging_runtime_loglevels.c
index 79b888c56..9b5b1228a 100644
--- a/src/util/test_common_logging_runtime_loglevels.c
+++ b/src/util/test_common_logging_runtime_loglevels.c
@@ -314,14 +314,13 @@ runone ()
314 break; 314 break;
315 } 315 }
316 316
317 proc = 317 proc = GNUNET_OS_start_process (NULL, pipe_stdout,
318 GNUNET_OS_start_process (NULL, pipe_stdout,
319#if MINGW 318#if MINGW
320 "test_common_logging_dummy", 319 "test_common_logging_dummy",
321#else 320#else
322 "./test_common_logging_dummy", 321 "./test_common_logging_dummy",
323#endif 322#endif
324 "test_common_logging_dummy", NULL); 323 "test_common_logging_dummy", NULL);
325 putenv ("GNUNET_FORCE_LOG="); 324 putenv ("GNUNET_FORCE_LOG=");
326 putenv ("GNUNET_LOG="); 325 putenv ("GNUNET_LOG=");
327 326
diff --git a/src/util/test_os_network.c b/src/util/test_os_network.c
index ab39e5eda..423e66f63 100644
--- a/src/util/test_os_network.c
+++ b/src/util/test_os_network.c
@@ -34,11 +34,8 @@
34 * (success). 34 * (success).
35 */ 35 */
36static int 36static int
37proc (void *cls, const char *name, 37proc (void *cls, const char *name, int isDefault, const struct sockaddr *addr,
38 int isDefault, 38 const struct sockaddr *broadcast_addr, const struct sockaddr *netmask,
39 const struct sockaddr * addr,
40 const struct sockaddr * broadcast_addr,
41 const struct sockaddr * netmask,
42 socklen_t addrlen) 39 socklen_t addrlen)
43{ 40{
44 int *ok = cls; 41 int *ok = cls;