~mdw
/
sgt
/
agedu
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Why on earth was I creating the data file with x permission? Silly
[sgt/agedu]
/
agedu.c
diff --git
a/agedu.c
b/agedu.c
index
8a6affb
..
76e884c
100644
(file)
--- a/
agedu.c
+++ b/
agedu.c
@@
-2,25
+2,8
@@
* Main program for agedu.
*/
* Main program for agedu.
*/
-#define _GNU_SOURCE
-#include <stdio.h>
-#include <errno.h>
-#include <stdarg.h>
-#include <stdlib.h>
-#include <stdint.h>
-#include <string.h>
-#include <time.h>
-#include <assert.h>
-
-#include <unistd.h>
-#include <sys/types.h>
-#include <fcntl.h>
-#include <sys/mman.h>
-#include <termios.h>
-#include <sys/ioctl.h>
-#include <fnmatch.h>
-
#include "agedu.h"
#include "agedu.h"
+
#include "du.h"
#include "trie.h"
#include "index.h"
#include "du.h"
#include "trie.h"
#include "index.h"
@@
-66,6
+49,7
@@
struct ctx {
struct inclusion_exclusion *inex;
int ninex;
int crossfs;
struct inclusion_exclusion *inex;
int ninex;
int crossfs;
+ int usemtime;
int fakeatimes;
};
int fakeatimes;
};
@@
-82,7
+66,7
@@
static void dump_line(const char *pathname, const struct trie_file *tf)
putchar('\n');
}
putchar('\n');
}
-static int gotdata(void *vctx, const char *pathname, const
struct stat64
*st)
+static int gotdata(void *vctx, const char *pathname, const
STRUCT_STAT
*st)
{
struct ctx *ctx = (struct ctx *)vctx;
struct trie_file file;
{
struct ctx *ctx = (struct ctx *)vctx;
struct trie_file file;
@@
-103,7
+87,7
@@
static int gotdata(void *vctx, const char *pathname, const struct stat64 *st)
return 0;
file.size = (unsigned long long)512 * st->st_blocks;
return 0;
file.size = (unsigned long long)512 * st->st_blocks;
- if (ctx->
fakeatimes && S_ISDIR(st->st_mode
))
+ if (ctx->
usemtime || (ctx->fakeatimes && S_ISDIR(st->st_mode)
))
file.atime = st->st_mtime;
else
file.atime = st->st_atime;
file.atime = st->st_mtime;
else
file.atime = st->st_atime;
@@
-316,6
+300,8
@@
static void text_query(const void *mappedfile, const char *querydir,
HELPOPT("[--scan,--load] keep real atimes on directories") \
NOVAL(NODIRATIME) LONG(no_dir_atime) LONG(no_dir_atimes) \
HELPOPT("[--scan,--load] fake atimes on directories") \
HELPOPT("[--scan,--load] keep real atimes on directories") \
NOVAL(NODIRATIME) LONG(no_dir_atime) LONG(no_dir_atimes) \
HELPOPT("[--scan,--load] fake atimes on directories") \
+ NOVAL(MTIME) LONG(mtime) \
+ HELPOPT("[--scan] use mtime instead of atime") \
VAL(AGERANGE) SHORT(r) LONG(age_range) LONG(range) LONG(ages) \
HELPARG("age[-age]") HELPOPT("[--web,--html] set limits of colour coding") \
VAL(SERVERADDR) LONG(address) LONG(addr) LONG(server_address) \
VAL(AGERANGE) SHORT(r) LONG(age_range) LONG(range) LONG(ages) \
HELPARG("age[-age]") HELPOPT("[--web,--html] set limits of colour coding") \
VAL(SERVERADDR) LONG(address) LONG(addr) LONG(server_address) \
@@
-477,6
+463,7
@@
int main(int argc, char **argv)
int crossfs = 0;
int tqdepth = 1;
int fakediratimes = 1;
int crossfs = 0;
int tqdepth = 1;
int fakediratimes = 1;
+ int mtime = 0;
#ifdef DEBUG_MAD_OPTION_PARSING_MACROS
{
#ifdef DEBUG_MAD_OPTION_PARSING_MACROS
{
@@
-616,7
+603,12
@@
int main(int argc, char **argv)
usage(stdout);
return 0;
case OPT_VERSION:
usage(stdout);
return 0;
case OPT_VERSION:
- printf("FIXME: version();\n");
+#ifdef PACKAGE_VERSION
+ printf("%s, revision %s\n", PNAME, PACKAGE_VERSION);
+#else
+ printf("%s: version number not available when not built"
+ " via automake\n", PNAME);
+#endif
return 0;
case OPT_LICENCE:
{
return 0;
case OPT_LICENCE:
{
@@
-722,6
+714,9
@@
int main(int argc, char **argv)
case OPT_NODIRATIME:
fakediratimes = 1;
break;
case OPT_NODIRATIME:
fakediratimes = 1;
break;
+ case OPT_MTIME:
+ mtime = 1;
+ break;
case OPT_DATAFILE:
filename = optval;
break;
case OPT_DATAFILE:
filename = optval;
break;
@@
-892,7
+887,8
@@
int main(int argc, char **argv)
/*
* Prepare to write out the index file.
*/
/*
* Prepare to write out the index file.
*/
- fd = open(filename, O_RDWR | O_TRUNC | O_CREAT, S_IRWXU);
+ fd = open(filename, O_RDWR | O_TRUNC | O_CREAT,
+ S_IRUSR | S_IWUSR);
if (fd < 0) {
fprintf(stderr, "%s: %s: open: %s\n", PNAME, filename,
strerror(errno));
if (fd < 0) {
fprintf(stderr, "%s: %s: open: %s\n", PNAME, filename,
strerror(errno));
@@
-924,6
+920,7
@@
int main(int argc, char **argv)
ctx->ninex = ninex;
ctx->crossfs = crossfs;
ctx->fakeatimes = fakediratimes;
ctx->ninex = ninex;
ctx->crossfs = crossfs;
ctx->fakeatimes = fakediratimes;
+ ctx->usemtime = mtime;
ctx->last_output_update = time(NULL);
ctx->last_output_update = time(NULL);
@@
-1028,8
+1025,8
@@
int main(int argc, char **argv)
return 1;
}
return 1;
}
- printf("Built pathname index, %d entries, %
j
u bytes\n", count,
- (
intmax_t
)st.st_size);
+ printf("Built pathname index, %d entries, %
ll
u bytes\n", count,
+ (
unsigned long long
)st.st_size);
totalsize = index_compute_size(st.st_size, count);
totalsize = index_compute_size(st.st_size, count);
@@
-1042,8
+1039,8
@@
int main(int argc, char **argv)
return 1;
}
return 1;
}
- printf("Upper bound on index file size = %
j
u bytes\n",
- (
intmax_t
)totalsize);
+ printf("Upper bound on index file size = %
ll
u bytes\n",
+ (
unsigned long long
)totalsize);
mappedfile = mmap(NULL, totalsize, PROT_READ|PROT_WRITE,MAP_SHARED, fd, 0);
if (!mappedfile) {
mappedfile = mmap(NULL, totalsize, PROT_READ|PROT_WRITE,MAP_SHARED, fd, 0);
if (!mappedfile) {
@@
-1068,7
+1065,8
@@
int main(int argc, char **argv)
munmap(mappedfile, totalsize);
ftruncate(fd, realsize);
close(fd);
munmap(mappedfile, totalsize);
ftruncate(fd, realsize);
close(fd);
- printf("Actual index file size = %ju bytes\n", (intmax_t)realsize);
+ printf("Actual index file size = %llu bytes\n",
+ (unsigned long long)realsize);
}
} else if (mode == TEXT) {
char *querydir = actions[action].arg;
}
} else if (mode == TEXT) {
char *querydir = actions[action].arg;
@@
-1100,6
+1098,8
@@
int main(int argc, char **argv)
querydir[--pathlen] = '\0';
text_query(mappedfile, querydir, textcutoff, tqdepth);
querydir[--pathlen] = '\0';
text_query(mappedfile, querydir, textcutoff, tqdepth);
+
+ munmap(mappedfile, totalsize);
} else if (mode == HTML) {
char *querydir = actions[action].arg;
size_t pathlen;
} else if (mode == HTML) {
char *querydir = actions[action].arg;
size_t pathlen;
@@
-1139,6
+1139,8
@@
int main(int argc, char **argv)
cfg.newest = htmlnewest;
html = html_query(mappedfile, xi, &cfg);
fputs(html, stdout);
cfg.newest = htmlnewest;
html = html_query(mappedfile, xi, &cfg);
fputs(html, stdout);
+
+ munmap(mappedfile, totalsize);
} else if (mode == DUMP) {
size_t maxpathlen;
char *buf;
} else if (mode == DUMP) {
size_t maxpathlen;
char *buf;
@@
-1169,6
+1171,8
@@
int main(int argc, char **argv)
while ((tf = triewalk_next(tw, buf)) != NULL)
dump_line(buf, tf);
triewalk_free(tw);
while ((tf = triewalk_next(tw, buf)) != NULL)
dump_line(buf, tf);
triewalk_free(tw);
+
+ munmap(mappedfile, totalsize);
} else if (mode == HTTPD) {
struct html_config pcfg;
struct httpd_config dcfg;
} else if (mode == HTTPD) {
struct html_config pcfg;
struct httpd_config dcfg;
@@
-1199,6
+1203,7
@@
int main(int argc, char **argv)
pcfg.oldest = htmloldest;
pcfg.newest = htmlnewest;
run_httpd(mappedfile, auth, &dcfg, &pcfg);
pcfg.oldest = htmloldest;
pcfg.newest = htmlnewest;
run_httpd(mappedfile, auth, &dcfg, &pcfg);
+ munmap(mappedfile, totalsize);
} else if (mode == REMOVE) {
if (remove(filename) < 0) {
fprintf(stderr, "%s: %s: remove: %s\n", PNAME, filename,
} else if (mode == REMOVE) {
if (remove(filename) < 0) {
fprintf(stderr, "%s: %s: remove: %s\n", PNAME, filename,