]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core: make the LimitXYZ= properties settable for transient service units
authorLennart Poettering <lennart@poettering.net>
Wed, 5 Mar 2014 02:49:00 +0000 (03:49 +0100)
committerLennart Poettering <lennart@poettering.net>
Wed, 5 Mar 2014 03:08:04 +0000 (04:08 +0100)
src/core/dbus-execute.c
src/libsystemd/sd-bus/bus-util.c

index 4c3ad6582507e85307248586702a8a1930ac0c28..bf4a682d3a9b6f018fc5c3a2709bd38aafa42f61 100644 (file)
@@ -850,6 +850,44 @@ int bus_exec_context_set_transient_property(
                         unit_write_drop_in_private_format(u, mode, name, "Environment=%s\n", joined);
                 }
 
+                return 1;
+
+        } else if (rlimit_from_string(name) >= 0) {
+                uint64_t rl;
+                rlim_t x;
+
+                r = sd_bus_message_read(message, "t", &rl);
+                if (r < 0)
+                        return r;
+
+                if (rl == (uint64_t) -1)
+                        x = RLIM_INFINITY;
+                else {
+                        x = (rlim_t) rl;
+
+                        if ((uint64_t) x != rl)
+                                return -ERANGE;
+                }
+
+                if (mode != UNIT_CHECK) {
+                        int z;
+
+                        z = rlimit_from_string(name);
+
+                        if (!c->rlimit[z]) {
+                                c->rlimit[z] = new(struct rlimit, 1);
+                                if (!c->rlimit[z])
+                                        return -ENOMEM;
+                        }
+
+                        c->rlimit[z]->rlim_cur = c->rlimit[z]->rlim_max = x;
+
+                        if (x == RLIM_INFINITY)
+                                unit_write_drop_in_private_format(u, mode, name, "%s=infinity\n", name);
+                        else
+                                unit_write_drop_in_private_format(u, mode, name, "%s=%" PRIu64 "\n", name, rl);
+                }
+
                 return 1;
         }
 
index 40aab2a88c7c42874ce26b0c52c8b249ae6d9d7e..d0ae43da4ed06da74672ab1342534369e6bde490 100644 (file)
@@ -1372,6 +1372,21 @@ int bus_append_unit_property_assignment(sd_bus_message *m, const char *assignmen
                         r = sd_bus_message_append(m, "v", "a(st)", path, u);
                 }
 
+        } else if (rlimit_from_string(field) >= 0) {
+                uint64_t rl;
+
+                if (streq(eq, "infinity"))
+                        rl = (uint64_t) -1;
+                else {
+                        r = safe_atou64(eq, &rl);
+                        if (r < 0) {
+                                log_error("Invalid resource limit: %s", eq);
+                                return -EINVAL;
+                        }
+                }
+
+                r = sd_bus_message_append(m, "v", "t", rl);
+
         } else {
                 log_error("Unknown assignment %s.", assignment);
                 return -EINVAL;