g_timeout_set_expiration() expects DBUS_SESSION_BUS_ADDRESS to contain machine-unique ID
I was looking at the implementation of g_timeout_add_seconds()
and I noticed that it uses DBUS_SESSION_BUS_ADDRESS
to generate a machine-specific offset:
/*
* we want a per machine/session unique 'random' value; try the dbus
* address first, that has a UUID in it. If there is no dbus, use the
* hostname for hashing.
*/
const char *session_bus_address = g_getenv ("DBUS_SESSION_BUS_ADDRESS");
if (!session_bus_address)
session_bus_address = g_getenv ("HOSTNAME");
if (session_bus_address)
timer_perturb = ABS ((gint) g_str_hash (session_bus_address)) % 1000000;
else
timer_perturb = 0;
This doesn't work anymore because nowadays DBUS_SESSION_BUS_ADDRESS
is non-unique ("unix:path=/run/user/1000/bus"
). The obvious replacement would be reading /etc/machine-id
, but I don't know if introducing file i/o is worth it. Maybe HOSTNAME
alone is sufficient?
From the original bugzilla thread:
[ I might imagine that long-term it would be good to have a per-computer random time within the second to fire timeouts rather than always firing at usecs=0, since a common thing that is going to be done in timeouts is access network resources. And NTP is pretty common these days. ]
P.S. This comment in the same function doesn't match the implementation since 121ce56f. My understanding of the current behavior is that it selects the first 'mark' that is less than 0.25s earlier than the desired interval.