From 0b0721f4e65c7626045256473f43488edf67798b Mon Sep 17 00:00:00 2001
From: =?utf8?q?Pawe=C5=82=20Szewczyk?=
Date: Wed, 18 Apr 2018 15:09:51 +0200
Subject: [PATCH] usb_funcfs: Check descriptors received from systemd
MIME-Version: 1.0
Content-Type: text/plain; charset=utf8
Content-Transfer-Encoding: 8bit
Change-Id: I178e04a49f4691923455066572f1e26396c65af4
Signed-off-by: PaweÅ Szewczyk
---
src/usb_funcfs_client.c | 24 ++++++++++++++++++++----
1 file changed, 20 insertions(+), 4 deletions(-)
diff --git a/src/usb_funcfs_client.c b/src/usb_funcfs_client.c
index 94f56f4..a7cee7d 100644
--- a/src/usb_funcfs_client.c
+++ b/src/usb_funcfs_client.c
@@ -138,13 +138,29 @@ error:
static void *usb_open_thread(void *x)
{
struct usb_handle *usb = (struct usb_handle *)x;
+ int maxfd = sd_listen_fds(0) + SD_LISTEN_FDS_START;
+ int fd;
+ int ep[3];
+ int received;
+
+ usb->control = -1;
+ usb->bulk_in = -1;
+ usb->bulk_out = -1;
+
+ received = 0;
+ for (fd = SD_LISTEN_FDS_START; fd < maxfd; ++fd) {
+ if (sd_is_special(fd, NULL) > 0) {
+ ep[received++] = fd;
+ }
+ }
/* Endpoints are received from sytemd */
- if (sd_listen_fds(0) >= 3) {
+ if (received == 3) {
+ D("Using functionfs socket activation\n");
sdb_mutex_lock(&usb->control_lock);
- usb->control = SD_LISTEN_FDS_START + 0;
- usb->bulk_out = SD_LISTEN_FDS_START + 1;
- usb->bulk_in = SD_LISTEN_FDS_START + 2;
+ usb->control = ep[0];
+ usb->bulk_out = ep[1];
+ usb->bulk_in = ep[2];
sdb_cond_signal(&usb->control_notify);
sdb_mutex_unlock(&usb->control_lock);
} else {
--
2.34.1