1 | /* |
---|
2 | * $Id: track.h,v 4.18 1999-12-16 01:58:11 danw Exp $ |
---|
3 | */ |
---|
4 | |
---|
5 | #include "bellcore-copyright.h" |
---|
6 | #include "mit-copyright.h" |
---|
7 | |
---|
8 | #include <stdlib.h> |
---|
9 | #include <unistd.h> |
---|
10 | #include <sys/types.h> |
---|
11 | #include <sys/time.h> |
---|
12 | #include <sys/stat.h> |
---|
13 | #include <dirent.h> |
---|
14 | #include <sys/param.h> |
---|
15 | #include <fcntl.h> |
---|
16 | #include <ctype.h> |
---|
17 | #include <signal.h> |
---|
18 | #include <stdio.h> |
---|
19 | #include <string.h> |
---|
20 | #include <limits.h> |
---|
21 | |
---|
22 | /* Default working directory - under to- or from- root */ |
---|
23 | #define DEF_WORKDIR "/usr/athena/lib" |
---|
24 | |
---|
25 | /* Default administrator */ |
---|
26 | #define DEF_ADM "root" |
---|
27 | |
---|
28 | /* Default binary directory - under real root */ |
---|
29 | #define DEF_BINDIR "/usr/athena/etc" |
---|
30 | |
---|
31 | /* Default root for source of transfer */ |
---|
32 | #define DEF_FROMROOT "/srvd" |
---|
33 | |
---|
34 | /* Default subscription list */ |
---|
35 | #define DEF_LOG "/var/tmp/TRACKLOG" |
---|
36 | |
---|
37 | /* Default root for destination of transfer: "" == root. */ |
---|
38 | #define DEF_TOROOT "" |
---|
39 | |
---|
40 | /* Default subscription list */ |
---|
41 | #define DEF_SUB "sys_rvd" |
---|
42 | |
---|
43 | /* Default directory containing subscription lists under working dir */ |
---|
44 | #define DEF_SLISTDIR "slists" |
---|
45 | |
---|
46 | /* Default directory containing stat files under working dir */ |
---|
47 | #define DEF_STATDIR "stats" |
---|
48 | |
---|
49 | /* Default directory containing lock files under real root */ |
---|
50 | #define DEF_LOCKDIR "/tmp" |
---|
51 | |
---|
52 | /* Default global exceptions: filenames shouldn't contain whitespace */ |
---|
53 | #define DEF_EXCEPT { "#*", "*~", "*\t*", "* *", "*\n*" } |
---|
54 | |
---|
55 | /* Default shell */ |
---|
56 | #define DEF_SHELL "/bin/sh" |
---|
57 | |
---|
58 | /* Default command to set a shell variable */ |
---|
59 | #define DEF_SETCMD "" |
---|
60 | |
---|
61 | #define BUFLEN 1024 |
---|
62 | #define BLOCKSIZE 1024 |
---|
63 | #define LINELEN PATH_MAX |
---|
64 | #define MAXLINES 300 |
---|
65 | #define WORDLEN 20 |
---|
66 | #define WORDMAX 128 |
---|
67 | #define ENTRYMAX 256 |
---|
68 | #define STACKMAX 50 |
---|
69 | |
---|
70 | #define CNT 0 |
---|
71 | #define ROOT 1 |
---|
72 | #define NAME 2 |
---|
73 | |
---|
74 | typedef struct currentness { |
---|
75 | char name[ LINELEN]; |
---|
76 | unsigned int cksum; |
---|
77 | char link[ LINELEN]; |
---|
78 | struct stat sbuf; |
---|
79 | } Currentness; |
---|
80 | |
---|
81 | extern char **statfilebufs; |
---|
82 | extern int cur_line; |
---|
83 | extern FILE *statfile; |
---|
84 | |
---|
85 | /* NEXT is defined weirdly, |
---|
86 | * so that it can appear as an lvalue. |
---|
87 | */ |
---|
88 | #define FLAG( list_elt) (((char *)( list_elt))[-1]) |
---|
89 | #define PNEXT( list_elt) ((List_element **)&((char *)( list_elt))[-5]) |
---|
90 | #define NEXT( list_elt) *PNEXT( list_elt) |
---|
91 | #define TEXT( list_elt) ((char*)(list_elt)) |
---|
92 | #define NORMALCASE ((char) 0) |
---|
93 | #define FORCE_LINK ((char)-1) |
---|
94 | #define DONT_TRACK ((char) 1) |
---|
95 | |
---|
96 | typedef struct list_element { |
---|
97 | struct list_element *next; |
---|
98 | char flag; |
---|
99 | char first_char[1]; |
---|
100 | } List_element; |
---|
101 | |
---|
102 | /* XXX: if shift field is negative, the table field contains a linked-list. |
---|
103 | * if shift is positive, the table is a hash-table. |
---|
104 | * this enables justshow() to dump an incompletely-parsed subscription-list. |
---|
105 | * LIST() macro should only be used when adding list-elts during parsing. |
---|
106 | */ |
---|
107 | #define LIST( tbl) ( (tbl).shift--, (List_element**)&(tbl).table) |
---|
108 | typedef struct Tbl { |
---|
109 | List_element **table; |
---|
110 | short shift; |
---|
111 | } Table; |
---|
112 | |
---|
113 | /* sortkey must be at the beginning of this structure because we compare |
---|
114 | * them against each other using strcmp() in stamp.c:sort_entries(). */ |
---|
115 | typedef struct entry { |
---|
116 | char sortkey[ LINELEN]; |
---|
117 | int islink; |
---|
118 | int keylen; |
---|
119 | char *fromfile; |
---|
120 | char *tofile; |
---|
121 | char *cmpfile; |
---|
122 | Currentness currency; |
---|
123 | Table names; |
---|
124 | List_element *patterns; |
---|
125 | char *cmdbuf; |
---|
126 | } Entry ; |
---|
127 | extern Entry entries[]; |
---|
128 | |
---|
129 | extern int errno; |
---|
130 | extern int cksumflag; |
---|
131 | extern int forceflag; |
---|
132 | extern int ignore_prots; |
---|
133 | extern int incl_devs; |
---|
134 | extern int nopullflag; |
---|
135 | extern int parseflag; |
---|
136 | extern int quietflag; |
---|
137 | extern int uflag; |
---|
138 | extern int verboseflag; |
---|
139 | extern int writeflag; |
---|
140 | extern int entnum; |
---|
141 | extern int entrycnt; |
---|
142 | extern unsigned stackmax; |
---|
143 | extern unsigned maxlines; |
---|
144 | |
---|
145 | #define IS_LIST 1 |
---|
146 | #define NO_LIST 0 |
---|
147 | |
---|
148 | #define LOCK_TIME ((long)(60 * 60 * 6)) /* amount of time to let a lockfile |
---|
149 | sit before trying again |
---|
150 | i.e. 6 hours */ |
---|
151 | extern char binarydir[]; |
---|
152 | extern char fromroot[]; |
---|
153 | extern char toroot[]; |
---|
154 | extern char twdir[]; |
---|
155 | extern char cwd[]; |
---|
156 | extern char subfilename[]; |
---|
157 | extern char logfilepath[]; |
---|
158 | extern char subfilepath[]; |
---|
159 | extern char prgname[]; |
---|
160 | extern FILE *logfile; |
---|
161 | extern int debug; |
---|
162 | |
---|
163 | #define DO_CLOBBER 1 |
---|
164 | #define NO_CLOBBER 0 |
---|
165 | extern int clobber; |
---|
166 | |
---|
167 | /* parser stuff */ |
---|
168 | extern char wordbuf[]; |
---|
169 | extern char linebuf[]; |
---|
170 | extern FILE *yyin,*yyout; |
---|
171 | |
---|
172 | #define TYPE( statbuf) ((statbuf).st_mode & S_IFMT) |
---|
173 | #define MODE( statbuf) ((statbuf).st_mode & 07777) |
---|
174 | #define TIME( statbuf) ((statbuf).st_mtime) |
---|
175 | #define UID( statbuf) ((statbuf).st_uid) |
---|
176 | #define GID( statbuf) ((statbuf).st_gid) |
---|
177 | #define RDEV( statbuf) ((statbuf).st_rdev) |
---|
178 | |
---|
179 | extern int access(); |
---|
180 | |
---|
181 | extern char errmsg[]; |
---|
182 | char *gets(),*re_comp(); |
---|
183 | long time(); |
---|
184 | |
---|
185 | int stat(), lstat(); |
---|
186 | |
---|
187 | /* track's internal functions which need decl's */ |
---|
188 | |
---|
189 | extern Entry *clear_ent(); |
---|
190 | |
---|
191 | extern FILE *opensubfile(); |
---|
192 | |
---|
193 | extern List_element *add_list_elt(); |
---|
194 | extern List_element **lookup(); |
---|
195 | |
---|
196 | extern char *dec_statfile(); |
---|
197 | extern char *goodname(); |
---|
198 | extern char **initpath(); |
---|
199 | extern char *next_def_except(); |
---|
200 | extern char *re_conv(); |
---|
201 | extern char *resolve(); |
---|
202 | |
---|
203 | extern int entrycmp(), statlinecmp(); |
---|
204 | extern unsigned long hash(); |
---|
205 | extern unsigned in_cksum(); |
---|
206 | |
---|
207 | extern struct currentness *dec_entry(); |
---|
208 | extern struct currentness *get_cmp_currency(); |
---|
209 | |
---|
210 | #define SIGN( i) (((i) > 0)? 1 : ((i)? -1 : 0)) |
---|
211 | |
---|
212 | /* make a sortkey out of a pathname. |
---|
213 | * because several printing characters, notably '.', |
---|
214 | * come before '/' in the standard ascii sort-order, |
---|
215 | * we need a non-standard sorting order: |
---|
216 | * /etc |
---|
217 | * /etc/blah |
---|
218 | * /etc/whoop |
---|
219 | * /etc.athena ... |
---|
220 | * this requires that slashes get mapped to low-ranking |
---|
221 | * non-printing characters, for the purposes of the sort. |
---|
222 | * this macro allows us to do it fast. |
---|
223 | */ |
---|
224 | #define KEYCPY( key, name) \ |
---|
225 | {char *k,*p; k=key; for (p=name;*p;p++) *k++ = (*p=='/') ? '\001' : *p; *k= *p;} |
---|