Support binary, switch-type proximity sensors. They are are exposed over the
input subsystem, emitting the SW_FRONT_PROXIMITY event code.
Also provide simple tests, based on the tests for evdev-based accelerometers.
Fixes#363
The enable_sensors() function has an error preventing sensor
disabling: it checks if the sensor is already enabled and does nothing
even if we need to disable it.
Also, there is lack of error handling in the _write_sysfs_int()
function: the result of fprintf() is not checked. If some error occurs
during writing to the sysfs attribute, it is ignored.
Fix these errors and change the order of sysfs attribute writing during
device releasing to avoid "Device or resource busy" errors (a buffer
should be disabled before scan elements).
Gracefully stop the main loop and release used drivers upon receiving a
termination signal.
Without this, iio kernel drivers are not released, and modules cannot
be unloaded after iio-sensor-proxy termination.
Moving multiple files into a non existent target folder won't work.
Just move the whole directory instead.
While at that list the folder content so we get an idea what CI
produced.
That would be used in the cm36651 kernel driver, as well as devices with
multiple channels, such as combined proximity and light sensors, which use
"illuminance_clear" as the channel name.
dbus supports policy files in both /usr/share/dbus-1/system.d and
/etc/dbus-1/systemd. The recently released dbus 1.14.0, officially
deprecates installing packages' default policies into /etc/dbus-1/systemd,
instead reserving it for the sysadmin. This is the same idea as the
difference between /usr/lib/udev/rules.d and /etc/udev/rules.d.
See https://bugs.debian.org/1006631
Add 2 tests for parsing the *sampling_frequency_available sysfs attribute
and then picking the closest supported value higher then the desired 10 Hz:
1: Check whether the sampling frequency gets corrected to >= 10Hz,
integer numbers sorted low to high
2: Check whether the sampling frequency gets corrected to >= 10Hz,
double numbers sorted high to low
Some iio drivers only accept sampling_frequency values listed in
sampling_frequency_available and will reject any other values with
an EINVAL error.
This causes iio_fixup_sampling_frequency() to fail to fixup
the sampling rate making screen-rotation really really slow on
e.g. devices where the st_accel driver is used.
Add support for parsing sampling_frequency_available and pick
a value from there to fix this.
As part of this also switch to using g_ascii_dtostr() to format
the string to write so that numbers which are not whole can be
represented.
Hotplugged sensors were not working because of the missing
DEVICE_FOR_TYPE entry.
Logged error message:
driver_set_polling: assertion 'sensor_device' failed
Fixes: 4baa1f ("main: Make it possible to instantiate multiple drivers")
We forgot to "steal" the pointer before returning from the function
successfully, so the file descriptor was closed. Oops.
Fixes: cc11240 ("fake-input-accelerometer: Simplify error paths")
sysfs usually appends newlines at the end of attributes to make them
easier to consume, but the test suite can't test for that.
** (iio-sensor-proxy:4882): WARNING **: 14:14:46.792: Possible failure in string write of 'accel_3d-dev0
' Should be 'accel_3d-dev0' written to /sys/devices/platform/AMDI0010:02/i2c-2/i2c-BMA250E:00/0018:6243:0001.0002/HID-SENSOR-200073.2.auto/iio:device0/trigger/current_trigger
Closes: #347
Fixes: ac053f8a12
From Coverity:
iio-sensor-proxy-3.3/src/iio-sensor-proxy.c:727:16: warning[deadcode.DeadStores]: Value stored to 'orientation' during its initialization is never read
From Coverity:
iio-sensor-proxy-3.3/src/iio-buffer-utils.c:435: dont_call: "fscanf" assumes an arbitrarily long string, so callers must use correct precision specifiers or never use "fscanf".
This also fixes the temp variable being reused to parse the contents of
the sysfs file before being freed. How this behaves depends on the
length of the sysfs file path and the length of the string inside the
file.
On error, the channel info would just be left unfreed.
From Coverity:
iio-sensor-proxy-3.3/src/iio-buffer-utils.c:330: leaked_storage: Variable "current" going out of scope leaks the storage it points to.
iio-sensor-proxy-3.3/src/iio-buffer-utils.c:312: leaked_storage: Variable "current" going out of scope leaks the storage it points to.
iio-sensor-proxy-3.3/src/iio-buffer-utils.c:304: leaked_storage: Variable "current" going out of scope leaks the storage it points to.
iio-sensor-proxy-3.3/src/iio-buffer-utils.c:302: leaked_storage: Variable "current" going out of scope leaks the storage it points to.
iio-sensor-proxy-3.3/src/iio-buffer-utils.c:293: leaked_storage: Variable "current" going out of scope leaks the storage it points to.
iio-sensor-proxy-3.3/src/iio-buffer-utils.c:289: leaked_storage: Variable "current" going out of scope leaks the storage it points to.
iio-sensor-proxy-3.3/src/iio-buffer-utils.c:350:2: warning[unix.Malloc]: Potential leak of memory pointed to by 'current'
From Coverity:
iio-sensor-proxy-3.3/src/iio-buffer-utils.c:769: noescape: Resource "buffer_data" is not freed or pointed-to in "buffer_drv_data_free".
iio-sensor-proxy-3.3/src/iio-buffer-utils.c:770:3: warning[unix.Malloc]: Potential leak of memory pointed to by 'buffer_data'
From Coverity:
iio-sensor-proxy-3.3/src/accel-mount-matrix.c:86: check_return: Calling "parse_mount_matrix" without checking return value (as is done elsewhere 10 out of 11 times).
From Coverity:
iio-sensor-proxy-3.3/src/iio-sensor-proxy.c:964: check_return: Calling "g_setenv("G_MESSAGES_DEBUG", "all", 1)" without checking return value. This library function may fail and return an error code.
From Coverity:
iio-sensor-proxy-3.3/src/iio-buffer-utils.c:111: overwrite_var: Overwriting "filename" in "filename = g_build_filename(device_dir, "scan_elements", builtname, NULL)" leaks the storage that "filename" points to.
WARNING: You should add the boolean check kwarg to the run_command call.
It currently defaults to false,
but it will default to true in future releases of meson.
See also: https://github.com/mesonbuild/meson/issues/9300
In c7fb43e0, we added a buffer driver for ambient light sensors, but we
added it to the list of drivers in a way that would favour polling
drivers. Since we started using IIO_SENSOR_PROXY_TYPE to tag devices,
and as those can support multiple drivers, we need to prefer the buffer
driver as it's the one that doesn't require constant monitoring.
This also fixes operations on some Dell laptops where the polling driver
is completely broken.
See https://gitlab.freedesktop.org/hadess/iio-sensor-proxy/-/merge_requests/352
Check whether a particular user/D-Bus client is allowed to claim a
sensor.
The ClaimCompass method on net.hadess.SensorProxy.Compass doesn't have a
check as only the geoclue user is allowed to access this interface, as
per the D-Bus configuration.