#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];
{
struct oper_data *data = user_data;
int ret;
+ operation_key_e key;
if (!data || !result)
return -EINVAL;
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,
[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