return bus_send_error_reply(connection, message, &error, -EINVAL);
dev = makedev(major, minor);
- assert_cc(sizeof(unsigned long) >= sizeof(dev_t));
-
- sd = hashmap_get(s->devices, ULONG_TO_PTR((unsigned long)dev));
+ sd = hashmap_get(s->devices, &dev);
if (sd) {
/* We don't allow retrieving a device multiple times.
* The related ReleaseDevice call is not ref-counted.
} else if (dbus_message_is_method_call(message, "org.freedesktop.login1.Session", "ReleaseDevice")) {
SessionDevice *sd;
uint32_t major, minor;
+ dev_t dev;
if (!session_is_controller(s, bus_message_get_sender_with_fallback(message)))
return bus_send_error_reply(connection, message, NULL, -EPERM);
DBUS_TYPE_INVALID))
return bus_send_error_reply(connection, message, &error, -EINVAL);
- sd = hashmap_get(s->devices, ULONG_TO_PTR((unsigned long)makedev(major, minor)));
+ dev = makedev(major, minor);
+ sd = hashmap_get(s->devices, &dev);
if (!sd)
return bus_send_error_reply(connection, message, NULL, -ENODEV);
} else if (dbus_message_is_method_call(message, "org.freedesktop.login1.Session", "PauseDeviceComplete")) {
SessionDevice *sd;
uint32_t major, minor;
+ dev_t dev;
if (!session_is_controller(s, bus_message_get_sender_with_fallback(message)))
return bus_send_error_reply(connection, message, NULL, -EPERM);
DBUS_TYPE_INVALID))
return bus_send_error_reply(connection, message, &error, -EINVAL);
- sd = hashmap_get(s->devices, ULONG_TO_PTR((unsigned long)makedev(major, minor)));
+ dev = makedev(major, minor);
+ sd = hashmap_get(s->devices, &dev);
if (!sd)
return bus_send_error_reply(connection, message, NULL, -ENODEV);
if (r < 0)
goto error;
- assert_cc(sizeof(unsigned long) >= sizeof(dev_t));
-
- r = hashmap_put(s->devices, ULONG_TO_PTR((unsigned long)sd->dev), sd);
+ r = hashmap_put(s->devices, &sd->dev, sd);
if (r < 0) {
r = -ENOMEM;
goto error;
return 0;
error:
- hashmap_remove(s->devices, ULONG_TO_PTR((unsigned long)sd->dev));
+ hashmap_remove(s->devices, &sd->dev);
free(sd->node);
free(sd);
return r;
LIST_REMOVE(SessionDevice, sd_by_device, sd->device->session_devices, sd);
- hashmap_remove(sd->session->devices, ULONG_TO_PTR((unsigned long)sd->dev));
+ hashmap_remove(sd->session->devices, &sd->dev);
free(sd->node);
free(sd);
#include "dbus-common.h"
#include "logind-session.h"
+static unsigned devt_hash_func(const void *p) {
+ uint64_t u = *(const dev_t*)p;
+
+ return uint64_hash_func(&u);
+}
+
+static int devt_compare_func(const void *_a, const void *_b) {
+ dev_t a, b;
+
+ a = *(const dev_t*) _a;
+ b = *(const dev_t*) _b;
+
+ return a < b ? -1 : (a > b ? 1 : 0);
+}
+
Session* session_new(Manager *m, const char *id) {
Session *s;
return NULL;
}
- s->devices = hashmap_new(trivial_hash_func, trivial_compare_func);
+ s->devices = hashmap_new(devt_hash_func, devt_compare_func);
if (!s->devices) {
free(s->state_file);
free(s);