summaryrefslogtreecommitdiffstats
path: root/manup.c
diff options
context:
space:
mode:
authorKristaps Dzonsons <kristaps@bsd.lv>2011-11-24 12:22:53 +0000
committerKristaps Dzonsons <kristaps@bsd.lv>2011-11-24 12:22:53 +0000
commit111404fc74972291dad2ea0761de281514975b42 (patch)
tree054a7c8612b5dbe0749800dd3aaa421af3d940ac /manup.c
parent2d1ee60475147395c6882b1d665727e5ca188f69 (diff)
downloadmandoc-111404fc74972291dad2ea0761de281514975b42.tar.gz
Have manup(8) put relative paths in its output man.conf. This lets us
have arbitrarily-located cache directories for man.cgi.
Diffstat (limited to 'manup.c')
-rw-r--r--manup.c19
1 files changed, 17 insertions, 2 deletions
diff --git a/manup.c b/manup.c
index da97c7be..fa3c2774 100644
--- a/manup.c
+++ b/manup.c
@@ -391,8 +391,10 @@ treecpy(char *dst, char *src)
xstrlcat(src, "/mandoc.db", MAXPATHLEN);
xstrlcat(dst, "/mandoc.db", MAXPATHLEN);
- if ((rc = isnewer(dst, src)) <= 0)
+ if (-1 == (rc = isnewer(dst, src)))
return(0);
+ else if (rc == 0)
+ return(1);
dst[(int)dsz] = src[(int)ssz] = '\0';
@@ -425,6 +427,9 @@ manup(const struct manpaths *dirs, const char *dir)
xstrlcat(dst, "/man.conf", MAXPATHLEN);
+ if (verbose)
+ printf("%s\n", dst);
+
if (NULL == (f = fopen(dst, "w"))) {
perror(dst);
return(0);
@@ -451,7 +456,17 @@ manup(const struct manpaths *dirs, const char *dir)
else if (0 == c)
continue;
- fprintf(f, "_whatdb %s/whatis.db\n", path);
+ /*
+ * We want to use a relative path here because manpath.h
+ * will realpath() when invoked with man.cgi, and we'll
+ * make sure to chdir() into the cache directory before.
+ *
+ * This allows the cache directory to be in an arbitrary
+ * place, working in both chroot() and non-chroot()
+ * "safe" modes.
+ */
+ assert('/' == path[0]);
+ fprintf(f, "_whatdb %s/whatis.db\n", path + 1);
}
fclose(f);