@@ -342,17 +342,17 @@ static char *read_symlink(const char *syspath, const char *name)
342
342
return strdup (strrchr (link , '/' ) + 1 );
343
343
}
344
344
345
- static void set_properties_from_uevent (struct udev_device * udev_device )
345
+ static int set_properties_from_uevent (struct udev_device * udev_device , const char * syspath )
346
346
{
347
- char line [LINE_MAX ], path [PATH_MAX ], devnode [PATH_MAX ];
347
+ char line [LINE_MAX ], path [PATH_MAX + sizeof ( "/uevent" ) ], devnode [PATH_MAX ];
348
348
FILE * file ;
349
349
char * pos ;
350
350
351
- snprintf (path , sizeof (path ), "%s/uevent" , udev_device_get_syspath ( udev_device ) );
351
+ snprintf (path , sizeof (path ), "%s/uevent" , syspath );
352
352
file = fopen (path , "r" );
353
353
354
354
if (!file ) {
355
- return ;
355
+ return -1 ;
356
356
}
357
357
358
358
while (fgets (line , sizeof (line ), file )) {
@@ -364,11 +364,12 @@ static void set_properties_from_uevent(struct udev_device *udev_device)
364
364
}
365
365
else if ((pos = strchr (line , '=' ))) {
366
366
* pos = '\0' ;
367
- udev_list_entry_add (& udev_device -> properties , line , pos + 1 , 1 );
367
+ udev_list_entry_add (& udev_device -> properties , line , pos + 1 , 0 );
368
368
}
369
369
}
370
370
371
371
fclose (file );
372
+ return 0 ;
372
373
}
373
374
374
375
static void make_bit (unsigned long * arr , int cnt , const char * str )
@@ -543,21 +544,13 @@ struct udev_device *udev_device_new_from_syspath(struct udev *udev, const char *
543
544
return NULL ;
544
545
}
545
546
546
- subsystem = read_symlink (syspath , "subsystem" );
547
-
548
- if (!subsystem ) {
549
- return NULL ;
550
- }
551
-
552
547
if (!realpath (syspath , path )) {
553
- free (subsystem );
554
548
return NULL ;
555
549
}
556
550
557
551
udev_device = calloc (1 , sizeof (* udev_device ));
558
552
559
553
if (!udev_device ) {
560
- free (subsystem );
561
554
return NULL ;
562
555
}
563
556
@@ -568,11 +561,17 @@ struct udev_device *udev_device_new_from_syspath(struct udev *udev, const char *
568
561
udev_list_entry_init (& udev_device -> properties );
569
562
udev_list_entry_init (& udev_device -> sysattrs );
570
563
564
+ if (set_properties_from_uevent (udev_device , path ) == -1 ) {
565
+ free (udev_device );
566
+ return NULL ;
567
+ }
568
+
571
569
udev_list_entry_add (& udev_device -> properties , "SYSPATH" , path , 0 );
572
570
udev_list_entry_add (& udev_device -> properties , "DEVPATH" , path + 4 , 0 );
573
571
574
572
sysname = strrchr (path , '/' ) + 1 ;
575
573
driver = read_symlink (path , "driver" );
574
+ subsystem = read_symlink (path , "subsystem" );
576
575
577
576
udev_list_entry_add (& udev_device -> properties , "SUBSYSTEM" , subsystem , 0 );
578
577
udev_list_entry_add (& udev_device -> properties , "SYSNAME" , sysname , 0 );
@@ -585,7 +584,6 @@ struct udev_device *udev_device_new_from_syspath(struct udev *udev, const char *
585
584
}
586
585
}
587
586
588
- set_properties_from_uevent (udev_device );
589
587
set_properties_from_evdev (udev_device );
590
588
set_properties_from_props (udev_device );
591
589
0 commit comments