You are right.  I've create a patch that utilizes SO_NOSIGPIPE.
This works on macOS and should work on FreeBSD (I didn't test).

On 1/24/19 1:07 AM, Waldek Hebisch wrote:
> oldk1331 wrote:
>>
>> I think we can ignore SIGPIPE when "send" syscall can return EPIPE:
>>
> 
> No.  We can ignore SIGPIPE when "send" syscall _will_ return EPIPE
> and this happens when we say it to do so.   On Linux we
> use MSG_NOSIGNAL for this.  On Mac you found SO_NOSIGPIPE...
> So we need appropriate configure magic to find out if
> one MSG_NOSIGNAL or SO_NOSIGPIPE is available and conditionals
> in code to act on this.
> 

-- 
You received this message because you are subscribed to the Google Groups 
"FriCAS - computer algebra system" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/fricas-devel/4defefad-3fe4-0944-e02d-50c229a5a12c%40gmail.com.
For more options, visit https://groups.google.com/d/optout.
diff --git a/config/fricas_c_macros.h.in b/config/fricas_c_macros.h.in
index 01aeabdd..59c1247c 100644
--- a/config/fricas_c_macros.h.in
+++ b/config/fricas_c_macros.h.in
@@ -94,6 +94,9 @@
 /* Define to 1 if you have the <signal.h> header file. */
 #undef HAVE_SIGNAL_H
 
+/* Host has SO_NOSIGPIPE */
+#undef HAVE_SO_NOSIGPIPE
+
 /* Define to 1 if you have the <stdint.h> header file. */
 #undef HAVE_STDINT_H
 
diff --git a/configure b/configure
index a0c6ca27..df5aa8f7 100755
--- a/configure
+++ b/configure
@@ -5086,6 +5086,29 @@ rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
 cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
 
+#include <sys/types.h>
+#include <sys/socket.h>
+
+int
+main ()
+{
+
+int flag = SO_NOSIGPIPE;
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+
+$as_echo "#define HAVE_SO_NOSIGPIPE 1" >>confdefs.h
+
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
 #include <errno.h>
 #include <sys/socket.h>
 
diff --git a/configure.ac b/configure.ac
index d2431ce0..4de9a3d0 100644
--- a/configure.ac
+++ b/configure.ac
@@ -534,6 +534,14 @@ int flag = MSG_NOSIGNAL;
    ],
    [AC_DEFINE([HAVE_MSG_NOSIGNAL], [1], [Host has MSG_NOSIGNAL])],[])
 
+AC_TRY_COMPILE([
+#include <sys/types.h>
+#include <sys/socket.h>
+   ], [
+int flag = SO_NOSIGPIPE;
+   ],
+   [AC_DEFINE([HAVE_SO_NOSIGPIPE], [1], [Host has SO_NOSIGPIPE])],[])
+
 AC_TRY_COMPILE([
 #include <errno.h>
 #include <sys/socket.h>
diff --git a/src/lib/sockio-c.c b/src/lib/sockio-c.c
index 17cc1056..30e0eba5 100644
--- a/src/lib/sockio-c.c
+++ b/src/lib/sockio-c.c
@@ -882,9 +882,11 @@ open_server(char *server_name)
 
   init_socks();
 #ifndef HAVE_MSG_NOSIGNAL
+#ifndef HAVE_SO_NOSIGPIPE
 #ifdef SIGPIPE
   bsdSignal(SIGPIPE, sigpipe_handler,RestartSystemCalls);
 #endif
+#endif
 #endif
   if (make_server_name(name, server_name) == -1)
     return -2;
@@ -931,6 +933,11 @@ open_server(char *server_name)
       server[1].socket = 0;
       return -2;
     }
+#ifdef HAVE_SO_NOSIGPIPE
+    /* macOS doesn't have MSG_NOSIGNAL, so use SO_NOSIGPIPE instead */
+    int set = 1;
+    setsockopt(server[1].socket, SOL_SOCKET, SO_NOSIGPIPE, (void *)&set, sizeof(int));
+#endif
     FD_SET(server[1].socket, &socket_mask);
     FD_SET(server[1].socket, &server_mask);
     listen(server[1].socket, 5);

Reply via email to