summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2012-07-20 00:09:35 +0200
committerLennart Poettering <lennart@poettering.net>2012-07-20 00:10:32 +0200
commitcba6e0627d659a33df31aaa74d0d701c4bc9f317 (patch)
treee973cc904a6f703a4a1836d130e16d4cc780bf28 /src
parentc74f17d96cccd4cc998fd037cb92046930188c91 (diff)
units: apply default resource limits to socket/mount/swap processes too
Diffstat (limited to 'src')
-rw-r--r--src/core/mount.c2
-rw-r--r--src/core/service.c6
-rw-r--r--src/core/socket.c2
-rw-r--r--src/core/swap.c2
-rw-r--r--src/core/unit.c26
-rw-r--r--src/core/unit.h2
6 files changed, 25 insertions, 15 deletions
diff --git a/src/core/mount.c b/src/core/mount.c
index 5709db2266..83e51a7aba 100644
--- a/src/core/mount.c
+++ b/src/core/mount.c
@@ -634,7 +634,7 @@ static int mount_load(Unit *u) {
if (r < 0)
return r;
- r = unit_patch_working_directory(UNIT(m), &m->exec_context);
+ r = unit_exec_context_defaults(u, &m->exec_context);
if (r < 0)
return r;
}
diff --git a/src/core/service.c b/src/core/service.c
index 78f9a59c7f..30598de9b8 100644
--- a/src/core/service.c
+++ b/src/core/service.c
@@ -130,7 +130,6 @@ static const UnitActiveState state_translation_table_idle[_SERVICE_STATE_MAX] =
static void service_init(Unit *u) {
Service *s = SERVICE(u);
- int i;
assert(u);
assert(u->load_state == UNIT_STUB);
@@ -150,9 +149,6 @@ static void service_init(Unit *u) {
s->guess_main_pid = true;
exec_context_init(&s->exec_context);
- for (i = 0; i < RLIMIT_NLIMITS; i++)
- if (UNIT(s)->manager->rlimit[i])
- s->exec_context.rlimit[i] = newdup(struct rlimit, UNIT(s)->manager->rlimit[i], 1);
kill_context_init(&s->kill_context);
RATELIMIT_INIT(s->start_limit, 10*USEC_PER_SEC, 5);
@@ -1284,7 +1280,7 @@ static int service_load(Unit *u) {
if ((r = service_add_default_dependencies(s)) < 0)
return r;
- r = unit_patch_working_directory(UNIT(s), &s->exec_context);
+ r = unit_exec_context_defaults(u, &s->exec_context);
if (r < 0)
return r;
}
diff --git a/src/core/socket.c b/src/core/socket.c
index 19b463e6a4..837b166e3b 100644
--- a/src/core/socket.c
+++ b/src/core/socket.c
@@ -374,7 +374,7 @@ static int socket_load(Unit *u) {
if ((r = socket_add_default_dependencies(s)) < 0)
return r;
- r = unit_patch_working_directory(UNIT(s), &s->exec_context);
+ r = unit_exec_context_defaults(u, &s->exec_context);
if (r < 0)
return r;
}
diff --git a/src/core/swap.c b/src/core/swap.c
index 91bb0215b1..458e00efe5 100644
--- a/src/core/swap.c
+++ b/src/core/swap.c
@@ -296,7 +296,7 @@ static int swap_load(Unit *u) {
if ((r = swap_add_default_dependencies(s)) < 0)
return r;
- r = unit_patch_working_directory(UNIT(s), &s->exec_context);
+ r = unit_exec_context_defaults(u, &s->exec_context);
if (r < 0)
return r;
}
diff --git a/src/core/unit.c b/src/core/unit.c
index 3b416f945f..7b2f597589 100644
--- a/src/core/unit.c
+++ b/src/core/unit.c
@@ -2816,17 +2816,31 @@ int unit_add_mount_links(Unit *u) {
return 0;
}
-int unit_patch_working_directory(Unit *u, ExecContext *c) {
+int unit_exec_context_defaults(Unit *u, ExecContext *c) {
+ unsigned i;
+ int r;
+
assert(u);
assert(c);
- if (u->manager->running_as != MANAGER_USER)
- return 0;
+ /* This only copies in the ones that need memory */
- if (c->working_directory)
- return 0;
+ for (i = 0; i < RLIMIT_NLIMITS; i++)
+ if (u->manager->rlimit[i] && !c->rlimit[i]) {
+ c->rlimit[i] = newdup(struct rlimit, u->manager->rlimit[i], 1);
+ if (!c->rlimit[i])
+ return -ENOMEM;
+ }
+
+ if (u->manager->running_as == MANAGER_USER &&
+ !c->working_directory) {
- return get_home_dir(&c->working_directory);
+ r = get_home_dir(&c->working_directory);
+ if (r < 0)
+ return r;
+ }
+
+ return 0;
}
static const char* const unit_active_state_table[_UNIT_ACTIVE_STATE_MAX] = {
diff --git a/src/core/unit.h b/src/core/unit.h
index f004179894..2102b7a570 100644
--- a/src/core/unit.h
+++ b/src/core/unit.h
@@ -536,7 +536,7 @@ void unit_ref_unset(UnitRef *ref);
int unit_add_one_mount_link(Unit *u, Mount *m);
int unit_add_mount_links(Unit *u);
-int unit_patch_working_directory(Unit *u, ExecContext *c);
+int unit_exec_context_defaults(Unit *u, ExecContext *c);
const char *unit_active_state_to_string(UnitActiveState i);
UnitActiveState unit_active_state_from_string(const char *s);