1818#include "fd-util.h"
1919#include "format-util.h"
2020#include "fs-util.h"
21- #include "libudev-private.h"
2221#include "logind.h"
2322#include "parse-util.h"
2423#include "process-util.h"
@@ -127,10 +126,6 @@ static Manager* manager_unref(Manager *m) {
127126 sd_event_source_unref (m -> wall_message_timeout_source );
128127
129128 sd_event_source_unref (m -> console_active_event_source );
130- sd_event_source_unref (m -> udev_seat_event_source );
131- sd_event_source_unref (m -> udev_device_event_source );
132- sd_event_source_unref (m -> udev_vcsa_event_source );
133- sd_event_source_unref (m -> udev_button_event_source );
134129 sd_event_source_unref (m -> lid_switch_ignore_event_source );
135130
136131#if ENABLE_UTMP
@@ -139,10 +134,10 @@ static Manager* manager_unref(Manager *m) {
139134
140135 safe_close (m -> console_active_fd );
141136
142- udev_monitor_unref (m -> udev_seat_monitor );
143- udev_monitor_unref (m -> udev_device_monitor );
144- udev_monitor_unref (m -> udev_vcsa_monitor );
145- udev_monitor_unref (m -> udev_button_monitor );
137+ sd_device_monitor_unref (m -> device_seat_monitor );
138+ sd_device_monitor_unref (m -> device_monitor );
139+ sd_device_monitor_unref (m -> device_vcsa_monitor );
140+ sd_device_monitor_unref (m -> device_button_monitor );
146141
147142 if (m -> unlink_nologin )
148143 (void ) unlink_or_warn ("/run/nologin" );
@@ -540,72 +535,52 @@ static int manager_enumerate_inhibitors(Manager *m) {
540535 return r ;
541536}
542537
543- static int manager_dispatch_seat_udev (sd_event_source * s , int fd , uint32_t revents , void * userdata ) {
544- _cleanup_ (sd_device_unrefp ) sd_device * d = NULL ;
538+ static int manager_dispatch_seat_udev (sd_device_monitor * monitor , sd_device * device , void * userdata ) {
545539 Manager * m = userdata ;
546- int r ;
547540
548541 assert (m );
542+ assert (device );
549543
550- r = udev_monitor_receive_sd_device (m -> udev_seat_monitor , & d );
551- if (r < 0 )
552- return r ;
553-
554- manager_process_seat_device (m , d );
544+ manager_process_seat_device (m , device );
555545 return 0 ;
556546}
557547
558- static int manager_dispatch_device_udev (sd_event_source * s , int fd , uint32_t revents , void * userdata ) {
559- _cleanup_ (sd_device_unrefp ) sd_device * d = NULL ;
548+ static int manager_dispatch_device_udev (sd_device_monitor * monitor , sd_device * device , void * userdata ) {
560549 Manager * m = userdata ;
561- int r ;
562550
563551 assert (m );
552+ assert (device );
564553
565- r = udev_monitor_receive_sd_device (m -> udev_device_monitor , & d );
566- if (r < 0 )
567- return r ;
568-
569- manager_process_seat_device (m , d );
554+ manager_process_seat_device (m , device );
570555 return 0 ;
571556}
572557
573- static int manager_dispatch_vcsa_udev (sd_event_source * s , int fd , uint32_t revents , void * userdata ) {
574- _cleanup_ (sd_device_unrefp ) sd_device * d = NULL ;
558+ static int manager_dispatch_vcsa_udev (sd_device_monitor * monitor , sd_device * device , void * userdata ) {
575559 Manager * m = userdata ;
576560 const char * name , * action ;
577- int r ;
578561
579562 assert (m );
580-
581- r = udev_monitor_receive_sd_device (m -> udev_vcsa_monitor , & d );
582- if (r < 0 )
583- return r ;
563+ assert (device );
584564
585565 /* Whenever a VCSA device is removed try to reallocate our
586566 * VTs, to make sure our auto VTs never go away. */
587567
588- if (sd_device_get_sysname (d , & name ) >= 0 &&
568+ if (sd_device_get_sysname (device , & name ) >= 0 &&
589569 startswith (name , "vcsa" ) &&
590- sd_device_get_property_value (d , "ACTION" , & action ) >= 0 &&
570+ sd_device_get_property_value (device , "ACTION" , & action ) >= 0 &&
591571 streq (action , "remove" ))
592572 seat_preallocate_vts (m -> seat0 );
593573
594574 return 0 ;
595575}
596576
597- static int manager_dispatch_button_udev (sd_event_source * s , int fd , uint32_t revents , void * userdata ) {
598- _cleanup_ (sd_device_unrefp ) sd_device * d = NULL ;
577+ static int manager_dispatch_button_udev (sd_device_monitor * monitor , sd_device * device , void * userdata ) {
599578 Manager * m = userdata ;
600- int r ;
601579
602580 assert (m );
581+ assert (device );
603582
604- r = udev_monitor_receive_sd_device (m -> udev_button_monitor , & d );
605- if (r < 0 )
606- return r ;
607-
608- manager_process_button_device (m , d );
583+ manager_process_button_device (m , device );
609584 return 0 ;
610585}
611586
@@ -844,90 +819,90 @@ static int manager_connect_udev(Manager *m) {
844819 int r ;
845820
846821 assert (m );
847- assert (!m -> udev_seat_monitor );
848- assert (!m -> udev_device_monitor );
849- assert (!m -> udev_vcsa_monitor );
850- assert (!m -> udev_button_monitor );
822+ assert (!m -> device_seat_monitor );
823+ assert (!m -> device_monitor );
824+ assert (!m -> device_vcsa_monitor );
825+ assert (!m -> device_button_monitor );
851826
852- m -> udev_seat_monitor = udev_monitor_new_from_netlink ( NULL , "udev" );
853- if (! m -> udev_seat_monitor )
854- return - ENOMEM ;
827+ r = sd_device_monitor_new ( & m -> device_seat_monitor );
828+ if (r < 0 )
829+ return r ;
855830
856- r = udev_monitor_filter_add_match_tag (m -> udev_seat_monitor , "master-of-seat" );
831+ r = sd_device_monitor_filter_add_match_tag (m -> device_seat_monitor , "master-of-seat" );
857832 if (r < 0 )
858833 return r ;
859834
860- r = udev_monitor_enable_receiving (m -> udev_seat_monitor );
835+ r = sd_device_monitor_attach_event (m -> device_seat_monitor , m -> event , 0 );
861836 if (r < 0 )
862837 return r ;
863838
864- r = sd_event_add_io (m -> event , & m -> udev_seat_event_source , udev_monitor_get_fd ( m -> udev_seat_monitor ), EPOLLIN , manager_dispatch_seat_udev , m );
839+ r = sd_device_monitor_start (m -> device_seat_monitor , manager_dispatch_seat_udev , m , "logind-seat-monitor" );
865840 if (r < 0 )
866841 return r ;
867842
868- m -> udev_device_monitor = udev_monitor_new_from_netlink ( NULL , "udev" );
869- if (! m -> udev_device_monitor )
870- return - ENOMEM ;
843+ r = sd_device_monitor_new ( & m -> device_monitor );
844+ if (r < 0 )
845+ return r ;
871846
872- r = udev_monitor_filter_add_match_subsystem_devtype (m -> udev_device_monitor , "input" , NULL );
847+ r = sd_device_monitor_filter_add_match_subsystem_devtype (m -> device_monitor , "input" , NULL );
873848 if (r < 0 )
874849 return r ;
875850
876- r = udev_monitor_filter_add_match_subsystem_devtype (m -> udev_device_monitor , "graphics" , NULL );
851+ r = sd_device_monitor_filter_add_match_subsystem_devtype (m -> device_monitor , "graphics" , NULL );
877852 if (r < 0 )
878853 return r ;
879854
880- r = udev_monitor_filter_add_match_subsystem_devtype (m -> udev_device_monitor , "drm" , NULL );
855+ r = sd_device_monitor_filter_add_match_subsystem_devtype (m -> device_monitor , "drm" , NULL );
881856 if (r < 0 )
882857 return r ;
883858
884- r = udev_monitor_enable_receiving (m -> udev_device_monitor );
859+ r = sd_device_monitor_attach_event (m -> device_monitor , m -> event , 0 );
885860 if (r < 0 )
886861 return r ;
887862
888- r = sd_event_add_io (m -> event , & m -> udev_device_event_source , udev_monitor_get_fd ( m -> udev_device_monitor ), EPOLLIN , manager_dispatch_device_udev , m );
863+ r = sd_device_monitor_start (m -> device_monitor , manager_dispatch_device_udev , m , "logind-device-monitor" );
889864 if (r < 0 )
890865 return r ;
891866
892867 /* Don't watch keys if nobody cares */
893868 if (!manager_all_buttons_ignored (m )) {
894- m -> udev_button_monitor = udev_monitor_new_from_netlink ( NULL , "udev" );
895- if (! m -> udev_button_monitor )
896- return - ENOMEM ;
869+ r = sd_device_monitor_new ( & m -> device_button_monitor );
870+ if (r < 0 )
871+ return r ;
897872
898- r = udev_monitor_filter_add_match_tag (m -> udev_button_monitor , "power-switch" );
873+ r = sd_device_monitor_filter_add_match_tag (m -> device_button_monitor , "power-switch" );
899874 if (r < 0 )
900875 return r ;
901876
902- r = udev_monitor_filter_add_match_subsystem_devtype (m -> udev_button_monitor , "input" , NULL );
877+ r = sd_device_monitor_filter_add_match_subsystem_devtype (m -> device_button_monitor , "input" , NULL );
903878 if (r < 0 )
904879 return r ;
905880
906- r = udev_monitor_enable_receiving (m -> udev_button_monitor );
881+ r = sd_device_monitor_attach_event (m -> device_button_monitor , m -> event , 0 );
907882 if (r < 0 )
908883 return r ;
909884
910- r = sd_event_add_io (m -> event , & m -> udev_button_event_source , udev_monitor_get_fd ( m -> udev_button_monitor ), EPOLLIN , manager_dispatch_button_udev , m );
885+ r = sd_device_monitor_start (m -> device_button_monitor , manager_dispatch_button_udev , m , "logind-button-monitor" );
911886 if (r < 0 )
912887 return r ;
913888 }
914889
915890 /* Don't bother watching VCSA devices, if nobody cares */
916891 if (m -> n_autovts > 0 && m -> console_active_fd >= 0 ) {
917892
918- m -> udev_vcsa_monitor = udev_monitor_new_from_netlink ( NULL , "udev" );
919- if (! m -> udev_vcsa_monitor )
920- return - ENOMEM ;
893+ r = sd_device_monitor_new ( & m -> device_vcsa_monitor );
894+ if (r < 0 )
895+ return r ;
921896
922- r = udev_monitor_filter_add_match_subsystem_devtype (m -> udev_vcsa_monitor , "vc" , NULL );
897+ r = sd_device_monitor_filter_add_match_subsystem_devtype (m -> device_vcsa_monitor , "vc" , NULL );
923898 if (r < 0 )
924899 return r ;
925900
926- r = udev_monitor_enable_receiving (m -> udev_vcsa_monitor );
901+ r = sd_device_monitor_attach_event (m -> device_vcsa_monitor , m -> event , 0 );
927902 if (r < 0 )
928903 return r ;
929904
930- r = sd_event_add_io (m -> event , & m -> udev_vcsa_event_source , udev_monitor_get_fd ( m -> udev_vcsa_monitor ), EPOLLIN , manager_dispatch_vcsa_udev , m );
905+ r = sd_device_monitor_start (m -> device_vcsa_monitor , manager_dispatch_vcsa_udev , m , "logind-vcsa-monitor" );
931906 if (r < 0 )
932907 return r ;
933908 }
0 commit comments