Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[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: Simo Piiroinen <simo.piiroinen@jollamobile.com>
  • Loading branch information
spiiroin committed Feb 21, 2019
1 parent 0a81774 commit 0e9f72c
Show file tree
Hide file tree
Showing 5 changed files with 246 additions and 238 deletions.
5 changes: 5 additions & 0 deletions rpm/usb-moded.spec
Expand Up @@ -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
Expand Down Expand Up @@ -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,-)
Expand Down
13 changes: 12 additions & 1 deletion src/usb_moded-config-private.h
Expand Up @@ -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
* ========================================================================= */
Expand All @@ -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);
Expand Down

0 comments on commit 0e9f72c

Please sign in to comment.