mirror of
https://github.com/systemd/systemd.git
synced 2024-12-02 23:03:50 +08:00
tree-wide: parse permyriads wherever we can
Given that we now have a parser for permyriads, let's use it everywhere for greater accuracy. This means wherever we previously supported % and ‰, we now also support ‱.
This commit is contained in:
parent
75b86b564a
commit
fe845b5e76
@ -3593,13 +3593,13 @@ int config_parse_cpu_quota(
|
||||
return 0;
|
||||
}
|
||||
|
||||
r = parse_permille_unbounded(rvalue);
|
||||
r = parse_permyriad_unbounded(rvalue);
|
||||
if (r <= 0) {
|
||||
log_syntax(unit, LOG_WARNING, filename, line, r, "Invalid CPU quota '%s', ignoring.", rvalue);
|
||||
return 0;
|
||||
}
|
||||
|
||||
c->cpu_quota_per_sec_usec = ((usec_t) r * USEC_PER_SEC) / 1000U;
|
||||
c->cpu_quota_per_sec_usec = ((usec_t) r * USEC_PER_SEC) / 10000U;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -3664,7 +3664,7 @@ int config_parse_memory_limit(
|
||||
bytes = CGROUP_LIMIT_MIN;
|
||||
else if (!isempty(rvalue) && !streq(rvalue, "infinity")) {
|
||||
|
||||
r = parse_permille(rvalue);
|
||||
r = parse_permyriad(rvalue);
|
||||
if (r < 0) {
|
||||
r = parse_size(rvalue, 1024, &bytes);
|
||||
if (r < 0) {
|
||||
@ -3672,7 +3672,7 @@ int config_parse_memory_limit(
|
||||
return 0;
|
||||
}
|
||||
} else
|
||||
bytes = physical_memory_scale(r, 1000U);
|
||||
bytes = physical_memory_scale(r, 10000U);
|
||||
|
||||
if (bytes >= UINT64_MAX ||
|
||||
(bytes <= 0 && !STR_IN_SET(lvalue, "MemorySwapMax", "MemoryLow", "MemoryMin", "DefaultMemoryLow", "DefaultMemoryMin"))) {
|
||||
@ -3734,9 +3734,9 @@ int config_parse_tasks_max(
|
||||
return 0;
|
||||
}
|
||||
|
||||
r = parse_permille(rvalue);
|
||||
r = parse_permyriad(rvalue);
|
||||
if (r >= 0)
|
||||
*tasks_max = (TasksMax) { r, 1000U }; /* r‰ */
|
||||
*tasks_max = (TasksMax) { r, 10000U }; /* r‱ */
|
||||
else {
|
||||
r = safe_atou64(rvalue, &v);
|
||||
if (r < 0) {
|
||||
|
@ -1567,7 +1567,7 @@ static int resize_home(int argc, char *argv[], void *userdata) {
|
||||
(void) polkit_agent_open_if_enabled(arg_transport, arg_ask_password);
|
||||
|
||||
if (arg_disk_size_relative != UINT64_MAX ||
|
||||
(argc > 2 && parse_percent(argv[2]) >= 0))
|
||||
(argc > 2 && parse_permyriad(argv[2]) >= 0))
|
||||
return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP),
|
||||
"Relative disk size specification currently not supported when resizing.");
|
||||
|
||||
@ -2653,7 +2653,7 @@ static int parse_argv(int argc, char *argv[]) {
|
||||
break;
|
||||
}
|
||||
|
||||
r = parse_permille(optarg);
|
||||
r = parse_permyriad(optarg);
|
||||
if (r < 0) {
|
||||
r = parse_size(optarg, 1024, &arg_disk_size);
|
||||
if (r < 0)
|
||||
@ -2670,7 +2670,7 @@ static int parse_argv(int argc, char *argv[]) {
|
||||
arg_disk_size_relative = UINT64_MAX;
|
||||
} else {
|
||||
/* Normalize to UINT32_MAX == 100% */
|
||||
arg_disk_size_relative = (uint64_t) r * UINT32_MAX / 1000U;
|
||||
arg_disk_size_relative = (uint64_t) r * UINT32_MAX / 10000U;
|
||||
|
||||
r = drop_from_identity("diskSize");
|
||||
if (r < 0)
|
||||
|
@ -907,9 +907,9 @@ int config_parse_tmpfs_size(
|
||||
assert(data);
|
||||
|
||||
/* First, try to parse as percentage */
|
||||
r = parse_permille(rvalue);
|
||||
if (r > 0 && r < 1000)
|
||||
*sz = physical_memory_scale(r, 1000U);
|
||||
r = parse_permyriad(rvalue);
|
||||
if (r > 0)
|
||||
*sz = physical_memory_scale(r, 10000U);
|
||||
else {
|
||||
uint64_t k;
|
||||
|
||||
|
@ -334,9 +334,9 @@ static int append_session_memory_max(pam_handle_t *handle, sd_bus_message *m, co
|
||||
return PAM_SUCCESS;
|
||||
}
|
||||
|
||||
r = parse_permille(limit);
|
||||
r = parse_permyriad(limit);
|
||||
if (r >= 0) {
|
||||
r = sd_bus_message_append(m, "(sv)", "MemoryMaxScale", "u", (uint32_t) (((uint64_t) r * UINT32_MAX) / 1000U));
|
||||
r = sd_bus_message_append(m, "(sv)", "MemoryMaxScale", "u", (uint32_t) ((uint64_t) r * UINT32_MAX) / 10000U);
|
||||
if (r < 0)
|
||||
return pam_bus_log_create_error(handle, r);
|
||||
|
||||
|
@ -57,17 +57,17 @@ int tc_time_to_tick(usec_t t, uint32_t *ret) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int parse_tc_percent(const char *s, uint32_t *percent) {
|
||||
int parse_tc_percent(const char *s, uint32_t *ret_fraction) {
|
||||
int r;
|
||||
|
||||
assert(s);
|
||||
assert(percent);
|
||||
assert(ret_fraction);
|
||||
|
||||
r = parse_permille(s);
|
||||
r = parse_permyriad(s);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
*percent = (double) r / 1000 * UINT32_MAX;
|
||||
*ret_fraction = (double) r / 10000 * UINT32_MAX;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -539,7 +539,7 @@ static int bus_append_cgroup_property(sd_bus_message *m, const char *field, cons
|
||||
return 1;
|
||||
}
|
||||
|
||||
r = parse_permille(eq);
|
||||
r = parse_permyriad(eq);
|
||||
if (r >= 0) {
|
||||
char *n;
|
||||
|
||||
@ -548,7 +548,7 @@ static int bus_append_cgroup_property(sd_bus_message *m, const char *field, cons
|
||||
* size can be determined server-side. */
|
||||
|
||||
n = strjoina(field, "Scale");
|
||||
r = sd_bus_message_append(m, "(sv)", n, "u", (uint32_t) (((uint64_t) r * UINT32_MAX) / 1000U));
|
||||
r = sd_bus_message_append(m, "(sv)", n, "u", (uint32_t) (((uint64_t) r * UINT32_MAX) / 10000U));
|
||||
if (r < 0)
|
||||
return bus_log_create_error(r);
|
||||
|
||||
@ -565,14 +565,14 @@ static int bus_append_cgroup_property(sd_bus_message *m, const char *field, cons
|
||||
if (isempty(eq))
|
||||
r = sd_bus_message_append(m, "(sv)", "CPUQuotaPerSecUSec", "t", USEC_INFINITY);
|
||||
else {
|
||||
r = parse_permille_unbounded(eq);
|
||||
r = parse_permyriad_unbounded(eq);
|
||||
if (r == 0)
|
||||
return log_error_errno(SYNTHETIC_ERRNO(ERANGE),
|
||||
"CPU quota too small.");
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "CPU quota '%s' invalid.", eq);
|
||||
|
||||
r = sd_bus_message_append(m, "(sv)", "CPUQuotaPerSecUSec", "t", (((uint64_t) r * USEC_PER_SEC) / 1000U));
|
||||
r = sd_bus_message_append(m, "(sv)", "CPUQuotaPerSecUSec", "t", (((uint64_t) r * USEC_PER_SEC) / 10000U));
|
||||
}
|
||||
|
||||
if (r < 0)
|
||||
|
Loading…
Reference in New Issue
Block a user