[M3devel] Juno (X) networking problem on AMD64_FREEBSD

Jay jay.krell at cornell.edu
Sun Jan 11 14:37:37 CET 2009


I commited a workaround here, that introduces essentially a third copy of relevant code.
Anyone have further ideas?
 
 
 
(* This is a clone of IP.GetHostAddr that returns
TRUE if IP.GetHostAddr is likely to succeed and
FALSE if IP.GetHostAddr is likely to fail. *)
VAR mu := NEW(MUTEX);
 
PROCEDURE PredictIPGetHostAddrSuccess(): BOOLEAN =
VAR hname: ARRAY [0..255] OF CHAR;
BEGIN
LOCK mu DO
RETURN (Unix.gethostname(ADR(hname[0]), BYTESIZE(hname)) = 0)
AND (Unetdb.gethostbyname(ADR(hname[0])) # NIL);
END;
END PredictIPGetHostAddrSuccess;
 
(* return TRUE if server and client are on same host *)
PROCEDURE SameHost (trsl: XClient.T): BOOLEAN =
VAR
display := DisplayHost(trsl);
displayAddr: IP.Address;
 
BEGIN
 
IF display = NIL THEN RETURN TRUE; END;
 
TRY
 
IF NOT IP.GetHostByName(display, displayAddr) THEN RETURN FALSE; END;
 
(* IP.GetHostAddr can return a fatal exception; try to avoid that
by predicting its success. *)
IF NOT PredictIPGetHostAddrSuccess() THEN
RETURN FALSE;
END;
 
RETURN displayAddr = IP.GetHostAddr();
EXCEPT
| IP.Error => RETURN FALSE;
END;
END SameHost;
 
 - Jay



From: jay.krell at cornell.eduTo: m3devel at elegosoft.comDate: Sun, 11 Jan 2009 12:57:13 +0000Subject: [M3devel] Juno (X) networking problem on AMD64_FREEBSD

Hi. Unix network programming question..AMD64_FREEBSD:$DISPLAY is set to point back to Cygwin host.It works for PPC_LINUX.[jay at fbsdamd64a /cm3/bin]$ ./Juno****** runtime error:***    Exception "IPError.FatalError" not in RAISES list***    file "../src/common/IPError.m3", line 27***Abort trap: 6 (core dumped)[jay at fbsdamd64a /cm3/bin]$IP.m3: PROCEDURE GetHostAddr(): Address =  VAR hname: ARRAY [0..255] OF CHAR;  BEGIN    LOCK mu DO      IF Unix.gethostname(ADR(hname[0]), BYTESIZE(hname)) # 0 THEN        IPError.Die ();      END;      VAR h := Unetdb.gethostbyname(ADR(hname[0])); BEGIN        IF h = NIL THEN IPError.Die(); END;        RETURN GetAddress(h);      END;    END;  END GetHostAddr;PROCEDURE GetAddress (ent: Unetdb.struct_hostent_star): Address =  VAR ua: Uin.struct_in_addr;  BEGIN    <* ASSERT ent.h_length <= BYTESIZE(Address) *>    ua := LOOPHOLE(ent.h_addr_list,                    UNTRACED REF UNTRACED REF Uin.struct_in_addr)^^;    RETURN LOOPHOLE(ua.s_addr, Address);  END GetAddress; gethostbyname is failing. Analogous C code also fails: [jay at fbsdamd64a /cm3/bin]$ cat ~/5.c#include <assert.h>#include <netdb.h>#include <stdio.h>#include <errno.h>typedef struct hostent hostent_t; int main(){ char hostname[200]; hostent_t* h; int i; i = gethostname(hostname, 200); assert(i == 0); printf("hostname: %s\n", hostname); h = gethostbyname(hostname); herror("foo"); printf("%p %d %d\n", h, errno, h_errno); assert(h); return 0;} herror says "unknown host".Stack is:    at ../src/runtime/ex_frame/RTExFrame.m3:58#13 0x0000000801a7f2b3 in RTHooks__Raise (M3_AJWxb1_ex=Error accessing memory address 0x8000ffffd278: Bad address.)    at ../src/runtime/common/RTHooks.m3:79#14 0x000000080169c8d3 in IPError__Die () at ../src/common/IPError.m3:27#15 0x0000000801698a3e in IP__GetHostAddr (M3_BCxjPn__result=Error accessing memory address 0x8000ffffd338: Bad address.)    at ../src/POSIX/IP.m3:82#16 0x00000008012133d0 in XSharedMem__SameHost (M3_AQuuui_trsl=Error accessing memory address 0x8000ffffd4d8: Bad address.)    at ../src/xvbt/XSharedMem.m3:96#17 0x0000000801212ab7 in XSharedMem__InitXClient (M3_AQuuui_v=Error accessing memory address 0x8000ffffd648: Bad address.)    at ../src/xvbt/XSharedMem.m3:29#18 0x0000000801211819 in XExtensions__InitXClient (M3_AQuuui_xclient=Error accessing memory address 0x8000ffffd7f8: Bad address.)    at ../src/xvbt/XExtensions.m3:14#19 0x00000008012467a4 in XClientF__Connect (M3_Bd56fi_inst=0x1879b,    M3_AQuuui_trsl=0x6) at ../src/xvbt/XClientF.m3:583---Type <return> to continue, or q <return> to quit---(More stack frames follow...)(gdb)(* return TRUE if server and client are on same host *)PROCEDURE SameHost (trsl: XClient.T): BOOLEAN =  VAR    display                 := DisplayHost(trsl);    displayAddr: IP.Address;  BEGIN    IF display = NIL THEN RETURN TRUE; END;    TRY      IF NOT IP.GetHostByName(display, displayAddr) THEN RETURN FALSE; END;      RETURN displayAddr = IP.GetHostAddr();    EXCEPT    | IP.Error => RETURN FALSE;    END;  END SameHost; Thoughts? Perhaps my network isn't setup well, like I should add the local machine to /etc/hosts.I think this can be made to fail gracefully though.It seems like it has nothing to do with AMD64_FREEBSD, but could have to do with FreeBSD. Seems like SocketPosix has nearly the exact same code but appearsmore forgiving.. IOError instead of Fatal? SocketPosix.m3: PROCEDURE GetHostAddr (): Address  RAISES {OSError.E} =  VAR    host : ARRAY [0..255] OF CHAR;    info : Unetdb.struct_hostent_star;    ua   : Uin.struct_in_addr;  BEGIN    IF Unix.gethostname (ADR (host[0]), BYTESIZE (host)) # 0 THEN      IOError (Unexpected);    END;    info := Unetdb.gethostbyname (ADR (host[0]));    IF info = NIL THEN IOError (Unexpected); END;    <* ASSERT info.h_length <= BYTESIZE (Address) *>    ua := LOOPHOLE(info.h_addr_list,                   UNTRACED REF UNTRACED REF Uin.struct_in_addr)^^;    RETURN LOOPHOLE (ua.s_addr, Address);  END GetHostAddr;  It is again disappointing to see such code duplication.  I guess SameHost can duplicate the logic to predict the error state and return false upon error?Duplicating the logic for a third time. :(  - Jay
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://m3lists.elegosoft.com/pipermail/m3devel/attachments/20090111/ef8bb3f8/attachment-0002.html>


More information about the M3devel mailing list