Standard GNOME way to handle sysfs changes?

Hi, im trying to add battery charge threshold feature to gnome-control-center application, and i wonder if there is any standard (GNOME) way to handle parameters exposed in sysfs?

I will be using /sys/class/power_supply/BATT/charge_control_end_threshold file to set the threshold on kernels >= 5.4.
I assume that i can access this subsystem via libudev, but the question is - “is this the way” Or should i just use plain old write() ?

//EDIT 1
Second question, maybe i should just handle gsettings [key] state inside gnome-control-center app and create daemon + new application for handling this changes and in that way i will not pollute gnome-control-center with libudev?

//EDIT 2

This snippet i wrote is doing great, and could be converted into something like “gnome-battery-threshold-manager” along with systemd daemon which will be managed by gnome-control-center:

    struct udev *udev;
    struct udev_enumerate *enumerate;
    struct udev_list_entry *devices, *dev_list_entry;
    struct udev_device *dev;
    const char new_value[3] = {'8','0','\0'};
    /* Create the udev object */
    udev = udev_new();
    if (!udev) {
        printf("Can't create udev\n");
    /* Create a list of the devices in the 'power_supply' subsystem. */
    enumerate = udev_enumerate_new(udev);
    udev_enumerate_add_match_subsystem(enumerate, "power_supply");
    devices = udev_enumerate_get_list_entry(enumerate);
    //Go through all supported devices
    udev_list_entry_foreach(dev_list_entry, devices) {
        const char* path = udev_list_entry_get_name(dev_list_entry);
        dev = udev_device_new_from_syspath(udev, path);
        //Check if supported this device supports this attribute by reading it.
        const char* ccet = udev_device_get_sysattr_value(dev, "charge_control_end_threshold");
        if(ccet != nullptr){
            //udev_device_set_sysattr_value needs evelated privileges.
            udev_device_set_sysattr_value(dev, "charge_control_end_threshold", &new_value[0]);
    /* Free the enumerator object */

//EDIT 3
Ok, so i noticed that GNOME have their own version of libudev, called gudev and this is the native way to handle sysfs access. This topic can be closed.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.