Commit 0e9f72cb authored by spiiroin's avatar spiiroin

[settings] Do not write dynamic data to /etc. Fixes JB#38241

While combining all configuration data into /etc/usb-moded/usb-moded.ini
works as expected when new configuration files are installed to the device,
it also means that 1) uninstalling / updating configuration files has no
effect and 2) /etc can't reside on a read-only file-system.

Maintain "delta to static configuration" and store it outside /etc - in
/var/lib/usb-moded/usb-moded.ini, so that also changes in / removal of
existing configuration files are handled in deterministic manner.

If /etc/usb-moded/usb-moded.ini exists, migrate data from it and then remove
the now unnecessary file.

Streamline handling of non-existing configuration and remove functions made
redundant in the process.

Note: The "read from filesystem on each setting access" is retained for now
to avoid regression is situations where such behavior might be expected.
Signed-off-by: spiiroin's avatarSimo Piiroinen <simo.piiroinen@jollamobile.com>
parent 0a817747
......@@ -353,6 +353,8 @@ install -m 644 -D config/diag/* %{buildroot}/%{_sysconfdir}/usb-moded/diag/
install -m 644 -D config/run/* %{buildroot}/%{_sysconfdir}/usb-moded/run/
install -m 644 -D config/run-diag/* %{buildroot}/%{_sysconfdir}/usb-moded/run-diag/
install -m 644 -D config/mass-storage-jolla.ini %{buildroot}/%{_sysconfdir}/usb-moded/
install -d %{buildroot}/%{_sharedstatedir}/usb-moded
touch %{buildroot}/%{_sysconfdir}/modprobe.d/g_ether.conf
touch %{buildroot}/%{_sysconfdir}/udhcpd.conf
......@@ -386,11 +388,14 @@ systemctl daemon-reload || :
%config(noreplace) %{_sysconfdir}/modprobe.d/usb_moded.conf
%ghost %config(noreplace) %{_sysconfdir}/modprobe.d/g_ether.conf
%ghost %{_sysconfdir}/udhcpd.conf
%ghost %{_sysconfdir}/usb-moded/usb-moded.ini
%{_sbindir}/usb_moded
%{_sbindir}/usb_moded_util
/lib/systemd/system/%{name}.service
/lib/systemd/system/basic.target.wants/%{name}.service
%config %{_sysconfdir}/tmpfiles.d/usb-moded.conf
%dir %{_sharedstatedir}/usb-moded
%ghost %{_sharedstatedir}/usb-moded/usb-moded.ini
%files devel
%defattr(-,root,root,-)
......
......@@ -36,8 +36,19 @@
# include "usb_moded-config.h"
# include <stdbool.h>
# include <glib.h>
/* ========================================================================= *
* Constants
* ========================================================================= */
# define USB_MODED_STATIC_CONFIG_DIR "/etc/usb-moded"
# define USB_MODED_STATIC_CONFIG_FILE USB_MODED_STATIC_CONFIG_DIR"/usb-moded.ini"
# define USB_MODED_DYNAMIC_CONFIG_DIR "/var/lib/usb-moded"
# define USB_MODED_DYNAMIC_CONFIG_FILE USB_MODED_DYNAMIC_CONFIG_DIR"/usb-moded.ini"
/* ========================================================================= *
* Prototypes
* ========================================================================= */
......@@ -64,7 +75,7 @@ set_config_result_t config_set_mode_whitelist (const char *whitelist);
set_config_result_t config_set_mode_in_whitelist (const char *mode, int allowed);
set_config_result_t config_set_network_setting (const char *config, const char *setting);
char *config_get_network_setting (const char *config);
int config_merge_conf_file (void);
bool config_init (void);
char *config_get_android_manufacturer(void);
char *config_get_android_vendor_id (void);
char *config_get_android_product (void);
......
This diff is collapsed.
......@@ -34,9 +34,6 @@
* Constants
* ========================================================================= */
# define CONFIG_FILE_DIR "/etc/usb-moded"
# define FS_MOUNT_CONFIG_FILE CONFIG_FILE_DIR"/usb-moded.ini"
# define MODE_SETTING_ENTRY "usbmode"
# define MODE_SETTING_KEY "mode"
# define FS_MOUNT_DEFAULT "/dev/mmcblk0p1"
......
......@@ -539,7 +539,7 @@ static bool usbmoded_init(void)
modesetting_init();
/* check config, merge or create if outdated */
if( config_merge_conf_file() != 0 ) {
if( !config_init() ) {
log_crit("Cannot create or find a valid configuration");
goto EXIT;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment