eudev-project / eudev

Repository for eudev development
GNU General Public License v2.0
521 stars 145 forks source link

Battery status remains unchanged with eudev pre 3.2.14 and libgudev 238 #254

Closed NaofumiHonda closed 1 year ago

NaofumiHonda commented 1 year ago

This issue is completely irrelevant with a current tag implementation. A cause of the problem is that the behavior of udev_device_set_sysattr_value() in udev is recently modified so that a cache value of sysfs attr is cleared when it is called with a null pointer value. According to this change, libgudev's g_udev_device_get_sysfs_attr_uncached is quite simplified in version 238 like

   udev_device_set_sysattr_value (device->priv->udevice, name, NULL);                                 
   return g_udev_device_get_sysfs_attr (device, name);   

Under the above implementation, for example, upower always get cached values of battery state because the current eudev does not clear cached values in udev_device_set_sysattr_value() call with a null pointer value.

A solution is very easy to add the following code in udev_device_set_sysattr_value:

       if (value == NULL) {                                                                       
               struct udev_list_entry *list_entry;                                                  

               list_entry = udev_list_get_entry(&udev_device->sysattr_value_list);                  
               list_entry = udev_list_entry_get_by_name(list_entry, sysattr);                       
               if (list_entry != NULL)                                                              
                       udev_list_entry_delete(list_entry);                                          
               ret = 0;                                                                             
               goto out;                                                                            
       }                 
bbonev commented 1 year ago

Thanks! Can you make a PR with this change?