code style format: clang-format applied to src/a*/*

[zj: this is a subset of changes generated by clang-format, just the ones
  I think improve readability or consistency.]

This is a part of https://github.com/systemd/systemd/pull/11811.
This commit is contained in:
Sebastian Jennen 2019-02-23 17:26:25 +01:00 committed by Lennart Poettering
parent c52db42b78
commit 1ace223ca7
4 changed files with 124 additions and 102 deletions

View File

@ -24,11 +24,11 @@
#include "terminal-util.h"
#include "util.h"
static char** arg_listen = NULL;
static char **arg_listen = NULL;
static bool arg_accept = false;
static int arg_socket_type = SOCK_STREAM;
static char** arg_args = NULL;
static char** arg_setenv = NULL;
static char **arg_args = NULL;
static char **arg_setenv = NULL;
static char **arg_fdnames = NULL;
static bool arg_inetd = false;
@ -86,7 +86,7 @@ static int open_sockets(int *epoll_fd, bool accept) {
*/
STRV_FOREACH(address, arg_listen) {
fd = make_socket_fd(LOG_DEBUG, *address, arg_socket_type, (arg_accept*SOCK_CLOEXEC));
fd = make_socket_fd(LOG_DEBUG, *address, arg_socket_type, (arg_accept * SOCK_CLOEXEC));
if (fd < 0) {
log_open();
return log_error_errno(fd, "Failed to open '%s': %m", *address);
@ -117,7 +117,7 @@ static int open_sockets(int *epoll_fd, bool accept) {
return count;
}
static int exec_process(const char* name, char **argv, char **env, int start_fd, size_t n_fds) {
static int exec_process(const char *name, char **argv, char **env, int start_fd, size_t n_fds) {
_cleanup_strv_free_ char **envp = NULL;
_cleanup_free_ char *joined = NULL;
@ -199,10 +199,10 @@ static int exec_process(const char* name, char **argv, char **env, int start_fd,
start_fd = SD_LISTEN_FDS_START;
}
if (asprintf((char**)(envp + n_env++), "LISTEN_FDS=%zu", n_fds) < 0)
if (asprintf((char **) (envp + n_env++), "LISTEN_FDS=%zu", n_fds) < 0)
return log_oom();
if (asprintf((char**)(envp + n_env++), "LISTEN_PID=" PID_FMT, getpid_cached()) < 0)
if (asprintf((char **) (envp + n_env++), "LISTEN_PID=" PID_FMT, getpid_cached()) < 0)
return log_oom();
if (arg_fdnames) {
@ -244,7 +244,7 @@ static int exec_process(const char* name, char **argv, char **env, int start_fd,
return log_error_errno(errno, "Failed to execp %s (%s): %m", name, joined);
}
static int fork_and_exec_process(const char* child, char** argv, char **env, int fd) {
static int fork_and_exec_process(const char *child, char **argv, char **env, int fd) {
_cleanup_free_ char *joined = NULL;
pid_t child_pid;
int r;
@ -253,7 +253,9 @@ static int fork_and_exec_process(const char* child, char** argv, char **env, int
if (!joined)
return log_oom();
r = safe_fork("(activate)", FORK_RESET_SIGNALS|FORK_DEATHSIG|FORK_RLIMIT_NOFILE_SAFE|FORK_LOG, &child_pid);
r = safe_fork("(activate)",
FORK_RESET_SIGNALS | FORK_DEATHSIG | FORK_RLIMIT_NOFILE_SAFE | FORK_LOG,
&child_pid);
if (r < 0)
return r;
if (r == 0) {
@ -266,7 +268,7 @@ static int fork_and_exec_process(const char* child, char** argv, char **env, int
return 0;
}
static int do_accept(const char* name, char **argv, char **envp, int fd) {
static int do_accept(const char *name, char **argv, char **envp, int fd) {
_cleanup_free_ char *local = NULL, *peer = NULL;
_cleanup_close_ int fd_accepted = -1;
@ -294,7 +296,7 @@ static void sigchld_hdl(int sig) {
int r;
si.si_pid = 0;
r = waitid(P_ALL, 0, &si, WEXITED|WNOHANG);
r = waitid(P_ALL, 0, &si, WEXITED | WNOHANG);
if (r < 0) {
if (errno != ECHILD)
log_error_errno(errno, "Failed to reap children: %m");
@ -309,7 +311,7 @@ static void sigchld_hdl(int sig) {
static int install_chld_handler(void) {
static const struct sigaction act = {
.sa_flags = SA_NOCLDSTOP|SA_RESTART,
.sa_flags = SA_NOCLDSTOP | SA_RESTART,
.sa_handler = sigchld_hdl,
};
@ -376,7 +378,7 @@ static int parse_argv(int argc, char *argv[]) {
assert(argv);
while ((c = getopt_long(argc, argv, "+hl:aE:d", options, NULL)) >= 0)
switch(c) {
switch (c) {
case 'h':
return help();

View File

@ -100,7 +100,12 @@ struct security_assessor {
const char *url;
uint64_t weight;
uint64_t range;
int (*assess)(const struct security_assessor *a, const struct security_info *info, const void *data, uint64_t *ret_badness, char **ret_description);
int (*assess)(
const struct security_assessor *a,
const struct security_info *info,
const void *data,
uint64_t *ret_badness,
char **ret_description);
size_t offset;
uint64_t parameter;
bool default_dependencies_only;
@ -1438,7 +1443,7 @@ static int assess(const struct security_info *info, Table *overview_table, Analy
uint64_t badness;
void *data;
data = (uint8_t*) info + a->offset;
data = (uint8_t *) info + a->offset;
if (a->default_dependencies_only && !info->default_dependencies) {
badness = UINT64_MAX;
@ -1916,14 +1921,15 @@ static int acquire_security_info(sd_bus *bus, const char *name, struct security_
if (!path)
return log_oom();
r = bus_map_all_properties(bus,
"org.freedesktop.systemd1",
path,
security_map,
BUS_MAP_STRDUP|BUS_MAP_BOOLEAN_AS_BOOL,
&error,
NULL,
info);
r = bus_map_all_properties(
bus,
"org.freedesktop.systemd1",
path,
security_map,
BUS_MAP_STRDUP | BUS_MAP_BOOLEAN_AS_BOOL,
&error,
NULL,
info);
if (r < 0)
return log_error_errno(r, "Failed to get unit properties: %s", bus_error_message(&error, r));
@ -1965,7 +1971,7 @@ static int acquire_security_info(sd_bus *bus, const char *name, struct security_
return 0;
}
static int analyze_security_one(sd_bus *bus, const char *name, Table* overview_table, AnalyzeSecurityFlags flags) {
static int analyze_security_one(sd_bus *bus, const char *name, Table *overview_table, AnalyzeSecurityFlags flags) {
_cleanup_(security_info_free) struct security_info info = {
.default_dependencies = true,
.capability_bounding_set = UINT64_MAX,
@ -2015,7 +2021,8 @@ int analyze_security(sd_bus *bus, char **units, AnalyzeSecurityFlags flags) {
"/org/freedesktop/systemd1",
"org.freedesktop.systemd1.Manager",
"ListUnits",
&error, &reply,
&error,
&reply,
NULL);
if (r < 0)
return log_error_errno(r, "Failed to list units: %s", bus_error_message(&error, r));
@ -2037,7 +2044,7 @@ int analyze_security(sd_bus *bus, char **units, AnalyzeSecurityFlags flags) {
if (!endswith(info.id, ".service"))
continue;
if (!GREEDY_REALLOC(list, allocated, n+2))
if (!GREEDY_REALLOC(list, allocated, n + 2))
return log_oom();
copy = strdup(info.id);

View File

@ -5,8 +5,4 @@
#include "path-lookup.h"
int verify_units(
char **filenames,
UnitFileScope scope,
bool check_man,
bool run_generators);
int verify_units(char **filenames, UnitFileScope scope, bool check_man, bool run_generators);

View File

@ -48,7 +48,7 @@
#include "util.h"
#include "verbs.h"
#define SCALE_X (0.1 / 1000.0) /* pixels per us */
#define SCALE_X (0.1 / 1000.0) /* pixels per us */
#define SCALE_Y (20.0)
#define svg(...) printf(__VA_ARGS__)
@ -71,8 +71,8 @@ static enum dot {
DEP_ORDER,
DEP_REQUIRE
} arg_dot = DEP_ALL;
static char** arg_dot_from_patterns = NULL;
static char** arg_dot_to_patterns = NULL;
static char **arg_dot_from_patterns = NULL;
static char **arg_dot_to_patterns = NULL;
static usec_t arg_fuzz = 0;
static PagerFlags arg_pager_flags = 0;
static BusTransport arg_transport = BUS_TRANSPORT_LOCAL;
@ -295,8 +295,8 @@ static int acquire_boot_times(sd_bus *bus, struct boot_times **bt) {
*/
times.reverse_offset = times.userspace_time;
times.firmware_time = times.loader_time = times.kernel_time = times.initrd_time = times.userspace_time =
times.security_start_time = times.security_finish_time = 0;
times.firmware_time = times.loader_time = times.kernel_time = times.initrd_time =
times.userspace_time = times.security_start_time = times.security_finish_time = 0;
subtract_timestamp(&times.finish_time, times.reverse_offset);
@ -328,7 +328,7 @@ static void free_host_info(struct host_info *hi) {
free(hi);
}
DEFINE_TRIVIAL_CLEANUP_FUNC(struct host_info*, free_host_info);
DEFINE_TRIVIAL_CLEANUP_FUNC(struct host_info *, free_host_info);
static int acquire_time_data(sd_bus *bus, struct unit_times **out) {
static const struct bus_properties_map property_map[] = {
@ -368,10 +368,10 @@ static int acquire_time_data(sd_bus *bus, struct unit_times **out) {
while ((r = bus_parse_unit_info(reply, &u)) > 0) {
struct unit_times *t;
if (!GREEDY_REALLOC(unit_times, allocated, c+2))
if (!GREEDY_REALLOC(unit_times, allocated, c + 2))
return log_oom();
unit_times[c+1].has_data = false;
unit_times[c + 1].has_data = false;
t = &unit_times[c];
t->name = NULL;
@ -430,8 +430,8 @@ static int acquire_host_info(sd_bus *bus, struct host_info **hi) {
};
static const struct bus_properties_map manager_map[] = {
{ "Virtualization", "s", NULL, offsetof(struct host_info, virtualization) },
{ "Architecture", "s", NULL, offsetof(struct host_info, architecture) },
{ "Virtualization", "s", NULL, offsetof(struct host_info, virtualization) },
{ "Architecture", "s", NULL, offsetof(struct host_info, architecture) },
{}
};
@ -452,14 +452,15 @@ static int acquire_host_info(sd_bus *bus, struct host_info **hi) {
}
}
r = bus_map_all_properties(system_bus ?: bus,
"org.freedesktop.hostname1",
"/org/freedesktop/hostname1",
hostname_map,
BUS_MAP_STRDUP,
&error,
NULL,
host);
r = bus_map_all_properties(
system_bus ?: bus,
"org.freedesktop.hostname1",
"/org/freedesktop/hostname1",
hostname_map,
BUS_MAP_STRDUP,
&error,
NULL,
host);
if (r < 0) {
log_debug_errno(r, "Failed to get host information from systemd-hostnamed, ignoring: %s",
bus_error_message(&error, r));
@ -467,14 +468,15 @@ static int acquire_host_info(sd_bus *bus, struct host_info **hi) {
}
manager:
r = bus_map_all_properties(bus,
"org.freedesktop.systemd1",
"/org/freedesktop/systemd1",
manager_map,
BUS_MAP_STRDUP,
&error,
NULL,
host);
r = bus_map_all_properties(
bus,
"org.freedesktop.systemd1",
"/org/freedesktop/systemd1",
manager_map,
BUS_MAP_STRDUP,
&error,
NULL,
host);
if (r < 0)
return log_error_errno(r, "Failed to get host information from systemd: %s",
bus_error_message(&error, r));
@ -491,7 +493,7 @@ static int pretty_boot_time(sd_bus *bus, char **_buf) {
char *ptr;
int r;
usec_t activated_time = USEC_INFINITY;
_cleanup_free_ char* path = NULL, *unit_id = NULL;
_cleanup_free_ char *path = NULL, *unit_id = NULL;
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
r = acquire_boot_times(bus, &t);
@ -566,21 +568,34 @@ static void svg_graph_box(double height, double begin, double end) {
/* outside box, fill */
svg("<rect class=\"box\" x=\"0\" y=\"0\" width=\"%.03f\" height=\"%.03f\" />\n",
SCALE_X * (end - begin), SCALE_Y * height);
SCALE_X * (end - begin),
SCALE_Y * height);
for (i = ((long long) (begin / 100000)) * 100000; i <= end; i+=100000) {
for (i = ((long long) (begin / 100000)) * 100000; i <= end; i += 100000) {
/* lines for each second */
if (i % 5000000 == 0)
svg(" <line class=\"sec5\" x1=\"%.03f\" y1=\"0\" x2=\"%.03f\" y2=\"%.03f\" />\n"
" <text class=\"sec\" x=\"%.03f\" y=\"%.03f\" >%.01fs</text>\n",
SCALE_X * i, SCALE_X * i, SCALE_Y * height, SCALE_X * i, -5.0, 0.000001 * i);
SCALE_X * i,
SCALE_X * i,
SCALE_Y * height,
SCALE_X * i,
-5.0,
0.000001 * i);
else if (i % 1000000 == 0)
svg(" <line class=\"sec1\" x1=\"%.03f\" y1=\"0\" x2=\"%.03f\" y2=\"%.03f\" />\n"
" <text class=\"sec\" x=\"%.03f\" y=\"%.03f\" >%.01fs</text>\n",
SCALE_X * i, SCALE_X * i, SCALE_Y * height, SCALE_X * i, -5.0, 0.000001 * i);
SCALE_X * i,
SCALE_X * i,
SCALE_Y * height,
SCALE_X * i,
-5.0,
0.000001 * i);
else
svg(" <line class=\"sec01\" x1=\"%.03f\" y1=\"0\" x2=\"%.03f\" y2=\"%.03f\" />\n",
SCALE_X * i, SCALE_X * i, SCALE_Y * height);
SCALE_X * i,
SCALE_X * i,
SCALE_Y * height);
}
}
@ -822,8 +837,14 @@ static int analyze_plot(int argc, char *argv[], void *userdata) {
return 0;
}
static int list_dependencies_print(const char *name, unsigned level, unsigned branches,
bool last, struct unit_times *times, struct boot_times *boot) {
static int list_dependencies_print(
const char *name,
unsigned level,
unsigned branches,
bool last,
struct unit_times *times,
struct boot_times *boot) {
unsigned i;
char ts[FORMAT_TIMESPAN_MAX], ts2[FORMAT_TIMESPAN_MAX];
@ -864,7 +885,7 @@ static int list_dependencies_get_dependencies(sd_bus *bus, const char *name, cha
static Hashmap *unit_times_hashmap;
static int list_dependencies_compare(char * const *a, char * const *b) {
static int list_dependencies_compare(char *const *a, char *const *b) {
usec_t usa = 0, usb = 0;
struct unit_times *times;
@ -879,12 +900,10 @@ static int list_dependencies_compare(char * const *a, char * const *b) {
}
static bool times_in_range(const struct unit_times *times, const struct boot_times *boot) {
return times &&
times->activated > 0 && times->activated <= boot->finish_time;
return times && times->activated > 0 && times->activated <= boot->finish_time;
}
static int list_dependencies_one(sd_bus *bus, const char *name, unsigned level, char ***units,
unsigned branches) {
static int list_dependencies_one(sd_bus *bus, const char *name, unsigned level, char ***units, unsigned branches) {
_cleanup_strv_free_ char **deps = NULL;
char **c;
int r = 0;
@ -908,8 +927,7 @@ static int list_dependencies_one(sd_bus *bus, const char *name, unsigned level,
STRV_FOREACH(c, deps) {
times = hashmap_get(unit_times_hashmap, *c);
if (times_in_range(times, boot) &&
times->activated >= service_longest)
if (times_in_range(times, boot) && times->activated >= service_longest)
service_longest = times->activated;
}
@ -918,8 +936,7 @@ static int list_dependencies_one(sd_bus *bus, const char *name, unsigned level,
STRV_FOREACH(c, deps) {
times = hashmap_get(unit_times_hashmap, *c);
if (times_in_range(times, boot) &&
service_longest - times->activated <= arg_fuzz)
if (times_in_range(times, boot) && service_longest - times->activated <= arg_fuzz)
to_print++;
}
@ -928,8 +945,7 @@ static int list_dependencies_one(sd_bus *bus, const char *name, unsigned level,
STRV_FOREACH(c, deps) {
times = hashmap_get(unit_times_hashmap, *c);
if (!times_in_range(times, boot) ||
service_longest - times->activated > arg_fuzz)
if (!times_in_range(times, boot) || service_longest - times->activated > arg_fuzz)
continue;
to_print--;
@ -946,8 +962,7 @@ static int list_dependencies_one(sd_bus *bus, const char *name, unsigned level,
continue;
}
r = list_dependencies_one(bus, *c, level + 1, units,
(branches << 1) | (to_print ? 1 : 0));
r = list_dependencies_one(bus, *c, level + 1, units, (branches << 1) | (to_print ? 1 : 0));
if (r < 0)
return r;
@ -1096,7 +1111,15 @@ static int analyze_time(int argc, char *argv[], void *userdata) {
return 0;
}
static int graph_one_property(sd_bus *bus, const UnitInfo *u, const char* prop, const char *color, char* patterns[], char* from_patterns[], char* to_patterns[]) {
static int graph_one_property(
sd_bus *bus,
const UnitInfo *u,
const char *prop,
const char *color,
char *patterns[],
char *from_patterns[],
char *to_patterns[]) {
_cleanup_strv_free_ char **units = NULL;
char **unit;
int r;
@ -1108,10 +1131,8 @@ static int graph_one_property(sd_bus *bus, const UnitInfo *u, const char* prop,
match_patterns = strv_fnmatch(patterns, u->id, 0);
if (!strv_isempty(from_patterns) &&
!match_patterns &&
!strv_fnmatch(from_patterns, u->id, 0))
return 0;
if (!strv_isempty(from_patterns) && !match_patterns && !strv_fnmatch(from_patterns, u->id, 0))
return 0;
r = bus_get_unit_property_strv(bus, u->unit_path, prop, &units);
if (r < 0)
@ -1122,9 +1143,7 @@ static int graph_one_property(sd_bus *bus, const UnitInfo *u, const char* prop,
match_patterns2 = strv_fnmatch(patterns, *unit, 0);
if (!strv_isempty(to_patterns) &&
!match_patterns2 &&
!strv_fnmatch(to_patterns, *unit, 0))
if (!strv_isempty(to_patterns) && !match_patterns2 && !strv_fnmatch(to_patterns, *unit, 0))
continue;
if (!strv_isempty(patterns) && !match_patterns && !match_patterns2)
@ -1516,8 +1535,8 @@ static int load_kernel_syscalls(Set **ret) {
_cleanup_fclose_ FILE *f = NULL;
int r;
/* Let's read the available system calls from the list of available tracing events. Slightly dirty, but good
* enough for analysis purposes. */
/* Let's read the available system calls from the list of available tracing events. Slightly dirty,
* but good enough for analysis purposes. */
f = fopen("/sys/kernel/tracing/available_events", "re");
if (!f) {
@ -1543,7 +1562,8 @@ static int load_kernel_syscalls(Set **ret) {
if (!e)
continue;
/* These are named differently inside the kernel than their external name for historical reasons. Let's hide them here. */
/* These are named differently inside the kernel than their external name for historical
* reasons. Let's hide them here. */
if (STR_IN_SET(e, "newuname", "newfstat", "newstat", "newlstat", "sysctl"))
continue;
@ -1582,10 +1602,7 @@ static void dump_syscall_filter(const SyscallFilterSet *set) {
set->help);
NULSTR_FOREACH(syscall, set->value)
printf(" %s%s%s\n",
syscall[0] == '@' ? ansi_underline() : "",
syscall,
ansi_normal());
printf(" %s%s%s\n", syscall[0] == '@' ? ansi_underline() : "", syscall, ansi_normal());
}
static int dump_syscall_filters(int argc, char *argv[], void *userdata) {
@ -1652,8 +1669,7 @@ static int dump_syscall_filters(int argc, char *argv[], void *userdata) {
#else
static int dump_syscall_filters(int argc, char *argv[], void *userdata) {
return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP),
"Not compiled with syscall filters, sorry.");
return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP), "Not compiled with syscall filters, sorry.");
}
#endif
@ -1709,8 +1725,7 @@ static int test_calendar_one(usec_t n, const char *p) {
r = calendar_spec_next_usec(spec, n, &next);
if (r == -ENOENT) {
if (i == 0)
printf(" Next elapse: %snever%s\n",
ansi_highlight_yellow(), ansi_normal());
printf(" Next elapse: %snever%s\n", ansi_highlight_yellow(), ansi_normal());
return 0;
}
if (r < 0)
@ -1718,9 +1733,11 @@ static int test_calendar_one(usec_t n, const char *p) {
if (i == 0)
printf(" Next elapse: %s%s%s\n",
ansi_highlight_blue(), format_timestamp(buffer, sizeof(buffer), next), ansi_normal());
ansi_highlight_blue(),
format_timestamp(buffer, sizeof(buffer), next),
ansi_normal());
else {
int k = DECIMAL_STR_WIDTH(i+1);
int k = DECIMAL_STR_WIDTH(i + 1);
if (k < 8)
k = 8 - k;
@ -1755,7 +1772,7 @@ static int test_calendar(int argc, char *argv[], void *userdata) {
if (ret == 0 && r < 0)
ret = r;
if (*(p+1))
if (*(p + 1))
putchar('\n');
}
@ -1883,8 +1900,8 @@ static int help(int argc, char *argv[], void *userdata) {
, link
);
/* When updating this list, including descriptions, apply changes to shell-completion/bash/systemd-analyze and
* shell-completion/zsh/_systemd-analyze too. */
/* When updating this list, including descriptions, apply changes to
* shell-completion/bash/systemd-analyze and shell-completion/zsh/_systemd-analyze too. */
return 0;
}