From 8b273a478d1fb8fcbda3a0ddec4f0bc3095705a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Thu, 10 Dec 2020 17:05:42 +0100 Subject: [PATCH 1/4] man: s/dash/mdash/ --- man/systemd-detect-virt.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/man/systemd-detect-virt.xml b/man/systemd-detect-virt.xml index 09491f7f11..654cf9b84c 100644 --- a/man/systemd-detect-virt.xml +++ b/man/systemd-detect-virt.xml @@ -94,7 +94,7 @@ powervm - IBM PowerVM hypervisor - comes as firmware with some IBM POWER servers + IBM PowerVM hypervisor — comes as firmware with some IBM POWER servers From 0c659eb8056383a55249eece65bbdd7d366b3490 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Thu, 10 Dec 2020 17:13:12 +0100 Subject: [PATCH 2/4] sysctl.d: shorten comment The grammar was a bit suspect in a few places... --- sysctl.d/50-coredump.conf.in | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/sysctl.d/50-coredump.conf.in b/sysctl.d/50-coredump.conf.in index 4338756efd..2ffc1cb0fb 100644 --- a/sysctl.d/50-coredump.conf.in +++ b/sysctl.d/50-coredump.conf.in @@ -15,15 +15,14 @@ # See systemd-coredump(8) and core(5). kernel.core_pattern=|@rootlibexecdir@/systemd-coredump %P %u %g %s %t %c %h -# Allow that 16 coredumps are dispatched in parallel by the kernel. We want to -# be able to collect process metadata from /proc/%P/ while processing -# coredumps, and thus need to make sure the crashed processes are not reaped -# until we finished collecting what we need. The kernel default for this sysctl -# is "0" which means the kernel doesn't wait for userspace processes to finish -# processing before reaping the crashed processes — by setting this higher the -# kernel will delay reaping until we are done, but only for the specified -# number of crashes in parallel. The value of 16 is chosen to match -# systemd-coredump.socket's MaxConnections= value. +# Allow 16 coredumps to be dispatched in parallel by the kernel. +# We collect metadata from /proc/%P/, and thus need to make sure the crashed +# processes are not reaped until we have finished collecting what we need. The +# kernel default for this sysctl is "0" which means the kernel doesn't wait for +# userspace to finish processing before reaping the crashed processes. With a +# higher setting the kernel will delay reaping until we are done, but only for +# the specified number of crashes in parallel. The value of 16 is chosen to +# match systemd-coredump.socket's MaxConnections= value. kernel.core_pipe_limit=16 # Also dump processes executing a set-user-ID/set-group-ID program that is From d2b99ed7c53fff6657d4f3b20ae7535f6bdabe57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Fri, 11 Dec 2020 12:24:26 +0100 Subject: [PATCH 3/4] nspawn: minor modernization --- src/nspawn/nspawn-mount.c | 37 +++++++++---------------------------- 1 file changed, 9 insertions(+), 28 deletions(-) diff --git a/src/nspawn/nspawn-mount.c b/src/nspawn/nspawn-mount.c index 2ea1bed361..dbebc49ae7 100644 --- a/src/nspawn/nspawn-mount.c +++ b/src/nspawn/nspawn-mount.c @@ -48,9 +48,7 @@ CustomMount* custom_mount_add(CustomMount **l, size_t *n, CustomMountType t) { } void custom_mount_free_all(CustomMount *l, size_t n) { - size_t i; - - for (i = 0; i < n; i++) { + for (size_t i = 0; i < n; i++) { CustomMount *m = l + i; free(m->source); @@ -94,7 +92,6 @@ static bool source_path_is_valid(const char *p) { } static char *resolve_source_path(const char *dest, const char *source) { - if (!source) return NULL; @@ -129,7 +126,6 @@ static int allocate_temporary_source(CustomMount *m) { } int custom_mount_prepare_all(const char *dest, CustomMount *l, size_t n) { - size_t i; int r; /* Prepare all custom mounts. This will make source we know all temporary directories. This is called in the @@ -141,7 +137,7 @@ int custom_mount_prepare_all(const char *dest, CustomMount *l, size_t n) { /* Order the custom mounts, and make sure we have a working directory */ typesafe_qsort(l, n, custom_mount_compare); - for (i = 0; i < n; i++) { + for (size_t i = 0; i < n; i++) { CustomMount *m = l + i; /* /proc we mount in the inner child, i.e. when we acquired CLONE_NEWPID. All other mounts we mount @@ -588,10 +584,9 @@ int mount_all(const char *dest, bool ro = FLAGS_SET(mount_settings, MOUNT_APPLY_APIVFS_RO); bool in_userns = FLAGS_SET(mount_settings, MOUNT_IN_USERNS); bool tmpfs_tmp = FLAGS_SET(mount_settings, MOUNT_APPLY_TMPFS_TMP); - size_t k; int r; - for (k = 0; k < ELEMENTSOF(mount_table); k++) { + for (size_t k = 0; k < ELEMENTSOF(mount_table); k++) { _cleanup_free_ char *where = NULL, *options = NULL, *prefixed = NULL; bool fatal = FLAGS_SET(mount_table[k].mount_settings, MOUNT_FATAL); const char *o; @@ -688,7 +683,6 @@ int mount_all(const char *dest, } static int parse_mount_bind_options(const char *options, unsigned long *mount_flags, char **mount_opts) { - const char *p = options; unsigned long flags = *mount_flags; char *opts = NULL; int r; @@ -698,7 +692,7 @@ static int parse_mount_bind_options(const char *options, unsigned long *mount_fl for (;;) { _cleanup_free_ char *word = NULL; - r = extract_first_word(&p, &word, ",", 0); + r = extract_first_word(&options, &word, ",", 0); if (r < 0) return log_error_errno(r, "Failed to extract mount option: %m"); if (r == 0) @@ -708,11 +702,9 @@ static int parse_mount_bind_options(const char *options, unsigned long *mount_fl flags |= MS_REC; else if (streq(word, "norbind")) flags &= ~MS_REC; - else { + else return log_error_errno(SYNTHETIC_ERRNO(EINVAL), - "Invalid bind mount option: %s", - word); - } + "Invalid bind mount option: %s", word); } *mount_flags = flags; @@ -789,7 +781,6 @@ static int mount_bind(const char *dest, CustomMount *m) { } static int mount_tmpfs(const char *dest, CustomMount *m, uid_t uid_shift, const char *selinux_apifs_context) { - const char *options; _cleanup_free_ char *buf = NULL, *where = NULL; int r; @@ -927,13 +918,11 @@ int mount_custom( uid_t uid_shift, const char *selinux_apifs_context, MountSettingsMask mount_settings) { - - size_t i; int r; assert(dest); - for (i = 0; i < n; i++) { + for (size_t i = 0; i < n; i++) { CustomMount *m = mounts + i; if (FLAGS_SET(mount_settings, MOUNT_IN_USERNS) != m->in_userns) @@ -979,20 +968,14 @@ int mount_custom( } bool has_custom_root_mount(const CustomMount *mounts, size_t n) { - size_t i; - - for (i = 0; i < n; i++) { - const CustomMount *m = mounts + i; - - if (path_equal(m->destination, "/")) + for (size_t i = 0; i < n; i++) + if (path_equal(mounts[i].destination, "/")) return true; - } return false; } static int setup_volatile_state(const char *directory, uid_t uid_shift, const char *selinux_apifs_context) { - _cleanup_free_ char *buf = NULL; const char *p, *options; int r; @@ -1021,7 +1004,6 @@ static int setup_volatile_state(const char *directory, uid_t uid_shift, const ch } static int setup_volatile_yes(const char *directory, uid_t uid_shift, const char *selinux_apifs_context) { - bool tmpfs_mounted = false, bind_mounted = false; char template[] = "/tmp/nspawn-volatile-XXXXXX"; _cleanup_free_ char *buf = NULL, *bindir = NULL; @@ -1109,7 +1091,6 @@ fail: } static int setup_volatile_overlay(const char *directory, uid_t uid_shift, const char *selinux_apifs_context) { - _cleanup_free_ char *buf = NULL, *escaped_directory = NULL, *escaped_upper = NULL, *escaped_work = NULL; char template[] = "/tmp/nspawn-volatile-XXXXXX"; const char *upper, *work, *options; From 5b935a388cdc95209317f8be95ef5b2b5909ad70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Fri, 15 Jan 2021 10:23:57 +0100 Subject: [PATCH 4/4] basic/env-util: modernization --- src/basic/env-util.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/basic/env-util.c b/src/basic/env-util.c index a84863ff22..03bdba022d 100644 --- a/src/basic/env-util.c +++ b/src/basic/env-util.c @@ -22,8 +22,6 @@ "_" static bool env_name_is_valid_n(const char *e, size_t n) { - const char *p; - if (!e) return false; @@ -41,7 +39,7 @@ static bool env_name_is_valid_n(const char *e, size_t n) { if (n > (size_t) sysconf(_SC_ARG_MAX) - 2) return false; - for (p = e; p < e + n; p++) + for (const char *p = e; p < e + n; p++) if (!strchr(VALID_BASH_ENV_NAME_CHARS, *p)) return false; @@ -189,14 +187,14 @@ static int env_append(char **r, char ***k, char **a) { char **strv_env_merge(size_t n_lists, ...) { _cleanup_strv_free_ char **ret = NULL; - size_t n = 0, i; + size_t n = 0; char **l, **k; va_list ap; /* Merges an arbitrary number of environment sets */ va_start(ap, n_lists); - for (i = 0; i < n_lists; i++) { + for (size_t i = 0; i < n_lists; i++) { l = va_arg(ap, char**); n += strv_length(l); } @@ -210,7 +208,7 @@ char **strv_env_merge(size_t n_lists, ...) { k = ret; va_start(ap, n_lists); - for (i = 0; i < n_lists; i++) { + for (size_t i = 0; i < n_lists; i++) { l = va_arg(ap, char**); if (env_append(ret, &k, l) < 0) { va_end(ap); @@ -276,10 +274,8 @@ char **strv_env_delete(char **x, size_t n_lists, ...) { return NULL; STRV_FOREACH(k, x) { - size_t v; - va_start(ap, n_lists); - for (v = 0; v < n_lists; v++) { + for (size_t v = 0; v < n_lists; v++) { char **l, **j; l = va_arg(ap, char**); @@ -310,7 +306,6 @@ char **strv_env_delete(char **x, size_t n_lists, ...) { } char **strv_env_unset(char **l, const char *p) { - char **f, **t; if (!l)