Annotation of 3BSD/cmd/uucp/uuclean.c, revision 1.1.1.1

1.1       root        1: #include "uucp.h"
                      2: #include "uucpdefs.h"
                      3: #include <signal.h>
                      4: #include <pwd.h>
                      5: #include <sys/types.h>
                      6: #include <sys/stat.h>
                      7: #include <sys/dir.h>
                      8: 
                      9: /*******
                     10:  *
                     11:  *     uuclean  -  this program will search through the spool
                     12:  *     directory (Spool) and delete all files with a requested
                     13:  *     prefix which are older than (nomtime) seconds.
                     14:  *     If the -m option is set, the program will try to
                     15:  *     send mail to the usid of the file.
                     16:  *
                     17:  *     options:
                     18:  *             -m  -  send mail for deleted file
                     19:  *             -d  -  directory to clean
                     20:  *             -n  -  time to age files before delete (in hours)
                     21:  *             -p  -  prefix for search
                     22:  *             -x  -  turn on debug outputs
                     23:  *     exit status:
                     24:  *             0  -  normal return
                     25:  *             1  -  can not read directory
                     26:  */
                     27: 
                     28: #define DPREFIX "U"
                     29: #define NOMTIME 72     /* hours to age files before deletion */
                     30: 
                     31: main(argc, argv)
                     32: char *argv[];
                     33: {
                     34:        FILE *pdirf;
                     35:        char file[NAMESIZE];
                     36:        time_t nomtime, ptime;
                     37:        struct stat stbuf;
                     38:        int mflg=0;
                     39:        extern int onintr();
                     40: 
                     41:        nomtime = NOMTIME * 3600L;
                     42: 
                     43:        while (argc>1 && argv[1][0] == '-') {
                     44:                switch (argv[1][1]) {
                     45:                case 'd':
                     46:                        Spool = &argv[1][2];
                     47:                        break;
                     48:                case 'm':
                     49:                        mflg = 1;
                     50:                        break;
                     51:                case 'n':
                     52:                        nomtime = atoi(&argv[1][2]) * 3600L;
                     53:                        break;
                     54:                case 'p':
                     55:                        if (&argv[1][2] != '\0')
                     56:                                stpre(&argv[1][2]);
                     57:                        break;
                     58:                case 'x':
                     59:                        Debug = atoi(&argv[1][2]);
                     60:                        if (Debug <= 0)
                     61:                                Debug = 1;
                     62:                        break;
                     63:                default:
                     64:                        printf("unknown flag %s\n", argv[1]); break;
                     65:                }
                     66:                --argc;  argv++;
                     67:        }
                     68: 
                     69:        DEBUG(4, "DEBUG# %s\n", "START");
                     70:        chdir(Spool);
                     71: 
                     72:        if ((pdirf = fopen(Spool, "r")) == NULL) {
                     73:                printf("%s directory unreadable\n", Spool);
                     74:                exit(1);
                     75:        }
                     76: 
                     77:        time(&ptime);
                     78:        while (gnamef(pdirf, file)) {
                     79:                if (!chkpre(file))
                     80:                        continue;
                     81: 
                     82:                if (stat(file, &stbuf) == -1) {
                     83:                DEBUG(4, "stat on %s failed\n", file);
                     84:                        continue;
                     85:                }
                     86: 
                     87: 
                     88:                if ((stbuf.st_mode & S_IFMT) == S_IFDIR)
                     89:                        continue;
                     90:                if ((ptime - stbuf.st_ctime) < nomtime)
                     91:                        continue;
                     92:                DEBUG(4, "unlink file %s\n", file);
                     93:                unlink(file);
                     94:                if (mflg) sdmail(file, stbuf.st_uid);
                     95:        }
                     96: 
                     97:        fclose(pdirf);
                     98:        exit(0);
                     99: }
                    100: 
                    101: 
                    102: #define MAXPRE 10
                    103: char Pre[MAXPRE][DIRSIZ];
                    104: int Npre = 0;
                    105: /***
                    106:  *     chkpre(file)    check for prefix
                    107:  *     char *file;
                    108:  *
                    109:  *     return codes:
                    110:  *             0  -  not prefix
                    111:  *             1  -  is prefix
                    112:  */
                    113: 
                    114: chkpre(file)
                    115: char *file;
                    116: {
                    117:        int i;
                    118: 
                    119:        for (i = 0; i < Npre; i++) {
                    120:                if (prefix(Pre[i], file))
                    121:                        return(1);
                    122:                }
                    123:        return(0);
                    124: }
                    125: 
                    126: /***
                    127:  *     stpre(p)        store prefix
                    128:  *     char *p;
                    129:  *
                    130:  *     return codes:  none
                    131:  */
                    132: 
                    133: stpre(p)
                    134: char *p;
                    135: {
                    136:        if (Npre < MAXPRE - 2)
                    137:                strcpy(Pre[Npre++], p);
                    138:        return;
                    139: }

unix.superglobalmegacorp.com

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