Module Name:    src
Committed By:   wiz
Date:           Sat Oct  6 15:33:59 UTC 2012

Modified Files:
        src/etc: man.conf
        src/usr.sbin/makemandb: Makefile apropos-utils.c apropos-utils.h
            apropos.1 apropos.c init_db.3 makemandb.8 makemandb.c whatis.1
            whatis.c

Log Message:
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.upadh...@gmail.com>.


To generate a diff of this commit:
cvs rdiff -u -r1.30 -r1.31 src/etc/man.conf
cvs rdiff -u -r1.2 -r1.3 src/usr.sbin/makemandb/Makefile
cvs rdiff -u -r1.6 -r1.7 src/usr.sbin/makemandb/apropos-utils.c
cvs rdiff -u -r1.3 -r1.4 src/usr.sbin/makemandb/apropos-utils.h \
    src/usr.sbin/makemandb/whatis.c
cvs rdiff -u -r1.5 -r1.6 src/usr.sbin/makemandb/apropos.1 \
    src/usr.sbin/makemandb/makemandb.8
cvs rdiff -u -r1.7 -r1.8 src/usr.sbin/makemandb/apropos.c
cvs rdiff -u -r1.1 -r1.2 src/usr.sbin/makemandb/init_db.3 \
    src/usr.sbin/makemandb/whatis.1
cvs rdiff -u -r1.14 -r1.15 src/usr.sbin/makemandb/makemandb.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/etc/man.conf
diff -u src/etc/man.conf:1.30 src/etc/man.conf:1.31
--- src/etc/man.conf:1.30	Thu Feb 16 22:57:19 2012
+++ src/etc/man.conf	Sat Oct  6 15:33:59 2012
@@ -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

Index: src/usr.sbin/makemandb/Makefile
diff -u src/usr.sbin/makemandb/Makefile:1.2 src/usr.sbin/makemandb/Makefile:1.3
--- src/usr.sbin/makemandb/Makefile:1.2	Thu Feb 16 20:58:55 2012
+++ src/usr.sbin/makemandb/Makefile	Sat Oct  6 15:33:59 2012
@@ -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

Index: src/usr.sbin/makemandb/apropos-utils.c
diff -u src/usr.sbin/makemandb/apropos-utils.c:1.6 src/usr.sbin/makemandb/apropos-utils.c:1.7
--- src/usr.sbin/makemandb/apropos-utils.c:1.6	Thu May 10 15:36:09 2012
+++ src/usr.sbin/makemandb/apropos-utils.c	Sat Oct  6 15:33:59 2012
@@ -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.upadh...@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 
 #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, s
 	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, s
  *  	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();

Index: src/usr.sbin/makemandb/apropos-utils.h
diff -u src/usr.sbin/makemandb/apropos-utils.h:1.3 src/usr.sbin/makemandb/apropos-utils.h:1.4
--- src/usr.sbin/makemandb/apropos-utils.h:1.3	Mon May  7 11:18:16 2012
+++ src/usr.sbin/makemandb/apropos-utils.h	Sat Oct  6 15:33:59 2012
@@ -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.upadh...@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 *);
Index: src/usr.sbin/makemandb/whatis.c
diff -u src/usr.sbin/makemandb/whatis.c:1.3 src/usr.sbin/makemandb/whatis.c:1.4
--- src/usr.sbin/makemandb/whatis.c:1.3	Mon Feb 20 18:27:30 2012
+++ src/usr.sbin/makemandb/whatis.c	Sat Oct  6 15:33:59 2012
@@ -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 <jo...@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;

Index: src/usr.sbin/makemandb/apropos.1
diff -u src/usr.sbin/makemandb/apropos.1:1.5 src/usr.sbin/makemandb/apropos.1:1.6
--- src/usr.sbin/makemandb/apropos.1:1.5	Sun Apr 22 21:27:07 2012
+++ src/usr.sbin/makemandb/apropos.1	Sat Oct  6 15:33:59 2012
@@ -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.upadh...@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 ,
Index: src/usr.sbin/makemandb/makemandb.8
diff -u src/usr.sbin/makemandb/makemandb.8:1.5 src/usr.sbin/makemandb/makemandb.8:1.6
--- src/usr.sbin/makemandb/makemandb.8:1.5	Wed Aug 29 20:33:01 2012
+++ src/usr.sbin/makemandb/makemandb.8	Sat Oct  6 15:33:59 2012
@@ -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.upadh...@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
 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 i
 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 ,

Index: src/usr.sbin/makemandb/apropos.c
diff -u src/usr.sbin/makemandb/apropos.c:1.7 src/usr.sbin/makemandb/apropos.c:1.8
--- src/usr.sbin/makemandb/apropos.c:1.7	Fri Sep  7 11:28:46 2012
+++ src/usr.sbin/makemandb/apropos.c	Sat Oct  6 15:33:59 2012
@@ -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.upadh...@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 */

Index: src/usr.sbin/makemandb/init_db.3
diff -u src/usr.sbin/makemandb/init_db.3:1.1 src/usr.sbin/makemandb/init_db.3:1.2
--- src/usr.sbin/makemandb/init_db.3:1.1	Tue Feb  7 19:13:32 2012
+++ src/usr.sbin/makemandb/init_db.3	Sat Oct  6 15:33:59 2012
@@ -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.upadh...@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/writ
 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 ,
Index: src/usr.sbin/makemandb/whatis.1
diff -u src/usr.sbin/makemandb/whatis.1:1.1 src/usr.sbin/makemandb/whatis.1:1.2
--- src/usr.sbin/makemandb/whatis.1:1.1	Tue Feb  7 19:13:32 2012
+++ src/usr.sbin/makemandb/whatis.1	Sat Oct  6 15:33:59 2012
@@ -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 <jo...@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

Index: src/usr.sbin/makemandb/makemandb.c
diff -u src/usr.sbin/makemandb/makemandb.c:1.14 src/usr.sbin/makemandb/makemandb.c:1.15
--- src/usr.sbin/makemandb/makemandb.c:1.14	Fri Sep  7 11:29:04 2012
+++ src/usr.sbin/makemandb/makemandb.c	Sat Oct  6 15:33:59 2012
@@ -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.upadh...@gmail.com>
  * Copyright (c) 2011 Kristaps Dzonsons <krist...@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) {

Reply via email to