summaryrefslogtreecommitdiff
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
GNUNET_abort ()
{
#if WINDOWS
- DebugBreak();
+ DebugBreak ();
#endif
- abort();
+ abort ();
}
@@ -292,6 +292,7 @@ add_definition (char *component, char *file, char *function, int from_line,
{
struct LogDef n;
int r;
+
if (logdefs_size == logdefs_len)
resize_logdefs ();
memset (&n, 0, sizeof (n));
@@ -299,27 +300,26 @@ add_definition (char *component, char *file, char *function, int from_line,
component = (char *) ".*";
r = regcomp (&n.component_regex, (const char *) component, REG_NOSUB);
if (r != 0)
- {
- return r;
- }
+ {
+ return r;
+ }
if (strlen (file) == 0)
file = (char *) ".*";
r = regcomp (&n.file_regex, (const char *) file, REG_NOSUB);
if (r != 0)
- {
- regfree (&n.component_regex);
- return r;
- }
- if ( (NULL == function) ||
- (strlen (function) == 0))
+ {
+ regfree (&n.component_regex);
+ return r;
+ }
+ if ((NULL == function) || (strlen (function) == 0))
function = (char *) ".*";
r = regcomp (&n.function_regex, (const char *) function, REG_NOSUB);
if (r != 0)
- {
- regfree (&n.component_regex);
- regfree (&n.file_regex);
- return r;
- }
+ {
+ regfree (&n.component_regex);
+ regfree (&n.file_regex);
+ return r;
+ }
n.from_line = from_line;
n.to_line = to_line;
n.level = level;
@@ -364,16 +364,16 @@ GNUNET_get_log_call_status (int caller_level, const char *comp,
force_only = min_level >= 0;
for (i = 0; i < logdefs_len; i++)
{
- ld = &logdefs[i];
- if ((!force_only || ld->force) &&
- (line >= ld->from_line && line <= ld->to_line) &&
- (regexec (&ld->component_regex, comp, 0, NULL, 0) == 0) &&
- (regexec (&ld->file_regex, file, 0, NULL, 0) == 0) &&
- (regexec (&ld->function_regex, function, 0, NULL, 0) == 0))
- {
- /* We're finished */
- return caller_level <= ld->level;
- }
+ ld = &logdefs[i];
+ if ((!force_only || ld->force) &&
+ (line >= ld->from_line && line <= ld->to_line) &&
+ (regexec (&ld->component_regex, comp, 0, NULL, 0) == 0) &&
+ (regexec (&ld->file_regex, file, 0, NULL, 0) == 0) &&
+ (regexec (&ld->function_regex, function, 0, NULL, 0) == 0))
+ {
+ /* We're finished */
+ return caller_level <= ld->level;
+ }
}
/* No matches - use global level, if defined */
if (min_level >= 0)
@@ -434,83 +434,83 @@ parse_definitions (const char *constname, int force)
to_line = INT_MAX;
for (p = def, state = 0, start = def; keep_looking; p++)
{
- switch (p[0])
- {
- case ';': /* found a field separator */
- p[0] = '\0';
- switch (state)
- {
- case 0: /* within a component name */
- comp = start;
- break;
- case 1: /* within a file name */
- file = start;
- break;
- case 2: /* within a function name */
- /* after a file name there must be a function name */
- function = start;
- break;
- case 3: /* within a from-to line range */
- if (strlen (start) > 0)
- {
- errno = 0;
- from_line = strtol (start, &t, 10);
- if (errno != 0 || from_line < 0)
- {
- free (def);
- return counter;
- }
- if (t < p && t[0] == '-')
- {
- errno = 0;
- start = t + 1;
- to_line = strtol (start, &t, 10);
- if (errno != 0 || to_line < 0 || t != p)
- {
- free (def);
- return counter;
- }
- }
- else /* one number means "match this line only" */
- to_line = from_line;
- }
- else /* default to 0-max */
- {
- from_line = 0;
- to_line = INT_MAX;
- }
- break;
- }
- start = p + 1;
- state += 1;
- break;
- case '\0': /* found EOL */
- keep_looking = 0;
- /* fall through to '/' */
- case '/': /* found a definition separator */
- switch (state)
- {
- case 4: /* within a log level */
- p[0] = '\0';
- state = 0;
- level = get_type ((const char *) start);
- if (level == GNUNET_ERROR_TYPE_INVALID
- || level == GNUNET_ERROR_TYPE_UNSPECIFIED
- || 0 != add_definition (comp, file, function, from_line,
- to_line, level, force))
- {
- free (def);
- return counter;
- }
- counter += 1;
- start = p + 1;
- break;
- default:
- break;
- }
- default:
- break;
- }
+ switch (p[0])
+ {
+ case ';': /* found a field separator */
+ p[0] = '\0';
+ switch (state)
+ {
+ case 0: /* within a component name */
+ comp = start;
+ break;
+ case 1: /* within a file name */
+ file = start;
+ break;
+ case 2: /* within a function name */
+ /* after a file name there must be a function name */
+ function = start;
+ break;
+ case 3: /* within a from-to line range */
+ if (strlen (start) > 0)
+ {
+ errno = 0;
+ from_line = strtol (start, &t, 10);
+ if (errno != 0 || from_line < 0)
+ {
+ free (def);
+ return counter;
+ }
+ if (t < p && t[0] == '-')
+ {
+ errno = 0;
+ start = t + 1;
+ to_line = strtol (start, &t, 10);
+ if (errno != 0 || to_line < 0 || t != p)
+ {
+ free (def);
+ return counter;
+ }
+ }
+ else /* one number means "match this line only" */
+ to_line = from_line;
+ }
+ else /* default to 0-max */
+ {
+ from_line = 0;
+ to_line = INT_MAX;
+ }
+ break;
+ }
+ start = p + 1;
+ state += 1;
+ break;
+ case '\0': /* found EOL */
+ keep_looking = 0;
+ /* fall through to '/' */
+ case '/': /* found a definition separator */
+ switch (state)
+ {
+ case 4: /* within a log level */
+ p[0] = '\0';
+ state = 0;
+ level = get_type ((const char *) start);
+ if (level == GNUNET_ERROR_TYPE_INVALID ||
+ level == GNUNET_ERROR_TYPE_UNSPECIFIED ||
+ 0 != add_definition (comp, file, function, from_line, to_line,
+ level, force))
+ {
+ free (def);
+ return counter;
+ }
+ counter += 1;
+ start = p + 1;
+ break;
+ default:
+ break;
+ }
+ default:
+ break;
+ }
}
free (def);
return counter;
@@ -560,8 +560,7 @@ GNUNET_log_setup (const char *comp, const char *loglevel, const char *logfile)
component_nopid = GNUNET_strdup (comp);
env_logfile = getenv ("GNUNET_FORCE_LOGFILE");
- if ( (env_logfile != NULL) &&
- (strlen (env_logfile) > 0) )
+ if ((env_logfile != NULL) && (strlen (env_logfile) > 0))
logfile = env_logfile;
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 @@
/* The code is derived from glibc, obviously */
#if MINGW
#ifdef RANDOM
-# undef RANDOM
+#undef RANDOM
#endif
#ifdef SRANDOM
-# undef SRANDOM
+#undef SRANDOM
#endif
#define RANDOM() glibc_weak_rand32()
#define SRANDOM(s) glibc_weak_srand32(s)
@@ -57,6 +57,7 @@ int32_t
glibc_weak_rand32 ()
{
int32_t val = glibc_weak_rand32_state;
+
val = ((glibc_weak_rand32_state * 1103515245) + 12345) & 0x7fffffff;
glibc_weak_rand32_state = val;
return val;
@@ -314,7 +315,8 @@ void __attribute__ ((constructor)) GNUNET_CRYPTO_random_init ()
gcry_set_progress_handler (&entropy_generator, NULL);
atexit (&killfind);
GNUNET_CRYPTO_seed_weak_random (time (NULL) ^
- GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX));
+ GNUNET_CRYPTO_random_u32
+ (GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX));
}
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;
/* Make sure the environment variable bash 2.0 puts in the environment
is valid for the getopt call we must make sure that the ARGV passed
to getopt is that one passed to the process. */
-static void
- GNUNET_UNUSED store_args_and_env (int argc, char *const *argv)
+static void GNUNET_UNUSED
+store_args_and_env (int argc, char *const *argv)
{
/* XXX This is no good solution. We should rather copy the args so
* 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,
for (i = 0; i < results_count; i++)
{
- if (GNUNET_OK != proc (proc_cls, results[i].pretty_name,
- results[i].is_default,
- &results[i].address,
- results[i].flags & ENUMNICS3_MASK_OK ? &results[i].mask : NULL,
- results[i].flags & ENUMNICS3_BCAST_OK ? &results[i].broadcast : NULL,
- results[i].addr_size))
+ if (GNUNET_OK !=
+ proc (proc_cls, results[i].pretty_name, results[i].is_default,
+ &results[i].address,
+ results[i].flags & ENUMNICS3_MASK_OK ? &results[i].mask : NULL,
+ results[i].
+ flags & ENUMNICS3_BCAST_OK ? &results[i].broadcast : NULL,
+ results[i].addr_size))
break;
}
EnumNICs3_free (results);
@@ -92,10 +93,8 @@ GNUNET_OS_network_interfaces_list (GNUNET_OS_NetworkInterfaceProcessor proc,
if (GNUNET_OK !=
proc (proc_cls, ifa_ptr->ifa_name,
0 == strcmp (ifa_ptr->ifa_name, GNUNET_DEFAULT_INTERFACE),
- ifa_ptr->ifa_addr,
- ifa_ptr->ifa_broadaddr,
- ifa_ptr->ifa_netmask,
- alen))
+ ifa_ptr->ifa_addr, ifa_ptr->ifa_broadaddr,
+ ifa_ptr->ifa_netmask, alen))
break;
}
}
@@ -169,9 +168,7 @@ GNUNET_OS_network_interfaces_list (GNUNET_OS_NetworkInterfaceProcessor proc,
proc (proc_cls, ifc, 0 == strcmp (ifc, GNUNET_DEFAULT_INTERFACE),
(const struct sockaddr *) &a4,
/* TODO broadcast and netmask */
- NULL,
- NULL,
- sizeof (a4)))
+ NULL, NULL, sizeof (a4)))
break;
continue;
}
@@ -188,9 +185,7 @@ GNUNET_OS_network_interfaces_list (GNUNET_OS_NetworkInterfaceProcessor proc,
proc (proc_cls, ifc, 0 == strcmp (ifc, GNUNET_DEFAULT_INTERFACE),
(const struct sockaddr *) &a6,
/* TODO broadcast and netmask */
- NULL,
- NULL,
- sizeof (a6)))
+ NULL, NULL, sizeof (a6)))
break;
continue;
}
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)
if (((tc.reason & GNUNET_SCHEDULER_REASON_WRITE_READY) != 0) &&
(pos->write_fd != -1) &&
(!GNUNET_NETWORK_fdset_test_native (ws, pos->write_fd)))
- GNUNET_abort (); // added to ready in previous select loop!
+ GNUNET_abort (); // added to ready in previous select loop!
#if DEBUG_TASKS
LOG (GNUNET_ERROR_TYPE_DEBUG, "Running task: %llu / %p\n", pos->id,
pos->callback_cls);
@@ -726,9 +726,9 @@ sighandler_shutdown ()
static char c;
int old_errno = errno; /* backup errno */
- if (getpid() != my_pid)
- exit(1); /* we have fork'ed since the signal handler was created,
- ignore the signal, see https://gnunet.org/vfork discussion */
+ if (getpid () != my_pid)
+ exit (1); /* we have fork'ed since the signal handler was created,
+ * ignore the signal, see https://gnunet.org/vfork discussion */
GNUNET_DISK_file_write (GNUNET_DISK_pipe_handle
(shutdown_pipe_handle, GNUNET_DISK_PIPE_END_WRITE),
&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,
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Service `%s' runs with configuration from `%s'\n", serviceName, cfg_fn);
#endif
- if ( (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_number (sctx.cfg, "TESTING", "SKEW_OFFSET",
- &skew_offset)) &&
- (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_number (sctx.cfg, "TESTING",
- "SKEW_VARIANCE", &skew_variance)) )
+ if ((GNUNET_OK ==
+ GNUNET_CONFIGURATION_get_value_number (sctx.cfg, "TESTING",
+ "SKEW_OFFSET", &skew_offset)) &&
+ (GNUNET_OK ==
+ GNUNET_CONFIGURATION_get_value_number (sctx.cfg, "TESTING",
+ "SKEW_VARIANCE", &skew_variance)))
{
clock_offset = skew_offset - skew_variance;
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,
last = 0;
if (1 != sscanf (tok, "%llu", &last))
{
- GNUNET_free (in);
+ GNUNET_free (in);
return GNUNET_SYSERR; /* expected number */
}
}
@@ -316,7 +316,7 @@ GNUNET_STRINGS_fancy_time_to_relative (const char *fancy_size,
last = 0;
if (1 != sscanf (tok, "%llu", &last))
{
- GNUNET_free (in);
+ GNUNET_free (in);
return GNUNET_SYSERR; /* expected number */
}
}
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 ()
static int
test_directory_r ()
{
-#if LINUX
+#if LINUX
char *msg;
char readResult[200];
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 ()
break;
}
- proc =
- GNUNET_OS_start_process (NULL, pipe_stdout,
+ proc = GNUNET_OS_start_process (NULL, pipe_stdout,
#if MINGW
- "test_common_logging_dummy",
+ "test_common_logging_dummy",
#else
- "./test_common_logging_dummy",
+ "./test_common_logging_dummy",
#endif
- "test_common_logging_dummy", NULL);
+ "test_common_logging_dummy", NULL);
putenv ("GNUNET_FORCE_LOG=");
putenv ("GNUNET_LOG=");
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 @@
* (success).
*/
static int
-proc (void *cls, const char *name,
- int isDefault,
- const struct sockaddr * addr,
- const struct sockaddr * broadcast_addr,
- const struct sockaddr * netmask,
+proc (void *cls, const char *name, int isDefault, const struct sockaddr *addr,
+ const struct sockaddr *broadcast_addr, const struct sockaddr *netmask,
socklen_t addrlen)
{
int *ok = cls;