Annotation of 3BSD/cmd/uucp/uurecover.c, revision 1.1

1.1     ! root        1: #include <stdio.h>
        !             2: #include <a.out.h>
        !             3: #include <param.h>
        !             4: #include <proc.h>
        !             5: #include <sys/stat.h>
        !             6: struct stat xstat;
        !             7: struct proc mproc[NPROC];
        !             8: struct nlist nl[]
        !             9: {      { "_proc"},
        !            10:        { ""},
        !            11: };
        !            12: int err;
        !            13: main(argc,argv) char **argv;
        !            14: {      int i,j;
        !            15:        if(argc<=1) exit(0);
        !            16:        for(i=1;i<argc;i++)
        !            17:        {       if((j=isalock(argv[i]))>0)
        !            18:                        if(isapid(j))
        !            19:                        {       fprintf(stderr,"recovery: %s in use\n",argv[i]);
        !            20:                                err=1;
        !            21:                        }
        !            22:                        else    unlink(argv[i]);
        !            23:                else    fprintf(stderr,"reocvery: %s not a lock\n",argv[i]);
        !            24:        }
        !            25:        exit(err);
        !            26: }
        !            27: isalock(s) char *s;
        !            28: {      int pid,fd;
        !            29:        if(stat(s,&xstat)<0) return(0);
        !            30:        if(xstat.st_size!=2) return(0);
        !            31:        fd=open(s,0);
        !            32:        if(fd<0) return(-1);
        !            33:        read(fd,&pid,2);
        !            34:        close(fd);
        !            35:        return(pid);
        !            36: }
        !            37: int gotpids,pids[NPROC];
        !            38: isapid(n)
        !            39: {      int i;
        !            40:        if(gotpids==0) getpids();
        !            41:        for(i=0;i<NPROC;i++)
        !            42:                if(n==pids[i]) return(1);
        !            43:        return(0);
        !            44: }
        !            45: getpids()
        !            46: {      int i,mem;
        !            47:        nlist("/unix",nl);
        !            48:        if(nl[0].n_type==0)
        !            49:        {       fprintf(stderr,"no namelist, no lock recovery\n");
        !            50:                exit(1);
        !            51:        }
        !            52:        mem=open("/dev/mem",0);
        !            53:        lseek(mem,(long)nl[0].n_value,0);
        !            54:        read(mem,mproc,sizeof(mproc));
        !            55:        if(mproc[0].p_pid != 0)
        !            56:        {       fprintf(stderr,"/unix not loaded, no lock recovery\n");
        !            57:                exit(1);
        !            58:        }
        !            59:        for(i=0;i<NPROC;i++)
        !            60:        {       if(mproc[i].p_stat==0 ||
        !            61:                        mproc[i].p_stat==SZOMB)
        !            62:                        pids[i]=0;
        !            63:                else    pids[i]=mproc[i].p_pid;
        !            64:        }
        !            65:        gotpids=1;
        !            66: }
        !            67: unlock(s) char *s;
        !            68: {
        !            69:        unlink(s);
        !            70: }

unix.superglobalmegacorp.com

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