diff options
author | Luca Boccassi <bluca@debian.org> | 2022-06-08 17:08:13 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-08 17:08:13 +0100 |
commit | e8f1b50f271f5e28b99182c56eb1b8c704456c34 (patch) | |
tree | 03b68639a885962343ed2de287ea7319e0230e60 | |
parent | 647475c7df4d13e30c328e6697231781d9d83d46 (diff) | |
parent | 0d7e34e3e636e9d01da9d3379d49db1889e59b66 (diff) | |
download | systemd-e8f1b50f271f5e28b99182c56eb1b8c704456c34.tar.gz |
Merge pull request #23641 from keszybz/janitorials
Janitorial cleanups
-rw-r--r-- | src/activate/activate.c | 21 | ||||
-rw-r--r-- | src/basic/socket-util.c | 40 | ||||
-rw-r--r-- | src/boot/bootctl.c | 11 | ||||
-rw-r--r-- | src/core/mount.c | 14 | ||||
-rw-r--r-- | src/shared/condition.c | 25 |
5 files changed, 48 insertions, 63 deletions
diff --git a/src/activate/activate.c b/src/activate/activate.c index 8ee7a3ec60..24ebde0283 100644 --- a/src/activate/activate.c +++ b/src/activate/activate.c @@ -49,7 +49,7 @@ static int add_epoll(int epoll_fd, int fd) { } static int open_sockets(int *epoll_fd, bool accept) { - int n, fd, r, count = 0; + int n, r, count = 0; n = sd_listen_fds(true); if (n < 0) @@ -57,7 +57,7 @@ static int open_sockets(int *epoll_fd, bool accept) { if (n > 0) { log_info("Received %i descriptors via the environment.", n); - for (fd = SD_LISTEN_FDS_START; fd < SD_LISTEN_FDS_START + n; fd++) { + for (int fd = SD_LISTEN_FDS_START; fd < SD_LISTEN_FDS_START + n; fd++) { r = fd_cloexec(fd, arg_accept); if (r < 0) return r; @@ -68,14 +68,11 @@ static int open_sockets(int *epoll_fd, bool accept) { /* Close logging and all other descriptors */ if (arg_listen) { - _cleanup_free_ int *except = NULL; - int i; - - except = new(int, n); + _cleanup_free_ int *except = new(int, n); if (!except) return log_oom(); - for (i = 0; i < n; i++) + for (int i = 0; i < n; i++) except[i] = SD_LISTEN_FDS_START + i; log_close(); @@ -90,13 +87,13 @@ 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)); - if (fd < 0) { + r = make_socket_fd(LOG_DEBUG, *address, arg_socket_type, (arg_accept * SOCK_CLOEXEC)); + if (r < 0) { log_open(); - return log_error_errno(fd, "Failed to open '%s': %m", *address); + return log_error_errno(r, "Failed to open '%s': %m", *address); } - assert(fd == SD_LISTEN_FDS_START + count); + assert(r == SD_LISTEN_FDS_START + count); count++; } @@ -107,7 +104,7 @@ static int open_sockets(int *epoll_fd, bool accept) { if (*epoll_fd < 0) return log_error_errno(errno, "Failed to create epoll object: %m"); - for (fd = SD_LISTEN_FDS_START; fd < SD_LISTEN_FDS_START + count; fd++) { + for (int fd = SD_LISTEN_FDS_START; fd < SD_LISTEN_FDS_START + count; fd++) { _cleanup_free_ char *name = NULL; getsockname_pretty(fd, &name); diff --git a/src/basic/socket-util.c b/src/basic/socket-util.c index bd6d329d94..9429f451df 100644 --- a/src/basic/socket-util.c +++ b/src/basic/socket-util.c @@ -651,24 +651,24 @@ int socknameinfo_pretty(union sockaddr_union *sa, socklen_t salen, char **_ret) } static const char* const netlink_family_table[] = { - [NETLINK_ROUTE] = "route", - [NETLINK_FIREWALL] = "firewall", - [NETLINK_INET_DIAG] = "inet-diag", - [NETLINK_NFLOG] = "nflog", - [NETLINK_XFRM] = "xfrm", - [NETLINK_SELINUX] = "selinux", - [NETLINK_ISCSI] = "iscsi", - [NETLINK_AUDIT] = "audit", - [NETLINK_FIB_LOOKUP] = "fib-lookup", - [NETLINK_CONNECTOR] = "connector", - [NETLINK_NETFILTER] = "netfilter", - [NETLINK_IP6_FW] = "ip6-fw", - [NETLINK_DNRTMSG] = "dnrtmsg", + [NETLINK_ROUTE] = "route", + [NETLINK_FIREWALL] = "firewall", + [NETLINK_INET_DIAG] = "inet-diag", + [NETLINK_NFLOG] = "nflog", + [NETLINK_XFRM] = "xfrm", + [NETLINK_SELINUX] = "selinux", + [NETLINK_ISCSI] = "iscsi", + [NETLINK_AUDIT] = "audit", + [NETLINK_FIB_LOOKUP] = "fib-lookup", + [NETLINK_CONNECTOR] = "connector", + [NETLINK_NETFILTER] = "netfilter", + [NETLINK_IP6_FW] = "ip6-fw", + [NETLINK_DNRTMSG] = "dnrtmsg", [NETLINK_KOBJECT_UEVENT] = "kobject-uevent", - [NETLINK_GENERIC] = "generic", - [NETLINK_SCSITRANSPORT] = "scsitransport", - [NETLINK_ECRYPTFS] = "ecryptfs", - [NETLINK_RDMA] = "rdma", + [NETLINK_GENERIC] = "generic", + [NETLINK_SCSITRANSPORT] = "scsitransport", + [NETLINK_ECRYPTFS] = "ecryptfs", + [NETLINK_RDMA] = "rdma", }; DEFINE_STRING_TABLE_LOOKUP_WITH_FALLBACK(netlink_family, int, INT_MAX); @@ -775,10 +775,10 @@ int fd_set_rcvbuf(int fd, size_t n, bool increase) { } static const char* const ip_tos_table[] = { - [IPTOS_LOWDELAY] = "low-delay", - [IPTOS_THROUGHPUT] = "throughput", + [IPTOS_LOWDELAY] = "low-delay", + [IPTOS_THROUGHPUT] = "throughput", [IPTOS_RELIABILITY] = "reliability", - [IPTOS_LOWCOST] = "low-cost", + [IPTOS_LOWCOST] = "low-cost", }; DEFINE_STRING_TABLE_LOOKUP_WITH_FALLBACK(ip_tos, int, 0xff); diff --git a/src/boot/bootctl.c b/src/boot/bootctl.c index 814e068158..a27a0d45e4 100644 --- a/src/boot/bootctl.c +++ b/src/boot/bootctl.c @@ -923,30 +923,29 @@ static bool same_entry(uint16_t id, sd_id128_t uuid, const char *path) { static int find_slot(sd_id128_t uuid, const char *path, uint16_t *id) { _cleanup_free_ uint16_t *options = NULL; - int n, i; - n = efi_get_boot_options(&options); + int n = efi_get_boot_options(&options); if (n < 0) return n; /* find already existing systemd-boot entry */ - for (i = 0; i < n; i++) + for (int i = 0; i < n; i++) if (same_entry(options[i], uuid, path)) { *id = options[i]; return 1; } /* find free slot in the sorted BootXXXX variable list */ - for (i = 0; i < n; i++) + for (int i = 0; i < n; i++) if (i != options[i]) { *id = i; return 0; } /* use the next one */ - if (i == 0xffff) + if (n == 0xffff) return -ENOSPC; - *id = i; + *id = n; return 0; } diff --git a/src/core/mount.c b/src/core/mount.c index b47bd12c96..836ba132cb 100644 --- a/src/core/mount.c +++ b/src/core/mount.c @@ -1602,13 +1602,13 @@ static int mount_setup_new_unit( if (r < 0) return r; - /* This unit was generated because /proc/self/mountinfo reported it. Remember this, so that by the time we load - * the unit file for it (and thus add in extra deps right after) we know what source to attributes the deps - * to. */ + /* This unit was generated because /proc/self/mountinfo reported it. Remember this, so that by the + * time we load the unit file for it (and thus add in extra deps right after) we know what source to + * attributes the deps to. */ MOUNT(u)->from_proc_self_mountinfo = true; - /* We have only allocated the stub now, let's enqueue this unit for loading now, so that everything else is - * loaded in now. */ + /* We have only allocated the stub now, let's enqueue this unit for loading now, so that everything + * else is loaded in now. */ unit_add_to_load_queue(u); *ret_flags = MOUNT_PROC_IS_MOUNTED | MOUNT_PROC_JUST_MOUNTED | MOUNT_PROC_JUST_CHANGED; @@ -1751,8 +1751,8 @@ static int mount_setup_unit( if (u) r = mount_setup_existing_unit(u, what, where, options, fstype, &flags); else - /* First time we see this mount point meaning that it's not been initiated by a mount unit but rather - * by the sysadmin having called mount(8) directly. */ + /* First time we see this mount point meaning that it's not been initiated by a mount unit + * but rather by the sysadmin having called mount(8) directly. */ r = mount_setup_new_unit(m, e, what, where, options, fstype, &flags, &u); if (r < 0) return log_warning_errno(r, "Failed to set up mount unit for '%s': %m", where); diff --git a/src/shared/condition.c b/src/shared/condition.c index 67de6fc62f..542e3f729e 100644 --- a/src/shared/condition.c +++ b/src/shared/condition.c @@ -102,8 +102,6 @@ Condition* condition_free_list_type(Condition *head, ConditionType type) { static int condition_test_kernel_command_line(Condition *c, char **env) { _cleanup_free_ char *line = NULL; - const char *p; - bool equal; int r; assert(c); @@ -114,9 +112,9 @@ static int condition_test_kernel_command_line(Condition *c, char **env) { if (r < 0) return r; - equal = strchr(c->parameter, '='); + bool equal = strchr(c->parameter, '='); - for (p = line;;) { + for (const char *p = line;;) { _cleanup_free_ char *word = NULL; bool found; @@ -156,7 +154,6 @@ typedef enum { } OrderOperator; static OrderOperator parse_order(const char **s) { - static const char *const prefix[_ORDER_MAX] = { [ORDER_LOWER_OR_EQUAL] = "<=", [ORDER_GREATER_OR_EQUAL] = ">=", @@ -166,9 +163,7 @@ static OrderOperator parse_order(const char **s) { [ORDER_UNEQUAL] = "!=", }; - OrderOperator i; - - for (i = 0; i < _ORDER_MAX; i++) { + for (OrderOperator i = 0; i < _ORDER_MAX; i++) { const char *e; e = startswith(*s, prefix[i]); @@ -212,7 +207,6 @@ static bool test_order(int k, OrderOperator p) { static int condition_test_kernel_version(Condition *c, char **env) { OrderOperator order; struct utsname u; - const char *p; bool first = true; assert(c); @@ -221,9 +215,7 @@ static int condition_test_kernel_version(Condition *c, char **env) { assert_se(uname(&u) >= 0); - p = c->parameter; - - for (;;) { + for (const char *p = c->parameter;;) { _cleanup_free_ char *word = NULL; const char *s; int r; @@ -268,14 +260,12 @@ static int condition_test_kernel_version(Condition *c, char **env) { } static int condition_test_osrelease(Condition *c, char **env) { - const char *parameter = c->parameter; int r; assert(c); - assert(c->parameter); assert(c->type == CONDITION_OS_RELEASE); - for (;;) { + for (const char *parameter = ASSERT_PTR(c->parameter);;) { _cleanup_free_ char *key = NULL, *condition = NULL, *actual_value = NULL; OrderOperator order; const char *word; @@ -682,7 +672,6 @@ static int condition_test_capability(Condition *c, char **env) { for (;;) { _cleanup_free_ char *line = NULL; - const char *p; r = read_line(f, LONG_LINE_MAX, &line); if (r < 0) @@ -690,9 +679,9 @@ static int condition_test_capability(Condition *c, char **env) { if (r == 0) break; - p = startswith(line, "CapBnd:"); + const char *p = startswith(line, "CapBnd:"); if (p) { - if (sscanf(line+7, "%llx", &capabilities) != 1) + if (sscanf(p, "%llx", &capabilities) != 1) return -EIO; break; |