core: Add socket type for usb functionfs endpoints
authorPawel Szewczyk <p.szewczyk@samsung.com>
Mon, 21 Sep 2015 13:43:47 +0000 (15:43 +0200)
committerŁukasz Stelmach <l.stelmach@samsung.com>
Fri, 26 Jan 2024 16:49:49 +0000 (17:49 +0100)
For handling functionfs endpoints additional socket type is added.

origin: https://github.com/systemd/systemd/commit/602524469e

Change-Id: I6906db41734b0b8352b363528f788ac2859b5103
Signed-off-by: Georgia Brikis <g.brikis@samsung.com>
src/core/load-fragment-gperf.gperf.m4
src/core/socket.c

index 6a5c16a..e26e669 100644 (file)
@@ -276,7 +276,10 @@ Socket.ListenNetlink,            config_parse_socket_listen,         SOCKET_SOCK
 Socket.ListenSpecial,            config_parse_socket_listen,         SOCKET_SPECIAL,                0
 Socket.ListenMessageQueue,       config_parse_socket_listen,         SOCKET_MQUEUE,                 0
 Socket.ListenUSBFunction,        config_parse_socket_listen,         SOCKET_USB_FUNCTION,           0
+<<<<<<< HEAD
 Socket.SocketProtocol,           config_parse_socket_protocol,       0,                             0
+=======
+>>>>>>> core: Add socket type for usb functionfs endpoints
 Socket.BindIPv6Only,             config_parse_socket_bind,           0,                             0,
 Socket.Backlog,                  config_parse_unsigned,              0,                             offsetof(Socket, backlog)
 Socket.BindToDevice,             config_parse_socket_bindtodevice,   0,                             0
index e098055..b8bf7cb 100644 (file)
@@ -1116,6 +1116,33 @@ static int usbffs_address_create(const char *path) {
         return r;
 }
 
+static int ffs_address_create(
+                const char *path,
+                int *_fd) {
+
+        _cleanup_close_ int fd = -1;
+        struct stat st;
+
+        assert(path);
+        assert(_fd);
+
+        fd = open(path, O_RDWR|O_CLOEXEC|O_NOCTTY|O_NONBLOCK|O_NOFOLLOW);
+        if (fd < 0)
+                return -errno;
+
+        if (fstat(fd, &st) < 0)
+                return -errno;
+
+        /* Check whether this is a regular file (ffs endpoint)*/
+        if (!S_ISREG(st.st_mode))
+                return -EEXIST;
+
+        *_fd = fd;
+        fd = -1;
+
+        return 0;
+}
+
 static int mq_address_create(
                 const char *path,
                 mode_t mq_mode,