chiark / gitweb /
Make sure that keys are properly removed from hashmap
[elogind.git] / src / core / load-fragment.c
index c604f9096d0e4d33e48830e90134db6c95802ac9..14c194bf967bfc91b431bfdb96ec04b2267c5461 100644 (file)
@@ -97,9 +97,8 @@ int config_parse_unit_deps(const char* unit,
 
         UnitDependency d = ltype;
         Unit *u = userdata;
-        char *w;
+        char *w, *state;
         size_t l;
-        char *state;
 
         assert(filename);
         assert(lvalue);
@@ -2000,7 +1999,7 @@ int config_parse_unit_condition_null(const char *unit,
 }
 
 DEFINE_CONFIG_PARSE_ENUM(config_parse_notify_access, notify_access, NotifyAccess, "Failed to parse notify access specifier");
-DEFINE_CONFIG_PARSE_ENUM(config_parse_start_limit_action, start_limit_action, StartLimitAction, "Failed to parse start limit action specifier");
+DEFINE_CONFIG_PARSE_ENUM(config_parse_failure_action, failure_action, FailureAction, "Failed to parse failure action specifier");
 
 int config_parse_unit_requires_mounts_for(
                 const char *unit,
@@ -2455,6 +2454,54 @@ int config_parse_cpu_shares(
         return 0;
 }
 
+int config_parse_cpu_quota(
+                const char *unit,
+                const char *filename,
+                unsigned line,
+                const char *section,
+                unsigned section_line,
+                const char *lvalue,
+                int ltype,
+                const char *rvalue,
+                void *data,
+                void *userdata) {
+
+        CGroupContext *c = data;
+        int r;
+
+        assert(filename);
+        assert(lvalue);
+        assert(rvalue);
+
+        if (isempty(rvalue)) {
+                c->cpu_quota_per_sec_usec = (usec_t) -1;
+                c->cpu_quota_usec = (usec_t) -1;
+                return 0;
+        }
+
+        if (endswith(rvalue, "%")) {
+                double percent;
+
+                if (sscanf(rvalue, "%lf%%", &percent) != 1 || percent <= 0) {
+                        log_syntax(unit, LOG_ERR, filename, line, EINVAL, "CPU quota '%s' invalid. Ignoring.", rvalue);
+                        return 0;
+                }
+
+                c->cpu_quota_per_sec_usec = (usec_t) (percent * USEC_PER_SEC / 100);
+                c->cpu_quota_usec = (usec_t) -1;
+        } else {
+                r = parse_sec(rvalue, &c->cpu_quota_usec);
+                if (r < 0) {
+                        log_syntax(unit, LOG_ERR, filename, line, EINVAL, "CPU quota '%s' invalid. Ignoring.", rvalue);
+                        return 0;
+                }
+
+                c->cpu_quota_per_sec_usec = (usec_t) -1;
+        }
+
+        return 0;
+}
+
 int config_parse_memory_limit(
                 const char *unit,
                 const char *filename,
@@ -3387,7 +3434,7 @@ void unit_dump_config_items(FILE *f) {
                 { config_parse_unit_slice,            "SLICE" },
                 { config_parse_documentation,         "URL" },
                 { config_parse_service_timeout,       "SECONDS" },
-                { config_parse_start_limit_action,    "ACTION" },
+                { config_parse_failure_action,        "ACTION" },
                 { config_parse_set_status,            "STATUS" },
                 { config_parse_service_sockets,       "SOCKETS" },
                 { config_parse_environ,               "ENVIRON" },