Skip to content

Commit

Permalink
[appsync] Stop post-enum apps before stopping pre-enum apps. JB#35683
Browse files Browse the repository at this point in the history
When appsync is starting applications, pre-enum applications are started
before post-enum apps. However stopping applications is done in whatever
order they happen to be after configuration parsing - which could cause
problems if post apps have explicit dependencies on pre apps.

Do also application stopping in two phases: first post-enum apps followed
by pre-enum apps.

Also, apart from usb-moded startup/shutdown, attempt to skip stopping of
applications that have not been started.

Signed-off-by: Simo Piiroinen <simo.piiroinen@jollamobile.com>
  • Loading branch information
spiiroin committed Jul 7, 2016
1 parent 27518bf commit df105a6
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 14 deletions.
45 changes: 35 additions & 10 deletions src/usb_moded-appsync.c
Expand Up @@ -253,10 +253,9 @@ int activate_sync(const char *mode)
/* do not launch items marked as post, will be launched after usb is up */
if(data->post)
{
mark_active(data->name, data->post);
continue;
}
log_debug("launching app %s\n", data->name);
log_debug("launching pre-enum-app %s\n", data->name);
if(data->systemd)
{
if(!systemd_control_service(data->name, SYSTEMD_START))
Expand Down Expand Up @@ -318,11 +317,12 @@ int activate_sync_post(const char *mode)
/* launch only items marked as post, others are already running */
if(!data->post)
continue;
log_debug("launching app %s\n", data->name);
log_debug("launching post-enum-app %s\n", data->name);
if(data->systemd)
{
if(systemd_control_service(data->name, SYSTEMD_START))
goto error;
mark_active(data->name, 1);
}
else if(data->launch)
{
Expand Down Expand Up @@ -353,12 +353,12 @@ int mark_active(const gchar *name, int post)

GList *iter;

if(post)
log_debug("App %s notified it is ready\n", name);
log_debug("%s-enum-app %s is started\n", post ? "post" : "pre", name);

for( iter = sync_list; iter; iter = g_list_next(iter) )
{
struct list_elem *data = iter->data;

if(!strcmp(data->name, name))
{
/* TODO: do we need to worry about duplicate names in the list? */
Expand All @@ -368,17 +368,17 @@ int mark_active(const gchar *name, int post)
/* updated + missing -> not going to enumerate */
if( missing ) break;
}
else if( data->active == 0 )
else if( data->active == 0 && data->post == post )
{
missing = 1;

/* updated + missing -> not going to enumerate */
if( ret != -1 ) break;
}
}
if( !missing )
if( !post && !missing )
{
log_debug("All apps active. Let's enumerate\n");
log_debug("All pre-enum-apps active. Let's enumerate\n");
enumerate_usb();
}

Expand Down Expand Up @@ -446,21 +446,46 @@ static void enumerate_usb(void)
}
}

int appsync_stop(void)
static void appsync_stop_apps(int post)
{
GList *iter = 0;

for( iter = sync_list; iter; iter = g_list_next(iter) )
{
struct list_elem *data = iter->data;

if(data->systemd)
if(data->systemd && data->active && data->post == post)
{
log_debug("stopping %s-enum-app %s", post ? "post" : "pre", data->name);
if(systemd_control_service(data->name, SYSTEMD_STOP))
log_debug("Failed to stop %s\n", data->name);
data->active = 0;
}
}
}

int appsync_stop(int force)
{
/* If force arg is used, stop all applications that
* could have been started by usb-moded */
if(force)
{
GList *iter;
log_debug("assuming all applications are active");

for( iter = sync_list; iter; iter = g_list_next(iter) )
{
struct list_elem *data = iter->data;
data->active = 1;
}
}

/* Stop post-apps 1st */
appsync_stop_apps(1);

/* Then pre-apps */
appsync_stop_apps(0);

/* Do not leave active timers behind */
cancel_enumerate_usb_timer();
return(0);
Expand Down
2 changes: 1 addition & 1 deletion src/usb_moded-appsync.h
Expand Up @@ -48,6 +48,6 @@ void readlist(int diag);
int activate_sync(const char *mode);
int activate_sync_post(const char *mode);
int mark_active(const gchar *name, int post);
int appsync_stop(void);
int appsync_stop(int force);
void free_appsync_list(void);
void usb_moded_appsync_cleanup(void);
3 changes: 2 additions & 1 deletion src/usb_moded-modesetting.c
Expand Up @@ -566,7 +566,8 @@ int usb_moded_mode_cleanup(const char *module)
}

#ifdef APP_SYNC
appsync_stop();
/* Stop applications started due to entering this mode */
appsync_stop(0);
#endif /* APP_SYNC */

if(!strcmp(module, MODULE_MASS_STORAGE)|| !strcmp(module, MODULE_FILE_STORAGE))
Expand Down
4 changes: 2 additions & 2 deletions src/usb_moded.c
Expand Up @@ -623,7 +623,7 @@ static void usb_moded_init(void)
#ifdef APP_SYNC
readlist(diag_mode);
/* make sure all services are down when starting */
appsync_stop();
appsync_stop(1);
modelist = read_mode_list(diag_mode);
#endif /* APP_SYNC */

Expand Down Expand Up @@ -670,7 +670,7 @@ static gboolean charging_fallback(gpointer data)
static void handle_exit(void)
{
/* exiting and clean-up when mainloop ended */
appsync_stop();
appsync_stop(1);
hwal_cleanup();
usb_moded_dbus_cleanup();
#ifdef MEEGOLOCK
Expand Down

0 comments on commit df105a6

Please sign in to comment.