Annotation of 43BSD/contrib/nntp/rrn/init.c, revision 1.1.1.1

1.1       root        1: /* $Header: init.c,v 4.3.1.2 85/05/21 14:22:46 lwall Exp $
                      2:  *
                      3:  * $Log:       init.c,v $
                      4:  * Revision 4.3.1.2  85/05/21  14:22:46  lwall
                      5:  * Sped up "rn -c" by avoiding unnecessary initialization.
                      6:  * 
                      7:  * Revision 4.3.1.1  85/05/10  11:33:39  lwall
                      8:  * Branch for patches.
                      9:  * 
                     10:  * Revision 4.3  85/05/01  16:16:13  lwall
                     11:  * Baseline for release with 4.3bsd.
                     12:  * 
                     13:  */
                     14: 
                     15: #include "EXTERN.h"
                     16: #include "common.h"
                     17: #include "util.h"
                     18: #include "final.h"
                     19: #include "term.h"
                     20: #include "last.h"
                     21: #include "rn.h"
                     22: #include "rcstuff.h"
                     23: #include "ngdata.h"
                     24: #include "only.h"
                     25: #include "intrp.h"
                     26: #include "addng.h"
                     27: #include "sw.h"
                     28: #include "art.h"
                     29: #include "artsrch.h"
                     30: #include "artio.h"
                     31: #include "backpage.h"
                     32: #include "bits.h"
                     33: #include "cheat.h"
                     34: #include "head.h"
                     35: #include "help.h"
                     36: #include "kfile.h"
                     37: #include "ngsrch.h"
                     38: #include "ngstuff.h"
                     39: #include "rcln.h"
                     40: #include "respond.h"
                     41: #include "ng.h"
                     42: #include "server.h"
                     43: #include "INTERN.h"
                     44: #include "init.h"
                     45: 
                     46: bool
                     47: initialize(argc,argv)
                     48: int argc;
                     49: char *argv[];
                     50: {
                     51:     char *tcbuf;
                     52:     register bool foundany = FALSE;
                     53:     long time();
                     54: #ifdef NOLINEBUF
                     55:     char std_out_buf[BUFSIZ];
                     56: 
                     57:     setbuf(std_out_buf);
                     58: #endif
                     59: 
                     60:     tcbuf = safemalloc(1024);          /* make temp buffer for termcap and */
                     61:                                        /* other initialization stuff */
                     62:     
                     63:     /* init terminal */
                     64:     
                     65:     term_init();                       /* must precede sw_init() so that */
                     66:                                        /* ospeed is set for baud-rate */
                     67:                                        /* switches.  Actually terminal */
                     68:                                        /* mode setting is in term_set() */
                     69: 
                     70:     /* we have to know rnlib to look up global switches in %X/INIT */
                     71: 
                     72:     lib = savestr(filexp(LIB));
                     73:     rnlib = savestr(filexp(RNLIB));
                     74: 
                     75:     /* decode switches */
                     76: 
                     77:     sw_init(argc,argv,&tcbuf);          /* must not do % interps! */
                     78:                                        /* (but may mung environment) */
                     79: 
                     80:     /* init signals, status flags */
                     81: 
                     82:     final_init();
                     83:     
                     84:     /* start up file expansion and the % interpreter */
                     85: 
                     86:     intrp_init(tcbuf);
                     87:     
                     88:     /* now make sure we have a current working directory */
                     89: 
                     90:     if (!checkflag)
                     91:        cwd_check();
                     92:     
                     93:     /* now that we know where to save things, cd to news directory */
                     94: 
                     95:     if (chdir(spool)) {
                     96:        printf(nocd,spool) FLUSH;
                     97:        finalize(1);
                     98:     }
                     99: 
                    100:     /* if we aren't just checking, turn off echo */
                    101: 
                    102:     if (!checkflag)
                    103:        term_set(tcbuf);
                    104: 
                    105:     /* get info on last rn run, if any */
                    106: 
                    107:     if (!checkflag)
                    108:        last_init(tcbuf);
                    109: 
                    110:     free(tcbuf);                       /* recover 1024 bytes */
                    111: 
                    112:     /* make sure we are the right version */
                    113: 
                    114: #ifndef SERVER
                    115:     if (!checkflag)
                    116:        version_check();
                    117: #endif
                    118: 
                    119:     /* make sure we are the sole possessors of .newsrc */
                    120: 
                    121:     if (!checkflag)
                    122:        lock_check();
                    123: 
                    124:     /* check for news news */
                    125: 
                    126:     if (!checkflag)
                    127:        newsnews_check();
                    128: 
                    129:     /* open connection to server if appropriate */
                    130: 
                    131: #ifdef SERVER
                    132:     if (server_init(SERVER_HOST) < 0)
                    133:        finalize(1);
                    134: #endif
                    135: 
                    136:     /* open active file, etc. */
                    137: 
                    138:     ngdata_init();
                    139: 
                    140:     /* now read in the .newsrc file */
                    141: 
                    142:     foundany = rcstuff_init();
                    143: 
                    144:     /* it looks like we will actually read something, so init everything */
                    145: 
                    146:     addng_init();
                    147:     art_init();
                    148:     artio_init();
                    149:     artsrch_init();
                    150:     backpage_init();
                    151:     bits_init();
                    152:     cheat_init();
                    153: /*  final_init();      already done */
                    154:     head_init();
                    155:     help_init();
                    156: /*  intrp_init();      already done */
                    157:     kfile_init();
                    158: /*  last_init();       already done */
                    159:     ng_init();
                    160: /*  ngdata_init();     already done */
                    161:     ngsrch_init();
                    162:     ngstuff_init();
                    163:     only_init();
                    164:     rcln_init();
                    165: /*  rcstuff_init();    already done */
                    166:     respond_init();
                    167:     rn_init();
                    168:     search_init();
                    169: /*  sw_init();      already done */
                    170: /*  term_init();       already done */
                    171:     util_init();
                    172: 
                    173: #ifdef FINDNEWNG
                    174:     fstat(actfp->_file,&filestat);     /* did active file grow? */
                    175:     if (filestat.st_size != lastactsiz) {
                    176:        long actsiz = filestat.st_size; /* remember new size */
                    177:        NG_NUM oldnext = nextrcline;    /* remember # lines in newsrc */
                    178: #ifdef FASTNEW
                    179:        bool munged = writesoft || !lastactsiz;
                    180:                                        /* bad soft ptrs -> edited active */
                    181: #else
                    182:        bool munged = TRUE;             /* just assume .newsrc munged */
                    183: #endif
                    184: 
                    185: #ifdef VERBOSE
                    186:        IF(verbose)
                    187:            fputs("\nChecking active list for new newsgroups...\n",stdout)
                    188:              FLUSH;
                    189:        ELSE
                    190: #endif
                    191: #ifdef TERSE
                    192:            fputs("\nNew newsgroups:\n",stdout) FLUSH;
                    193: #endif
                    194: #ifdef FASTNEW
                    195:        if (!munged) {                  /* maybe just do tail of file? */
                    196:            fseek(actfp,lastactsiz-1,0);
                    197:            fgets(buf,LBUFLEN,actfp);
                    198:            munged = (*buf != '\n');
                    199:            if (!munged)
                    200:                munged = newlist(munged,FALSE);
                    201:        }
                    202: #endif
                    203:        if (munged) {                   /* must we scan entire file? */
                    204:            fseek(actfp,0L,0);          /* rewind active file */
                    205:            newlist(munged,FALSE);      /* sure hope they use hashing... */
                    206:        }
                    207:        lastactsiz = actsiz;            /* remember for .rnlast */
                    208:        if (nextrcline != oldnext) {    /* did we add any new groups? */
                    209:            foundany = TRUE;            /* let main() know */
                    210:            starthere = 0;              /* and start ng scan from the top */
                    211:        }
                    212:     }
                    213: #endif
                    214:     time(&lasttime);                   /* remember when we inited-- */
                    215:                                        /* ends up back in .rnlast */
                    216:     writelast();                       /* in fact, put it there now */
                    217:     
                    218: #ifdef FINDNEWNG
                    219: # ifdef ONLY
                    220:     if (maxngtodo)                     /* patterns on command line? */
                    221:        foundany |= scanactive();
                    222: # endif
                    223: #endif
                    224: 
                    225:     return foundany;
                    226: }
                    227: 
                    228: /* make sure there is no rn out there already */
                    229: 
                    230: void
                    231: lock_check()
                    232: {
                    233:     lockname = savestr(filexp(LOCKNAME));
                    234:     if (!checkflag) {
                    235:        tmpfp = fopen(lockname,"r");
                    236:        if (tmpfp != Nullfp) {
                    237:            int processnum;
                    238:     
                    239:            fgets(buf,LBUFLEN,tmpfp);
                    240:            fclose(tmpfp);
                    241:            processnum = atoi(buf);
                    242: #ifdef VERBOSE
                    243:            IF(verbose)
                    244:                printf("You seem to have left an rn running, process %d.\n",
                    245:                    processnum) FLUSH;
                    246:            ELSE
                    247: #endif
                    248: #ifdef TERSE
                    249:                printf("Rn left running, #%d.\n", processnum) FLUSH;
                    250: #endif
                    251:            if (kill(processnum, SIGEMT)) {
                    252:                                    /* does process not exist? */
                    253:                                    /* (rn ignores SIGEMT) */
                    254:                sleep(2);
                    255: #ifdef VERBOSE
                    256:                IF(verbose)
                    257:                    fputs("\n\
                    258: That process does not seem to exist anymore.  The count of read articles\n\
                    259: may be incorrect in the last newsgroup accessed by that other (defunct)\n\
                    260: process.\n\n",stdout) FLUSH;
                    261:                ELSE
                    262: #endif
                    263: #ifdef TERSE
                    264:                    fputs("\nProcess crashed.\n",stdout) FLUSH;
                    265: #endif
                    266:                if (*lastngname) {
                    267: #ifdef VERBOSE
                    268:                    IF(verbose)
                    269:                        printf("(The last newsgroup accessed was %s.)\n\n",
                    270:                        lastngname) FLUSH;
                    271:                    ELSE
                    272: #endif
                    273: #ifdef TERSE
                    274:                        printf("(In %s.)\n\n",lastngname) FLUSH;
                    275: #endif
                    276:                }
                    277:                get_anything();
                    278:                putchar('\n') FLUSH;
                    279:            }
                    280:            else {
                    281: #ifdef VERBOSE
                    282:                IF(verbose)
                    283:                    fputs("\n\
                    284: You may not have two copies of rn running simultaneously.  Goodbye.\n\
                    285: ",stdout) FLUSH;
                    286:                ELSE
                    287: #endif
                    288: #ifdef TERSE
                    289:                    fputs("\nCan't start another.\n",stdout) FLUSH;
                    290: #endif
                    291:                finalize(0);
                    292:            }
                    293:        }
                    294:        tmpfp = fopen(lockname,"w");
                    295:        if (tmpfp == Nullfp) {
                    296:            printf(cantcreate,lockname) FLUSH;
                    297:            sig_catcher(0);
                    298:        }
                    299:        fprintf(tmpfp,"%d\n",getpid());
                    300:        fclose(tmpfp);
                    301:     }
                    302: }
                    303: 
                    304: void
                    305: newsnews_check()
                    306: {
                    307:     char *newsnewsname = filexp(NEWSNEWSNAME);
                    308: 
                    309:     if ((tmpfp = fopen(newsnewsname,"r")) != Nullfp) {
                    310:        fstat(tmpfp->_file,&filestat);
                    311:        if (filestat.st_mtime > lasttime) {
                    312:            while (fgets(buf,sizeof(buf),tmpfp) != Nullch)
                    313:                fputs(buf,stdout) FLUSH;
                    314:            get_anything();
                    315:            putchar('\n') FLUSH;
                    316:        }
                    317:        fclose(tmpfp);
                    318:     }
                    319: }
                    320: 
                    321: void
                    322: version_check()
                    323: {
                    324:     set_ngname("net.announce");
                    325:     if (access(ngdir,0)) {
                    326: #ifdef VERBOSE
                    327:        IF(verbose)
                    328:            fputs("Can't find net.announce.  Wrong news version?\n",stdout)
                    329:              FLUSH;
                    330:        ELSE
                    331: #endif
                    332: #ifdef TERSE
                    333:            fputs("Wrong version?\n",stdout) FLUSH;
                    334: #endif
                    335:        finalize(1);
                    336:     }
                    337: }

unix.superglobalmegacorp.com

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