2 * Main program for agedu.
16 #include <sys/types.h>
20 #include <sys/ioctl.h>
32 #define lenof(x) (sizeof((x))/sizeof(*(x)))
34 void fatal(const char *fmt
, ...)
37 fprintf(stderr
, "%s: ", PNAME
);
39 vfprintf(stderr
, fmt
, ap
);
41 fprintf(stderr
, "\n");
45 struct inclusion_exclusion
{
53 dev_t datafile_dev
, filesystem_dev
;
55 time_t last_output_update
;
56 int progress
, progwidth
;
57 struct inclusion_exclusion
*inex
;
62 static int gotdata(void *vctx
, const char *pathname
, const struct stat64
*st
)
64 struct ctx
*ctx
= (struct ctx
*)vctx
;
65 struct trie_file file
;
71 * Filter out our own data file.
73 if (st
->st_dev
== ctx
->datafile_dev
&& st
->st_ino
== ctx
->datafile_ino
)
77 * Don't cross the streams^W^Wany file system boundary.
79 if (!ctx
->crossfs
&& st
->st_dev
!= ctx
->filesystem_dev
)
82 file
.blocks
= st
->st_blocks
;
83 file
.atime
= st
->st_atime
;
86 * Filter based on wildcards.
89 filename
= strrchr(pathname
, '/');
94 for (i
= 0; i
< ctx
->ninex
; i
++) {
95 if (fnmatch(ctx
->inex
[i
].wildcard
,
96 ctx
->inex
[i
].path ? pathname
: filename
, 0) == 0)
97 include
= ctx
->inex
[i
].type
;
100 return 0; /* ignore this entry and any subdirs */
103 * Here we are supposed to be filtering an entry out, but
104 * still recursing into it if it's a directory. However,
105 * we can't actually leave out any directory whose
106 * subdirectories we then look at. So we cheat, in that
107 * case, by setting the size to zero.
109 if (!S_ISDIR(st
->st_mode
))
110 return 0; /* just ignore */
115 triebuild_add(ctx
->tb
, pathname
, &file
);
118 if (t
!= ctx
->last_output_update
) {
120 fprintf(stderr
, "%-*.*s\r", ctx
->progwidth
, ctx
->progwidth
,
124 ctx
->last_output_update
= t
;
130 static void text_query(const void *mappedfile
, const char *querydir
,
135 unsigned long xi1
, xi2
;
136 unsigned long long s1
, s2
;
138 maxpathlen
= trie_maxpathlen(mappedfile
);
139 pathbuf
= snewn(maxpathlen
+ 1, char);
142 * We want to query everything between the supplied filename
143 * (inclusive) and that filename with a ^A on the end
144 * (exclusive). So find the x indices for each.
146 sprintf(pathbuf
, "%s\001", querydir
);
147 xi1
= trie_before(mappedfile
, querydir
);
148 xi2
= trie_before(mappedfile
, pathbuf
);
151 * Now do the lookups in the age index.
153 s1
= index_query(mappedfile
, xi1
, t
);
154 s2
= index_query(mappedfile
, xi2
, t
);
157 return; /* no space taken up => no display */
159 /* Display in units of 2 512-byte blocks = 1Kb */
160 printf("%-11llu %s\n", (s2
- s1
) / 2, querydir
);
164 * Now scan for first-level subdirectories and report
169 trie_getpath(mappedfile
, xi1
, pathbuf
);
170 text_query(mappedfile
, pathbuf
, t
, depth
-1);
171 strcat(pathbuf
, "\001");
172 xi1
= trie_before(mappedfile
, pathbuf
);
178 * Largely frivolous way to define all my command-line options. I
179 * present here a parametric macro which declares a series of
180 * _logical_ option identifiers, and for each one declares zero or
181 * more short option characters and zero or more long option
182 * words. Then I repeatedly invoke that macro with its arguments
183 * defined to be various other macros, which allows me to
186 * - define an enum allocating a distinct integer value to each
188 * - define a string consisting of precisely all the short option
190 * - define a string array consisting of all the long option
192 * - define (with help from auxiliary enums) integer arrays
193 * parallel to both of the above giving the logical option id
194 * for each physical short and long option
195 * - define an array indexed by logical option id indicating
196 * whether the option in question takes a value
197 * - define a function which prints out brief online help for all
200 * It's not at all clear to me that this trickery is actually
201 * particularly _efficient_ - it still, after all, requires going
202 * linearly through the option list at run time and doing a
203 * strcmp, whereas in an ideal world I'd have liked the lists of
204 * long and short options to be pre-sorted so that a binary search
205 * or some other more efficient lookup was possible. (Not that
206 * asymptotic algorithmic complexity is remotely vital in option
207 * parsing, but if I were doing this in, say, Lisp or something
208 * with an equivalently powerful preprocessor then once I'd had
209 * the idea of preparing the option-parsing data structures at
210 * compile time I would probably have made the effort to prepare
211 * them _properly_. I could have Perl generate me a source file
212 * from some sort of description, I suppose, but that would seem
213 * like overkill. And in any case, it's more of a challenge to
214 * achieve as much as possible by cunning use of cpp and enum than
215 * to just write some sensible and logical code in a Turing-
216 * complete language. I said it was largely frivolous :-)
218 * This approach does have the virtue that it brings together the
219 * option ids, option spellings and help text into a single
220 * combined list and defines them all in exactly one place. If I
221 * want to add a new option, or a new spelling for an option, I
222 * only have to modify the main OPTHELP macro below and then add
223 * code to process the new logical id.
225 * (Though, really, even that isn't ideal, since it still involves
226 * modifying the source file in more than one place. In a
227 * _properly_ ideal world, I'd be able to interleave the option
228 * definitions with the code fragments that process them. And then
229 * not bother defining logical identifiers for them at all - those
230 * would be automatically generated, since I wouldn't have any
231 * need to specify them manually in another part of the code.)
234 #define OPTHELP(NOVAL, VAL, SHORT, LONG, HELPPFX, HELPARG, HELPLINE, HELPOPT) \
235 HELPPFX("usage") HELPLINE("agedu [options] action") \
237 VAL(SCAN) SHORT(s) LONG(scan) \
238 HELPARG("directory") HELPOPT("scan and index a directory") \
239 NOVAL(DUMP) SHORT(d) LONG(dump) HELPOPT("dump the index file") \
240 VAL(TEXT) SHORT(t) LONG(text) \
241 HELPARG("subdir") HELPOPT("print a plain text report on a subdirectory") \
242 VAL(HTML) SHORT(H) LONG(html) \
243 HELPARG("subdir") HELPOPT("print an HTML report on a subdirectory") \
244 NOVAL(HTTPD) SHORT(w) LONG(web) LONG(server) LONG(httpd) \
245 HELPOPT("serve reports from a temporary web server") \
247 VAL(DATAFILE) SHORT(f) LONG(file) \
248 HELPARG("filename") HELPOPT("[all modes] specify index file") \
249 NOVAL(PROGRESS) LONG(progress) LONG(scan_progress) \
250 HELPOPT("[--scan] report progress on stderr") \
251 NOVAL(NOPROGRESS) LONG(no_progress) LONG(no_scan_progress) \
252 HELPOPT("[--scan] do not report progress") \
253 NOVAL(TTYPROGRESS) LONG(tty_progress) LONG(tty_scan_progress) \
254 LONG(progress_tty) LONG(scan_progress_tty) \
255 HELPOPT("[--scan] report progress if stderr is a tty") \
256 NOVAL(CROSSFS) LONG(cross_fs) \
257 HELPOPT("[--scan] cross filesystem boundaries") \
258 NOVAL(NOCROSSFS) LONG(no_cross_fs) \
259 HELPOPT("[--scan] stick to one filesystem") \
260 VAL(INCLUDE) LONG(include) \
261 HELPARG("wildcard") HELPOPT("[--scan] include files matching pattern") \
262 VAL(INCLUDEPATH) LONG(include_path) \
263 HELPARG("wildcard") HELPOPT("[--scan] include pathnames matching pattern") \
264 VAL(EXCLUDE) LONG(exclude) \
265 HELPARG("wildcard") HELPOPT("[--scan] exclude files matching pattern") \
266 VAL(EXCLUDEPATH) LONG(exclude_path) \
267 HELPARG("wildcard") HELPOPT("[--scan] exclude pathnames matching pattern") \
268 VAL(PRUNE) LONG(prune) \
269 HELPARG("wildcard") HELPOPT("[--scan] prune files matching pattern") \
270 VAL(PRUNEPATH) LONG(prune_path) \
271 HELPARG("wildcard") HELPOPT("[--scan] prune pathnames matching pattern") \
272 VAL(MINAGE) SHORT(a) LONG(age) LONG(min_age) LONG(minimum_age) \
273 HELPARG("age") HELPOPT("[--text] include only files older than this") \
274 VAL(AGERANGE) SHORT(r) LONG(age_range) LONG(range) LONG(ages) \
275 HELPARG("age[-age]") HELPOPT("[--html,--web] set limits of colour coding") \
276 VAL(AUTH) LONG(auth) LONG(http_auth) LONG(httpd_auth) \
277 LONG(server_auth) LONG(web_auth) \
278 HELPARG("type") HELPOPT("[--web] specify HTTP authentication method") \
280 NOVAL(HELP) SHORT(h) LONG(help) HELPOPT("display this help text") \
281 NOVAL(VERSION) SHORT(V) LONG(version) HELPOPT("report version number") \
282 NOVAL(LICENCE) LONG(licence) LONG(license) \
283 HELPOPT("display (MIT) licence text") \
286 #define DEFENUM(x) OPT_ ## x,
289 #define STRING(x) #x ,
290 #define STRINGNOCOMMA(x) #x
291 #define SHORTNEWOPT(x) SHORTtmp_ ## x = OPT_ ## x,
292 #define SHORTTHISOPT(x) SHORTtmp2_ ## x, SHORTVAL_ ## x = SHORTtmp2_ ## x - 1,
293 #define SHORTOPTVAL(x) SHORTVAL_ ## x,
294 #define SHORTTMP(x) SHORTtmp3_ ## x,
295 #define LONGNEWOPT(x) LONGtmp_ ## x = OPT_ ## x,
296 #define LONGTHISOPT(x) LONGtmp2_ ## x, LONGVAL_ ## x = LONGtmp2_ ## x - 1,
297 #define LONGOPTVAL(x) LONGVAL_ ## x,
298 #define LONGTMP(x) SHORTtmp3_ ## x,
300 #define OPTIONS(NOVAL, VAL, SHORT, LONG) \
301 OPTHELP(NOVAL, VAL, SHORT, LONG, IGNORE, IGNORE, IGNORE, IGNORE)
303 enum { OPTIONS(DEFENUM
,DEFENUM
,IGNORE
,IGNORE
) NOPTIONS
};
304 enum { OPTIONS(IGNORE
,IGNORE
,SHORTTMP
,IGNORE
) NSHORTOPTS
};
305 enum { OPTIONS(IGNORE
,IGNORE
,IGNORE
,LONGTMP
) NLONGOPTS
};
306 static const int opthasval
[NOPTIONS
] = {OPTIONS(ZERO
,ONE
,IGNORE
,IGNORE
)};
307 static const char shortopts
[] = {OPTIONS(IGNORE
,IGNORE
,STRINGNOCOMMA
,IGNORE
)};
308 static const char *const longopts
[] = {OPTIONS(IGNORE
,IGNORE
,IGNORE
,STRING
)};
309 enum { OPTIONS(SHORTNEWOPT
,SHORTNEWOPT
,SHORTTHISOPT
,IGNORE
) };
310 enum { OPTIONS(LONGNEWOPT
,LONGNEWOPT
,IGNORE
,LONGTHISOPT
) };
311 static const int shortvals
[] = {OPTIONS(IGNORE
,IGNORE
,SHORTOPTVAL
,IGNORE
)};
312 static const int longvals
[] = {OPTIONS(IGNORE
,IGNORE
,IGNORE
,LONGOPTVAL
)};
314 static void usage(FILE *fp
)
317 const char *prefix
, *shortopt
, *longopt
, *optarg
;
320 #define HELPRESET prefix = shortopt = longopt = optarg = NULL, optex = -1
321 #define HELPNOVAL(s) optex = 0;
322 #define HELPVAL(s) optex = 1;
323 #define HELPSHORT(s) if (!shortopt) shortopt = "-" #s;
324 #define HELPLONG(s) if (!longopt) { \
325 strcpy(longbuf, "--" #s); longopt = longbuf; \
326 for (i = 0; longbuf[i]; i++) if (longbuf[i] == '_') longbuf[i] = '-'; }
327 #define HELPPFX(s) prefix = s;
328 #define HELPARG(s) optarg = s;
329 #define HELPLINE(s) assert(optex == -1); \
330 fprintf(fp, "%7s%c %s\n", prefix?prefix:"", prefix?':':' ', s); \
332 #define HELPOPT(s) assert((optex == 1 && optarg) || (optex == 0 && !optarg)); \
333 assert(shortopt || longopt); \
334 i = fprintf(fp, "%7s%c %s%s%s%s%s", prefix?prefix:"", prefix?':':' ', \
335 shortopt?shortopt:"", shortopt&&longopt?", ":"", longopt?longopt:"", \
336 optarg?" ":"", optarg?optarg:""); \
337 fprintf(fp, "%*s %s\n", i<32?32-i:0,"",s); HELPRESET;
340 OPTHELP(HELPNOVAL
, HELPVAL
, HELPSHORT
, HELPLONG
,
341 HELPPFX
, HELPARG
, HELPLINE
, HELPOPT
);
354 static time_t parse_age(time_t now
, const char *agestr
)
363 if (2 != sscanf(agestr
, "%d%1[DdWwMmYy]", &nunits
, unit
)) {
364 fprintf(stderr
, "%s: age specification should be a number followed by"
365 " one of d,w,m,y\n", PNAME
);
369 if (unit
[0] == 'd') {
371 } else if (unit
[0] == 'w') {
372 t
-= 86400 * 7 * nunits
;
377 ym
= tm
.tm_year
* 12 + tm
.tm_mon
;
384 tm
.tm_year
= ym
/ 12;
393 int main(int argc
, char **argv
)
396 struct ctx actx
, *ctx
= &actx
;
398 off_t totalsize
, realsize
;
402 const struct trie_file
*tf
;
403 char *filename
= "agedu.dat";
404 char *scandir
= NULL
;
405 char *querydir
= NULL
;
407 enum { USAGE
, TEXT
, HTML
, SCAN
, DUMP
, HTTPD
} mode
= USAGE
;
408 time_t now
= time(NULL
);
409 time_t textcutoff
= now
, htmlnewest
= now
, htmloldest
= now
;
410 int htmlautoagerange
= 1;
411 int auth
= HTTPD_AUTH_MAGIC
| HTTPD_AUTH_BASIC
;
413 struct inclusion_exclusion
*inex
= NULL
;
414 int ninex
= 0, inexsize
= 0;
417 #ifdef DEBUG_MAD_OPTION_PARSING_MACROS
419 static const char *const optnames
[NOPTIONS
] = {
420 OPTIONS(STRING
,STRING
,IGNORE
,IGNORE
)
423 for (i
= 0; i
< NSHORTOPTS
; i
++)
424 printf("-%c == %s [%s]\n", shortopts
[i
], optnames
[shortvals
[i
]],
425 opthasval
[shortvals
[i
]] ?
"value" : "no value");
426 for (i
= 0; i
< NLONGOPTS
; i
++)
427 printf("--%s == %s [%s]\n", longopts
[i
], optnames
[longvals
[i
]],
428 opthasval
[longvals
[i
]] ?
"value" : "no value");
435 if (doing_opts
&& *p
== '-') {
438 if (!strcmp(p
, "--")) {
449 if (wordstart
&& *p
== '-') {
451 * GNU-style long option.
454 optval
= strchr(p
, '=');
458 for (i
= 0; i
< NLONGOPTS
; i
++) {
459 const char *opt
= longopts
[i
], *s
= p
;
462 * The underscores in the option names
463 * defined above may be given by the user
464 * as underscores or dashes, or omitted
469 if (*s
== '-' || *s
== '_')
487 fprintf(stderr
, "%s: unrecognised option '--%s'\n",
492 if (!opthasval
[optid
]) {
494 fprintf(stderr
, "%s: unexpected argument to option"
495 " '--%s'\n", PNAME
, p
);
503 fprintf(stderr
, "%s: option '--%s' expects"
504 " an argument\n", PNAME
, p
);
510 p
+= strlen(p
); /* finished with this argument word */
517 for (i
= 0; i
< NSHORTOPTS
; i
++)
518 if (c
== shortopts
[i
]) {
519 optid
= shortvals
[i
];
524 fprintf(stderr
, "%s: unrecognised option '-%c'\n",
529 if (opthasval
[optid
]) {
533 } else if (--argc
> 0) {
536 fprintf(stderr
, "%s: option '-%c' expects"
537 " an argument\n", PNAME
, c
);
548 * Now actually process the option.
555 printf("FIXME: version();\n");
558 printf("FIXME: licence();\n");
584 case OPT_TTYPROGRESS
:
597 textcutoff
= parse_age(now
, optval
);
600 if (!strcmp(optval
, "auto")) {
601 htmlautoagerange
= 1;
603 char *q
= optval
+ strcspn(optval
, "-:");
606 htmloldest
= parse_age(now
, optval
);
607 htmlnewest
= *q ?
parse_age(now
, q
) : now
;
608 htmlautoagerange
= 0;
612 if (!strcmp(optval
, "magic"))
613 auth
= HTTPD_AUTH_MAGIC
;
614 else if (!strcmp(optval
, "basic"))
615 auth
= HTTPD_AUTH_BASIC
;
616 else if (!strcmp(optval
, "none"))
617 auth
= HTTPD_AUTH_NONE
;
618 else if (!strcmp(optval
, "default"))
619 auth
= HTTPD_AUTH_MAGIC
| HTTPD_AUTH_BASIC
;
620 else if (!strcmp(optval
, "help") ||
621 !strcmp(optval
, "list")) {
622 printf("agedu: supported HTTP authentication types"
624 " magic use Linux /proc/net/tcp to"
625 " determine owner of peer socket\n"
626 " basic HTTP Basic username and"
627 " password authentication\n"
628 " default use 'magic' if possible, "
629 " otherwise fall back to 'basic'\n"
630 " none unauthenticated HTTP (if"
631 " the data file is non-confidential)\n");
634 fprintf(stderr
, "%s: unrecognised authentication"
635 " type '%s'\n%*s options are 'magic',"
636 " 'basic', 'none', 'default'\n",
637 PNAME
, optval
, (int)strlen(PNAME
), "");
642 case OPT_INCLUDEPATH
:
644 case OPT_EXCLUDEPATH
:
647 if (ninex
>= inexsize
) {
648 inexsize
= ninex
* 3 / 2 + 16;
649 inex
= sresize(inex
, inexsize
,
650 struct inclusion_exclusion
);
652 inex
[ninex
].path
= (optid
== OPT_INCLUDEPATH
||
653 optid
== OPT_EXCLUDEPATH
||
654 optid
== OPT_PRUNEPATH
);
655 inex
[ninex
].type
= (optid
== OPT_INCLUDE ?
1 :
656 optid
== OPT_INCLUDEPATH ?
1 :
657 optid
== OPT_EXCLUDE ?
0 :
658 optid
== OPT_EXCLUDEPATH ?
0 :
659 optid
== OPT_PRUNE ?
-1 :
660 /* optid == OPT_PRUNEPATH ? */ -1);
661 inex
[ninex
].wildcard
= optval
;
667 fprintf(stderr
, "%s: unexpected argument '%s'\n", PNAME
, p
);
675 } else if (mode
== SCAN
) {
677 fd
= open(filename
, O_RDWR
| O_TRUNC
| O_CREAT
, S_IRWXU
);
679 fprintf(stderr
, "%s: %s: open: %s\n", PNAME
, filename
,
684 if (stat(scandir
, &st
) < 0) {
685 fprintf(stderr
, "%s: %s: stat: %s\n", PNAME
, scandir
,
689 ctx
->filesystem_dev
= crossfs ?
0 : st
.st_dev
;
691 if (fstat(fd
, &st
) < 0) {
692 perror("agedu: fstat");
695 ctx
->datafile_dev
= st
.st_dev
;
696 ctx
->datafile_ino
= st
.st_ino
;
699 ctx
->crossfs
= crossfs
;
701 ctx
->last_output_update
= time(NULL
);
703 /* progress==1 means report progress only if stderr is a tty */
705 progress
= isatty(2) ?
2 : 0;
706 ctx
->progress
= progress
;
709 if (progress
&& ioctl(2, TIOCGWINSZ
, &ws
) == 0)
710 ctx
->progwidth
= ws
.ws_col
- 1;
716 * Scan the directory tree, and write out the trie component
719 ctx
->tb
= triebuild_new(fd
);
720 du(scandir
, gotdata
, ctx
);
721 count
= triebuild_finish(ctx
->tb
);
722 triebuild_free(ctx
->tb
);
725 fprintf(stderr
, "%-*s\r", ctx
->progwidth
, "");
730 * Work out how much space the cumulative index trees will
731 * take; enlarge the file, and memory-map it.
733 if (fstat(fd
, &st
) < 0) {
734 perror("agedu: fstat");
738 printf("Built pathname index, %d entries, %ju bytes\n", count
,
739 (intmax_t)st
.st_size
);
741 totalsize
= index_compute_size(st
.st_size
, count
);
743 if (lseek(fd
, totalsize
-1, SEEK_SET
) < 0) {
744 perror("agedu: lseek");
747 if (write(fd
, "\0", 1) < 1) {
748 perror("agedu: write");
752 printf("Upper bound on index file size = %ju bytes\n",
753 (intmax_t)totalsize
);
755 mappedfile
= mmap(NULL
, totalsize
, PROT_READ
|PROT_WRITE
,MAP_SHARED
, fd
, 0);
757 perror("agedu: mmap");
761 ib
= indexbuild_new(mappedfile
, st
.st_size
, count
);
762 tw
= triewalk_new(mappedfile
);
763 while ((tf
= triewalk_next(tw
, NULL
)) != NULL
)
764 indexbuild_add(ib
, tf
);
766 realsize
= indexbuild_realsize(ib
);
769 munmap(mappedfile
, totalsize
);
770 ftruncate(fd
, realsize
);
772 printf("Actual index file size = %ju bytes\n", (intmax_t)realsize
);
773 } else if (mode
== TEXT
) {
776 fd
= open(filename
, O_RDONLY
);
778 fprintf(stderr
, "%s: %s: open: %s\n", PNAME
, filename
,
782 if (fstat(fd
, &st
) < 0) {
783 perror("agedu: fstat");
786 totalsize
= st
.st_size
;
787 mappedfile
= mmap(NULL
, totalsize
, PROT_READ
, MAP_SHARED
, fd
, 0);
789 perror("agedu: mmap");
794 * Trim trailing slash, just in case.
796 pathlen
= strlen(querydir
);
797 if (pathlen
> 0 && querydir
[pathlen
-1] == '/')
798 querydir
[--pathlen
] = '\0';
800 text_query(mappedfile
, querydir
, textcutoff
, 1);
801 } else if (mode
== HTML
) {
803 struct html_config cfg
;
807 fd
= open(filename
, O_RDONLY
);
809 fprintf(stderr
, "%s: %s: open: %s\n", PNAME
, filename
,
813 if (fstat(fd
, &st
) < 0) {
814 perror("agedu: fstat");
817 totalsize
= st
.st_size
;
818 mappedfile
= mmap(NULL
, totalsize
, PROT_READ
, MAP_SHARED
, fd
, 0);
820 perror("agedu: mmap");
825 * Trim trailing slash, just in case.
827 pathlen
= strlen(querydir
);
828 if (pathlen
> 0 && querydir
[pathlen
-1] == '/')
829 querydir
[--pathlen
] = '\0';
831 xi
= trie_before(mappedfile
, querydir
);
833 cfg
.autoage
= htmlautoagerange
;
834 cfg
.oldest
= htmloldest
;
835 cfg
.newest
= htmlnewest
;
836 html
= html_query(mappedfile
, xi
, &cfg
);
838 } else if (mode
== DUMP
) {
842 fd
= open(filename
, O_RDONLY
);
844 fprintf(stderr
, "%s: %s: open: %s\n", PNAME
, filename
,
848 if (fstat(fd
, &st
) < 0) {
849 perror("agedu: fstat");
852 totalsize
= st
.st_size
;
853 mappedfile
= mmap(NULL
, totalsize
, PROT_READ
, MAP_SHARED
, fd
, 0);
855 perror("agedu: mmap");
859 maxpathlen
= trie_maxpathlen(mappedfile
);
860 buf
= snewn(maxpathlen
, char);
862 tw
= triewalk_new(mappedfile
);
863 while ((tf
= triewalk_next(tw
, buf
)) != NULL
) {
864 printf("%s: %llu %llu\n", buf
, tf
->blocks
, tf
->atime
);
867 } else if (mode
== HTTPD
) {
868 struct html_config cfg
;
870 fd
= open(filename
, O_RDONLY
);
872 fprintf(stderr
, "%s: %s: open: %s\n", PNAME
, filename
,
876 if (fstat(fd
, &st
) < 0) {
877 perror("agedu: fstat");
880 totalsize
= st
.st_size
;
881 mappedfile
= mmap(NULL
, totalsize
, PROT_READ
, MAP_SHARED
, fd
, 0);
883 perror("agedu: mmap");
888 cfg
.autoage
= htmlautoagerange
;
889 cfg
.oldest
= htmloldest
;
890 cfg
.newest
= htmlnewest
;
891 run_httpd(mappedfile
, auth
, &cfg
);