Merge pull request #18254 from keszybz/trivial-cleanups
Assorted small cleanups
This commit is contained in:
@@ -94,7 +94,7 @@
|
|||||||
|
|
||||||
<row>
|
<row>
|
||||||
<entry><varname>powervm</varname></entry>
|
<entry><varname>powervm</varname></entry>
|
||||||
<entry>IBM PowerVM hypervisor - comes as firmware with some IBM POWER servers</entry>
|
<entry>IBM PowerVM hypervisor — comes as firmware with some IBM POWER servers</entry>
|
||||||
</row>
|
</row>
|
||||||
|
|
||||||
<row>
|
<row>
|
||||||
|
|||||||
+5
-10
@@ -22,8 +22,6 @@
|
|||||||
"_"
|
"_"
|
||||||
|
|
||||||
static bool env_name_is_valid_n(const char *e, size_t n) {
|
static bool env_name_is_valid_n(const char *e, size_t n) {
|
||||||
const char *p;
|
|
||||||
|
|
||||||
if (!e)
|
if (!e)
|
||||||
return false;
|
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)
|
if (n > (size_t) sysconf(_SC_ARG_MAX) - 2)
|
||||||
return false;
|
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))
|
if (!strchr(VALID_BASH_ENV_NAME_CHARS, *p))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@@ -189,14 +187,14 @@ static int env_append(char **r, char ***k, char **a) {
|
|||||||
|
|
||||||
char **strv_env_merge(size_t n_lists, ...) {
|
char **strv_env_merge(size_t n_lists, ...) {
|
||||||
_cleanup_strv_free_ char **ret = NULL;
|
_cleanup_strv_free_ char **ret = NULL;
|
||||||
size_t n = 0, i;
|
size_t n = 0;
|
||||||
char **l, **k;
|
char **l, **k;
|
||||||
va_list ap;
|
va_list ap;
|
||||||
|
|
||||||
/* Merges an arbitrary number of environment sets */
|
/* Merges an arbitrary number of environment sets */
|
||||||
|
|
||||||
va_start(ap, n_lists);
|
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**);
|
l = va_arg(ap, char**);
|
||||||
n += strv_length(l);
|
n += strv_length(l);
|
||||||
}
|
}
|
||||||
@@ -210,7 +208,7 @@ char **strv_env_merge(size_t n_lists, ...) {
|
|||||||
k = ret;
|
k = ret;
|
||||||
|
|
||||||
va_start(ap, n_lists);
|
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**);
|
l = va_arg(ap, char**);
|
||||||
if (env_append(ret, &k, l) < 0) {
|
if (env_append(ret, &k, l) < 0) {
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
@@ -276,10 +274,8 @@ char **strv_env_delete(char **x, size_t n_lists, ...) {
|
|||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
STRV_FOREACH(k, x) {
|
STRV_FOREACH(k, x) {
|
||||||
size_t v;
|
|
||||||
|
|
||||||
va_start(ap, n_lists);
|
va_start(ap, n_lists);
|
||||||
for (v = 0; v < n_lists; v++) {
|
for (size_t v = 0; v < n_lists; v++) {
|
||||||
char **l, **j;
|
char **l, **j;
|
||||||
|
|
||||||
l = va_arg(ap, char**);
|
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 **strv_env_unset(char **l, const char *p) {
|
||||||
|
|
||||||
char **f, **t;
|
char **f, **t;
|
||||||
|
|
||||||
if (!l)
|
if (!l)
|
||||||
|
|||||||
@@ -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) {
|
void custom_mount_free_all(CustomMount *l, size_t n) {
|
||||||
size_t i;
|
for (size_t i = 0; i < n; i++) {
|
||||||
|
|
||||||
for (i = 0; i < n; i++) {
|
|
||||||
CustomMount *m = l + i;
|
CustomMount *m = l + i;
|
||||||
|
|
||||||
free(m->source);
|
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) {
|
static char *resolve_source_path(const char *dest, const char *source) {
|
||||||
|
|
||||||
if (!source)
|
if (!source)
|
||||||
return NULL;
|
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) {
|
int custom_mount_prepare_all(const char *dest, CustomMount *l, size_t n) {
|
||||||
size_t i;
|
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
/* Prepare all custom mounts. This will make source we know all temporary directories. This is called in the
|
/* 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 */
|
/* Order the custom mounts, and make sure we have a working directory */
|
||||||
typesafe_qsort(l, n, custom_mount_compare);
|
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;
|
CustomMount *m = l + i;
|
||||||
|
|
||||||
/* /proc we mount in the inner child, i.e. when we acquired CLONE_NEWPID. All other mounts we mount
|
/* /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 ro = FLAGS_SET(mount_settings, MOUNT_APPLY_APIVFS_RO);
|
||||||
bool in_userns = FLAGS_SET(mount_settings, MOUNT_IN_USERNS);
|
bool in_userns = FLAGS_SET(mount_settings, MOUNT_IN_USERNS);
|
||||||
bool tmpfs_tmp = FLAGS_SET(mount_settings, MOUNT_APPLY_TMPFS_TMP);
|
bool tmpfs_tmp = FLAGS_SET(mount_settings, MOUNT_APPLY_TMPFS_TMP);
|
||||||
size_t k;
|
|
||||||
int r;
|
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;
|
_cleanup_free_ char *where = NULL, *options = NULL, *prefixed = NULL;
|
||||||
bool fatal = FLAGS_SET(mount_table[k].mount_settings, MOUNT_FATAL);
|
bool fatal = FLAGS_SET(mount_table[k].mount_settings, MOUNT_FATAL);
|
||||||
const char *o;
|
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) {
|
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;
|
unsigned long flags = *mount_flags;
|
||||||
char *opts = NULL;
|
char *opts = NULL;
|
||||||
int r;
|
int r;
|
||||||
@@ -698,7 +692,7 @@ static int parse_mount_bind_options(const char *options, unsigned long *mount_fl
|
|||||||
for (;;) {
|
for (;;) {
|
||||||
_cleanup_free_ char *word = NULL;
|
_cleanup_free_ char *word = NULL;
|
||||||
|
|
||||||
r = extract_first_word(&p, &word, ",", 0);
|
r = extract_first_word(&options, &word, ",", 0);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return log_error_errno(r, "Failed to extract mount option: %m");
|
return log_error_errno(r, "Failed to extract mount option: %m");
|
||||||
if (r == 0)
|
if (r == 0)
|
||||||
@@ -708,11 +702,9 @@ static int parse_mount_bind_options(const char *options, unsigned long *mount_fl
|
|||||||
flags |= MS_REC;
|
flags |= MS_REC;
|
||||||
else if (streq(word, "norbind"))
|
else if (streq(word, "norbind"))
|
||||||
flags &= ~MS_REC;
|
flags &= ~MS_REC;
|
||||||
else {
|
else
|
||||||
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
|
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
|
||||||
"Invalid bind mount option: %s",
|
"Invalid bind mount option: %s", word);
|
||||||
word);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
*mount_flags = flags;
|
*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) {
|
static int mount_tmpfs(const char *dest, CustomMount *m, uid_t uid_shift, const char *selinux_apifs_context) {
|
||||||
|
|
||||||
const char *options;
|
const char *options;
|
||||||
_cleanup_free_ char *buf = NULL, *where = NULL;
|
_cleanup_free_ char *buf = NULL, *where = NULL;
|
||||||
int r;
|
int r;
|
||||||
@@ -927,13 +918,11 @@ int mount_custom(
|
|||||||
uid_t uid_shift,
|
uid_t uid_shift,
|
||||||
const char *selinux_apifs_context,
|
const char *selinux_apifs_context,
|
||||||
MountSettingsMask mount_settings) {
|
MountSettingsMask mount_settings) {
|
||||||
|
|
||||||
size_t i;
|
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
assert(dest);
|
assert(dest);
|
||||||
|
|
||||||
for (i = 0; i < n; i++) {
|
for (size_t i = 0; i < n; i++) {
|
||||||
CustomMount *m = mounts + i;
|
CustomMount *m = mounts + i;
|
||||||
|
|
||||||
if (FLAGS_SET(mount_settings, MOUNT_IN_USERNS) != m->in_userns)
|
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) {
|
bool has_custom_root_mount(const CustomMount *mounts, size_t n) {
|
||||||
size_t i;
|
for (size_t i = 0; i < n; i++)
|
||||||
|
if (path_equal(mounts[i].destination, "/"))
|
||||||
for (i = 0; i < n; i++) {
|
|
||||||
const CustomMount *m = mounts + i;
|
|
||||||
|
|
||||||
if (path_equal(m->destination, "/"))
|
|
||||||
return true;
|
return true;
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int setup_volatile_state(const char *directory, uid_t uid_shift, const char *selinux_apifs_context) {
|
static int setup_volatile_state(const char *directory, uid_t uid_shift, const char *selinux_apifs_context) {
|
||||||
|
|
||||||
_cleanup_free_ char *buf = NULL;
|
_cleanup_free_ char *buf = NULL;
|
||||||
const char *p, *options;
|
const char *p, *options;
|
||||||
int r;
|
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) {
|
static int setup_volatile_yes(const char *directory, uid_t uid_shift, const char *selinux_apifs_context) {
|
||||||
|
|
||||||
bool tmpfs_mounted = false, bind_mounted = false;
|
bool tmpfs_mounted = false, bind_mounted = false;
|
||||||
char template[] = "/tmp/nspawn-volatile-XXXXXX";
|
char template[] = "/tmp/nspawn-volatile-XXXXXX";
|
||||||
_cleanup_free_ char *buf = NULL, *bindir = NULL;
|
_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) {
|
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;
|
_cleanup_free_ char *buf = NULL, *escaped_directory = NULL, *escaped_upper = NULL, *escaped_work = NULL;
|
||||||
char template[] = "/tmp/nspawn-volatile-XXXXXX";
|
char template[] = "/tmp/nspawn-volatile-XXXXXX";
|
||||||
const char *upper, *work, *options;
|
const char *upper, *work, *options;
|
||||||
|
|||||||
@@ -15,15 +15,14 @@
|
|||||||
# See systemd-coredump(8) and core(5).
|
# See systemd-coredump(8) and core(5).
|
||||||
kernel.core_pattern=|@rootlibexecdir@/systemd-coredump %P %u %g %s %t %c %h
|
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
|
# Allow 16 coredumps to be dispatched in parallel by the kernel.
|
||||||
# be able to collect process metadata from /proc/%P/ while processing
|
# We collect metadata from /proc/%P/, and thus need to make sure the crashed
|
||||||
# coredumps, and thus need to make sure the crashed processes are not reaped
|
# processes are not reaped until we have finished collecting what we need. The
|
||||||
# until we finished collecting what we need. The kernel default for this sysctl
|
# kernel default for this sysctl is "0" which means the kernel doesn't wait for
|
||||||
# is "0" which means the kernel doesn't wait for userspace processes to finish
|
# userspace to finish processing before reaping the crashed processes. With a
|
||||||
# processing before reaping the crashed processes — by setting this higher the
|
# higher setting the kernel will delay reaping until we are done, but only for
|
||||||
# kernel will delay reaping until we are done, but only for the specified
|
# the specified number of crashes in parallel. The value of 16 is chosen to
|
||||||
# number of crashes in parallel. The value of 16 is chosen to match
|
# match systemd-coredump.socket's MaxConnections= value.
|
||||||
# systemd-coredump.socket's MaxConnections= value.
|
|
||||||
kernel.core_pipe_limit=16
|
kernel.core_pipe_limit=16
|
||||||
|
|
||||||
# Also dump processes executing a set-user-ID/set-group-ID program that is
|
# Also dump processes executing a set-user-ID/set-group-ID program that is
|
||||||
|
|||||||
Reference in New Issue
Block a user