chiark / gitweb /
unit: use safe downcasts, remove pointless casts
authorMichal Schmidt <mschmidt@redhat.com>
Sun, 15 Jan 2012 11:37:16 +0000 (12:37 +0100)
committerMichal Schmidt <mschmidt@redhat.com>
Mon, 16 Jan 2012 12:34:42 +0000 (13:34 +0100)
Always use the macros for downcasting.
Remove a few obviously pointless casts.

src/automount.c
src/load-fragment.c
src/manager.c
src/mount.c
src/path.c
src/service.c
src/socket.c
src/swap.c

index 3c75335c20c5b8dd6da8013955b25372ff6f6c26..aa38492f10858e72759484d196f535e48f3461ba 100644 (file)
@@ -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;
index 0961d945aa3a2d042fc29389019d2bf032dd2ccf..deae2dc0abaf70e716d0ede0fb023c8d1148b137 100644 (file)
@@ -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;
index 43460f15913fae58958cf6122d8dfa755326ef5a..bab16627064abbe4572c44b03bfae8d3801e1be4 100644 (file)
@@ -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++;
         }
 
index 5c45686c2a0806d6f80e8bf7506cb7a8112b2e0b..6d0af4ef711555397762281b1caa4eb38d46fc89 100644 (file)
@@ -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. */
index c8086a8d1927c84e92fdd0d4ea0478b604b59d08..a16d3fa0f2d06cc4c4f0e274e0a9d2e8bc638235 100644 (file)
@@ -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;
index a84cee16af9e7e06811ce8d89d52fabeea3cc5ea..0a5c35ec96b7bcff45f0ecdf796ebb818f30b95f 100644 (file)
@@ -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;
index e0ddcef1b3710edd2a5c692a38deac50da8a862a..b2bb080263ee9b637b9ef498056903ad03a3c384 100644 (file)
@@ -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;
index ff62b1dc4b3adcc59197fbb2ba3e14ed948b65ad..b4a5b3c084794320f71dd5cac11ab899d9601431 100644 (file)
@@ -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 */