Skip to content

Commit

Permalink
[modesetting] Replace questionable async timer with sleep loop. JB#42757
Browse files Browse the repository at this point in the history
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: Simo Piiroinen <simo.piiroinen@jollamobile.com>
  • Loading branch information
spiiroin committed Sep 5, 2018
1 parent bf2e96a commit 1d9e91e
Showing 1 changed file with 11 additions and 32 deletions.
43 changes: 11 additions & 32 deletions src/usb_moded-modesetting.c
Expand Up @@ -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);
Expand All @@ -79,7 +77,6 @@ void modesetting_quit (void);
* ========================================================================= */

static GHashTable *tracked_values = 0;
static guint modesetting_network_retry_id = 0;

/* ========================================================================= *
* Functions
Expand Down Expand Up @@ -273,13 +270,6 @@ int modesetting_write_to_file_real(const char *file, int line, const char *func,
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
Expand Down Expand Up @@ -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");

Expand Down Expand Up @@ -780,20 +769,20 @@ bool modesetting_enter_dynamic_mode(void)
common_system(command);
#else
network_down(data);
network = network_up(data);
int error = network_up(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 */
}

/* 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);
}

/* Needs to be called before application post synching so
* that the dhcp server has the right config */
if(data->nat || data->dhcp_server)
Expand Down Expand Up @@ -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?
* - - - - - - - - - - - - - - - - - - - */
Expand Down

0 comments on commit 1d9e91e

Please sign in to comment.