[PATCH] build failure on Debian kfreebsd

Alessio Treglia <[email protected]>
Newsgroups gmane.comp.video.videolan.libdvbpsi.devel
Message-ID <CAMHuwoxSpa96-nv08F5On7AvO4rHLpznD3ya2T7_nV48GKOaNg@mail.gmail.com>
Hi there,

libdvbpsi failed to build on Debian kfreebsd in the past.
Sebastian Ramacher worked on a patch to fix such issue, the description follows:
   MSG_CMSG_CLOEXEC is a flag for recvmsg and not recv. Thus rewrite
   {udp,tcp}_open to create sockets with SOCK_CLOEXEC. If SOCK_CLOEXEC is not
   available, FD_CLOEXEC is set instead.

You find the patch attached, thanks for considering.
Cheers,

-- 
Alessio Treglia          | www.alessiotreglia.com
Debian Developer         | [email protected]
Ubuntu Core Developer    | [email protected]
0416 0004 A827 6E40 BB98 90FB E8A4 8AE5 311D 765A

_______________________________________________
libdvbpsi-devel mailing list
[email protected]
https://mailman.videolan.org/listinfo/libdvbpsi-devel
fix-kfreebsd-build.patch (application/octet-stream, 3.5 KB)
Description: Fix build failure on kfreebsd
 MSG_CMSG_CLOEXEC is a flag for recvmsg and not recv. Thus rewrite
 {udp,tcp}_open to create sockets with SOCK_CLOEXEC. If SOCK_CLOEXEC is not
 available, FD_CLOEXEC is set instead.
Author: Sebastian Ramacher <[email protected]>
Last-Update: 2013-08-19
Forwarded: [email protected]
---
 examples/dvbinfo/tcp.c |   27 ++++++++++++++++++++++++++-
 examples/dvbinfo/udp.c |   27 ++++++++++++++++++++++++++-
 2 files changed, 52 insertions(+), 2 deletions(-)

--- libdvbpsi.orig/examples/dvbinfo/udp.c
+++ libdvbpsi/examples/dvbinfo/udp.c
@@ -47,6 +47,11 @@
 #   include <arpa/inet.h>
 #endif
 
+#ifndef SOCK_CLOEXEC
+#include <unistd.h>
+#include <fcntl.h>
+#endif
+
 #include <assert.h>
 
 #include "udp.h"
@@ -211,13 +216,33 @@ int udp_open(const char *interface, cons
 
     for (struct addrinfo *ptr = addr; ptr != NULL; ptr = ptr->ai_next )
     {
+#ifdef SOCK_CLOEXEC
+        s_ctl = socket(ptr->ai_family, ptr->ai_socktype | SOCK_CLOEXEC, ptr->ai_protocol);
+#else
         s_ctl = socket(ptr->ai_family, ptr->ai_socktype, ptr->ai_protocol);
+#endif
         if (s_ctl <= 0)
         {
             perror("udp socket error");
             continue;
         }
 
+#ifndef SOCK_CLOEXEC
+        int flags = fcntl(s_ctl, F_GETFD);
+        if (flags == -1)
+        {
+            close(s_ctl);
+            perror("udp socket error");
+            continue;
+        }
+        if (fcntl(s_ctl, F_SETFD, flags | FD_CLOEXEC) == -1)
+        {
+            close(s_ctl);
+            perror("udp socket error");
+            continue;
+        }
+#endif
+
         /* Increase the receive buffer size to 1/2MB (8Mb/s during 1/2s)
          * to avoid packet loss caused in case of scheduling hiccups */
         setsockopt (s_ctl, SOL_SOCKET, SO_RCVBUF,
@@ -257,7 +282,7 @@ ssize_t udp_read(int fd, void *buf, size
 {
     ssize_t err;
 again:
-    err = recv(fd, buf, count, MSG_CMSG_CLOEXEC);
+    err = recv(fd, buf, count, 0);
     if (err < 0)
     {
         switch(errno)
--- libdvbpsi.orig/examples/dvbinfo/tcp.c
+++ libdvbpsi/examples/dvbinfo/tcp.c
@@ -50,6 +50,11 @@
 #   include <arpa/inet.h>
 #endif
 
+#ifndef SOCK_CLOEXEC
+#include <unistd.h>
+#include <fcntl.h>
+#endif
+
 #include "tcp.h"
 
 #ifdef HAVE_SYS_SOCKET_H
@@ -98,13 +103,33 @@ int tcp_open(const char *ipaddress, int
 
     for (struct addrinfo *ptr = addr; ptr != NULL; ptr = ptr->ai_next )
     {
+#ifdef SOCK_CLOEXEC
+        s_ctl = socket(ptr->ai_family, ptr->ai_socktype | SOCK_CLOEXEC, ptr->ai_protocol);
+#else
         s_ctl = socket(ptr->ai_family, ptr->ai_socktype, ptr->ai_protocol);
+#endif
         if (s_ctl <= 0)
         {
             perror("tcp socket error");
             continue;
         }
 
+#ifndef SOCK_CLOEXEC
+        int flags = fcntl(s_ctl, F_GETFD);
+        if (flags == -1)
+        {
+            close(s_ctl);
+            perror("tcp socket error");
+            continue;
+        }
+        if (fcntl(s_ctl, F_SETFD, flags | FD_CLOEXEC) == -1)
+        {
+            close(s_ctl);
+            perror("tcp socket error");
+            continue;
+        }
+#endif
+
         setsockopt (s_ctl, SOL_SOCKET, SO_REUSEADDR, &(int){ 1 }, sizeof (int));
 
         result = connect( s_ctl, ptr->ai_addr, ptr->ai_addrlen );
@@ -126,7 +151,7 @@ ssize_t tcp_read(int fd, void *buf, size
 {
     ssize_t err;
 again:
-    err = recv(fd, buf, count, MSG_CMSG_CLOEXEC | MSG_WAITALL);
+    err = recv(fd, buf, count, MSG_WAITALL);
     if (err < 0)
     {
         switch(errno)
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.