1
0
mirror of https://github.com/systemd/systemd.git synced 2024-12-25 01:34:28 +03:00

Merge pull request #18325 from ssahani/more-cleanup

Tree wide various cleanup
This commit is contained in:
Luca Boccassi 2021-01-20 20:48:18 +00:00 committed by GitHub
commit 7504f599e1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 37 additions and 71 deletions

View File

@ -1022,7 +1022,6 @@ static int list_dependencies(sd_bus *bus, const char *name) {
static int analyze_critical_chain(int argc, char *argv[], void *userdata) {
_cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL;
_cleanup_(unit_times_freep) struct unit_times *times = NULL;
struct unit_times *u;
Hashmap *h;
int n, r;
@ -1038,7 +1037,7 @@ static int analyze_critical_chain(int argc, char *argv[], void *userdata) {
if (!h)
return log_oom();
for (u = times; u->has_data; u++) {
for (struct unit_times *u = times; u->has_data; u++) {
r = hashmap_put(h, u->name, u);
if (r < 0)
return log_error_errno(r, "Failed to add entry to hashmap: %m");
@ -1065,7 +1064,6 @@ static int analyze_blame(int argc, char *argv[], void *userdata) {
_cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL;
_cleanup_(unit_times_freep) struct unit_times *times = NULL;
_cleanup_(table_unrefp) Table *table = NULL;
struct unit_times *u;
TableCell *cell;
int n, r;
@ -1105,7 +1103,7 @@ static int analyze_blame(int argc, char *argv[], void *userdata) {
if (r < 0)
return r;
for (u = times; u->has_data; u++) {
for (struct unit_times *u = times; u->has_data; u++) {
if (u->time <= 0)
continue;

View File

@ -673,7 +673,7 @@ int btrfs_qgroup_get_quota(const char *path, uint64_t qgroupid, BtrfsQuotaInfo *
int btrfs_subvol_find_subtree_qgroup(int fd, uint64_t subvol_id, uint64_t *ret) {
uint64_t level, lowest = (uint64_t) -1, lowest_qgroupid = 0;
_cleanup_free_ uint64_t *qgroups = NULL;
int r, n, i;
int r, n;
assert(fd >= 0);
assert(ret);
@ -703,7 +703,7 @@ int btrfs_subvol_find_subtree_qgroup(int fd, uint64_t subvol_id, uint64_t *ret)
if (n < 0)
return n;
for (i = 0; i < n; i++) {
for (int i = 0; i < n; i++) {
uint64_t id;
r = btrfs_qgroupid_split(qgroups[i], &level, &id);
@ -824,7 +824,6 @@ int btrfs_qgroup_set_limit_fd(int fd, uint64_t qgroupid, uint64_t referenced_max
.lim.max_rfer = referenced_max,
.lim.flags = BTRFS_QGROUP_LIMIT_MAX_RFER,
};
unsigned c;
int r;
assert(fd >= 0);
@ -843,7 +842,7 @@ int btrfs_qgroup_set_limit_fd(int fd, uint64_t qgroupid, uint64_t referenced_max
args.qgroupid = qgroupid;
for (c = 0;; c++) {
for (unsigned c = 0;; c++) {
if (ioctl(fd, BTRFS_IOC_QGROUP_LIMIT, &args) < 0) {
if (errno == EBUSY && c < 10) {
@ -924,7 +923,6 @@ static int qgroup_create_or_destroy(int fd, bool b, uint64_t qgroupid) {
.create = b,
.qgroupid = qgroupid,
};
unsigned c;
int r;
r = btrfs_is_filesystem(fd);
@ -933,7 +931,7 @@ static int qgroup_create_or_destroy(int fd, bool b, uint64_t qgroupid) {
if (r == 0)
return -ENOTTY;
for (c = 0;; c++) {
for (unsigned c = 0;; c++) {
if (ioctl(fd, BTRFS_IOC_QGROUP_CREATE, &args) < 0) {
/* On old kernels if quota is not enabled, we get EINVAL. On newer kernels we get
@ -968,7 +966,7 @@ int btrfs_qgroup_destroy(int fd, uint64_t qgroupid) {
int btrfs_qgroup_destroy_recursive(int fd, uint64_t qgroupid) {
_cleanup_free_ uint64_t *qgroups = NULL;
uint64_t subvol_id;
int i, n, r;
int n, r;
/* Destroys the specified qgroup, but unassigns it from all
* its parents first. Also, it recursively destroys all
@ -983,7 +981,7 @@ int btrfs_qgroup_destroy_recursive(int fd, uint64_t qgroupid) {
if (n < 0)
return n;
for (i = 0; i < n; i++) {
for (int i = 0; i < n; i++) {
uint64_t id;
r = btrfs_qgroupid_split(qgroups[i], NULL, &id);
@ -1043,7 +1041,6 @@ static int qgroup_assign_or_unassign(int fd, bool b, uint64_t child, uint64_t pa
.src = child,
.dst = parent,
};
unsigned c;
int r;
r = btrfs_is_filesystem(fd);
@ -1052,7 +1049,7 @@ static int qgroup_assign_or_unassign(int fd, bool b, uint64_t child, uint64_t pa
if (r == 0)
return -ENOTTY;
for (c = 0;; c++) {
for (unsigned c = 0;; c++) {
r = ioctl(fd, BTRFS_IOC_QGROUP_ASSIGN, &args);
if (r < 0) {
if (errno == EBUSY && c < 10) {
@ -1351,7 +1348,7 @@ int btrfs_qgroup_copy_limits(int fd, uint64_t old_qgroupid, uint64_t new_qgroupi
static int copy_quota_hierarchy(int fd, uint64_t old_subvol_id, uint64_t new_subvol_id) {
_cleanup_free_ uint64_t *old_qgroups = NULL, *old_parent_qgroups = NULL;
bool copy_from_parent = false, insert_intermediary_qgroup = false;
int n_old_qgroups, n_old_parent_qgroups, r, i;
int n_old_qgroups, n_old_parent_qgroups, r;
uint64_t old_parent_id;
assert(fd >= 0);
@ -1375,9 +1372,8 @@ static int copy_quota_hierarchy(int fd, uint64_t old_subvol_id, uint64_t new_sub
return n_old_parent_qgroups;
}
for (i = 0; i < n_old_qgroups; i++) {
for (int i = 0; i < n_old_qgroups; i++) {
uint64_t id;
int j;
r = btrfs_qgroupid_split(old_qgroups[i], NULL, &id);
if (r < 0)
@ -1392,7 +1388,7 @@ static int copy_quota_hierarchy(int fd, uint64_t old_subvol_id, uint64_t new_sub
break;
}
for (j = 0; j < n_old_parent_qgroups; j++)
for (int j = 0; j < n_old_parent_qgroups; j++)
if (old_parent_qgroups[j] == old_qgroups[i])
/* The old subvolume shared a common
* parent qgroup with its parent
@ -1880,12 +1876,11 @@ int btrfs_subvol_auto_qgroup_fd(int fd, uint64_t subvol_id, bool insert_intermed
if (insert_intermediary_qgroup) {
uint64_t lowest = 256, new_qgroupid;
bool created = false;
int i;
/* Determine the lowest qgroup that the parent
* subvolume is assigned to. */
for (i = 0; i < n; i++) {
for (int i = 0; i < n; i++) {
uint64_t level;
r = btrfs_qgroupid_split(qgroups[i], &level, NULL);
@ -1910,7 +1905,7 @@ int btrfs_subvol_auto_qgroup_fd(int fd, uint64_t subvol_id, bool insert_intermed
if (r >= 0)
changed = created = true;
for (i = 0; i < n; i++) {
for (int i = 0; i < n; i++) {
r = btrfs_qgroup_assign(fd, new_qgroupid, qgroups[i]);
if (r < 0 && r != -EEXIST) {
if (created)

View File

@ -732,15 +732,13 @@ _public_ int sd_device_monitor_filter_add_match_subsystem_devtype(sd_device_moni
return -ENOMEM;
}
r = hashmap_ensure_allocated(&m->subsystem_filter, NULL);
r = hashmap_ensure_put(&m->subsystem_filter, NULL, s, d);
if (r < 0)
return r;
r = hashmap_put(m->subsystem_filter, s, d);
if (r < 0)
return r;
TAKE_PTR(s);
TAKE_PTR(d);
s = d = NULL;
m->filter_uptodate = false;
return 0;

View File

@ -629,10 +629,6 @@ static int event_make_signal_data(
return 0;
}
} else {
r = hashmap_ensure_allocated(&e->signal_data, &uint64_hash_ops);
if (r < 0)
return r;
d = new(struct signal_data, 1);
if (!d)
return -ENOMEM;
@ -643,7 +639,7 @@ static int event_make_signal_data(
.priority = priority,
};
r = hashmap_put(e->signal_data, &d->priority, d);
r = hashmap_ensure_put(&e->signal_data, &uint64_hash_ops, &d->priority, d);
if (r < 0) {
free(d);
return r;
@ -1727,10 +1723,6 @@ static int event_make_inotify_data(
fd = fd_move_above_stdio(fd);
r = hashmap_ensure_allocated(&e->inotify_data, &uint64_hash_ops);
if (r < 0)
return r;
d = new(struct inotify_data, 1);
if (!d)
return -ENOMEM;
@ -1741,7 +1733,7 @@ static int event_make_inotify_data(
.priority = priority,
};
r = hashmap_put(e->inotify_data, &d->priority, d);
r = hashmap_ensure_put(&e->inotify_data, &uint64_hash_ops, &d->priority, d);
if (r < 0) {
d->fd = safe_close(d->fd);
free(d);

View File

@ -63,7 +63,7 @@ static bool journal_pid_changed(sd_journal *j) {
}
static int journal_put_error(sd_journal *j, int r, const char *path) {
char *copy;
_cleanup_free_ char *copy = NULL;
int k;
/* Memorize an error we encountered, and store which
@ -80,27 +80,21 @@ static int journal_put_error(sd_journal *j, int r, const char *path) {
if (r >= 0)
return r;
k = hashmap_ensure_allocated(&j->errors, NULL);
if (k < 0)
return k;
if (path) {
copy = strdup(path);
if (!copy)
return -ENOMEM;
} else
copy = NULL;
}
k = hashmap_put(j->errors, INT_TO_PTR(r), copy);
k = hashmap_ensure_put(&j->errors, NULL, INT_TO_PTR(r), copy);
if (k < 0) {
free(copy);
if (k == -EEXIST)
return 0;
return k;
}
TAKE_PTR(copy);
return 0;
}

View File

@ -217,10 +217,6 @@ int manager_write_brightness(
return 0;
}
r = hashmap_ensure_allocated(&m->brightness_writers, &brightness_writer_hash_ops);
if (r < 0)
return log_oom();
w = new(BrightnessWriter, 1);
if (!w)
return log_oom();
@ -234,9 +230,12 @@ int manager_write_brightness(
if (!w->path)
return log_oom();
r = hashmap_put(m->brightness_writers, w->path, w);
r = hashmap_ensure_put(&m->brightness_writers, &brightness_writer_hash_ops, w->path, w);
if (r == -ENOMEM)
return log_oom();
if (r < 0)
return log_error_errno(r, "Failed to add brightness writer to hashmap: %m");
w->manager = m;
r = set_add_message(&w->current_messages, message);

View File

@ -390,10 +390,6 @@ static int image_object_find(sd_bus *bus, const char *path, const char *interfac
return 1;
}
r = hashmap_ensure_allocated(&m->image_cache, &image_hash_ops);
if (r < 0)
return r;
if (!m->image_cache_defer_event) {
r = sd_event_add_defer(m->event, &m->image_cache_defer_event, image_flush_cache, m);
if (r < 0)
@ -416,7 +412,7 @@ static int image_object_find(sd_bus *bus, const char *path, const char *interfac
image->userdata = m;
r = hashmap_put(m->image_cache, image->name, image);
r = hashmap_ensure_put(&m->image_cache, &image_hash_ops, image->name, image);
if (r < 0) {
image_unref(image);
return r;

View File

@ -1544,11 +1544,9 @@ int config_parse_address_generation_type(
token->prefix = buffer.in6;
}
r = ordered_set_ensure_allocated(&network->ipv6_tokens, &ipv6_token_hash_ops);
if (r < 0)
r = ordered_set_ensure_put(&network->ipv6_tokens, &ipv6_token_hash_ops, token);
if (r == -ENOMEM)
return log_oom();
r = ordered_set_put(network->ipv6_tokens, token);
if (r == -EEXIST)
log_syntax(unit, LOG_DEBUG, filename, line, r,
"IPv6 token '%s' is duplicated, ignoring: %m", rvalue);

View File

@ -805,11 +805,9 @@ int config_parse_stacked_netdev(const char *unit,
if (!name)
return log_oom();
r = hashmap_ensure_allocated(h, &string_hash_ops);
if (r < 0)
r = hashmap_ensure_put(h, &string_hash_ops, name, INT_TO_PTR(kind));
if (r == -ENOMEM)
return log_oom();
r = hashmap_put(*h, name, INT_TO_PTR(kind));
if (r < 0)
log_syntax(unit, LOG_WARNING, filename, line, r,
"Cannot add NetDev '%s' to network, ignoring assignment: %m", name);
@ -817,7 +815,7 @@ int config_parse_stacked_netdev(const char *unit,
log_syntax(unit, LOG_DEBUG, filename, line, r,
"NetDev '%s' specified twice, ignoring.", name);
else
name = NULL;
TAKE_PTR(name);
return 0;
}

View File

@ -2147,19 +2147,17 @@ static int udev_rule_apply_token_to_event(
if (IN_SET(token->op, OP_ASSIGN, OP_ASSIGN_FINAL))
ordered_hashmap_clear_free_key(event->run_list);
r = ordered_hashmap_ensure_allocated(&event->run_list, NULL);
if (r < 0)
return log_oom();
(void) udev_event_apply_format(event, token->value, buf, sizeof(buf), false);
cmd = strdup(buf);
if (!cmd)
return log_oom();
r = ordered_hashmap_put(event->run_list, cmd, token->data);
if (r < 0)
r = ordered_hashmap_ensure_put(&event->run_list, NULL, cmd, token->data);
if (r == -ENOMEM)
return log_oom();
if (r < 0)
return log_rule_error_errno(dev, rules, r, "Failed to store command '%s': %m", cmd);
TAKE_PTR(cmd);