Skip to content

Commit

Permalink
[common] Avoid false warnings on legacy config remove. JB#44449
Browse files Browse the repository at this point in the history
Attempting to remove a file from read-only filesystem yields
EROFS error even if the file does not exist. Which then leads
usb-moded complaining about not being able to remove a file
that does not exist.

Check that legacy config file /etc/usb-moded/usb-moded.ini
exist before attempting to remove it.

Signed-off-by: Simo Piiroinen <simo.piiroinen@jollamobile.com>
  • Loading branch information
spiiroin committed Jan 28, 2020
1 parent 7dcafec commit b6c6315
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/usb_moded-config.c
Expand Up @@ -859,7 +859,15 @@ static void config_remove_legacy_config(void)
{
LOG_REGISTER_CONTEXT;

if( unlink(USB_MODED_STATIC_CONFIG_FILE) == -1 && errno != ENOENT ) {
/* Note: In case of read-only /tmp, unlink attempt leads to
* EROFS regardless of whether the file exists or not
* -> do a separate existance check 1st.
*/

if( access(USB_MODED_STATIC_CONFIG_FILE, F_OK) == -1 && errno == ENOENT ) {
/* nop */
}
else if( unlink(USB_MODED_STATIC_CONFIG_FILE) == -1 && errno != ENOENT ) {
log_warning("%s: can't remove stale config file: %m",
USB_MODED_STATIC_CONFIG_FILE);
}
Expand Down

0 comments on commit b6c6315

Please sign in to comment.