jayduhon / inferno-os

Automatically exported from code.google.com/p/inferno-os
2 stars 0 forks source link

sys->announce announces on the wrong netdir #315

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
/emu/port/dial.c:/^nettrans lacks the namespace correction step at 
/appl/lib/dial.b:/^nettrans/+/redir
 which can result in announcing on the wrong netdir. Listen(1) is notably affected. I don't think I can be arsed writing a patch when it's easier to switch to dial(2).

% mount minooka /n/minooka
% atest '/n/minooka/net/tcp!*!210'
sys:    /net/tcp/clone
dial:   /n/minooka/net/tcp/clone

implement Atest;

include "sys.m";
include "draw.m";
include "dial.m";

Atest: module {
    init: fn(nil: ref Draw->Context, nil: list of string);
};

init(nil: ref Draw->Context, args: list of string)
{
    sys := load Sys Sys->PATH;
    dial := load Dial Dial->PATH;

    addr := "/n/minooka/net/tcp!*!3306";
    if(len args > 1)
        addr = hd tl args;

    sys->print("sys:    ");
    (failed, sysconn) := sys->announce(addr);
    if(failed)
        sys->print("%r\n");
    else
        sys->print("%s\n", sys->fd2path(sysconn.cfd));

    sys->print("dial:   ");
    if((dialconn := dial->announce(addr)) == nil)
        sys->print("%r\n");
    else
        sys->print("%s\n", sys->fd2path(dialconn.cfd));
}

Original issue reported on code.google.com by kristofwycz on 13 Jun 2014 at 12:31

GoogleCodeExporter commented 9 years ago
I've changed sys-dial(2) to declare those routines deprecated, in favour of 
dial(2) as you say. Much though I'd like to remove them, until there's a big 
change overall to justify it, it's probably not worth making existing Dis files 
fail.

Original comment by Charles....@gmail.com on 13 Jun 2014 at 11:57

GoogleCodeExporter commented 9 years ago
Would you be interested in patches for the few programs that still use 
sys->announce and ->listen that convert them to the dial(2) functions?

Original comment by kristofwycz on 13 Jun 2014 at 4:00

GoogleCodeExporter commented 9 years ago
Maybe I'm not too lazy to copy the fix from Plan 9.

diff -r 01665ab22684 emu/port/dial.c
--- a/emu/port/dial.c   Sat Sep 07 11:32:50 2013 +0100
+++ b/emu/port/dial.c   Fri Jun 13 16:48:44 2014 +0000
@@ -408,7 +408,14 @@
    *p++ = 0;
    strncpy(naddr, p, na);
    naddr[na-1] = 0;
-   strncpy(file, buf, nf);
-   file[nf-1] = 0;
+
+   if(buf[0] == '/'){
+       p = strchr(buf+1, '/');
+       if(p == nil)
+           p = buf;
+       else
+           p++;
+   }
+   snprint(file, nf, "%s/%s", netdir, p);
    return 0;
 }

Original comment by kristofwycz on 13 Jun 2014 at 5:07

GoogleCodeExporter commented 9 years ago
Actually, given the number of programs still using it, it would be better to 
make that small change. I had converted most existing programs, but that was 
lost in a small disaster. Laptops. SSDs. Ext2 (not its fault, but it confused 
things). I've put the status back to Accepted and I'll merge in that code. 
Thanks.

Original comment by Charles....@gmail.com on 13 Jun 2014 at 7:22

GoogleCodeExporter commented 9 years ago
I've changed both emu/port/dial.c and os/port/dial.c

Original comment by Charles....@gmail.com on 16 Jun 2014 at 10:43