Skip to content

Commit

Permalink
try to avoid potential race condition in always ask
Browse files Browse the repository at this point in the history
Signed-off-by: Philippe De Swert <philippedeswert@gmail.com>
  • Loading branch information
philippedeswert committed Jul 14, 2011
1 parent b33b3aa commit e47996d
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
2 changes: 1 addition & 1 deletion configure.ac
@@ -1,4 +1,4 @@
AC_INIT([usb_moded], [0.43])
AC_INIT([usb_moded], [0.45])
AM_INIT_AUTOMAKE([-Wall -Werror foreign])

AM_CONFIG_HEADER([config.h])
Expand Down
7 changes: 7 additions & 0 deletions debian/changelog
@@ -1,3 +1,10 @@
usb-moded (0.45) unstable; urgency=low

* Send disconnect signal only after clean-up has been done.
* Actually use cdrom timeout

-- Philippe De Swert <philippe.de-swert@nokia.com> Wed, 13 Jul 2011 14:45:42 +0300

usb-moded (0.44) unstable; urgency=low

* Delay mode cleanup together with module cleanup for USB cert Fixes: NB#266884
Expand Down
1 change: 1 addition & 0 deletions src/usb_moded-modules.c
Expand Up @@ -266,6 +266,7 @@ void check_module_state(const char *module_name)
#ifdef NOKIA
gboolean usb_cleanup_timeout(gpointer data)
{
usb_moded_send_signal(USB_DISCONNECTED);
usb_moded_mode_cleanup(get_usb_module());
usb_moded_module_cleanup(get_usb_module());
return FALSE;
Expand Down
14 changes: 10 additions & 4 deletions src/usb_moded.c
Expand Up @@ -54,7 +54,7 @@ extern int log_type;
gboolean run_as_daemon = FALSE;
gboolean runlevel_ignore = FALSE;
struct usb_mode current_mode;
guint debounce = 0;
guint charging_timeout = 0;
#ifdef NOKIA
gboolean special_mode = FALSE;
guint timeout_source = 0;
Expand Down Expand Up @@ -108,6 +108,11 @@ void set_usb_connected(gboolean connected)
timeout_source = 0;
}
#endif /* NOKIA */
if(charging_timeout)
{
g_source_remove(charging_timeout);
charging_timeout = 0;
}
current_mode.connected = TRUE;
set_usb_connected_state();
}
Expand All @@ -124,13 +129,13 @@ static gboolean set_disconnected(gpointer data)
/* only disconnect for real if we are actually still disconnected */
if(!get_usb_connection_state())
{
/* signal usb disconnected */
log_debug("usb disconnected\n");
usb_moded_send_signal(USB_DISCONNECTED);
#ifdef NOKIA
/* delayed clean-up of state */
timeout_source = g_timeout_add_seconds(3, usb_cleanup_timeout, NULL);
#else
/* signal usb disconnected */
usb_moded_send_signal(USB_DISCONNECTED);
/* unload modules and general cleanup */
usb_moded_mode_cleanup(get_usb_module());
usb_moded_module_cleanup(get_usb_module());
Expand Down Expand Up @@ -173,7 +178,7 @@ void set_usb_connected_state(void)
*/
usb_moded_send_signal(USB_CONNECTED_DIALOG_SHOW);
/* fallback to charging mode after 3 seconds */
g_timeout_add_seconds(3, charging_fallback, NULL);
charging_timeout = g_timeout_add_seconds(3, charging_fallback, NULL);
/* in case there was nobody listening for the UI, they will know
that the UI is needed by requesting the current mode */
set_usb_mode(MODE_ASK);
Expand Down Expand Up @@ -408,6 +413,7 @@ static gboolean charging_fallback(gpointer data)
*/
free(current_mode.mode);
current_mode.mode = strdup(MODE_ASK);
charging_timeout = 0;
log_info("Falling back on charging mode.\n");

return(FALSE);
Expand Down

0 comments on commit e47996d

Please sign in to comment.