From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from krisdoz.my.domain (kristaps@localhost [127.0.0.1]) by krisdoz.my.domain (8.14.5/8.14.5) with ESMTP id pBG84Y2v005969 for ; Fri, 16 Dec 2011 03:04:34 -0500 (EST) Received: (from kristaps@localhost) by krisdoz.my.domain (8.14.5/8.14.3/Submit) id pBG84Y8L003498; Fri, 16 Dec 2011 03:04:34 -0500 (EST) Date: Fri, 16 Dec 2011 03:04:34 -0500 (EST) Message-Id: <201112160804.pBG84Y8L003498@krisdoz.my.domain> X-Mailinglist: mdocml-source Reply-To: source@mdocml.bsd.lv MIME-Version: 1.0 From: kristaps@mdocml.bsd.lv To: source@mdocml.bsd.lv Subject: mdocml: Make paths in the mandocdb(8) index relative to the databases' X-Mailer: activitymail 1.26, http://search.cpan.org/dist/activitymail/ Content-Type: text/plain; charset=utf-8 Log Message: ----------- Make paths in the mandocdb(8) index relative to the databases' path prefix. This means that an index in, say, /usr/share/man will point to man1/foo.1 instead of /usr/share/man/man1/foo.1. Not only does this save a lot of space, it also allows manual trees to be moved around without any side effects to the mandocdb(8) databases. Modified Files: -------------- mdocml: catman.c cgi.c mandocdb.8 mandocdb.c Revision Data ------------- Index: mandocdb.8 =================================================================== RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mandocdb.8,v retrieving revision 1.12 retrieving revision 1.13 diff -Lmandocdb.8 -Lmandocdb.8 -u -p -r1.12 -r1.13 --- mandocdb.8 +++ mandocdb.8 @@ -123,7 +123,7 @@ file in and post-formatted, respectively .Pc , .It -the filename, +the filename relative to the databases' path, .It the manual section, .It Index: catman.c =================================================================== RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/catman.c,v retrieving revision 1.5 retrieving revision 1.6 diff -Lcatman.c -Lcatman.c -u -p -r1.5 -r1.6 --- catman.c +++ catman.c @@ -51,11 +51,11 @@ exit(EXIT_FAILURE); \ } while (/* CONSTCOND */0) -static int indexhtml(char *, char *); +static int indexhtml(char *, size_t, char *, size_t); static int manup(const struct manpaths *, char *); static int mkpath(char *, mode_t, mode_t); -static int treecpy(char *, char *, char *); -static int update(char *, char *, char *); +static int treecpy(char *, char *); +static int update(char *, char *); static void usage(void); static const char *progname; @@ -198,11 +198,10 @@ out: * Returns -1 on fatal error, 1 on success. */ static int -indexhtml(char *base, char *dst) +indexhtml(char *src, size_t ssz, char *dst, size_t dsz) { DB *idx; DBT key, val; - size_t sz; int c, rc; unsigned int fl; const char *f, *cp; @@ -210,7 +209,6 @@ indexhtml(char *base, char *dst) char fname[MAXPATHLEN]; pid_t pid; - sz = strlen(base); pid = -1; xstrlcpy(fname, dst, MAXPATHLEN); @@ -235,32 +233,35 @@ indexhtml(char *base, char *dst) if (NULL == memchr(f, '\0', val.size - (f - cp))) break; - base[(int)sz] = '\0'; + src[(int)ssz] = dst[(int)dsz] = '\0'; + + xstrlcat(dst, "/", MAXPATHLEN); + xstrlcat(dst, f, MAXPATHLEN); - xstrlcat(base, "/", MAXPATHLEN); - xstrlcat(base, f, MAXPATHLEN); + xstrlcat(src, "/", MAXPATHLEN); + xstrlcat(src, f, MAXPATHLEN); - if (-1 == (rc = isnewer(base, f))) { + if (-1 == (rc = isnewer(dst, src))) { fprintf(stderr, "%s: File missing\n", f); break; } else if (0 == rc) continue; - d = strrchr(base, '/'); + d = strrchr(dst, '/'); assert(NULL != d); *d = '\0'; - if (-1 == mkpath(base, 0755, 0755)) { - perror(base); + if (-1 == mkpath(dst, 0755, 0755)) { + perror(dst); break; } *d = '/'; - if ( ! filecpy(base, f)) + if ( ! filecpy(dst, src)) break; if (verbose) - printf("%s\n", base); + printf("%s\n", dst); } (*idx->close)(idx); @@ -279,7 +280,7 @@ indexhtml(char *base, char *dst) * Return -1 on fatal error and 1 if the update went well. */ static int -update(char *base, char *dst, char *src) +update(char *dst, char *src) { size_t dsz, ssz; @@ -304,9 +305,9 @@ update(char *base, char *dst, char *src) if (verbose) printf("%s\n", dst); - dst[(int)dsz] = '\0'; + dst[(int)dsz] = src[(int)ssz] = '\0'; - return(indexhtml(base, dst)); + return(indexhtml(src, ssz, dst, dsz)); } /* @@ -316,7 +317,7 @@ update(char *base, char *dst, char *src) * shouldn't be listed), and 1 if the update went well. */ static int -treecpy(char *base, char *dst, char *src) +treecpy(char *dst, char *src) { size_t dsz, ssz; int rc; @@ -333,7 +334,7 @@ treecpy(char *base, char *dst, char *src dst[(int)dsz] = src[(int)ssz] = '\0'; if (1 == rc) - return(update(base, dst, src)); + return(update(dst, src)); xstrlcat(src, "/mandoc.db", MAXPATHLEN); xstrlcat(dst, "/mandoc.db", MAXPATHLEN); @@ -345,7 +346,7 @@ treecpy(char *base, char *dst, char *src dst[(int)dsz] = src[(int)ssz] = '\0'; - return(update(base, dst, src)); + return(update(dst, src)); } /* @@ -383,7 +384,7 @@ manup(const struct manpaths *dirs, char for (i = 0; i < dirs->sz; i++) { path = dirs->paths[i]; - dst[(int)sz] = base[(int)sz] = '\0'; + dst[(int)sz] = '\0'; xstrlcat(dst, path, MAXPATHLEN); if (-1 == mkpath(dst, 0755, 0755)) { perror(dst); @@ -391,7 +392,7 @@ manup(const struct manpaths *dirs, char } xstrlcpy(src, path, MAXPATHLEN); - if (-1 == (c = treecpy(base, dst, src))) + if (-1 == (c = treecpy(dst, src))) break; else if (0 == c) continue; Index: mandocdb.c =================================================================== RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mandocdb.c,v retrieving revision 1.34 retrieving revision 1.35 diff -Lmandocdb.c -Lmandocdb.c -u -p -r1.34 -r1.35 --- mandocdb.c +++ mandocdb.c @@ -21,7 +21,6 @@ #include #include -#include #include #include @@ -110,7 +109,7 @@ static void index_prune(const struct recno_t *, recno_t **, size_t *, size_t *); static void ofile_argbuild(int, char *[], struct of **); -static int ofile_dirbuild(const char *, const char *, +static void ofile_dirbuild(const char *, const char *, const char *, int, struct of **); static void ofile_free(struct of *); static void pformatted(DB *, struct buf *, struct buf *, @@ -384,12 +383,8 @@ main(int argc, char *argv[]) exit((int)MANDOCLEVEL_SYSERR); } - if (verb > 2) { - printf("%s: Opened\n", fbuf); - printf("%s: Opened\n", ibuf); - } - ofile_argbuild(argc, argv, &of); + if (NULL == of) goto out; @@ -399,13 +394,16 @@ main(int argc, char *argv[]) &maxrec, &recs, &recsz, &reccur); /* - * Go to the root of the respective manual tree - * such that .so links work. In case of failure, - * just prod on, even though .so links won't work. + * Go to the root of the respective manual tree. + * This must work or no manuals may be found (they're + * indexed relative to the root). */ if (OP_UPDATE == op) { - chdir(dir); + if (-1 == chdir(dir)) { + perror(dir); + exit((int)MANDOCLEVEL_SYSERR); + } index_merge(of, mp, &dbuf, &buf, hash, db, fbuf, idx, ibuf, maxrec, recs, reccur); @@ -466,17 +464,15 @@ main(int argc, char *argv[]) exit((int)MANDOCLEVEL_SYSERR); } - if (verb > 2) { - printf("%s: Truncated\n", fbuf); - printf("%s: Truncated\n", ibuf); - } - ofile_free(of); of = NULL; - if ( ! ofile_dirbuild(dirs.paths[i], NULL, NULL, - 0, &of)) + if (-1 == chdir(dirs.paths[i])) { + perror(dirs.paths[i]); exit((int)MANDOCLEVEL_SYSERR); + } + + ofile_dirbuild(".", NULL, NULL, 0, &of); if (NULL == of) continue; @@ -484,12 +480,16 @@ main(int argc, char *argv[]) of = of->first; /* - * Go to the root of the respective manual tree - * such that .so links work. In case of failure, - * just prod on, even though .so links won't work. + * Go to the root of the respective manual tree. + * This must work or no manuals may be found (they're + * indexed relative to the root). */ - chdir(dirs.paths[i]); + if (-1 == chdir(dirs.paths[i])) { + perror(dirs.paths[i]); + exit((int)MANDOCLEVEL_SYSERR); + } + index_merge(of, mp, &dbuf, &buf, hash, db, fbuf, idx, ibuf, maxrec, recs, reccur); } @@ -1434,8 +1434,6 @@ ofile_argbuild(int argc, char *argv[], s * Add the structure to the list. */ - if (verb > 2) - printf("%s: Scheduling\n", argv[i]); if (NULL == *of) { *of = nof; (*of)->first = nof; @@ -1455,12 +1453,11 @@ ofile_argbuild(int argc, char *argv[], s * everything else is a manual. * Pass in a pointer to a NULL structure for the first invocation. */ -static int +static void ofile_dirbuild(const char *dir, const char* psec, const char *parch, int p_src_form, struct of **of) { char buf[MAXPATHLEN]; - struct stat sb; size_t sz; DIR *d; const char *fn, *sec, *arch; @@ -1471,7 +1468,7 @@ ofile_dirbuild(const char *dir, const ch if (NULL == (d = opendir(dir))) { perror(dir); - return(0); + exit((int)MANDOCLEVEL_SYSERR); } while (NULL != (dp = readdir(d))) { @@ -1516,20 +1513,16 @@ ofile_dirbuild(const char *dir, const ch if (MAXPATHLEN <= sz) { fprintf(stderr, "%s: Path too long\n", dir); - return(0); + exit((int)MANDOCLEVEL_SYSERR); } - if (verb > 2) - printf("%s: Scanning\n", buf); - - if ( ! ofile_dirbuild(buf, sec, arch, - src_form, of)) - return(0); + ofile_dirbuild(buf, sec, arch, src_form, of); } + if (DT_REG != dp->d_type || - (NULL == psec && !use_all) || - !strcmp(MANDOC_DB, fn) || - !strcmp(MANDOC_IDX, fn)) + (NULL == psec && !use_all) || + ! strcmp(MANDOC_DB, fn) || + ! strcmp(MANDOC_IDX, fn)) continue; /* @@ -1593,13 +1586,15 @@ ofile_dirbuild(const char *dir, const ch "%s: Path too long\n", buf); continue; } - if (0 == stat(buf, &sb)) + if (0 == access(buf, R_OK)) continue; } } + assert('.' == dir[0]); + assert('/' == dir[1]); buf[0] = '\0'; - strlcat(buf, dir, MAXPATHLEN); + strlcat(buf, dir + 2, MAXPATHLEN); strlcat(buf, "/", MAXPATHLEN); sz = strlcat(buf, fn, MAXPATHLEN); if (sz >= MAXPATHLEN) { @@ -1628,8 +1623,6 @@ ofile_dirbuild(const char *dir, const ch * Add the structure to the list. */ - if (verb > 2) - printf("%s: Scheduling\n", buf); if (NULL == *of) { *of = nof; (*of)->first = nof; @@ -1641,7 +1634,6 @@ ofile_dirbuild(const char *dir, const ch } closedir(d); - return(1); } static void Index: cgi.c =================================================================== RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/cgi.c,v retrieving revision 1.33 retrieving revision 1.34 diff -Lcgi.c -Lcgi.c -u -p -r1.33 -r1.34 --- cgi.c +++ cgi.c @@ -749,6 +749,7 @@ static void pg_show(const struct req *req, char *path) { struct manpaths ps; + size_t sz; char *sub; char file[MAXPATHLEN]; const char *fn, *cp; @@ -804,7 +805,8 @@ pg_show(const struct req *req, char *pat goto out; } - strlcpy(file, ps.paths[vol], MAXPATHLEN); + sz = strlcpy(file, ps.paths[vol], MAXPATHLEN); + assert(sz < MAXPATHLEN); strlcat(file, "/mandoc.index", MAXPATHLEN); /* Open the index recno(3) database. */ @@ -833,10 +835,13 @@ pg_show(const struct req *req, char *pat else if (NULL == memchr(fn, '\0', val.size - (fn - cp))) resp_baddb(); else { + file[(int)sz] = '\0'; + strlcat(file, "/", MAXPATHLEN); + strlcat(file, fn, MAXPATHLEN); if (0 == strcmp(cp, "cat")) - catman(req, fn + 1); + catman(req, file); else - format(req, fn + 1); + format(req, file); } out: if (idx) -- To unsubscribe send an email to source+unsubscribe@mdocml.bsd.lv