usb: change manner for starting/stopping services to dbus method 56/67956/1
authorTaeyoung Kim <ty317.kim@samsung.com>
Fri, 29 Apr 2016 10:23:44 +0000 (19:23 +0900)
committerTaeyoung Kim <ty317.kim@samsung.com>
Fri, 29 Apr 2016 10:23:44 +0000 (19:23 +0900)
- Previously, services are started/stopped by forking systemctl command.
  However, the manner cannot guarantee the sequence of the services
  due to the scheduling issue.
- Now, the services are started/stopped by dbus method to systemd.
  The requests are stored in queue of systemd, and thus the sequence
  of services is guaranteed.

Change-Id: I36d0391fd426e271fe2d760d308efd9efd8b52ed
Signed-off-by: Taeyoung Kim <ty317.kim@samsung.com>
src/usb/usb-default.c
src/usb/usb-operation.conf

index c05a543..b9d02d7 100644 (file)
@@ -24,6 +24,7 @@
 #include "core/common.h"
 #include "core/config-parser.h"
 #include "core/launch.h"
+#include "shared/deviced-systemd.h"
 #include "usb.h"
 
 #define USB_SETTING     "/etc/deviced/usb-setting.conf"
 #define KEY_ROOTPATH    "rootpath"
 #define KEY_LOAD        "load"
 #define KEY_DEFAULT     "default"
-#define KEY_START       "start"
-#define KEY_STOP        "stop"
+#define KEY_START_STR   "Start"
+#define KEY_STOP_STR    "Stop"
 
 #define CONFIG_ENABLE   "1"
 #define CONFIG_DISABLE  "0"
 
 #define BUF_MAX 128
 
+typedef enum {
+       KEY_STOP,
+       KEY_START,
+} operation_key_e;
+
 struct oper_data {
        char *type;
-       char *name;
+       operation_key_e key;
 };
 
 static char config_rootpath[BUF_MAX];
@@ -143,6 +149,7 @@ static int load_operation_config(struct parse_result *result, void *user_data)
 {
        struct oper_data *data = user_data;
        int ret;
+       operation_key_e key;
 
        if (!data || !result)
                return -EINVAL;
@@ -150,28 +157,40 @@ static int load_operation_config(struct parse_result *result, void *user_data)
        if (strncmp(result->section, data->type, strlen(result->section)))
                return 0;
 
-       if (strncmp(result->name, data->name, strlen(result->name)))
+       if (!strncmp(result->name, KEY_START_STR, strlen(KEY_START_STR)))
+               key = KEY_START;
+       else if (!strncmp(result->name, KEY_STOP_STR, strlen(KEY_STOP_STR)))
+               key = KEY_STOP;
+       else {
+               _E("Invalid name (%s)", result->name);
+               return -EINVAL;
+       }
+
+       if (key != data->key)
                return 0;
 
-       ret = launch_app_cmd(result->value);
+       if (strstr(result->name, "Service")) {
+               if (key == KEY_START)
+                       ret = deviced_systemd_start_unit(result->value);
+               if (key == KEY_STOP)
+                       ret = deviced_systemd_stop_unit(result->value);
+       } else
+               ret = launch_app_cmd(result->value);
 
-       _I("Execute(%s: %d)", result->value, ret);
+       _I("Execute(%s %s: %d)", result->name, result->value, ret);
 
        return ret;
 }
 
-static int usb_execute_operation(char *type, char *name)
+static int usb_execute_operation(char *type, operation_key_e key)
 {
        int ret;
        struct oper_data data;
 
-       if (!name)
-               return -EINVAL;
-
        if (!type)
                type = config_default;
 
-       data.name = name;
+       data.key = key;
        data.type = type;
 
        ret = config_parse(USB_OPERATION,
index f0e52fe..47fd43b 100644 (file)
@@ -1,14 +1,14 @@
 [SDB]
-start=/usr/bin/systemctl start mtp-responder.service
-start=/usr/bin/systemctl start sdbd.service
-stop=/usr/bin/systemctl stop sdbd.service
-stop=/usr/bin/systemctl stop mtp-responder.service
+StartService=mtp-responder.service
+StartService=sdbd.service
+StopService=sdbd.service
+StopService=mtp-responder.service
 
 [TETHERING]
-start=/sbin/ifconfig usb0 192.168.129.3 up
-start=/sbin/route add -net 192.168.129.0 netmask 255.255.255.0 dev usb0
-start=/usr/bin/systemctl start sshd.service
-start=/usr/bin/systemctl start sdbd.service
-stop=/usr/bin/systemctl stop sshd.service
-stop=/sbin/ifconfig usb0 down
-stop=/usr/bin/systemctl stop sdbd.service
+Start=/sbin/ifconfig usb0 192.168.129.3 up
+Start=/sbin/route add -net 192.168.129.0 netmask 255.255.255.0 dev usb0
+StartService=sshd.service
+StartService=sdbd.service
+StopService=sshd.service
+Stop=/sbin/ifconfig usb0 down
+StopService=sdbd.service