mirror of
https://github.com/systemd/systemd-stable.git
synced 2024-12-25 23:21:33 +03:00
unit: use safe downcasts, remove pointless casts
Always use the macros for downcasting. Remove a few obviously pointless casts.
This commit is contained in:
parent
1124fe6f01
commit
595ed347a8
@ -143,7 +143,7 @@ static int automount_add_mount_links(Automount *a) {
|
||||
assert(a);
|
||||
|
||||
LIST_FOREACH(units_by_type, other, UNIT(a)->manager->units_by_type[UNIT_MOUNT])
|
||||
if ((r = automount_add_one_mount_link(a, (Mount*) other)) < 0)
|
||||
if ((r = automount_add_one_mount_link(a, MOUNT(other))) < 0)
|
||||
return r;
|
||||
|
||||
return 0;
|
||||
|
@ -269,7 +269,7 @@ int config_parse_socket_listen(
|
||||
assert(rvalue);
|
||||
assert(data);
|
||||
|
||||
s = (Socket*) data;
|
||||
s = SOCKET(data);
|
||||
|
||||
if (!(p = new0(SocketPort, 1)))
|
||||
return -ENOMEM;
|
||||
@ -380,7 +380,7 @@ int config_parse_socket_bind(
|
||||
assert(rvalue);
|
||||
assert(data);
|
||||
|
||||
s = (Socket*) data;
|
||||
s = SOCKET(data);
|
||||
|
||||
if ((b = socket_address_bind_ipv6_only_from_string(rvalue)) < 0) {
|
||||
int r;
|
||||
|
@ -306,15 +306,15 @@ fail:
|
||||
}
|
||||
|
||||
static unsigned manager_dispatch_cleanup_queue(Manager *m) {
|
||||
Unit *meta;
|
||||
Unit *u;
|
||||
unsigned n = 0;
|
||||
|
||||
assert(m);
|
||||
|
||||
while ((meta = m->cleanup_queue)) {
|
||||
assert(meta->in_cleanup_queue);
|
||||
while ((u = m->cleanup_queue)) {
|
||||
assert(u->in_cleanup_queue);
|
||||
|
||||
unit_free((Unit*) meta);
|
||||
unit_free(u);
|
||||
n++;
|
||||
}
|
||||
|
||||
@ -382,7 +382,7 @@ good:
|
||||
}
|
||||
|
||||
static unsigned manager_dispatch_gc_queue(Manager *m) {
|
||||
Unit *meta;
|
||||
Unit *u;
|
||||
unsigned n = 0;
|
||||
unsigned gc_marker;
|
||||
|
||||
@ -401,21 +401,21 @@ static unsigned manager_dispatch_gc_queue(Manager *m) {
|
||||
|
||||
gc_marker = m->gc_marker;
|
||||
|
||||
while ((meta = m->gc_queue)) {
|
||||
assert(meta->in_gc_queue);
|
||||
while ((u = m->gc_queue)) {
|
||||
assert(u->in_gc_queue);
|
||||
|
||||
unit_gc_sweep((Unit*) meta, gc_marker);
|
||||
unit_gc_sweep(u, gc_marker);
|
||||
|
||||
LIST_REMOVE(Unit, gc_queue, m->gc_queue, meta);
|
||||
meta->in_gc_queue = false;
|
||||
LIST_REMOVE(Unit, gc_queue, m->gc_queue, u);
|
||||
u->in_gc_queue = false;
|
||||
|
||||
n++;
|
||||
|
||||
if (meta->gc_marker == gc_marker + GC_OFFSET_BAD ||
|
||||
meta->gc_marker == gc_marker + GC_OFFSET_UNSURE) {
|
||||
log_debug("Collecting %s", meta->id);
|
||||
meta->gc_marker = gc_marker + GC_OFFSET_BAD;
|
||||
unit_add_to_cleanup_queue((Unit*) meta);
|
||||
if (u->gc_marker == gc_marker + GC_OFFSET_BAD ||
|
||||
u->gc_marker == gc_marker + GC_OFFSET_UNSURE) {
|
||||
log_debug("Collecting %s", u->id);
|
||||
u->gc_marker = gc_marker + GC_OFFSET_BAD;
|
||||
unit_add_to_cleanup_queue(u);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1768,7 +1768,7 @@ Unit *manager_get_unit(Manager *m, const char *name) {
|
||||
}
|
||||
|
||||
unsigned manager_dispatch_load_queue(Manager *m) {
|
||||
Unit *meta;
|
||||
Unit *u;
|
||||
unsigned n = 0;
|
||||
|
||||
assert(m);
|
||||
@ -1782,10 +1782,10 @@ unsigned manager_dispatch_load_queue(Manager *m) {
|
||||
/* Dispatches the load queue. Takes a unit from the queue and
|
||||
* tries to load its data until the queue is empty */
|
||||
|
||||
while ((meta = m->load_queue)) {
|
||||
assert(meta->in_load_queue);
|
||||
while ((u = m->load_queue)) {
|
||||
assert(u->in_load_queue);
|
||||
|
||||
unit_load((Unit*) meta);
|
||||
unit_load(u);
|
||||
n++;
|
||||
}
|
||||
|
||||
@ -1929,7 +1929,7 @@ unsigned manager_dispatch_run_queue(Manager *m) {
|
||||
|
||||
unsigned manager_dispatch_dbus_queue(Manager *m) {
|
||||
Job *j;
|
||||
Unit *meta;
|
||||
Unit *u;
|
||||
unsigned n = 0;
|
||||
|
||||
assert(m);
|
||||
@ -1939,10 +1939,10 @@ unsigned manager_dispatch_dbus_queue(Manager *m) {
|
||||
|
||||
m->dispatching_dbus_queue = true;
|
||||
|
||||
while ((meta = m->dbus_unit_queue)) {
|
||||
assert(meta->in_dbus_queue);
|
||||
while ((u = m->dbus_unit_queue)) {
|
||||
assert(u->in_dbus_queue);
|
||||
|
||||
bus_unit_send_change_signal((Unit*) meta);
|
||||
bus_unit_send_change_signal(u);
|
||||
n++;
|
||||
}
|
||||
|
||||
|
20
src/mount.c
20
src/mount.c
@ -160,7 +160,7 @@ static int mount_add_mount_links(Mount *m) {
|
||||
* above us in the hierarchy */
|
||||
|
||||
LIST_FOREACH(units_by_type, other, UNIT(m)->manager->units_by_type[UNIT_MOUNT]) {
|
||||
Mount *n = (Mount*) other;
|
||||
Mount *n = MOUNT(other);
|
||||
MountParameters *pn;
|
||||
|
||||
if (n == m)
|
||||
@ -217,7 +217,7 @@ static int mount_add_swap_links(Mount *m) {
|
||||
assert(m);
|
||||
|
||||
LIST_FOREACH(units_by_type, other, UNIT(m)->manager->units_by_type[UNIT_SWAP])
|
||||
if ((r = swap_add_one_mount_link((Swap*) other, m)) < 0)
|
||||
if ((r = swap_add_one_mount_link(SWAP(other), m)) < 0)
|
||||
return r;
|
||||
|
||||
return 0;
|
||||
@ -230,7 +230,7 @@ static int mount_add_path_links(Mount *m) {
|
||||
assert(m);
|
||||
|
||||
LIST_FOREACH(units_by_type, other, UNIT(m)->manager->units_by_type[UNIT_PATH])
|
||||
if ((r = path_add_one_mount_link((Path*) other, m)) < 0)
|
||||
if ((r = path_add_one_mount_link(PATH(other), m)) < 0)
|
||||
return r;
|
||||
|
||||
return 0;
|
||||
@ -243,7 +243,7 @@ static int mount_add_automount_links(Mount *m) {
|
||||
assert(m);
|
||||
|
||||
LIST_FOREACH(units_by_type, other, UNIT(m)->manager->units_by_type[UNIT_AUTOMOUNT])
|
||||
if ((r = automount_add_one_mount_link((Automount*) other, m)) < 0)
|
||||
if ((r = automount_add_one_mount_link(AUTOMOUNT(other), m)) < 0)
|
||||
return r;
|
||||
|
||||
return 0;
|
||||
@ -256,7 +256,7 @@ static int mount_add_socket_links(Mount *m) {
|
||||
assert(m);
|
||||
|
||||
LIST_FOREACH(units_by_type, other, UNIT(m)->manager->units_by_type[UNIT_SOCKET])
|
||||
if ((r = socket_add_one_mount_link((Socket*) other, m)) < 0)
|
||||
if ((r = socket_add_one_mount_link(SOCKET(other), m)) < 0)
|
||||
return r;
|
||||
|
||||
return 0;
|
||||
@ -1679,7 +1679,7 @@ fail:
|
||||
}
|
||||
|
||||
void mount_fd_event(Manager *m, int events) {
|
||||
Unit *meta;
|
||||
Unit *u;
|
||||
int r;
|
||||
|
||||
assert(m);
|
||||
@ -1693,8 +1693,8 @@ void mount_fd_event(Manager *m, int events) {
|
||||
log_error("Failed to reread /proc/self/mountinfo: %s", strerror(-r));
|
||||
|
||||
/* Reset flags, just in case, for later calls */
|
||||
LIST_FOREACH(units_by_type, meta, m->units_by_type[UNIT_MOUNT]) {
|
||||
Mount *mount = (Mount*) meta;
|
||||
LIST_FOREACH(units_by_type, u, m->units_by_type[UNIT_MOUNT]) {
|
||||
Mount *mount = MOUNT(u);
|
||||
|
||||
mount->is_mounted = mount->just_mounted = mount->just_changed = false;
|
||||
}
|
||||
@ -1704,8 +1704,8 @@ void mount_fd_event(Manager *m, int events) {
|
||||
|
||||
manager_dispatch_load_queue(m);
|
||||
|
||||
LIST_FOREACH(units_by_type, meta, m->units_by_type[UNIT_MOUNT]) {
|
||||
Mount *mount = (Mount*) meta;
|
||||
LIST_FOREACH(units_by_type, u, m->units_by_type[UNIT_MOUNT]) {
|
||||
Mount *mount = MOUNT(u);
|
||||
|
||||
if (!mount->is_mounted) {
|
||||
/* This has just been unmounted. */
|
||||
|
@ -287,7 +287,7 @@ static int path_add_mount_links(Path *p) {
|
||||
assert(p);
|
||||
|
||||
LIST_FOREACH(units_by_type, other, UNIT(p)->manager->units_by_type[UNIT_MOUNT])
|
||||
if ((r = path_add_one_mount_link(p, (Mount*) other)) < 0)
|
||||
if ((r = path_add_one_mount_link(p, MOUNT(other))) < 0)
|
||||
return r;
|
||||
|
||||
return 0;
|
||||
|
@ -376,7 +376,7 @@ static int sysv_fix_order(Service *s) {
|
||||
UnitDependency d;
|
||||
bool special_s, special_t;
|
||||
|
||||
t = (Service*) other;
|
||||
t = SERVICE(other);
|
||||
|
||||
if (s == t)
|
||||
continue;
|
||||
@ -1023,7 +1023,7 @@ static int fsck_fix_order(Service *s) {
|
||||
Service *t;
|
||||
UnitDependency d;
|
||||
|
||||
t = (Service*) other;
|
||||
t = SERVICE(other);
|
||||
|
||||
if (s == t)
|
||||
continue;
|
||||
|
@ -274,7 +274,7 @@ static int socket_add_mount_links(Socket *s) {
|
||||
assert(s);
|
||||
|
||||
LIST_FOREACH(units_by_type, other, UNIT(s)->manager->units_by_type[UNIT_MOUNT])
|
||||
if ((r = socket_add_one_mount_link(s, (Mount*) other)) < 0)
|
||||
if ((r = socket_add_one_mount_link(s, MOUNT(other))) < 0)
|
||||
return r;
|
||||
|
||||
return 0;
|
||||
|
12
src/swap.c
12
src/swap.c
@ -157,7 +157,7 @@ static int swap_add_mount_links(Swap *s) {
|
||||
assert(s);
|
||||
|
||||
LIST_FOREACH(units_by_type, other, UNIT(s)->manager->units_by_type[UNIT_MOUNT])
|
||||
if ((r = swap_add_one_mount_link(s, (Mount*) other)) < 0)
|
||||
if ((r = swap_add_one_mount_link(s, MOUNT(other))) < 0)
|
||||
return r;
|
||||
|
||||
return 0;
|
||||
@ -1096,7 +1096,7 @@ int swap_dispatch_reload(Manager *m) {
|
||||
}
|
||||
|
||||
int swap_fd_event(Manager *m, int events) {
|
||||
Unit *meta;
|
||||
Unit *u;
|
||||
int r;
|
||||
|
||||
assert(m);
|
||||
@ -1106,8 +1106,8 @@ int swap_fd_event(Manager *m, int events) {
|
||||
log_error("Failed to reread /proc/swaps: %s", strerror(-r));
|
||||
|
||||
/* Reset flags, just in case, for late calls */
|
||||
LIST_FOREACH(units_by_type, meta, m->units_by_type[UNIT_SWAP]) {
|
||||
Swap *swap = (Swap*) meta;
|
||||
LIST_FOREACH(units_by_type, u, m->units_by_type[UNIT_SWAP]) {
|
||||
Swap *swap = SWAP(u);
|
||||
|
||||
swap->is_active = swap->just_activated = false;
|
||||
}
|
||||
@ -1117,8 +1117,8 @@ int swap_fd_event(Manager *m, int events) {
|
||||
|
||||
manager_dispatch_load_queue(m);
|
||||
|
||||
LIST_FOREACH(units_by_type, meta, m->units_by_type[UNIT_SWAP]) {
|
||||
Swap *swap = (Swap*) meta;
|
||||
LIST_FOREACH(units_by_type, u, m->units_by_type[UNIT_SWAP]) {
|
||||
Swap *swap = SWAP(u);
|
||||
|
||||
if (!swap->is_active) {
|
||||
/* This has just been deactivated */
|
||||
|
Loading…
Reference in New Issue
Block a user