* indefinitely for plugged in devices, something which cannot
* happen for the other units since their operations time out
* anyway. */
- u->job_timeout = u->manager->default_timeout_start_usec;
+ u->job_running_timeout = u->manager->default_timeout_start_usec;
u->ignore_on_isolate = true;
}
}
}
+static bool device_is_bound_by_mounts(Unit *d, struct udev_device *dev) {
+ const char *bound_by;
+ int r = false;
+
+ assert(d);
+ assert(dev);
+
+ bound_by = udev_device_get_property_value(dev, "SYSTEMD_MOUNT_DEVICE_BOUND");
+ if (bound_by)
+ r = parse_boolean(bound_by) > 0;
+
+ DEVICE(d)->bind_mounts = r;
+ return r;
+}
+
+static int device_upgrade_mount_deps(Unit *u) {
+ Unit *other;
+ Iterator i;
+ int r;
+
+ SET_FOREACH(other, u->dependencies[UNIT_REQUIRED_BY], i) {
+ if (other->type != UNIT_MOUNT)
+ continue;
+
+ r = unit_add_dependency(other, UNIT_BINDS_TO, u, true);
+ if (r < 0)
+ return r;
+ }
+ return 0;
+}
+
static int device_setup_unit(Manager *m, struct udev_device *dev, const char *path, bool main) {
_cleanup_free_ char *e = NULL;
const char *sysfs = NULL;
(void) device_add_udev_wants(u, dev);
}
+ /* So the user wants the mount units to be bound to the device but a
+ * mount unit might has been seen by systemd before the device appears
+ * on its radar. In this case the device unit is partially initialized
+ * and includes the deps on the mount unit but at that time the "bind
+ * mounts" flag wasn't not present. Fix this up now. */
+ if (dev && device_is_bound_by_mounts(u, dev))
+ device_upgrade_mount_deps(u);
/* Note that this won't dispatch the load queue, the caller
* has to do that if needed and appropriate */
* aliases */
alias = udev_device_get_property_value(dev, "SYSTEMD_ALIAS");
for (;;) {
- _cleanup_free_ char *word = NULL, *k = NULL;
+ _cleanup_free_ char *word = NULL;
r = extract_first_word(&alias, &word, NULL, EXTRACT_QUOTES);
if (r == 0)
* now referenced by the kernel, then we assume the
* kernel knows it now, and udev might soon too. */
device_set_state(d, DEVICE_TENTATIVE);
- else
+ else {
/* If nobody sees the device, or if the device was
* previously seen by udev and now is only referenced
* from the kernel, then we consider the device is
* gone, the kernel just hasn't noticed it yet. */
+
device_set_state(d, DEVICE_DEAD);
+ device_unset_sysfs(d);
+ }
+
}
static int device_update_found_by_sysfs(Manager *m, const char *sysfs, bool add, DeviceFound found, bool now) {
- Device *d, *l;
+ Device *d, *l, *n;
assert(m);
assert(sysfs);
return 0;
l = hashmap_get(m->devices_by_sysfs, sysfs);
- LIST_FOREACH(same_sysfs, d, l)
+ LIST_FOREACH_SAFE(same_sysfs, d, n, l)
device_update_found_one(d, add, found, now);
return 0;
return device_update_found_by_name(m, node, add, found, now);
}
+bool device_shall_be_bound_by(Unit *device, Unit *u) {
+
+ if (u->type != UNIT_MOUNT)
+ return false;
+
+ return DEVICE(device)->bind_mounts;
+}
+
const UnitVTable device_vtable = {
.object_size = sizeof(Device),
.sections =
"Device\0"
"Install\0",
+ .gc_jobs = true,
+
.init = device_init,
.done = device_done,
.load = unit_load_fragment_and_dropin_optional,