summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
Diffstat (limited to 'src/core')
-rw-r--r--src/core/cgroup.c14
-rw-r--r--src/core/dbus-cgroup.c12
-rw-r--r--src/core/main.c26
3 files changed, 36 insertions, 16 deletions
diff --git a/src/core/cgroup.c b/src/core/cgroup.c
index 981aca53cd..ec8a262314 100644
--- a/src/core/cgroup.c
+++ b/src/core/cgroup.c
@@ -360,9 +360,7 @@ static char *format_cgroup_memory_limit_comparison(char *buf, size_t l, Unit *u,
}
void cgroup_context_dump(Unit *u, FILE* f, const char *prefix) {
- _cleanup_free_ char *disable_controllers_str = NULL;
- _cleanup_free_ char *cpuset_cpus = NULL;
- _cleanup_free_ char *cpuset_mems = NULL;
+ _cleanup_free_ char *disable_controllers_str = NULL, *cpuset_cpus = NULL, *cpuset_mems = NULL;
CGroupIODeviceLimit *il;
CGroupIODeviceWeight *iw;
CGroupIODeviceLatency *l;
@@ -437,8 +435,8 @@ void cgroup_context_dump(Unit *u, FILE* f, const char *prefix) {
prefix, c->startup_cpu_shares,
prefix, format_timespan(q, sizeof(q), c->cpu_quota_per_sec_usec, 1),
prefix, format_timespan(v, sizeof(v), c->cpu_quota_period_usec, 1),
- prefix, cpuset_cpus,
- prefix, cpuset_mems,
+ prefix, strempty(cpuset_cpus),
+ prefix, strempty(cpuset_mems),
prefix, c->io_weight,
prefix, c->startup_io_weight,
prefix, c->blockio_weight,
@@ -974,8 +972,10 @@ static void cgroup_apply_unified_cpuset(Unit *u, const CPUSet *cpus, const char
_cleanup_free_ char *buf = NULL;
buf = cpu_set_to_range_string(cpus);
- if (!buf)
- return;
+ if (!buf) {
+ log_oom();
+ return;
+ }
(void) set_attribute_and_warn(u, "cpuset", name, buf);
}
diff --git a/src/core/dbus-cgroup.c b/src/core/dbus-cgroup.c
index b30318b943..647c3a512c 100644
--- a/src/core/dbus-cgroup.c
+++ b/src/core/dbus-cgroup.c
@@ -926,23 +926,23 @@ int bus_cgroup_set_property(
if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
_cleanup_free_ char *setstr = NULL;
- _cleanup_free_ char *data = NULL;
CPUSet *set;
setstr = cpu_set_to_range_string(&new_set);
+ if (!setstr)
+ return -ENOMEM;
if (streq(name, "AllowedCPUs"))
set = &c->cpuset_cpus;
else
set = &c->cpuset_mems;
- if (asprintf(&data, "%s=%s", name, setstr) < 0)
- return -ENOMEM;
-
cpu_set_reset(set);
- cpu_set_add_all(set, &new_set);
+ *set = new_set;
+ new_set = (CPUSet) {};
+
unit_invalidate_cgroup(u, CGROUP_MASK_CPUSET);
- unit_write_setting(u, flags, name, data);
+ unit_write_settingf(u, flags, name, "%s=%s", name, setstr);
}
return 1;
diff --git a/src/core/main.c b/src/core/main.c
index 7c814f3237..3545fde71d 100644
--- a/src/core/main.c
+++ b/src/core/main.c
@@ -146,6 +146,9 @@ static OOMPolicy arg_default_oom_policy;
static CPUSet arg_cpu_affinity;
static NUMAPolicy arg_numa_policy;
+/* A copy of the original environment block */
+static char **saved_env = NULL;
+
static int parse_configuration(const struct rlimit *saved_rlimit_nofile,
const struct rlimit *saved_rlimit_memlock);
@@ -2353,6 +2356,17 @@ static bool early_skip_setup_check(int argc, char *argv[]) {
return found_deserialize; /* When we are deserializing, then we are reexecuting, hence avoid the extensive setup */
}
+static int save_env(void) {
+ char **l;
+
+ l = strv_copy(environ);
+ if (!l)
+ return -ENOMEM;
+
+ strv_free_and_replace(saved_env, l);
+ return 0;
+}
+
int main(int argc, char *argv[]) {
dual_timestamp initrd_timestamp = DUAL_TIMESTAMP_NULL, userspace_timestamp = DUAL_TIMESTAMP_NULL, kernel_timestamp = DUAL_TIMESTAMP_NULL,
@@ -2391,9 +2405,13 @@ int main(int argc, char *argv[]) {
/* Save the original command line */
save_argc_argv(argc, argv);
- /* Save the original environment as we might need to restore it if we're requested to
- * execute another system manager later. */
- save_env();
+ /* Save the original environment as we might need to restore it if we're requested to execute another
+ * system manager later. */
+ r = save_env();
+ if (r < 0) {
+ error_message = "Failed to copy environment block";
+ goto finish;
+ }
/* Make sure that if the user says "syslog" we actually log to the journal. */
log_set_upgrade_syslog_to_journal(true);
@@ -2681,6 +2699,8 @@ finish:
arg_serialization = safe_fclose(arg_serialization);
fds = fdset_free(fds);
+ saved_env = strv_free(saved_env);
+
#if HAVE_VALGRIND_VALGRIND_H
/* If we are PID 1 and running under valgrind, then let's exit
* here explicitly. valgrind will only generate nice output on