On 6/26/22 22:00, Waldek Hebisch wrote:
On Tue, Jun 21, 2022 at 10:15:27PM +0800, Qian Yun wrote:
Can we try to fix this bug with 'sockaddr_un'?

I am not sure what you mean here.  We want ability to
handle both Unix domain sockets and Internet sockets.
With proper conditiononals this should be possible.
So we could use 'sockaddr_un', but with conditionals
making sure that it is used when appropriate (and
only in such cases).

What I meant is this patch (or see end of email):

https://github.com/oldk1331/fricas/commit/39037b7cb5dff9cff8a42068dbc51fe4e91e33c2.patch

Tested on Linux, fixes the original problem.

About windows:

Cygwin should work, because it is an POSIX emulation layer.

Mingw64 (aka native WIN32) never worked: sman was never built
as WIN32.  So on (native WIN32) windows, the socket related code
is never used, right?

The WinSock code was there when FriCAS was forked
from Axiom.  And Axiom doesn't contain this WinSock code.
Not sure why it was there in the first place.

WinSock code is due to Gabriel Dos Reis (possibly parts
are due to Mike Thomas who had special Windows patches).
The code was in build-improvements branch and probably
never made it to Tim Daly Axiom.

AFAIK this code compiled on Windows and presumably passed all
tests that Gaby did.

Concerning sman: AFAICS the big trouble here are pty-s, they
are not directly available in Windows and the best one can
do is to provide some kind of emulation.  Cygwin provides
emulation of pty-s, I do not know how it is done and if
it is feasible to provide such emulation for Mingw.
However, it seem easier (but not easy) to replace all
uses of pty-s by sockets.  Of course, in such scenario
Winsock code would be quite important.

Separate issue is Cygwin, I am not sure if it used
Winsock sockets or Cygwin emulation.

This patch fails on Mingw64.

I believe Cygwin uses emulation of POSIX AF_UNIX.  I haven't
try that, but I can test it.

So, for Mingw64, the Winsock code was there, but never used.
Can I disable socket related functions on Mingw64?

BTW, open axiom now uses named pipe on Windows:
https://github.com/GabrielDosReis/open-axiom/blob/master/src/lib/sockio-c.cxx#L252

- Qian

=================

From 39037b7cb5dff9cff8a42068dbc51fe4e91e33c2 Mon Sep 17 00:00:00 2001
From: Qian Yun <oldk1...@gmail.com>
Date: Sun, 26 Jun 2022 23:56:38 +0800
Subject: [PATCH] try to use sockaddr_un

---
 src/include/com.h  |  4 ++--
 src/lib/sockio-c.c | 20 ++++++++------------
 2 files changed, 10 insertions(+), 14 deletions(-)

diff --git a/src/include/com.h b/src/include/com.h
index 4faeb2c1c..465e3a491 100644
--- a/src/include/com.h
+++ b/src/include/com.h
@@ -39,6 +39,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 #else
 #  include <sys/types.h>
 #  include <sys/socket.h>
+#  include <sys/un.h>
 #  include <netinet/in.h>
 #endif

@@ -68,9 +69,8 @@ typedef struct {
int frame; /* spad interpreter frame (for interpreter windows) */
   fricas_socket remote;  /* file descriptor of remote socket */
   union {
-    struct sockaddr u_addr;
+    struct sockaddr_un u_addr;
     struct sockaddr_in i_addr;
-    char pad[32];
   } addr;
   char *host_name;      /* name of foreign host if type == AF_INET */
 } Sock;
diff --git a/src/lib/sockio-c.c b/src/lib/sockio-c.c
index 5878cfb11..2f6a5edb8 100644
--- a/src/lib/sockio-c.c
+++ b/src/lib/sockio-c.c
@@ -752,13 +752,11 @@ connect_to_local_server(char *server_name, int purpose, int time_out)
     return NULL;
   }
   /* connect socket using name specified in command line */
-  sock->addr.u_addr.sa_family = FRICAS_AF_LOCAL;
-  strcpy(sock->addr.pad +
-          ((char *)(&(sock->addr.u_addr.sa_data))
-           -(char *)(&(sock->addr.u_addr))), name);
+  struct sockaddr_un *uaddr = &(sock->addr.u_addr);
+  uaddr->sun_family = FRICAS_AF_LOCAL;
+  strncpy(uaddr->sun_path, name, sizeof(uaddr->sun_path) - 1);
   for(i=0; i<max_con; i++) {
-    code = connect(sock->socket, &sock->addr.u_addr,
-                   sizeof(sock->addr.pad));
+    code = connect(sock->socket, uaddr, sizeof(*uaddr));
     if (code == -1) {
       if (
         /* @@@ Why we need this */
@@ -924,12 +922,10 @@ open_server(char *server_name)
     return -2;
   } else {
     Sock * sock = &(server[1]);
-    sock->addr.u_addr.sa_family = FRICAS_AF_LOCAL;
-    strcpy(sock->addr.pad +
-          ((char *)(&(sock->addr.u_addr.sa_data))
-           -(char *)(&(sock->addr.u_addr))), name);
-    if (bind(sock->socket, &(sock->addr.u_addr),
-             sizeof(sock->addr.pad))) {
+    struct sockaddr_un * uaddr = &(sock->addr.u_addr);
+    uaddr->sun_family = FRICAS_AF_LOCAL;
+    strncpy(uaddr->sun_path, name, sizeof(uaddr->sun_path) - 1);
+    if (bind(sock->socket, uaddr, sizeof(*uaddr))) {
       perror("binding local server socket");
       server[1].socket = 0;
       return -2;

--
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 fricas-devel+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/fricas-devel/1fcfbcb6-2bdc-60e7-da12-fb9c36690d69%40gmail.com.

Reply via email to