summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorwiz <wiz@NetBSD.org>2012-10-06 15:33:59 +0000
committerwiz <wiz@NetBSD.org>2012-10-06 15:33:59 +0000
commit4fdac3eaf546c6aefae19ee2dbc26be22d0ea670 (patch)
tree0cc84e8a634b5f56fc8335acf64de1e2e96c374e
parentf527c568f26c36916be00b2b8b77fcfcdd683e9d (diff)
Make mandb path configurable. makemandb (and related tools) use
the path from the _mandb variable from man.conf now. Set _mandb in man.conf to same value as was used before. From Abhinav Upadhyay <er.abhinav.upadhyay@gmail.com>.
-rw-r--r--etc/man.conf8
-rw-r--r--usr.sbin/makemandb/Makefile13
-rw-r--r--usr.sbin/makemandb/apropos-utils.c38
-rw-r--r--usr.sbin/makemandb/apropos-utils.h7
-rw-r--r--usr.sbin/makemandb/apropos.112
-rw-r--r--usr.sbin/makemandb/apropos.c6
-rw-r--r--usr.sbin/makemandb/init_db.328
-rw-r--r--usr.sbin/makemandb/makemandb.815
-rw-r--r--usr.sbin/makemandb/makemandb.c32
-rw-r--r--usr.sbin/makemandb/whatis.121
-rw-r--r--usr.sbin/makemandb/whatis.c6
11 files changed, 118 insertions, 68 deletions
diff --git a/etc/man.conf b/etc/man.conf
index 529f3fdb447..dc50ec05df6 100644
--- a/etc/man.conf
+++ b/etc/man.conf
@@ -1,14 +1,10 @@
-# $NetBSD: man.conf,v 1.30 2012/02/16 22:57:19 joerg Exp $
+# $NetBSD: man.conf,v 1.31 2012/10/06 15:33:59 wiz Exp $
# Sheer, raging paranoia...
_version BSD.2
# The whatis/apropos database.
-_whatdb /usr/share/man/whatis.db
-_whatdb /usr/X11R7/man/whatis.db
-_whatdb /usr/X11R6/man/whatis.db
-_whatdb /usr/pkg/man/whatis.db
-_whatdb /usr/local/man/whatis.db
+_mandb /var/db/man.db
# Subdirectories for paths ending in '/', IN SEARCH ORDER.
_subdir cat1 man1 cat8 man8 cat6 man6 cat2 man2 cat3 man3 cat4 man4 cat5 man5 cat7 man7 man3f cat9 man9 catn mann catl manl
diff --git a/usr.sbin/makemandb/Makefile b/usr.sbin/makemandb/Makefile
index d35f0acc07c..42fcb1ca7a0 100644
--- a/usr.sbin/makemandb/Makefile
+++ b/usr.sbin/makemandb/Makefile
@@ -1,14 +1,15 @@
-# $NetBSD: Makefile,v 1.2 2012/02/16 20:58:55 joerg Exp $
+# $NetBSD: Makefile,v 1.3 2012/10/06 15:33:59 wiz Exp $
.include <bsd.own.mk>
MDIST= ${NETBSDSRCDIR}/external/bsd/mdocml/dist
MDOCDIR=${NETBSDSRCDIR}/external/bsd/mdocml
+MANCONFDIR=${NETBSDSRCDIR}/usr.bin/man
PROGS= makemandb apropos whatis
-SRCS.makemandb= makemandb.c apropos-utils.c
-SRCS.apropos= apropos.c apropos-utils.c
-SRCS.whatis= whatis.c apropos-utils.c
+SRCS.makemandb= makemandb.c apropos-utils.c manconf.c
+SRCS.apropos= apropos.c apropos-utils.c manconf.c
+SRCS.whatis= whatis.c apropos-utils.c manconf.c
MAN.makemandb= makemandb.8
MAN.apropos= apropos.1
MAN.whatis= whatis.1
@@ -17,7 +18,9 @@ BINDIR.apropos= /usr/bin
BINDIR.makemandb= /usr/sbin
BINDIR.whatis= /usr/bin
-CPPFLAGS+=-I${MDIST} -I${.OBJDIR}
+.PATH: ${MANCONFDIR}
+
+CPPFLAGS+=-I${MDIST} -I${MANCONFDIR} -I${.OBJDIR}
MDOCMLOBJDIR!= cd ${MDOCDIR}/lib/libmandoc && ${PRINTOBJDIR}
MDOCMLLIB= ${MDOCMLOBJDIR}/libmandoc.a
diff --git a/usr.sbin/makemandb/apropos-utils.c b/usr.sbin/makemandb/apropos-utils.c
index 7ddb260d971..596f4525a9f 100644
--- a/usr.sbin/makemandb/apropos-utils.c
+++ b/usr.sbin/makemandb/apropos-utils.c
@@ -1,4 +1,4 @@
-/* $NetBSD: apropos-utils.c,v 1.6 2012/05/10 15:36:09 joerg Exp $ */
+/* $NetBSD: apropos-utils.c,v 1.7 2012/10/06 15:33:59 wiz Exp $ */
/*-
* Copyright (c) 2011 Abhinav Upadhyay <er.abhinav.upadhyay@gmail.com>
* All rights reserved.
@@ -31,8 +31,9 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: apropos-utils.c,v 1.6 2012/05/10 15:36:09 joerg Exp $");
+__RCSID("$NetBSD: apropos-utils.c,v 1.7 2012/10/06 15:33:59 wiz Exp $");
+#include <sys/queue.h>
#include <sys/stat.h>
#include <assert.h>
@@ -46,6 +47,7 @@ __RCSID("$NetBSD: apropos-utils.c,v 1.6 2012/05/10 15:36:09 joerg Exp $");
#include <zlib.h>
#include "apropos-utils.h"
+#include "manconf.h"
#include "mandoc.h"
#include "sqlite3.h"
@@ -260,6 +262,28 @@ unzip(sqlite3_context *pctx, int nval, sqlite3_value **apval)
sqlite3_result_text(pctx, (const char *) outbuf, stream.total_out, free);
}
+/*
+ * get_dbpath --
+ * Read the path of the database from man.conf and return.
+ */
+char *
+get_dbpath(const char *manconf)
+{
+ TAG *tp;
+ char *dbpath;
+
+ config(manconf);
+ tp = gettag("_mandb", 1);
+ if (!tp)
+ return NULL;
+
+ if (TAILQ_EMPTY(&tp->entrylist))
+ return NULL;
+
+ dbpath = TAILQ_LAST(&tp->entrylist, tqh)->s;
+ return dbpath;
+}
+
/* init_db --
* Prepare the database. Register the compress/uncompress functions and the
* stopword tokenizer.
@@ -276,7 +300,7 @@ unzip(sqlite3_context *pctx, int nval, sqlite3_value **apval)
* In normal cases the function should return a handle to the db.
*/
sqlite3 *
-init_db(int db_flag)
+init_db(int db_flag, const char *manconf)
{
sqlite3 *db = NULL;
sqlite3_stmt *stmt;
@@ -284,8 +308,11 @@ init_db(int db_flag)
int rc;
int create_db_flag = 0;
+ char *dbpath = get_dbpath(manconf);
+ if (dbpath == NULL)
+ errx(EXIT_FAILURE, "_mandb entry not found in man.conf");
/* Check if the database exists or not */
- if (!(stat(DBPATH, &sb) == 0 && S_ISREG(sb.st_mode))) {
+ if (!(stat(dbpath, &sb) == 0 && S_ISREG(sb.st_mode))) {
/* Database does not exist, check if DB_CREATE was specified, and set
* flag to create the database schema
*/
@@ -299,7 +326,7 @@ init_db(int db_flag)
/* Now initialize the database connection */
sqlite3_initialize();
- rc = sqlite3_open_v2(DBPATH, &db, db_flag, NULL);
+ rc = sqlite3_open_v2(dbpath, &db, db_flag, NULL);
if (rc != SQLITE_OK) {
warnx("%s", sqlite3_errmsg(db));
@@ -350,6 +377,7 @@ init_db(int db_flag)
goto error;
}
return db;
+
error:
sqlite3_close(db);
sqlite3_shutdown();
diff --git a/usr.sbin/makemandb/apropos-utils.h b/usr.sbin/makemandb/apropos-utils.h
index 8f521f10c86..cf1bddbe25d 100644
--- a/usr.sbin/makemandb/apropos-utils.h
+++ b/usr.sbin/makemandb/apropos-utils.h
@@ -1,4 +1,4 @@
-/* $NetBSD: apropos-utils.h,v 1.3 2012/05/07 11:18:16 wiz Exp $ */
+/* $NetBSD: apropos-utils.h,v 1.4 2012/10/06 15:33:59 wiz Exp $ */
/*-
* Copyright (c) 2011 Abhinav Upadhyay <er.abhinav.upadhyay@gmail.com>
* All rights reserved.
@@ -35,7 +35,7 @@
#include "sqlite3.h"
-#define DBPATH "/var/db/man.db"
+#define MANCONF "/etc/man.conf"
#define SECMAX 9
/* Flags for opening the database */
@@ -84,8 +84,9 @@ typedef struct query_args {
char *lower(char *);
void concat(char **, const char *);
void concat2(char **, const char *, size_t);
-sqlite3 *init_db(int);
+sqlite3 *init_db(int, const char *);
void close_db(sqlite3 *);
+char *get_dbpath(const char *);
int run_query(sqlite3 *, const char *[3], query_args *);
int run_query_html(sqlite3 *, query_args *);
int run_query_pager(sqlite3 *, query_args *);
diff --git a/usr.sbin/makemandb/apropos.1 b/usr.sbin/makemandb/apropos.1
index b1491bf92ab..b4a7363f9d2 100644
--- a/usr.sbin/makemandb/apropos.1
+++ b/usr.sbin/makemandb/apropos.1
@@ -1,4 +1,4 @@
-.\" $NetBSD: apropos.1,v 1.5 2012/04/22 21:27:07 wiz Exp $
+.\" $NetBSD: apropos.1,v 1.6 2012/10/06 15:33:59 wiz Exp $
.\"
.\" Copyright (c) 2011 Abhinav Upadhyay <er.abhinav.upadhyay@gmail.com>
.\" All rights reserved.
@@ -29,7 +29,7 @@
.\" OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.Dd April 21, 2012
+.Dd October 5, 2012
.Dt APROPOS 1
.Os
.Sh NAME
@@ -106,9 +106,11 @@ using it is equivalent to using the
options directly.
.El
.Sh FILES
-.Bl -hang -width -compact
-.It Pa /var/db/man.db
-The Sqlite FTS database which contains an index of the manual pages.
+.Bl -hang -width /etc/man.conf -compact
+.It Pa /etc/man.conf
+The location of the Sqlite FTS database can be configured using the
+.Cd _mandb
+tag.
.El
.Sh SEE ALSO
.Xr man 1 ,
diff --git a/usr.sbin/makemandb/apropos.c b/usr.sbin/makemandb/apropos.c
index f5298df9dfe..0bb5be384cd 100644
--- a/usr.sbin/makemandb/apropos.c
+++ b/usr.sbin/makemandb/apropos.c
@@ -1,4 +1,4 @@
-/* $NetBSD: apropos.c,v 1.7 2012/09/07 11:28:46 wiz Exp $ */
+/* $NetBSD: apropos.c,v 1.8 2012/10/06 15:33:59 wiz Exp $ */
/*-
* Copyright (c) 2011 Abhinav Upadhyay <er.abhinav.upadhyay@gmail.com>
* All rights reserved.
@@ -31,7 +31,7 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: apropos.c,v 1.7 2012/09/07 11:28:46 wiz Exp $");
+__RCSID("$NetBSD: apropos.c,v 1.8 2012/10/06 15:33:59 wiz Exp $");
#include <err.h>
#include <search.h>
@@ -151,7 +151,7 @@ main(int argc, char *argv[])
if (query == NULL)
errx(EXIT_FAILURE, "Try using more relevant keywords");
- if ((db = init_db(MANDB_READONLY)) == NULL)
+ if ((db = init_db(MANDB_READONLY, MANCONF)) == NULL)
exit(EXIT_FAILURE);
/* If user wants to page the output, then set some settings */
diff --git a/usr.sbin/makemandb/init_db.3 b/usr.sbin/makemandb/init_db.3
index bee7241bf42..359f1ee4778 100644
--- a/usr.sbin/makemandb/init_db.3
+++ b/usr.sbin/makemandb/init_db.3
@@ -1,4 +1,4 @@
-.\" $NetBSD: init_db.3,v 1.1 2012/02/07 19:13:32 joerg Exp $
+.\" $NetBSD: init_db.3,v 1.2 2012/10/06 15:33:59 wiz Exp $
.\"
.\" Copyright (c) 2011 Abhinav Upadhyay <er.abhinav.upadhyay@gmail.com>
.\" All rights reserved.
@@ -29,7 +29,7 @@
.\" OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.Dd August 17, 2011
+.Dd October 5, 2011
.Dt INIT_DB 3
.Os
.Sh NAME
@@ -38,7 +38,7 @@
.Sh SYNOPSIS
.In apropos-utils.h
.Ft sqlite3 *
-.Fn init_db "int db_flag"
+.Fn init_db "int db_flag" "char *manconf"
.Sh DESCRIPTION
The
.Fn init_db
@@ -63,24 +63,34 @@ This will open the database in read/write mode.
This will open the database in read/write mode, and will also create
the database schema if it does not exist already.
.El
+.Pp
+The second argument
+.Fa manconf
+specifies the location of the man.conf configuration file.
+By default it is stored at
+.Pa /etc/man.conf .
+The location of the man.db database is configured in the configuration file
+using the
+.Cd _mandb
+tag.
.Sh RETURN VALUES
On successful execution the
.Fn init_db
function will return a pointer to a sqlite3 structure which represents
a connection to the database.
.Pp
-In case the file
-.Pa /var/db/man.db
-does not exist and
+In case the man.db file does not exist and
.Dv DB_CREATE
is not used as a value of
.Fa db_flag ,
.Dv NULL
will be returned.
.Sh FILES
-.Bl -hang -width /var/db/man.db -compact
-.It Pa /var/db/man.db
-The Sqlite FTS database which contains an index of the manual pages.
+.Bl -hang -width /etc/man.conf -compact
+.It Pa /etc/man.conf
+The location of the Sqlite FTS database can be configured using the
+.Cd _mandb
+tag.
.El
.Sh SEE ALSO
.Xr apropos-utils 3 ,
diff --git a/usr.sbin/makemandb/makemandb.8 b/usr.sbin/makemandb/makemandb.8
index 75354ec7bce..3298925630c 100644
--- a/usr.sbin/makemandb/makemandb.8
+++ b/usr.sbin/makemandb/makemandb.8
@@ -1,4 +1,4 @@
-.\" $NetBSD: makemandb.8,v 1.5 2012/08/29 20:33:01 wiz Exp $
+.\" $NetBSD: makemandb.8,v 1.6 2012/10/06 15:33:59 wiz Exp $
.\"
.\" Copyright (c) 2011 Abhinav Upadhyay <er.abhinav.upadhyay@gmail.com>
.\" All rights reserved.
@@ -29,7 +29,7 @@
.\" OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.Dd August 29, 2012
+.Dd October 5, 2012
.Dt MAKEMANDB 8
.Os
.Sh NAME
@@ -82,9 +82,6 @@ This prints the name of every file being parsed
and a summary at the end of the index update.
.El
.Pp
-As the database file is stored under
-.Pa /var/db ,
-root privileges are required to run
.Nm .
.Ss DATABASE SCHEMA
The name of the FTS table is mandb and its schema is as follows:
@@ -105,9 +102,11 @@ The name of the FTS table is mandb and its schema is as follows:
page is relevant.
.El
.Sh FILES
-.Bl -hang -width /var/db/man.db -compact
-.It Pa /var/db/man.db
-The Sqlite FTS database which contains an index of the manual pages.
+.Bl -hang -width /etc/man.conf -compact
+.It Pa /etc/man.conf
+The location of the Sqlite FTS database can be configured using the
+.Cd _mandb
+tag.
.El
.Sh SEE ALSO
.Xr apropos 1 ,
diff --git a/usr.sbin/makemandb/makemandb.c b/usr.sbin/makemandb/makemandb.c
index afdbe8f70da..ff7a20a5356 100644
--- a/usr.sbin/makemandb/makemandb.c
+++ b/usr.sbin/makemandb/makemandb.c
@@ -1,4 +1,4 @@
-/* $NetBSD: makemandb.c,v 1.14 2012/09/07 11:29:04 wiz Exp $ */
+/* $NetBSD: makemandb.c,v 1.15 2012/10/06 15:33:59 wiz Exp $ */
/*
* Copyright (c) 2011 Abhinav Upadhyay <er.abhinav.upadhyay@gmail.com>
* Copyright (c) 2011 Kristaps Dzonsons <kristaps@bsd.lv>
@@ -17,7 +17,7 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: makemandb.c,v 1.14 2012/09/07 11:29:04 wiz Exp $");
+__RCSID("$NetBSD: makemandb.c,v 1.15 2012/10/06 15:33:59 wiz Exp $");
#include <sys/stat.h>
#include <sys/types.h>
@@ -310,7 +310,6 @@ main(int argc, char *argv[])
manconf = optarg;
break;
case 'f':
- remove(DBPATH);
mflags.recreate = 1;
break;
case 'l':
@@ -338,7 +337,22 @@ main(int argc, char *argv[])
init_secbuffs(&rec);
mp = mparse_alloc(MPARSE_AUTO, MANDOCLEVEL_FATAL, NULL, NULL);
- if ((db = init_db(MANDB_CREATE)) == NULL)
+ if (manconf) {
+ char *arg;
+ size_t command_len = shquote(manconf, NULL, 0) + 1;
+ arg = emalloc(command_len);
+ shquote(manconf, arg, command_len);
+ easprintf(&command, "man -p -C %s", arg);
+ free(arg);
+ } else {
+ command = estrdup("man -p");
+ manconf = MANCONF;
+ }
+
+ if (mflags.recreate)
+ remove(get_dbpath(manconf));
+
+ if ((db = init_db(MANDB_CREATE, manconf)) == NULL)
exit(EXIT_FAILURE);
sqlite3_exec(db, "PRAGMA synchronous = 0", NULL, NULL, &errmsg);
@@ -358,16 +372,6 @@ main(int argc, char *argv[])
exit(EXIT_FAILURE);
}
- if (manconf) {
- char *arg;
- size_t command_len = shquote(manconf, NULL, 0) + 1;
- arg = emalloc(command_len);
- shquote(manconf, arg, command_len);
- easprintf(&command, "man -p -C %s", arg);
- free(arg);
- } else {
- command = estrdup("man -p");
- }
/* Call man -p to get the list of man page dirs */
if ((file = popen(command, "r")) == NULL) {
diff --git a/usr.sbin/makemandb/whatis.1 b/usr.sbin/makemandb/whatis.1
index 4660b5a7468..beef08dc6fa 100644
--- a/usr.sbin/makemandb/whatis.1
+++ b/usr.sbin/makemandb/whatis.1
@@ -1,4 +1,4 @@
-.\" $NetBSD: whatis.1,v 1.1 2012/02/07 19:13:32 joerg Exp $
+.\" $NetBSD: whatis.1,v 1.2 2012/10/06 15:33:59 wiz Exp $
.\"
.\" Copyright (c) 2012 Joerg Sonnenberger <joerg@NetBSD.org>
.\" All rights reserved.
@@ -27,7 +27,7 @@
.\" OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.Dd February 1, 2012
+.Dd October 5, 2012
.Dt WHATIS 1
.Os
.Sh NAME
@@ -39,12 +39,19 @@
.Sh DESCRIPTION
The
.Nm
-program queries the database
-.Pa /var/db/man.db
-for manual pages with name
+program queries the apropos database built by
+.Xr makemandb 8 .
+It searches for manual pages with name
.Ar command
-and prints the name of the manual page, the section and the description from
-the section NAME.
+and outputs name of the matching manual pages along with the section and the
+brief description from the NAME section.
+.Sh FILES
+.Bl -hang -width /etc/man.conf -compact
+.It Pa /etc/man.conf
+The location of the Sqlite FTS database can be configured using the
+.Cd _mandb
+tag.
+.El
.Sh SEE ALSO
.Xr apropos 1 ,
.Xr makemandb 8
diff --git a/usr.sbin/makemandb/whatis.c b/usr.sbin/makemandb/whatis.c
index 211f85f4e23..68f95ed3d95 100644
--- a/usr.sbin/makemandb/whatis.c
+++ b/usr.sbin/makemandb/whatis.c
@@ -1,4 +1,4 @@
-/* $NetBSD: whatis.c,v 1.3 2012/02/20 18:27:30 joerg Exp $ */
+/* $NetBSD: whatis.c,v 1.4 2012/10/06 15:33:59 wiz Exp $ */
/*-
* Copyright (c) 2012 Joerg Sonnenberger <joerg@NetBSD.org>
* All rights reserved.
@@ -29,7 +29,7 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: whatis.c,v 1.3 2012/02/20 18:27:30 joerg Exp $");
+__RCSID("$NetBSD: whatis.c,v 1.4 2012/10/06 15:33:59 wiz Exp $");
#include <err.h>
#include <stdio.h>
@@ -91,7 +91,7 @@ main(int argc, char *argv[])
if (argc == 0)
usage();
- if ((db = init_db(MANDB_READONLY)) == NULL)
+ if ((db = init_db(MANDB_READONLY, MANCONF)) == NULL)
exit(EXIT_FAILURE);
retval = 0;