Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add system application starter
Signed-off-by: Philippe De Swert <philippe.deswert@jollamobile.com>
  • Loading branch information
philippedeswert committed Jun 5, 2013
1 parent aa57329 commit 468c399
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 7 deletions.
2 changes: 2 additions & 0 deletions src/Makefile.am
Expand Up @@ -32,6 +32,8 @@ usb_moded_SOURCES = \
usb_moded-mac.h \
usb_moded-dyn-config.c \
usb_moded-dyn-config.h \
usb_moded-systemd.c \
usb_moded-systemd.h \
usb_moded-modules.c

if GCONF
Expand Down
19 changes: 14 additions & 5 deletions src/usb_moded-appsync.c
Expand Up @@ -126,6 +126,8 @@ static struct list_elem *read_file(const gchar *filename)
log_debug("Launch mode = %s\n", list_item->mode);
list_item->upstart = g_key_file_get_integer(settingsfile, APP_INFO_ENTRY, APP_INFO_UPSTART_KEY, NULL);
log_debug("Upstart control = %d\n", list_item->upstart);
list_item->systemd = g_key_file_get_integer(settingsfile, APP_INFO_ENTRY, APP_INFO_SYSTEMD_KEY, NULL);
log_debug("Systemd control = %d\n", list_item->systemd);

cleanup:

Expand Down Expand Up @@ -201,14 +203,17 @@ int activate_sync(const char *mode)
if(!strcmp(mode, data->mode))
{
log_debug("launching app %s\n", data->launch);
if(data->systemd)
{
}
#ifdef UPSTART
if(data->upstart)
else if(data->upstart)
{
if(!upstart_control_job(data->name, UPSTART_START))
mark_active(data->name);
}
else
#endif /* UPSTART */
else
usb_moded_dbus_app_launch(data->launch);
}
}
Expand Down Expand Up @@ -291,22 +296,26 @@ static gboolean enumerate_usb(gpointer data)
return FALSE;
}

#ifdef UPSTART
int appsync_stop(void)
{
GList *iter = 0;

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

if(data->systemd)
{
}
#ifdef UPSTART
else if(data->upstart)
{
log_debug("Stopping %s\n", data->launch);
if(upstart_control_job(data->name, UPSTART_STOP))
log_debug("Failed to stop %s\n", data->name);
}
#endif /* UPSTART */
}

return(0);
}
#endif /* UPSTART */
2 changes: 2 additions & 0 deletions src/usb_moded-appsync.h
Expand Up @@ -26,6 +26,7 @@
#define APP_INFO_NAME_KEY "name"
#define APP_INFO_LAUNCH_KEY "launch"
#define APP_INFO_UPSTART_KEY "upstart"
#define APP_INFO_SYSTEMD_KEY "systemd"

/**
* keep all the needed info together for launching an app
Expand All @@ -38,6 +39,7 @@ typedef struct list_elem
char *launch; /* dbus launch command/address */
int active; /* marker to check if the app has started sucessfully */
int upstart; /* marker to know if we start it with upstart or not */
int systemd; /* marker to know if we start it with systemd or not */
/*@}*/
}list_elem;

Expand Down
2 changes: 0 additions & 2 deletions src/usb_moded-modesetting.c
Expand Up @@ -366,9 +366,7 @@ int usb_moded_mode_cleanup(const char *module)

log_debug("Cleaning up mode\n");

#ifdef UPSTART
appsync_stop();
#endif /* UPSTART */

if(!strcmp(module, MODULE_MASS_STORAGE)|| !strcmp(module, MODULE_FILE_STORAGE))
{
Expand Down
85 changes: 85 additions & 0 deletions src/usb_moded-systemd.c
@@ -0,0 +1,85 @@
/**
@file usb_moded-systemd.c
Copyright (C) 2013 Jolla oy. All rights reserved.
@author: Philippe De Swert <philippe.deswert@jollamobile.com>
This program is free software; you can redistribute it and/or
modify it under the terms of the Lesser GNU General Public License
version 2 as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the Lesser GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
02110-1301 USA
*/

#define _GNU_SOURCE
#include <stdio.h>
#include <string.h>

#include <dbus/dbus.h>
#include <dbus/dbus-glib.h>
#include <dbus/dbus-glib-lowlevel.h>

#include "usb_moded-dbus.h"
#include "usb_moded-dbus-private.h"
#include "usb_moded.h"
#include "usb_moded-log.h"
#include "usb_moded-systemd.h"

static DBusConnection * get_systemd_dbus_connection(void)
{
DBusError error;
DBusConnection *conn = 0;

dbus_error_init(&error);

conn = dbus_connection_open_private("unix:path=/run/systemd/private", &error);
if (!conn)
{
if (dbus_error_is_set(&error))
log_err("Cannot connect to systemd: %s", error.message);
else
log_err("Cannot connect to systemd");
return 0;
}

return conn;
}

// mode = isolate
// method = StartUnit or StopUnit
int systemd_control_service(const char *name, const char *method)
{

DBusConnection *bus;
DBusError error;
DBusMessage *msg = NULL, *reply = NULL;
int ret = 1;

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);
reply = dbus_connection_send_with_reply_and_block(bus, msg, -1, &error);
if(reply)
ret = 0;
dbus_message_unref(msg);
}

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

return(ret);
}
22 changes: 22 additions & 0 deletions src/usb_moded-systemd.h
@@ -0,0 +1,22 @@
/*
Copyright (C) 2013 Jolla Oy. All rights reserved.
author: Philippe De Swert <philippe.deswert@njollamobile.com>
This program is free software; you can redistribute it and/or
modify it under the terms of the Lesser GNU General Public License
version 2 as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the Lesser GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
02110-1301 USA
*/

int systemd_control_service(const char *name, const char *method);

0 comments on commit 468c399

Please sign in to comment.