tree-wide: use right cast macros for UIDs, GIDs and PIDs
authorLennart Poettering <lennart@poettering.net>
Mon, 16 Nov 2015 23:00:32 +0000 (00:00 +0100)
committerLennart Poettering <lennart@poettering.net>
Mon, 16 Nov 2015 23:52:10 +0000 (00:52 +0100)
src/basic/util.c
src/bus-proxyd/bus-xml-policy.c
src/journal/coredump-vacuum.c
src/journal/journald-server.c
src/libsystemd/sd-event/sd-event.c
src/machine/machine.c
src/machine/machined-dbus.c
src/nspawn/nspawn.c
src/remount-fs/remount-fs.c
src/udev/udevd.c

index 3e4ec42..58617b3 100644 (file)
@@ -206,7 +206,7 @@ static int do_execute(char **directories, usec_t timeout, char *argv[]) {
 
                         log_debug("Spawned %s as " PID_FMT ".", path, pid);
 
-                        r = hashmap_put(pids, UINT_TO_PTR(pid), path);
+                        r = hashmap_put(pids, PID_TO_PTR(pid), path);
                         if (r < 0)
                                 return log_oom();
                         path = NULL;
@@ -224,10 +224,10 @@ static int do_execute(char **directories, usec_t timeout, char *argv[]) {
                 _cleanup_free_ char *path = NULL;
                 pid_t pid;
 
-                pid = PTR_TO_UINT(hashmap_first_key(pids));
+                pid = PTR_TO_PID(hashmap_first_key(pids));
                 assert(pid > 0);
 
-                path = hashmap_remove(pids, UINT_TO_PTR(pid));
+                path = hashmap_remove(pids, PID_TO_PTR(pid));
                 assert(path);
 
                 wait_for_terminate_and_warn(path, pid, true);
index f0834e9..debd58c 100644 (file)
@@ -392,11 +392,11 @@ static int file_load(Policy *p, const char *path) {
                                         } else {
                                                 PolicyItem *first;
 
-                                                first = hashmap_get(p->user_items, UINT32_TO_PTR(i->uid));
+                                                first = hashmap_get(p->user_items, UID_TO_PTR(i->uid));
                                                 item_append(i, &first);
                                                 i->uid_valid = true;
 
-                                                r = hashmap_replace(p->user_items, UINT32_TO_PTR(i->uid), first);
+                                                r = hashmap_replace(p->user_items, UID_TO_PTR(i->uid), first);
                                                 if (r < 0) {
                                                         LIST_REMOVE(items, first, i);
                                                         return log_oom();
@@ -424,11 +424,11 @@ static int file_load(Policy *p, const char *path) {
                                         } else {
                                                 PolicyItem *first;
 
-                                                first = hashmap_get(p->group_items, UINT32_TO_PTR(i->gid));
+                                                first = hashmap_get(p->group_items, GID_TO_PTR(i->gid));
                                                 item_append(i, &first);
                                                 i->gid_valid = true;
 
-                                                r = hashmap_replace(p->group_items, UINT32_TO_PTR(i->gid), first);
+                                                r = hashmap_replace(p->group_items, GID_TO_PTR(i->gid), first);
                                                 if (r < 0) {
                                                         LIST_REMOVE(items, first, i);
                                                         return log_oom();
@@ -787,7 +787,7 @@ static int policy_check(Policy *p, const struct policy_check_filter *filter) {
         verdict = check_policy_items(p->default_items, filter);
 
         if (filter->gid != GID_INVALID) {
-                items = hashmap_get(p->group_items, UINT32_TO_PTR(filter->gid));
+                items = hashmap_get(p->group_items, GID_TO_PTR(filter->gid));
                 if (items) {
                         v = check_policy_items(items, filter);
                         if (v != DUNNO)
@@ -796,7 +796,7 @@ static int policy_check(Policy *p, const struct policy_check_filter *filter) {
         }
 
         if (filter->uid != UID_INVALID) {
-                items = hashmap_get(p->user_items, UINT32_TO_PTR(filter->uid));
+                items = hashmap_get(p->user_items, UID_TO_PTR(filter->uid));
                 if (items) {
                         v = check_policy_items(items, filter);
                         if (v != DUNNO)
@@ -1155,7 +1155,7 @@ static void dump_hashmap_items(Hashmap *h) {
         void *k;
 
         HASHMAP_FOREACH_KEY(i, k, h, j) {
-                printf("\t%s Item for %u:\n", draw_special_char(DRAW_ARROW), PTR_TO_UINT(k));
+                printf("\t%s Item for " UID_FMT ":\n", draw_special_char(DRAW_ARROW), PTR_TO_UID(k));
                 dump_items(i, "\t\t");
         }
 }
index 39bc2e4..65c49ce 100644 (file)
@@ -201,7 +201,7 @@ int coredump_vacuum(int exclude_fd, uint64_t keep_free, uint64_t max_use) {
 
                         t = timespec_load(&st.st_mtim);
 
-                        c = hashmap_get(h, UINT32_TO_PTR(uid));
+                        c = hashmap_get(h, UID_TO_PTR(uid));
                         if (c) {
 
                                 if (t < c->oldest_mtime) {
@@ -229,7 +229,7 @@ int coredump_vacuum(int exclude_fd, uint64_t keep_free, uint64_t max_use) {
 
                                 n->oldest_mtime = t;
 
-                                r = hashmap_put(h, UINT32_TO_PTR(uid), n);
+                                r = hashmap_put(h, UID_TO_PTR(uid), n);
                                 if (r < 0)
                                         return log_oom();
 
index b532616..a7eeafc 100644 (file)
@@ -69,6 +69,7 @@
 #include "socket-util.h"
 #include "string-table.h"
 #include "string-util.h"
+#include "user-util.h"
 
 #define USER_JOURNALS_MAX 1024
 
@@ -281,7 +282,7 @@ static JournalFile* find_journal(Server *s, uid_t uid) {
         if (r < 0)
                 return s->system_journal;
 
-        f = ordered_hashmap_get(s->user_journals, UINT32_TO_PTR(uid));
+        f = ordered_hashmap_get(s->user_journals, UID_TO_PTR(uid));
         if (f)
                 return f;
 
@@ -302,7 +303,7 @@ static JournalFile* find_journal(Server *s, uid_t uid) {
 
         server_fix_perms(s, f, uid);
 
-        r = ordered_hashmap_put(s->user_journals, UINT32_TO_PTR(uid), f);
+        r = ordered_hashmap_put(s->user_journals, UID_TO_PTR(uid), f);
         if (r < 0) {
                 journal_file_close(f);
                 return s->system_journal;
@@ -348,7 +349,7 @@ void server_rotate(Server *s) {
         (void) do_rotate(s, &s->system_journal, "system", s->seal, 0);
 
         ORDERED_HASHMAP_FOREACH_KEY(f, k, s->user_journals, i) {
-                r = do_rotate(s, &f, "user", s->seal, PTR_TO_UINT32(k));
+                r = do_rotate(s, &f, "user", s->seal, PTR_TO_UID(k));
                 if (r >= 0)
                         ordered_hashmap_replace(s->user_journals, k, f);
                 else if (!f)
index ee48867..700ac69 100644 (file)
@@ -34,6 +34,7 @@
 #include "macro.h"
 #include "missing.h"
 #include "prioq.h"
+#include "process-util.h"
 #include "set.h"
 #include "signal-util.h"
 #include "string-util.h"
@@ -808,7 +809,7 @@ static void source_disconnect(sd_event_source *s) {
                                 s->event->n_enabled_child_sources--;
                         }
 
-                        (void) hashmap_remove(s->event->child_sources, INT_TO_PTR(s->child.pid));
+                        (void) hashmap_remove(s->event->child_sources, PID_TO_PTR(s->child.pid));
                         event_gc_signal_data(s->event, &s->priority, SIGCHLD);
                 }
 
@@ -1188,7 +1189,7 @@ _public_ int sd_event_add_child(
         if (r < 0)
                 return r;
 
-        if (hashmap_contains(e->child_sources, INT_TO_PTR(pid)))
+        if (hashmap_contains(e->child_sources, PID_TO_PTR(pid)))
                 return -EBUSY;
 
         s = source_new(e, !ret, SOURCE_CHILD);
@@ -1201,7 +1202,7 @@ _public_ int sd_event_add_child(
         s->userdata = userdata;
         s->enabled = SD_EVENT_ONESHOT;
 
-        r = hashmap_put(e->child_sources, INT_TO_PTR(pid), s);
+        r = hashmap_put(e->child_sources, PID_TO_PTR(pid), s);
         if (r < 0) {
                 source_free(s);
                 return r;
index 282079f..6b1fae2 100644 (file)
@@ -38,6 +38,7 @@
 #include "machine.h"
 #include "mkdir.h"
 #include "parse-util.h"
+#include "process-util.h"
 #include "special.h"
 #include "string-table.h"
 #include "terminal-util.h"
@@ -105,7 +106,7 @@ void machine_free(Machine *m) {
                 m->manager->host_machine = NULL;
 
         if (m->leader > 0)
-                (void) hashmap_remove_value(m->manager->machine_leaders, UINT_TO_PTR(m->leader), m);
+                (void) hashmap_remove_value(m->manager->machine_leaders, PID_TO_PTR(m->leader), m);
 
         sd_bus_message_unref(m->create_message);
 
@@ -401,7 +402,7 @@ int machine_start(Machine *m, sd_bus_message *properties, sd_bus_error *error) {
         if (m->started)
                 return 0;
 
-        r = hashmap_put(m->manager->machine_leaders, UINT_TO_PTR(m->leader), m);
+        r = hashmap_put(m->manager->machine_leaders, PID_TO_PTR(m->leader), m);
         if (r < 0)
                 return r;
 
index 4ec6baa..961767c 100644 (file)
@@ -1508,7 +1508,7 @@ int manager_get_machine_by_pid(Manager *m, pid_t pid, Machine **machine) {
         assert(pid >= 1);
         assert(machine);
 
-        mm = hashmap_get(m->machine_leaders, UINT_TO_PTR(pid));
+        mm = hashmap_get(m->machine_leaders, PID_TO_PTR(pid));
         if (!mm) {
                 _cleanup_free_ char *unit = NULL;
 
index d2ce731..f6a2c03 100644 (file)
@@ -2283,7 +2283,7 @@ static int wait_for_container(pid_t pid, ContainerStatus *container) {
 static int on_orderly_shutdown(sd_event_source *s, const struct signalfd_siginfo *si, void *userdata) {
         pid_t pid;
 
-        pid = PTR_TO_UINT32(userdata);
+        pid = PTR_TO_PID(userdata);
         if (pid > 0) {
                 if (kill(pid, arg_kill_signal) >= 0) {
                         log_info("Trying to halt container. Send SIGTERM again to trigger immediate termination.");
@@ -3510,8 +3510,8 @@ int main(int argc, char *argv[]) {
 
                 if (arg_kill_signal > 0) {
                         /* Try to kill the init system on SIGINT or SIGTERM */
-                        sd_event_add_signal(event, NULL, SIGINT, on_orderly_shutdown, UINT32_TO_PTR(pid));
-                        sd_event_add_signal(event, NULL, SIGTERM, on_orderly_shutdown, UINT32_TO_PTR(pid));
+                        sd_event_add_signal(event, NULL, SIGINT, on_orderly_shutdown, PID_TO_PTR(pid));
+                        sd_event_add_signal(event, NULL, SIGTERM, on_orderly_shutdown, PID_TO_PTR(pid));
                 } else {
                         /* Immediately exit */
                         sd_event_add_signal(event, NULL, SIGINT, NULL, NULL);
index b155f99..912a426 100644 (file)
@@ -121,7 +121,7 @@ int main(int argc, char *argv[]) {
                 }
 
 
-                k = hashmap_put(pids, UINT_TO_PTR(pid), s);
+                k = hashmap_put(pids, PID_TO_PTR(pid), s);
                 if (k < 0) {
                         log_error_errno(k, "Failed to add PID to set: %m");
                         ret = EXIT_FAILURE;
@@ -143,7 +143,7 @@ int main(int argc, char *argv[]) {
                         break;
                 }
 
-                s = hashmap_remove(pids, UINT_TO_PTR(si.si_pid));
+                s = hashmap_remove(pids, PID_TO_PTR(si.si_pid));
                 if (s) {
                         if (!is_clean_exit(si.si_code, si.si_status, NULL)) {
                                 if (si.si_code == CLD_EXITED)
index 5364b92..6d9d765 100644 (file)
@@ -191,7 +191,7 @@ static void worker_free(struct worker *worker) {
 
         assert(worker->manager);
 
-        hashmap_remove(worker->manager->workers, UINT_TO_PTR(worker->pid));
+        hashmap_remove(worker->manager->workers, PID_TO_PTR(worker->pid));
         udev_monitor_unref(worker->monitor);
         event_free(worker->event);
 
@@ -234,7 +234,7 @@ static int worker_new(struct worker **ret, Manager *manager, struct udev_monitor
         if (r < 0)
                 return r;
 
-        r = hashmap_put(manager->workers, UINT_TO_PTR(pid), worker);
+        r = hashmap_put(manager->workers, PID_TO_PTR(pid), worker);
         if (r < 0)
                 return r;
 
@@ -891,7 +891,7 @@ static int on_worker(sd_event_source *s, int fd, uint32_t revents, void *userdat
                 }
 
                 /* lookup worker who sent the signal */
-                worker = hashmap_get(manager->workers, UINT_TO_PTR(ucred->pid));
+                worker = hashmap_get(manager->workers, PID_TO_PTR(ucred->pid));
                 if (!worker) {
                         log_debug("worker ["PID_FMT"] returned, but is no longer tracked", ucred->pid);
                         continue;
@@ -1195,7 +1195,7 @@ static int on_sigchld(sd_event_source *s, const struct signalfd_siginfo *si, voi
                 if (pid <= 0)
                         break;
 
-                worker = hashmap_get(manager->workers, UINT_TO_PTR(pid));
+                worker = hashmap_get(manager->workers, PID_TO_PTR(pid));
                 if (!worker) {
                         log_warning("worker ["PID_FMT"] is unknown, ignoring", pid);
                         continue;