@@ -349,32 +349,34 @@ static int device_setup_unit(Manager *m, struct udev_device *dev, const char *pa
349349 return log_error_errno (r , "Failed to generate unit name from device path: %m" );
350350
351351 u = manager_get_unit (m , e );
352-
353- /* The device unit can still be present even if the device was
354- * unplugged: a mount unit can reference it hence preventing
355- * the GC to have garbaged it. That's desired since the device
356- * unit may have a dependency on the mount unit which was
357- * added during the loading of the later. */
358- if (dev && u && DEVICE (u )-> state == DEVICE_PLUGGED ) {
359- /* This unit is in plugged state: we're sure it's
360- * attached to a device. */
361- if (!path_equal (DEVICE (u )-> sysfs , sysfs )) {
362- log_unit_debug (u , "Dev %s appeared twice with different sysfs paths %s and %s" ,
363- e , DEVICE (u )-> sysfs , sysfs );
364- return - EEXIST ;
352+ if (u ) {
353+ /* The device unit can still be present even if the device was unplugged: a mount unit can reference it hence
354+ * preventing the GC to have garbaged it. That's desired since the device unit may have a dependency on the
355+ * mount unit which was added during the loading of the later. */
356+ if (dev && DEVICE (u )-> state == DEVICE_PLUGGED ) {
357+
358+ /* This unit is in plugged state: we're sure it's attached to a device. */
359+ if (!path_equal (DEVICE (u )-> sysfs , sysfs )) {
360+ log_unit_debug (u , "Dev %s appeared twice with different sysfs paths %s and %s" ,
361+ e , DEVICE (u )-> sysfs , sysfs );
362+ return - EEXIST ;
363+ }
365364 }
366- }
367365
368- if (!u ) {
366+ delete = false;
367+
368+ /* Let's remove all dependencies generated due to udev properties. We'll readd whatever is configured
369+ * now below. */
370+ unit_remove_dependencies (u , UNIT_DEPENDENCY_UDEV );
371+ } else {
369372 delete = true;
370373
371374 r = unit_new_for_name (m , sizeof (Device ), e , & u );
372375 if (r < 0 )
373376 goto fail ;
374377
375378 unit_add_to_load_queue (u );
376- } else
377- delete = false;
379+ }
378380
379381 /* If this was created via some dependency and has not
380382 * actually been seen yet ->sysfs will not be
@@ -398,8 +400,7 @@ static int device_setup_unit(Manager *m, struct udev_device *dev, const char *pa
398400 if (dev && device_is_bound_by_mounts (DEVICE (u ), dev ))
399401 device_upgrade_mount_deps (u );
400402
401- /* Note that this won't dispatch the load queue, the caller
402- * has to do that if needed and appropriate */
403+ /* Note that this won't dispatch the load queue, the caller has to do that if needed and appropriate */
403404
404405 unit_add_to_dbus_queue (u );
405406 return 0 ;
0 commit comments