tvarious bug fixes - plan9port - [fork] Plan 9 from user space
 (HTM) git clone git://src.adamsgaard.dk/plan9port
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit 78802e6993a0f44d7ac7ff7d0922d55d1b089dac
 (DIR) parent 272fd660b41d7ec793bc9d8972878510f3b66055
 (HTM) Author: rsc <devnull@localhost>
       Date:   Sat, 24 Apr 2004 04:52:49 +0000
       
       various bug fixes
       
       Diffstat:
         M CHANGES                             |       8 ++++++++
         M bin/9c                              |      12 +++++++++++-
         M man/man1/stats.1                    |       4 +++-
         M src/cmd/9term/9term.c               |       4 ++++
         M src/cmd/auxstats/Linux.c            |      12 +++++++++++-
         M src/cmd/rio/README                  |       2 +-
         M src/cmd/rio/event.c                 |      15 +++++++++++++++
         M src/cmd/rio/manage.c                |       7 +++++++
         M src/libdraw/x11-mouse.c             |      26 +++++++++++++++++++++-----
         M src/libplumb/mesg.c                 |       8 ++++++++
       
       10 files changed, 89 insertions(+), 9 deletions(-)
       ---
 (DIR) diff --git a/CHANGES b/CHANGES
       t@@ -1,3 +1,11 @@
       +April 23, 2004
       +
       +        fix B to handle non-existent files properly
       +
       +        add stats
       +
       +        various 9term/rio fixes from axel belinfante
       +
        April 21, 2004
        
                add bc, units, mtime, primes, news
 (DIR) diff --git a/bin/9c b/bin/9c
       t@@ -35,6 +35,7 @@ case "$tag" in
                        u=`uname`
                        v=`uname -r`
                        s=`echo $u$v | tr '. ' '__'`
       +                cflags="$ngflags -g"
                        cflags="$cflags -D__$s__"
                        ;;
        *)
       t@@ -42,4 +43,13 @@ case "$tag" in
                exit 1
        esac
        
       -exec $cc -I$PLAN9/include $cflags "$@"
       +case "$tag" in
       +*SunOS*-cc)
       +        exec $cc -I$PLAN9/include $cflags "$@" | 
       +                /bin/sed 's/\"\([^\"][^\"]*\)\", line \([0-9][0-9]*\)/\1:\2/g'
       +        ;;
       +*)
       +        exec $cc -I$PLAN9/include $cflags "$@"
       +        ;;
       +esac
       +
 (DIR) diff --git a/man/man1/stats.1 b/man/man1/stats.1
       t@@ -176,12 +176,14 @@ and a remote BSD machine
        stats -lmisce `hostname` tux:/usr/local/plan9/bin/auxstats daemon
        .SH SOURCE
        .B /usr/local/plan9/src/cmd/draw/stats.c
       +.PP
       +.B /usr/local/plan9/src/cmd/auxstats
        .SH BUGS
        The
        .I auxstats
        binary needs read access to
        .B /dev/kmem
       -in order to collect network statistics on BSD systems.
       +in order to collect network statistics on non-Linux systems.
        Typically this can be arranged by setting the
        .I auxstat
        binary's
 (DIR) diff --git a/src/cmd/9term/9term.c b/src/cmd/9term/9term.c
       t@@ -544,9 +544,13 @@ mouse(void)
                        domenu2(2);
                        break;
                case 4:
       +                bouncemouse(&t.m);
       +                break;
       +        /*
                        if(aselect(&q0, &q1, plumbcolor) >= 0)
                                plumb(q0, q1);
                        break;
       +        */
                }
        }
        
 (DIR) diff --git a/src/cmd/auxstats/Linux.c b/src/cmd/auxstats/Linux.c
       t@@ -55,6 +55,7 @@ xmeminfo(int first)
        {
                int i;
                vlong tot, used;
       +        vlong mtot, mfree;
                static int fd = -1;
        
                if(first){
       t@@ -63,9 +64,10 @@ xmeminfo(int first)
                }
        
                readfile(fd);
       +        mtot = 0;
                for(i=0; i<nline; i++){
                        tokens(i);
       -                if(ntok < 4)
       +                if(ntok < 3)
                                continue;
                        tot = atoll(tok[1]);
                        used = atoll(tok[2]);
       t@@ -73,6 +75,14 @@ xmeminfo(int first)
                                Bprint(&bout, "mem =%lld %lld\n", used/1024, tot/1024);
                        else if(strcmp(tok[0], "Swap:") == 0)
                                Bprint(&bout, "swap =%lld %lld\n", used/1024, tot/1024);
       +                else if(strcmp(tok[0], "MemTotal:") == 0)
       +                        mtot = atoll(tok[1]);        /* kb */
       +                else if(strcmp(tok[0], "MemFree:") == 0){
       +                        mfree = atoll(tok[1]);
       +                        if(mtot < mfree)
       +                                continue;
       +                        Bprint(&bout, "mem =%lld %lld\n", mtot-mfree, mtot);
       +                }
                }
        }
        
 (DIR) diff --git a/src/cmd/rio/README b/src/cmd/rio/README
       t@@ -16,7 +16,7 @@ Current incompatibilities that would be nice to fix:
          can put up the usual b3 menu.
        
        Axel Belinfante contributed the code to handle border grabbing
       -for resize.
       +for resize and various other improvements.
        
        The original README is below.
        
 (DIR) diff --git a/src/cmd/rio/event.c b/src/cmd/rio/event.c
       t@@ -352,6 +352,7 @@ property(XPropertyEvent *e)
                Atom a;
                int delete;
                Client *c;
       +        long msize;
        
                /* we don't set curtime as nothing here uses it */
                a = e->atom;
       t@@ -378,6 +379,15 @@ property(XPropertyEvent *e)
                case XA_WM_TRANSIENT_FOR:
                        gettrans(c);
                        return;
       +        case XA_WM_HINTS:
       +        case XA_WM_SIZE_HINTS:
       +        case XA_WM_ZOOM_HINTS:
       +                /* placeholders to not forget.  ignore for now.  -Axel */
       +                return;
       +        case XA_WM_NORMAL_HINTS:
       +                if (XGetWMNormalHints(dpy, c->window, &c->size, &msize) == 0 || c->size.flags == 0)
       +                        c->size.flags = PSize;        /* not specified - punt */
       +                return;
                }
                if (a == _rio_hold_mode) {
                        c->hold = getiprop(c->window, _rio_hold_mode);
       t@@ -404,7 +414,12 @@ reparent(XReparentEvent *e)
                if ((s = getscreen(e->parent)) != 0) {
                        c = getclient(e->window, 1);
                        if (c != 0 && (c->dx == 0 || c->dy == 0)) {
       +                        /* flush any errors */
       +                        ignore_badwindow = 1;
                                XGetWindowAttributes(dpy, c->window, &attr);
       +                        XSync(dpy, False);
       +                        ignore_badwindow = 0;
       +
                                c->x = attr.x;
                                c->y = attr.y;
                                c->dx = attr.width;
 (DIR) diff --git a/src/cmd/rio/manage.c b/src/cmd/rio/manage.c
       t@@ -359,8 +359,11 @@ getcmaps(Client *c)
                XWindowAttributes attr;
        
                if (!c->init) {
       +                ignore_badwindow = 1;
                        XGetWindowAttributes(dpy, c->window, &attr);
                        c->cmap = attr.colormap;
       +                XSync(dpy, False);
       +                ignore_badwindow = 0;
                }
        
                n = _getprop(c->window, wm_colormaps, XA_WINDOW, 100L, (void*)&cw);
       t@@ -381,9 +384,13 @@ getcmaps(Client *c)
                        if (cw[i] == c->window)
                                c->wmcmaps[i] = c->cmap;
                        else {
       +                        /* flush any errors (e.g., caused by mozilla tabs) */
       +                        ignore_badwindow = 1;
                                XSelectInput(dpy, cw[i], ColormapChangeMask);
                                XGetWindowAttributes(dpy, cw[i], &attr);
                                c->wmcmaps[i] = attr.colormap;
       +                        XSync(dpy, False);
       +                        ignore_badwindow = 0;
                        }
                }
        }
 (DIR) diff --git a/src/libdraw/x11-mouse.c b/src/libdraw/x11-mouse.c
       t@@ -149,13 +149,21 @@ setcursor(Mousectl *mc, Cursor *c)
                _xsetcursor(c);
        }
        
       +/*
       + * Send the mouse event back to the window manager.
       + * So that 9term can tell rio to pop up its button3 menu.
       + * Note that we're using _x.mousecon in a few places,
       + * so we have to be sure that the mouse proc isn't using it
       + * when we call!  This is all a bit wonky and should be 
       + * avoided unless you know what you're doing.
       + */
        void
        bouncemouse(Mouse *m)
        {
                XButtonEvent e;
       +        XWindow dw;
        
                e.type = ButtonPress;
       -        e.window = DefaultRootWindow(_x.display);
                e.state = 0;
                e.button = 0;
                if(m->buttons&1)
       t@@ -164,10 +172,18 @@ bouncemouse(Mouse *m)
                        e.button = 2;
                else if(m->buttons&4)
                        e.button = 3;
       -        e.x = m->xy.x;
       -        e.y = m->xy.y;
       +        e.same_screen = 1;
       +        XTranslateCoordinates(_x.display, _x.drawable,
       +                DefaultRootWindow(_x.display),
       +                m->xy.x, m->xy.y, &e.x_root, &e.y_root, &dw);
       +        e.root = DefaultRootWindow(_x.mousecon);
       +        e.window = e.root;
       +        e.subwindow = None;
       +        e.x = e.x_root;
       +        e.y = e.y_root;
        #undef time
                e.time = CurrentTime;
       -        XSendEvent(_x.display, e.window, True, ButtonPressMask, (XEvent*)&e);
       -        XFlush(_x.display);
       +        XUngrabPointer(_x.mousecon, m->msec);
       +        XSendEvent(_x.mousecon, e.root, True, ButtonPressMask, (XEvent*)&e);
       +        XFlush(_x.mousecon);
        }
 (DIR) diff --git a/src/libplumb/mesg.c b/src/libplumb/mesg.c
       t@@ -64,6 +64,10 @@ plumbsendtofid(Fid *fid, Plumbmsg *m)
                char *buf;
                int n;
        
       +        if(fid == nil){
       +                werrstr("invalid fid");
       +                return -1;
       +        }
                buf = plumbpack(m, &n);
                if(buf == nil)
                        return -1;
       t@@ -75,6 +79,10 @@ plumbsendtofid(Fid *fid, Plumbmsg *m)
        int
        plumbsend(int fd, Plumbmsg *m)
        {
       +        if(fd == -1){
       +                werrstr("invalid fd");
       +                return -1;
       +        }
                if(fd != pfd){
                        werrstr("fd is not the plumber");
                        return -1;