Annotation of researchv9/cmd/ps/getargs.c, revision 1.1

1.1     ! root        1: #include "ps.h"
        !             2: #include <sys/vmmac.h>
        !             3: 
        !             4: #define NSTACK 8192
        !             5: #define NCMD   63
        !             6: #define CMDSIZ (4*((DIRSIZ + 3 + 3)/4))
        !             7: 
        !             8: char stack[NSTACK], cmdline[CMDSIZ];
        !             9: 
        !            10: char *
        !            11: getargs(f, pp, up)
        !            12: int f; register struct proc *pp; register struct user *up;
        !            13: {
        !            14:        register char *sp; char *argp, *argend, *envend;
        !            15:        int nstack, staddr, stblk;
        !            16: 
        !            17:        nstack = ctob(up->u_ssize);
        !            18:        if (nstack > NSTACK)
        !            19:                nstack = NSTACK;
        !            20:        staddr = STTOP - nstack;
        !            21: 
        !            22:        if (pp->p_flag & SLOAD) {
        !            23:                if (!Seek(f, staddr) || !Read(f, stack, nstack))
        !            24:                        goto ucommand;
        !            25:        } else {
        !            26:                stblk = up->u_smap.dm_map[dndmap()] + DMMIN;
        !            27:                if (!Seek(drum, stblk*NBPG/ctod(1) - nstack) ||
        !            28:                    !Read(drum, stack, nstack))
        !            29:                        goto ucommand;
        !            30:        }
        !            31: 
        !            32:        sp = stack + nstack;
        !            33:        while (*--sp == 0)
        !            34:                if (sp <= stack) goto ucommand;
        !            35:        envend = sp + 2;
        !            36: 
        !            37:        sp = (char *)((long)sp & (~3));
        !            38:        while (*(long *)(sp -= 4) != 0)
        !            39:                if (sp <= stack) goto ucommand;
        !            40:        argp = sp + 4;
        !            41: 
        !            42:        while (*(long *)(sp -= 4) != 0)
        !            43:                if (sp <= stack) goto ucommand;
        !            44:        argend = *(long *)(sp + 4) - staddr + stack;    /* envp[0] */
        !            45: 
        !            46:        if (argend <= argp || argend > envend )
        !            47:                argend = envend;
        !            48:        if (argend > (sp = argp + NCMD))
        !            49:                argend = sp;
        !            50:        for (sp = argp; sp < argend; sp++) {
        !            51:                if (*sp == 0 || *sp == '\t')
        !            52:                        *sp = ' ';
        !            53:                else if (*sp < ' ' || *sp >= 0177)
        !            54:                        *sp = '?';
        !            55:        }
        !            56:        while (sp[-1] == ' ')
        !            57:                sp--;
        !            58:        *sp = 0;
        !            59:        return argp;
        !            60: 
        !            61: ucommand:
        !            62:        sprintf(cmdline, "(%-.*s)", DIRSIZ, up->u_comm);
        !            63:        return cmdline;
        !            64: }
        !            65: 
        !            66: dndmap()
        !            67: {
        !            68:        register f, n; char cbuf[16];
        !            69:        static called, delta;
        !            70:        if (called++)
        !            71:                return delta;
        !            72:        if ((f = open("/etc/ndmap", 0)) < 0)
        !            73:                return 0;
        !            74:        n = read(f, cbuf, sizeof cbuf-1);
        !            75:        close(f);
        !            76:        if (n <= 0)
        !            77:                return 0;
        !            78:        cbuf[n] = 0;
        !            79:        return (delta = atoi(cbuf) - NDMAP);
        !            80: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.