Commit 1d9e91e4 authored by spiiroin's avatar spiiroin

[modesetting] Replace questionable async timer with sleep loop. JB#42757

In case of network setup failure usb-moded utilizes glib timer to retry
the operation once once after 3 second delay. How well that has worked is
a bit questionable as the dynamic mode setup continues with things that
probably require functional network. Also, while it used to be guaranteed
that the timer would not trigger before the synchronous mode switch
operations have finished, this is no longer guaranteed due to the use of
worker thread for the mode switch.

Use retry three times with one second delay between retries instead of
relying on a three second asynchronous timer with hazardous triggering
time and context.
Signed-off-by: spiiroin's avatarSimo Piiroinen <simo.piiroinen@jollamobile.com>
parent bf2e96af
......@@ -62,8 +62,6 @@ static char *modesetting_strip (char *str);
static char *modesetting_read_from_file (const char *path, size_t maxsize);
int modesetting_write_to_file_real (const char *file, int line, const char *func, const char *path, const char *text);
static gboolean modesetting_network_retry_cb (gpointer data);
static bool modesetting_enter_mass_storage_mode (mode_list_elem_t *data);
static int modesetting_leave_mass_storage_mode (mode_list_elem_t *data);
static void modesetting_report_mass_storage_blocker(const char *mountpoint, int try);
......@@ -79,7 +77,6 @@ void modesetting_quit (void);
* ========================================================================= */
static GHashTable *tracked_values = 0;
static guint modesetting_network_retry_id = 0;
/* ========================================================================= *
* Functions
......@@ -273,13 +270,6 @@ cleanup:
return err;
}
static gboolean modesetting_network_retry_cb(gpointer data)
{
modesetting_network_retry_id = 0;
network_up(data);
return(FALSE);
}
#include <mntent.h>
typedef struct storage_info_t
......@@ -686,7 +676,6 @@ bool modesetting_enter_dynamic_mode(void)
bool ack = false;
mode_list_elem_t *data;
int network = 1;
log_debug("DYNAMIC MODE: SETUP");
......@@ -780,18 +769,18 @@ bool modesetting_enter_dynamic_mode(void)
common_system(command);
#else
network_down(data);
network = network_up(data);
#endif /* DEBIAN */
}
int error = network_up(data);
/* try a second time to bring up the network if it failed the first time,
* this can happen with functionfs based gadgets (which is why we sleep for a bit */
if(network != 0 && data->network)
{
log_debug("Retry setting up the network later\n");
if(modesetting_network_retry_id)
g_source_remove(modesetting_network_retry_id);
modesetting_network_retry_id = g_timeout_add_seconds(3, modesetting_network_retry_cb, data);
/* In case of failure, retry upto 3 times */
for( int i = 0; error && i < 3; ++i ) {
log_warning("Retry setting up the network");
common_msleep(1000);
if( !(error = network_up(data)) )
log_warning("Setting up the network succeeded");
}
if( error )
log_err("Setting up the network failed");
#endif /* DEBIAN */
}
/* Needs to be called before application post synching so
......@@ -839,16 +828,6 @@ void modesetting_leave_dynamic_mode(void)
data = worker_get_usb_mode_data();
/* - - - - - - - - - - - - - - - - - - - *
* Do not leave timers behind
* - - - - - - - - - - - - - - - - - - - */
if(modesetting_network_retry_id)
{
g_source_remove(modesetting_network_retry_id);
modesetting_network_retry_id = 0;
}
/* - - - - - - - - - - - - - - - - - - - *
* Is a dynamic mode?
* - - - - - - - - - - - - - - - - - - - */
......
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