From 534fc25ad9d83069bbe63ea2eecc6d6d5ce43528 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Tue, 23 Jan 2024 13:01:43 +0100 Subject: [PATCH 1/7] basic/alloc-util: drop unnecessary parens By definition, a parameter cannot contain a comma because commas are used to delimit parameters. So we also don't need to use parens when the use site is delimited by commas. --- src/basic/alloc-util.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/basic/alloc-util.h b/src/basic/alloc-util.h index 136d2b3e68..c215c33f4b 100644 --- a/src/basic/alloc-util.h +++ b/src/basic/alloc-util.h @@ -20,7 +20,7 @@ typedef void* (*mfree_func_t)(void *p); * proceeding and smashing the stack limits. Note that by default RLIMIT_STACK is 8M on Linux. */ #define ALLOCA_MAX (4U*1024U*1024U) -#define new(t, n) ((t*) malloc_multiply((n), sizeof(t))) +#define new(t, n) ((t*) malloc_multiply(n, sizeof(t))) #define new0(t, n) ((t*) calloc((n) ?: 1, sizeof(t))) @@ -45,9 +45,9 @@ typedef void* (*mfree_func_t)(void *p); (t*) alloca0((sizeof(t)*_n_)); \ }) -#define newdup(t, p, n) ((t*) memdup_multiply(p, (n), sizeof(t))) +#define newdup(t, p, n) ((t*) memdup_multiply(p, n, sizeof(t))) -#define newdup_suffix0(t, p, n) ((t*) memdup_suffix0_multiply(p, (n), sizeof(t))) +#define newdup_suffix0(t, p, n) ((t*) memdup_suffix0_multiply(p, n, sizeof(t))) #define malloc0(n) (calloc(1, (n) ?: 1)) @@ -237,7 +237,7 @@ static inline size_t malloc_sizeof_safe(void **xp) { #define strndupa_safe(s, n) \ ({ \ const char *_t = (s); \ - (char*) memdupa_suffix0(_t, strnlen(_t, (n))); \ + (char*) memdupa_suffix0(_t, strnlen(_t, n)); \ }) /* Free every element of the array. */ From e1054a8bcd7ed3f29bc8ea72fd703760d3852392 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Fri, 8 Dec 2023 09:56:43 +0100 Subject: [PATCH 2/7] bsod: do not use STRLEN The compiler optimizes strlen away, so we can use the simplest form that is type safe and more natural. STRLEN is only for array initialization. --- src/journal/bsod.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/journal/bsod.c b/src/journal/bsod.c index a88cb66b81..059e255ea4 100644 --- a/src/journal/bsod.c +++ b/src/journal/bsod.c @@ -103,7 +103,7 @@ static int acquire_first_emergency_log_message(char **ret) { if (r < 0) return log_error_errno(r, "Failed to read journal message: %m"); - message = memdup_suffix0((const char*)d + STRLEN("MESSAGE="), l - STRLEN("MESSAGE=")); + message = memdup_suffix0((const char*)d + strlen("MESSAGE="), l - strlen("MESSAGE=")); if (!message) return log_oom(); From f3663c0ec9e3a92c9c7256a37e7e8872d8628d8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Thu, 14 Dec 2023 10:57:05 +0100 Subject: [PATCH 3/7] shared/pretty-print: use normal else-if cascade This is not a hot path, but it seems silly to evalute subsequent branches, which can never match once one has matched. Also, it makes the code harder to read, because the reader has to first figure out that only one branch can match. --- src/shared/pretty-print.c | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/src/shared/pretty-print.c b/src/shared/pretty-print.c index 7dd31a099f..d28c231d58 100644 --- a/src/shared/pretty-print.c +++ b/src/shared/pretty-print.c @@ -350,24 +350,17 @@ static int guess_type(const char **name, char ***prefixes, bool *is_collection, if (path_equal(n, "udev/hwdb.d")) ext = ".hwdb"; - - if (path_equal(n, "udev/rules.d")) + else if (path_equal(n, "udev/rules.d")) ext = ".rules"; - - if (path_equal(n, "kernel/install.d")) + else if (path_equal(n, "kernel/install.d")) ext = ".install"; - - if (path_equal(n, "systemd/ntp-units.d")) { + else if (path_equal(n, "systemd/ntp-units.d")) { coll = true; ext = ".list"; - } - - if (path_equal(n, "systemd/relabel-extra.d")) { + } else if (path_equal(n, "systemd/relabel-extra.d")) { coll = run = true; ext = ".relabel"; - } - - if (PATH_IN_SET(n, "systemd/system-preset", "systemd/user-preset")) { + } else if (PATH_IN_SET(n, "systemd/system-preset", "systemd/user-preset")) { coll = true; ext = ".preset"; } From 2673d6fae000fc7b22f95d12b4a3276c680513e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Thu, 14 Dec 2023 10:58:19 +0100 Subject: [PATCH 4/7] shared/pretty-print: inline one more variable declaration --- src/shared/pretty-print.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/shared/pretty-print.c b/src/shared/pretty-print.c index d28c231d58..946da5f42d 100644 --- a/src/shared/pretty-print.c +++ b/src/shared/pretty-print.c @@ -294,14 +294,12 @@ void print_separator(void) { * one line filled with spaces with ANSI underline set, followed by a second (empty) line. */ if (underline_enabled()) { - size_t i, c; - - c = columns(); + size_t c = columns(); flockfile(stdout); fputs_unlocked(ANSI_UNDERLINE, stdout); - for (i = 0; i < c; i++) + for (size_t i = 0; i < c; i++) fputc_unlocked(' ', stdout); fputs_unlocked(ANSI_NORMAL "\n\n", stdout); From e9dc98c56b6ddd95e577872686e6cd42c6d8d60c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Thu, 25 Jan 2024 16:38:28 +0100 Subject: [PATCH 5/7] journald: inline one variable declaration --- src/journal/journald-server.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/journal/journald-server.c b/src/journal/journald-server.c index 2469451fca..8f9ecd9622 100644 --- a/src/journal/journald-server.c +++ b/src/journal/journald-server.c @@ -2507,7 +2507,7 @@ int server_new(Server **ret) { int server_init(Server *s, const char *namespace) { const char *native_socket, *syslog_socket, *stdout_socket, *varlink_socket, *e; _cleanup_fdset_free_ FDSet *fds = NULL; - int n, r, fd, varlink_fd = -EBADF; + int n, r, varlink_fd = -EBADF; bool no_sockets; assert(s); @@ -2575,7 +2575,7 @@ int server_init(Server *s, const char *namespace) { syslog_socket = strjoina(s->runtime_directory, "/dev-log"); varlink_socket = strjoina(s->runtime_directory, "/io.systemd.journal"); - 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++) if (sd_is_socket_unix(fd, SOCK_DGRAM, -1, native_socket, 0) > 0) { @@ -2628,7 +2628,6 @@ int server_init(Server *s, const char *namespace) { if (r < 0) return log_oom(); } - } /* Try to restore streams, but don't bother if this fails */ (void) server_restore_streams(s, fds); From 9af1281ed7d0765c2842bc35e6ea525261793a9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Thu, 25 Jan 2024 18:34:08 +0100 Subject: [PATCH 6/7] pstore: align table --- src/pstore/pstore.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/pstore/pstore.c b/src/pstore/pstore.c index 8f32a0a2ae..835348f90e 100644 --- a/src/pstore/pstore.c +++ b/src/pstore/pstore.c @@ -56,9 +56,9 @@ typedef enum PStoreStorage { } PStoreStorage; static const char* const pstore_storage_table[_PSTORE_STORAGE_MAX] = { - [PSTORE_STORAGE_NONE] = "none", + [PSTORE_STORAGE_NONE] = "none", [PSTORE_STORAGE_EXTERNAL] = "external", - [PSTORE_STORAGE_JOURNAL] = "journal", + [PSTORE_STORAGE_JOURNAL] = "journal", }; DEFINE_PRIVATE_STRING_TABLE_LOOKUP(pstore_storage, PStoreStorage); @@ -279,6 +279,7 @@ static int process_dmesg_files(PStoreList *list) { } else log_debug("Unknown backend, ignoring \"%s\".", pe->dirent.d_name); } + return 0; } From 8835a6ff0c66cf51f1ecd296975e07802ebdf8e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Thu, 25 Jan 2024 21:31:30 +0100 Subject: [PATCH 7/7] man/networkd.conf: remove strange comment MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Does anyone even read those pages‽ --- man/networkd.conf.xml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/man/networkd.conf.xml b/man/networkd.conf.xml index ab1f7becbe..9477bfe5af 100644 --- a/man/networkd.conf.xml +++ b/man/networkd.conf.xml @@ -37,9 +37,7 @@ Description - These configuration files control global network parameters. - Currently the DHCP Unique Identifier (DUID). - + These configuration files control global network parameters.