chiark / gitweb /
units: apply default resource limits to socket/mount/swap processes too
authorLennart Poettering <lennart@poettering.net>
Thu, 19 Jul 2012 22:09:35 +0000 (00:09 +0200)
committerLennart Poettering <lennart@poettering.net>
Thu, 19 Jul 2012 22:10:32 +0000 (00:10 +0200)
src/core/mount.c
src/core/service.c
src/core/socket.c
src/core/swap.c
src/core/unit.c
src/core/unit.h

index 5709db2..83e51a7 100644 (file)
@@ -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;
         }
index 78f9a59..30598de 100644 (file)
@@ -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;
         }
index 19b463e..837b166 100644 (file)
@@ -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;
         }
index 91bb021..458e00e 100644 (file)
@@ -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;
         }
index 3b416f9..7b2f597 100644 (file)
@@ -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] = {
index f004179..2102b7a 100644 (file)
@@ -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);