Skip to content

Commit

Permalink
Refine appsync to skip dbus activations when session bus is unavailab…
Browse files Browse the repository at this point in the history
…le, make systemd start/stop actually work

Signed-off-by: Philippe De Swert <philippe.deswert@jollamobile.com>
  • Loading branch information
philippedeswert committed Jul 12, 2013
1 parent bbf16da commit f6f410b
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 15 deletions.
34 changes: 24 additions & 10 deletions src/usb_moded-appsync.c
Expand Up @@ -97,6 +97,7 @@ void readlist(void)

if( sync_list )
{
log_debug("Sync list valid\n");
usb_moded_app_sync_init_connection();
}
}
Expand Down Expand Up @@ -136,10 +137,12 @@ static struct list_elem *read_file(const gchar *filename)
g_key_file_free(settingsfile);
g_free(full_filename);

/* if not all the elements are filled in we discard the list_item */
if( list_item && !(list_item->launch && list_item->name && list_item->mode) )
/* if a minimum set of required elements is not filled in we discard the list_item */
if( list_item && !(list_item->name && list_item->mode) )
{
free_elem(list_item), list_item = 0;
log_debug("Element invalid, discarding\n");
free_elem(list_item);
list_item = 0;
}

return list_item;
Expand All @@ -149,6 +152,7 @@ int activate_sync(const char *mode)
{
GList *iter;
int count = 0, count2 = 0;
int no_dbus = 0;

log_debug("activate sync");

Expand All @@ -157,6 +161,7 @@ int activate_sync(const char *mode)

if( sync_list == 0 )
{
log_debug("No sync list! Enumerating\n");
enumerate_usb(NULL);
return 0;
}
Expand Down Expand Up @@ -185,12 +190,11 @@ int activate_sync(const char *mode)
return(1);
}

/* add dbus filter. Use session bus for ready method call? */
/* check dbus initialisation, skip dbus activated services if this fails */
if(!usb_moded_app_sync_init())
{
log_debug("dbus setup failed => activate immediately \n");
enumerate_usb(NULL);
return(1);
log_debug("dbus setup failed => skipping dbus launched apps \n");
no_dbus = 1;
}

/* start timer */
Expand All @@ -203,24 +207,34 @@ int activate_sync(const char *mode)
struct list_elem *data = iter->data;
if(!strcmp(mode, data->mode))
{
log_debug("launching app %s\n", data->launch);
log_debug("launching app %s\n", data->name);
if(data->systemd)
{
if(!systemd_control_service(data->name, SYSTEMD_START))
mark_active(data->name);
goto end;
}
#ifdef UPSTART
else if(data->upstart)
{
if(!upstart_control_job(data->name, UPSTART_START))
mark_active(data->name);
goto end;
}
#endif /* UPSTART */
else
usb_moded_dbus_app_launch(data->launch);
else if(data->launch)
{
/* skipping if dbus session bus is not available */
if(no_dbus)
mark_active(data->name);
else
usb_moded_dbus_app_launch(data->launch);
}
}
}

end:

return(0);
}

Expand Down
17 changes: 12 additions & 5 deletions src/usb_moded-systemd.c
Expand Up @@ -54,7 +54,7 @@ static DBusConnection * get_systemd_dbus_connection(void)
return conn;
}

// mode = isolate
// mode = replace
// method = StartUnit or StopUnit
int systemd_control_service(const char *name, const char *method)
{
Expand All @@ -63,26 +63,33 @@ int systemd_control_service(const char *name, const char *method)
DBusError error;
DBusMessage *msg = NULL, *reply = NULL;
int ret = 1;
const char * replace = "replace";

log_debug("Launchung %s, with systemd\n", name);
dbus_error_init(&error);

log_debug("Launching %s, with systemd\n", name);

bus = get_systemd_dbus_connection();

msg = dbus_message_new_method_call("org.freedesktop.systemd1",
"/org/freedesktop/systemd1", "org.freedesktop.systemd1.Manager", method);
if(msg)
{
dbus_message_append_args (msg, DBUS_TYPE_STRING, &name, DBUS_TYPE_STRING, "isolate", DBUS_TYPE_INVALID);
if(!dbus_message_append_args (msg, DBUS_TYPE_STRING, &name, DBUS_TYPE_STRING, &replace, DBUS_TYPE_INVALID))
{
log_debug("error appending arguments\n");
dbus_message_unref(msg);
goto quit;
}
reply = dbus_connection_send_with_reply_and_block(bus, msg, -1, &error);
if(reply)
{
ret = 0;
log_debug("systemd launch succesful\n");
}
dbus_message_unref(msg);
}

dbus_message_unref(msg);
quit:
dbus_connection_close(bus);
dbus_connection_unref(bus);

Expand Down

0 comments on commit f6f410b

Please sign in to comment.