chiark / gitweb /
clock-util: clock_[sg]et_time() -> clock_[sg]et_hwclock()
[elogind.git] / src / core / load-fragment.c
index 25a39055914bf08f2c69e31d1c6d7b80afb53233..6403e411132f39834512f3239e7d7224a9c70788 100644 (file)
@@ -2430,8 +2430,7 @@ int config_parse_cpu_shares(
                 void *data,
                 void *userdata) {
 
-        CGroupContext *c = data;
-        unsigned long lu;
+        unsigned long *shares = data, lu;
         int r;
 
         assert(filename);
@@ -2439,18 +2438,17 @@ int config_parse_cpu_shares(
         assert(rvalue);
 
         if (isempty(rvalue)) {
-                c->cpu_shares = 1024;
+                *shares = (unsigned long) -1;
                 return 0;
         }
 
         r = safe_atolu(rvalue, &lu);
         if (r < 0 || lu <= 0) {
-                log_syntax(unit, LOG_ERR, filename, line, EINVAL,
-                           "CPU shares '%s' invalid. Ignoring.", rvalue);
+                log_syntax(unit, LOG_ERR, filename, line, EINVAL, "CPU shares '%s' invalid. Ignoring.", rvalue);
                 return 0;
         }
 
-        c->cpu_shares = lu;
+        *shares = lu;
         return 0;
 }
 
@@ -2467,7 +2465,7 @@ int config_parse_cpu_quota(
                 void *userdata) {
 
         CGroupContext *c = data;
-        int r;
+        double percent;
 
         assert(filename);
         assert(lvalue);
@@ -2475,30 +2473,22 @@ int config_parse_cpu_quota(
 
         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;
-                }
+        if (!endswith(rvalue, "%")) {
 
-                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;
-                }
+                log_syntax(unit, LOG_ERR, filename, line, EINVAL, "CPU quota '%s' not ending in '%%'. Ignoring.", rvalue);
+                return 0;
+        }
 
-                c->cpu_quota_per_sec_usec = (usec_t) -1;
+        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);
+
         return 0;
 }
 
@@ -2607,8 +2597,7 @@ int config_parse_blockio_weight(
                 void *data,
                 void *userdata) {
 
-        CGroupContext *c = data;
-        unsigned long lu;
+        unsigned long *weight = data, lu;
         int r;
 
         assert(filename);
@@ -2616,19 +2605,17 @@ int config_parse_blockio_weight(
         assert(rvalue);
 
         if (isempty(rvalue)) {
-                c->blockio_weight = 1000;
+                *weight = (unsigned long) -1;
                 return 0;
         }
 
         r = safe_atolu(rvalue, &lu);
         if (r < 0 || lu < 10 || lu > 1000) {
-                log_syntax(unit, LOG_ERR, filename, line, EINVAL,
-                           "Block IO weight '%s' invalid. Ignoring.", rvalue);
+                log_syntax(unit, LOG_ERR, filename, line, EINVAL, "Block IO weight '%s' invalid. Ignoring.", rvalue);
                 return 0;
         }
 
-        c->blockio_weight = lu;
-
+        *weight = lu;
         return 0;
 }
 
@@ -2666,8 +2653,7 @@ int config_parse_blockio_device_weight(
         n = strcspn(rvalue, WHITESPACE);
         weight = rvalue + n;
         if (!*weight) {
-                log_syntax(unit, LOG_ERR, filename, line, EINVAL,
-                           "Expected block device and device weight. Ignoring.");
+                log_syntax(unit, LOG_ERR, filename, line, EINVAL, "Expected block device and device weight. Ignoring.");
                 return 0;
         }
 
@@ -2676,20 +2662,17 @@ int config_parse_blockio_device_weight(
                 return log_oom();
 
         if (!path_startswith(path, "/dev")) {
-                log_syntax(unit, LOG_ERR, filename, line, EINVAL,
-                           "Invalid device node path '%s'. Ignoring.", path);
+                log_syntax(unit, LOG_ERR, filename, line, EINVAL, "Invalid device node path '%s'. Ignoring.", path);
                 return 0;
         }
 
         weight += strspn(weight, WHITESPACE);
         r = safe_atolu(weight, &lu);
         if (r < 0 || lu < 10 || lu > 1000) {
-                log_syntax(unit, LOG_ERR, filename, line, EINVAL,
-                           "Block IO weight '%s' invalid. Ignoring.", rvalue);
+                log_syntax(unit, LOG_ERR, filename, line, EINVAL, "Block IO weight '%s' invalid. Ignoring.", rvalue);
                 return 0;
         }
 
-
         w = new0(CGroupBlockIODeviceWeight, 1);
         if (!w)
                 return log_oom();