summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPawel Szewczyk <p.szewczyk@samsung.com>2015-09-04 12:23:51 +0200
committerPawel Szewczyk <p.szewczyk@samsung.com>2015-09-22 16:32:16 +0200
commit6b7e59231014b94636f4a1b730143fbe6f60c3f4 (patch)
tree56638d1c47a56d87935aba6ef52d2b560670a435
parent602524469ecd7db0e0d5a71ecd1dce34f7a108b6 (diff)
core: Add FFSDescriptors and FFSStrings service parameters
By using these parameters functionfs service can specify ffs descriptors and strings which should be written to ep0.
-rw-r--r--src/core/dbus-service.c2
-rw-r--r--src/core/load-fragment-gperf.gperf.m42
-rw-r--r--src/core/service.c6
-rw-r--r--src/core/service.h3
-rw-r--r--src/core/socket.c21
5 files changed, 34 insertions, 0 deletions
diff --git a/src/core/dbus-service.c b/src/core/dbus-service.c
index e1f3d56495..3436342bef 100644
--- a/src/core/dbus-service.c
+++ b/src/core/dbus-service.c
@@ -62,6 +62,8 @@ const sd_bus_vtable bus_service_vtable[] = {
SD_BUS_PROPERTY("StatusText", "s", NULL, offsetof(Service, status_text), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
SD_BUS_PROPERTY("StatusErrno", "i", NULL, offsetof(Service, status_errno), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
SD_BUS_PROPERTY("Result", "s", property_get_result, offsetof(Service, result), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
+ SD_BUS_PROPERTY("USBFunctionDescriptors", "s", NULL, offsetof(Service, usb_function_descriptors), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
+ SD_BUS_PROPERTY("USBFunctionStrings", "s", NULL, offsetof(Service, usb_function_strings), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
BUS_EXEC_STATUS_VTABLE("ExecMain", offsetof(Service, main_exec_status), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
BUS_EXEC_COMMAND_LIST_VTABLE("ExecStartPre", offsetof(Service, exec_command[SERVICE_EXEC_START_PRE]), SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION),
BUS_EXEC_COMMAND_LIST_VTABLE("ExecStart", offsetof(Service, exec_command[SERVICE_EXEC_START]), SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION),
diff --git a/src/core/load-fragment-gperf.gperf.m4 b/src/core/load-fragment-gperf.gperf.m4
index d227f2af02..69e8d7a4d4 100644
--- a/src/core/load-fragment-gperf.gperf.m4
+++ b/src/core/load-fragment-gperf.gperf.m4
@@ -233,6 +233,8 @@ Service.FileDescriptorStoreMax, config_parse_unsigned, 0,
Service.NotifyAccess, config_parse_notify_access, 0, offsetof(Service, notify_access)
Service.Sockets, config_parse_service_sockets, 0, 0
Service.BusPolicy, config_parse_bus_endpoint_policy, 0, offsetof(Service, exec_context)
+Service.USBFunctionDescriptors, config_parse_path, 0, offsetof(Service, usb_function_descriptors)
+Service.USBFunctionStrings, config_parse_path, 0, offsetof(Service, usb_function_strings)
EXEC_CONTEXT_CONFIG_ITEMS(Service)m4_dnl
CGROUP_CONTEXT_CONFIG_ITEMS(Service)m4_dnl
KILL_CONTEXT_CONFIG_ITEMS(Service)m4_dnl
diff --git a/src/core/service.c b/src/core/service.c
index fc28ba4d07..f7de5e89ff 100644
--- a/src/core/service.c
+++ b/src/core/service.c
@@ -482,6 +482,12 @@ static int service_verify(Service *s) {
return -EINVAL;
}
+ if (s->usb_function_descriptors && !s->usb_function_strings)
+ log_unit_warning(UNIT(s), "Service has USBFunctionDescriptors= setting, but no USBFunctionStrings=. Ignoring.");
+
+ if (!s->usb_function_descriptors && s->usb_function_strings)
+ log_unit_warning(UNIT(s), "Service has USBFunctionStrings= setting, but no USBFunctionDescriptors=. Ignoring.");
+
return 0;
}
diff --git a/src/core/service.h b/src/core/service.h
index 7da0a93961..789dff23a9 100644
--- a/src/core/service.h
+++ b/src/core/service.h
@@ -212,6 +212,9 @@ struct Service {
ServiceFDStore *fd_store;
unsigned n_fd_store;
unsigned n_fd_store_max;
+
+ char *usb_function_descriptors;
+ char *usb_function_strings;
};
extern const UnitVTable service_vtable;
diff --git a/src/core/socket.c b/src/core/socket.c
index d8de58ef15..54e94c4f74 100644
--- a/src/core/socket.c
+++ b/src/core/socket.c
@@ -50,6 +50,7 @@
#include "formats-util.h"
#include "signal-util.h"
#include "socket.h"
+#include "copy.h"
static const UnitActiveState state_translation_table[_SOCKET_STATE_MAX] = {
[SOCKET_DEAD] = UNIT_INACTIVE,
@@ -1165,6 +1166,22 @@ static int socket_symlink(Socket *s) {
return 0;
}
+static int ffs_write_descs(int fd, Unit *u) {
+ Service *s = SERVICE(u);
+ int r;
+
+ if (!s->usb_function_descriptors || !s->usb_function_strings)
+ return -EINVAL;
+
+ r = copy_file_fd(s->usb_function_descriptors, fd, false);
+ if (r < 0)
+ return 0;
+
+ r = copy_file_fd(s->usb_function_strings, fd, false);
+
+ return r;
+}
+
static int select_ep(const struct dirent *d) {
return d->d_name[0] != '.' && !streq(d->d_name, "ep0");
}
@@ -1323,6 +1340,10 @@ static int socket_open_fds(Socket *s) {
if (r < 0)
goto rollback;
+ r = ffs_write_descs(p->fd, s->service.unit);
+ if (r < 0)
+ goto rollback;
+
r = ffs_dispatch_eps(p);
if (r < 0)
goto rollback;