mirror of
https://github.com/systemd/systemd.git
synced 2025-01-11 09:18:07 +03:00
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.
This commit is contained in:
parent
602524469e
commit
6b7e592310
@ -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),
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user