Pull up following revision(s) (requested by tron in ticket #676): netbsd-6
authorriz <riz@NetBSD.org>
Tue, 20 Nov 2012 23:11:47 +0000
branchnetbsd-6
changeset 256349 46ae8e13809b
parent 256348 b3e2fa3eb88e
child 256350 53a02d3a5e18
Pull up following revision(s) (requested by tron in ticket #676): usr.sbin/makemandb/apropos.c: revision 1.7 usr.sbin/makemandb/makemandb.8: revision 1.3 usr.sbin/makemandb/makemandb.8: revision 1.4 usr.sbin/makemandb/makemandb.8: revision 1.5 etc/rc.d/makemandb: revision 1.4 etc/weekly: revision 1.29 usr.sbin/makemandb/makemandb.c: revision 1.10 usr.sbin/makemandb/makemandb.c: revision 1.11 usr.sbin/makemandb/makemandb.c: revision 1.12 usr.sbin/makemandb/makemandb.c: revision 1.13 usr.sbin/makemandb/makemandb.c: revision 1.14 usr.sbin/makemandb/apropos.1: revision 1.5 etc/daily: revision 1.87 Add HISTORY section. From Abhinav Upadhyay in private mail. Sync with reality, From Abhinav Upadhyay in private mail. Fix typo in a message. Bug fix for PR 46733: > makemandb always reports the same number for "Total Number of new or > updated pages enountered" and "Total number of (hard or symbolic) > links found". Patch from Abhinav Upadhyay. Sort options in SYNOPSIS. Sync usage with manpage. Add -Q flag: Print only fatal error messages (i.e., when the database is left in an inconsistent state and needs manual intervention). From Abhinav Upadhyay <er.abhinav.upadhyay@gmail.com>. Use new makemandb -Q flag to be really quiet. Fix usage, from Abhinav Upadhyay <er.abhinav.upadhyay@gmail.com>. Use emalloc in one more place, like the rest of the code does. From Abhinav Upadhyay <er.abhinav.upadhyay@gmail.com>.
etc/daily
etc/rc.d/makemandb
etc/weekly
usr.sbin/makemandb/apropos.1
usr.sbin/makemandb/apropos.c
usr.sbin/makemandb/makemandb.8
usr.sbin/makemandb/makemandb.c
--- a/etc/daily	Tue Nov 20 22:33:37 2012 +0000
+++ b/etc/daily	Tue Nov 20 23:11:47 2012 +0000
@@ -1,6 +1,6 @@
 #!/bin/sh -
 #
-#	$NetBSD: daily,v 1.80.2.5 2012/08/08 14:49:24 martin Exp $
+#	$NetBSD: daily,v 1.80.2.6 2012/11/20 23:11:47 riz Exp $
 #	@(#)daily	8.2 (Berkeley) 1/25/94
 #
 
@@ -304,7 +304,7 @@
 	if [ -f /etc/man.conf -a -x /usr/sbin/makemandb ]; then
 		echo ""
 		echo "Updating man page index:"
-		(umask 022; nice -n 5 /usr/sbin/makemandb -q)
+		(umask 022; nice -n 5 /usr/sbin/makemandb -Q)
 	fi
 fi
 
--- a/etc/rc.d/makemandb	Tue Nov 20 22:33:37 2012 +0000
+++ b/etc/rc.d/makemandb	Tue Nov 20 23:11:47 2012 +0000
@@ -1,6 +1,6 @@
 #!/bin/sh
 #
-# $NetBSD: makemandb,v 1.1.2.1 2012/06/24 16:31:52 jdc Exp $
+# $NetBSD: makemandb,v 1.1.2.2 2012/11/20 23:11:47 riz Exp $
 #
 
 # PROVIDE: makemandb
@@ -18,7 +18,7 @@
 makemandb_start()
 {
 	# Initiate update build in the background
-	nice -n 5 /usr/sbin/makemandb -q > /dev/null 2>&1 &
+	nice -n 5 /usr/sbin/makemandb -Q > /dev/null 2>&1 &
 }
 
 load_rc_config $name
--- a/etc/weekly	Tue Nov 20 22:33:37 2012 +0000
+++ b/etc/weekly	Tue Nov 20 23:11:47 2012 +0000
@@ -1,6 +1,6 @@
 #!/bin/sh -
 #
-#	$NetBSD: weekly,v 1.25.2.3 2012/11/18 19:07:00 msaitoh Exp $
+#	$NetBSD: weekly,v 1.25.2.4 2012/11/20 23:11:47 riz Exp $
 #	from: @(#)weekly	8.2 (Berkeley) 1/2/94
 #
 
@@ -94,7 +94,7 @@
 	echo ""
 	if [ -f /etc/man.conf -a -x /usr/sbin/makemandb ]; then
 		echo "Rebuilding man page index:"
-		(umask 022; nice -n 5 /usr/sbin/makemandb -f -q)
+		(umask 022; nice -n 5 /usr/sbin/makemandb -f -Q)
 	else
 		echo "Not rebuilding man page index"
 	fi
--- a/usr.sbin/makemandb/apropos.1	Tue Nov 20 22:33:37 2012 +0000
+++ b/usr.sbin/makemandb/apropos.1	Tue Nov 20 23:11:47 2012 +0000
@@ -1,4 +1,4 @@
-.\" $NetBSD: apropos.1,v 1.2.2.2 2012/02/20 22:04:30 sborrill Exp $
+.\" $NetBSD: apropos.1,v 1.2.2.3 2012/11/20 23:11:47 riz 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 February 20, 2012
+.Dd April 21, 2012
 .Dt APROPOS 1
 .Os
 .Sh NAME
@@ -114,5 +114,12 @@
 .Xr man 1 ,
 .Xr whatis 1 ,
 .Xr makemandb 8
+.Sh HISTORY
+The
+.Nm
+command appeared in 3.0BSD.
+It was rewritten in
+.Nx 6.0
+to support full text search using Sqlite.
 .Sh AUTHORS
 .An Abhinav Upadhyay
--- a/usr.sbin/makemandb/apropos.c	Tue Nov 20 22:33:37 2012 +0000
+++ b/usr.sbin/makemandb/apropos.c	Tue Nov 20 23:11:47 2012 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: apropos.c,v 1.4.2.2 2012/04/19 20:03:00 riz Exp $	*/
+/*	$NetBSD: apropos.c,v 1.4.2.3 2012/11/20 23:11:47 riz 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.4.2.2 2012/04/19 20:03:00 riz Exp $");
+__RCSID("$NetBSD: apropos.c,v 1.4.2.3 2012/11/20 23:11:47 riz Exp $");
 
 #include <err.h>
 #include <search.h>
@@ -277,7 +277,7 @@
 usage(void)
 {
 	fprintf(stderr,
-		"Usage: %s [-n Number of records] [-p] [-123456789] [-S machine] query\n",
+		"Usage: %s [-n Number of records] [-123456789Ccp] [-S machine] query\n",
 		getprogname());
 	exit(1);
 }
--- a/usr.sbin/makemandb/makemandb.8	Tue Nov 20 22:33:37 2012 +0000
+++ b/usr.sbin/makemandb/makemandb.8	Tue Nov 20 23:11:47 2012 +0000
@@ -1,4 +1,4 @@
-.\" $NetBSD: makemandb.8,v 1.1.2.1 2012/02/20 22:04:30 sborrill Exp $
+.\" $NetBSD: makemandb.8,v 1.1.2.2 2012/11/20 23:11:47 riz 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 February 20, 2012
+.Dd August 29, 2012
 .Dt MAKEMANDB 8
 .Os
 .Sh NAME
@@ -37,8 +37,8 @@
 .Nd parse the manual pages and build a search index over them
 .Sh SYNOPSIS
 .Nm
+.Op Fl floQqv
 .Op Fl C Ar path
-.Op Fl floqv
 .Sh DESCRIPTION
 The
 .Nm
@@ -71,11 +71,15 @@
 Use this option to optimize the index for speed and also
 to significantly reduce disk space usage.
 This is a somewhat expensive operation.
+.It Fl Q
+Print only fatal error messages (i.e., when the database is left in
+an inconsistent state and needs manual intervention).
 .It Fl q
-Print only error messages and no status updates.
+Print only warnings and error messages but no status updates.
 .It Fl v
 Enable verbose output.
-This prints the name of every file being parsed.
+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
@@ -94,7 +98,11 @@
 .It Li env Ta The ENVIRONMENT section.
 .It Li files Ta The FILES section.
 .It Li exit_status Ta The EXIT STATUS section.
+.It Li diagnostics Ta The DIAGNOSTICS section.
 .It Li errors Ta The ERRORS section.
+.It Li md5_hash Ta  MD5 checksum of the man page.
+.It Li machine Ta The machine architecture (if any) for which the man
+page is relevant.
 .El
 .Sh FILES
 .Bl -hang -width /var/db/man.db -compact
--- a/usr.sbin/makemandb/makemandb.c	Tue Nov 20 22:33:37 2012 +0000
+++ b/usr.sbin/makemandb/makemandb.c	Tue Nov 20 23:11:47 2012 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: makemandb.c,v 1.2.2.5 2012/05/09 03:41:00 riz Exp $	*/
+/*	$NetBSD: makemandb.c,v 1.2.2.6 2012/11/20 23:11:47 riz 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.2.2.5 2012/05/09 03:41:00 riz Exp $");
+__RCSID("$NetBSD: makemandb.c,v 1.2.2.6 2012/11/20 23:11:47 riz Exp $");
 
 #include <sys/stat.h>
 #include <sys/types.h>
@@ -304,7 +304,7 @@
 	size_t linesize;
 	struct mandb_rec rec;
 
-	while ((ch = getopt(argc, argv, "C:floqv")) != -1) {
+	while ((ch = getopt(argc, argv, "C:floQqv")) != -1) {
 		switch (ch) {
 		case 'C':
 			manconf = optarg;
@@ -319,8 +319,11 @@
 		case 'o':
 			mflags.optimize = 1;
 			break;
+		case 'Q':
+			mflags.verbosity = 0;
+			break;
 		case 'q':
-			mflags.verbosity = 0;
+			mflags.verbosity = 1;
 			break;
 		case 'v':
 			mflags.verbosity = 2;
@@ -358,7 +361,7 @@
 	if (manconf) {
 		char *arg;
 		size_t command_len = shquote(manconf, NULL, 0) + 1;
-		arg = malloc(command_len );
+		arg = emalloc(command_len);
 		shquote(manconf, arg, command_len);
 		easprintf(&command, "man -p -C %s", arg);
 		free(arg);
@@ -417,6 +420,8 @@
 		err(EXIT_FAILURE, "pclose error");
 	}
 
+	if (mflags.verbosity)
+		printf("Performing index update\n");
 	update_db(db, mp, &rec);
 	mparse_free(mp);
 	free_secbuffs(&rec);
@@ -451,7 +456,8 @@
 	char *buf;
 
 	if (stat(file, &sb) < 0) {
-		warn("stat failed: %s", file);
+		if (mflags.verbosity)
+			warn("stat failed: %s", file);
 		return;
 	}
 	
@@ -464,7 +470,8 @@
 	/* If it is a directory, traverse it recursively */
 	if (S_ISDIR(sb.st_mode)) {
 		if ((dp = opendir(file)) == NULL) {
-			warn("opendir error: %s", file);
+			if (mflags.verbosity)
+				warn("opendir error: %s", file);
 			return;
 		}
 		
@@ -503,14 +510,16 @@
 		 " :mtime, :parent, :file)";
 	rc = sqlite3_prepare_v2(db, sqlstr, -1, &stmt, NULL);
 	if (rc != SQLITE_OK) {
-		warnx("%s", sqlite3_errmsg(db));
+		if (mflags.verbosity)
+			warnx("%s", sqlite3_errmsg(db));
 		return;
 	}
 
 	idx = sqlite3_bind_parameter_index(stmt, ":device");
 	rc = sqlite3_bind_int64(stmt, idx, device_cache);
 	if (rc != SQLITE_OK) {
-		warnx("%s", sqlite3_errmsg(db));
+		if (mflags.verbosity)
+			warnx("%s", sqlite3_errmsg(db));
 		sqlite3_finalize(stmt);
 		return;
 	}
@@ -518,7 +527,8 @@
 	idx = sqlite3_bind_parameter_index(stmt, ":inode");
 	rc = sqlite3_bind_int64(stmt, idx, inode_cache);
 	if (rc != SQLITE_OK) {
-		warnx("%s", sqlite3_errmsg(db));
+		if (mflags.verbosity)
+			warnx("%s", sqlite3_errmsg(db));
 		sqlite3_finalize(stmt);
 		return;
 	}
@@ -526,7 +536,8 @@
 	idx = sqlite3_bind_parameter_index(stmt, ":mtime");
 	rc = sqlite3_bind_int64(stmt, idx, mtime_cache);
 	if (rc != SQLITE_OK) {
-		warnx("%s", sqlite3_errmsg(db));
+		if (mflags.verbosity)
+			warnx("%s", sqlite3_errmsg(db));
 		sqlite3_finalize(stmt);
 		return;
 	}
@@ -534,7 +545,8 @@
 	idx = sqlite3_bind_parameter_index(stmt, ":parent");
 	rc = sqlite3_bind_text(stmt, idx, parent, -1, NULL);
 	if (rc != SQLITE_OK) {
-		warnx("%s", sqlite3_errmsg(db));
+		if (mflags.verbosity)
+			warnx("%s", sqlite3_errmsg(db));
 		sqlite3_finalize(stmt);
 		return;
 	}
@@ -542,7 +554,8 @@
 	idx = sqlite3_bind_parameter_index(stmt, ":file");
 	rc = sqlite3_bind_text(stmt, idx, file, -1, NULL);
 	if (rc != SQLITE_OK) {
-		warnx("%s", sqlite3_errmsg(db));
+		if (mflags.verbosity)
+			warnx("%s", sqlite3_errmsg(db));
 		sqlite3_finalize(stmt);
 		return;
 	}
@@ -567,7 +580,8 @@
 		       "  :inode2 OR mtime <> :mtime2)";
 	rc = sqlite3_prepare_v2(db, inner_sqlstr, -1, &inner_stmt, NULL);
 	if (rc != SQLITE_OK) {
-		warnx("%s", sqlite3_errmsg(db));
+		if (mflags.verbosity)
+			warnx("%s", sqlite3_errmsg(db));
 		return;
 	}
 	idx = sqlite3_bind_parameter_index(inner_stmt, ":device");
@@ -591,7 +605,7 @@
 	if (rc == SQLITE_DONE) {
 		/* Check if an update has been performed. */
 		if (update_count != sqlite3_total_changes(db)) {
-			if (mflags.verbosity)
+			if (mflags.verbosity == 2)
 				printf("Updated %s\n", file);
 			(*new_count)++;
 		} else {
@@ -599,7 +613,8 @@
 			(*link_count)++;
 		}
 	} else {
-		warnx("Could not update the meta data for %s", file);
+		if (mflags.verbosity == 2)
+			warnx("Could not update the meta data for %s", file);
 		(*err_count)++;
 	}
 	sqlite3_finalize(inner_stmt);
@@ -643,7 +658,8 @@
 		if (off == *len) {
 			*len *= 2;
 			if (*len < off) {
-				warnx("File too large: %s", file);
+				if (mflags.verbosity)
+					warnx("File too large: %s", file);
 				free(*buf);
 				archive_read_close(a);
 				return -1;
@@ -691,6 +707,7 @@
 
 	rc = sqlite3_prepare_v2(db, sqlstr, -1, &stmt, NULL);
 	if (rc != SQLITE_OK) {
+		if (mflags.verbosity)
 		warnx("%s", sqlite3_errmsg(db));
 		close_db(db);
 		errx(EXIT_FAILURE, "Could not query file cache");
@@ -713,7 +730,8 @@
 		md5_status = check_md5(file, db, "mandb_meta", &md5sum, buf, buflen);
 		assert(md5sum != NULL);
 		if (md5_status == -1) {
-			warnx("An error occurred in checking md5 value"
+			if (mflags.verbosity)
+				warnx("An error occurred in checking md5 value"
 			      " for file %s", file);
 			err_count++;
 			continue;
@@ -743,7 +761,7 @@
 			 * This means is either a new file or an updated file.
 			 * We should go ahead with parsing.
 			 */
-			if (mflags.verbosity > 1)
+			if (mflags.verbosity == 2)
 				printf("Parsing: %s\n", file);
 			rec->md5_hash = md5sum;
 			rec->file_path = estrdup(file);
@@ -751,7 +769,8 @@
 			chdir(parent);
 			begin_parse(file, mp, rec, buf, buflen);
 			if (insert_into_db(db, rec) < 0) {
-				warnx("Error in indexing %s", file);
+				if (mflags.verbosity)
+					warnx("Error in indexing %s", file);
 				err_count++;
 			} else {
 				new_count++;
@@ -762,20 +781,20 @@
 
 	sqlite3_finalize(stmt);
 	
-	if (mflags.verbosity) {
-		printf("Total Number of new or updated pages enountered = %d\n"
+	if (mflags.verbosity == 2) {
+		printf("Total Number of new or updated pages encountered = %d\n"
+			"Total number of (hard or symbolic) links found = %d\n"
 			"Total number of pages that were successfully"
 			" indexed/updated = %d\n"
-			"Total number of (hard or symbolic) links found = %d\n"
 			"Total number of pages that could not be indexed"
 			" due to errors = %d\n",
-			total_count, new_count, link_count, err_count);
+			total_count - link_count, link_count, new_count, err_count);
 	}
 
 	if (mflags.recreate)
 		return;
 
-	if (mflags.verbosity)
+	if (mflags.verbosity == 2)
 		printf("Deleting stale index entries\n");
 
 	sqlstr = "DELETE FROM mandb_meta WHERE file NOT IN"
@@ -810,13 +829,19 @@
 	rec->xr_found = 0;
 
 	if (mparse_readmem(mp, buf, len, file) >= MANDOCLEVEL_FATAL) {
-		warnx("%s: Parse failure", file);
+		/* Printing this warning at verbosity level 2
+		 * because some packages from pkgsrc might trigger several
+		 * of such warnings.
+		 */
+		if (mflags.verbosity == 2)
+			warnx("%s: Parse failure", file);
 		return;
 	}
 
 	mparse_result(mp, &mdoc, &man);
 	if (mdoc == NULL && man == NULL) {
-		warnx("Not a man(7) or mdoc(7) page");
+		if (mflags.verbosity == 2)
+			warnx("Not a man(7) or mdoc(7) page");
 		return;
 	}
 
@@ -1670,7 +1695,8 @@
 		sqlite3_exec(db, sql, NULL, NULL, &errmsg);
 		sqlite3_free(sql);
 		if (errmsg != NULL) {
-			warnx("%s", errmsg);
+			if (mflags.verbosity)
+				warnx("%s", errmsg);
 			free(errmsg);
 		}
 		sqlstr = "UPDATE mandb_meta SET device = :device,"
@@ -1678,7 +1704,8 @@
 			 " md5_hash = :md5 WHERE file = :file";
 		rc = sqlite3_prepare_v2(db, sqlstr, -1, &stmt, NULL);
 		if (rc != SQLITE_OK) {
-			warnx("Update failed with error: %s",
+			if (mflags.verbosity)
+				warnx("Update failed with error: %s",
 			    sqlite3_errmsg(db));
 			close_db(db);
 			cleanup(rec);
@@ -1702,7 +1729,8 @@
 		sqlite3_finalize(stmt);
 
 		if (rc != SQLITE_DONE) {
-			warnx("%s", sqlite3_errmsg(db));
+			if (mflags.verbosity)
+				warnx("%s", sqlite3_errmsg(db));
 			close_db(db);
 			cleanup(rec);
 			errx(EXIT_FAILURE,
@@ -1746,7 +1774,8 @@
 	return 0;
 
   Out:
-	warnx("%s", sqlite3_errmsg(db));
+	if (mflags.verbosity)
+		warnx("%s", sqlite3_errmsg(db));
 	cleanup(rec);
 	return -1;
 }
@@ -1776,7 +1805,8 @@
 	assert(file != NULL);
 	*md5sum = MD5Data(buf, buflen, NULL);
 	if (*md5sum == NULL) {
-		warn("md5 failed: %s", file);
+		if (mflags.verbosity)
+			warn("md5 failed: %s", file);
 		return -1;
 	}
 
@@ -1793,7 +1823,8 @@
 	idx = sqlite3_bind_parameter_index(stmt, ":md5_hash");
 	rc = sqlite3_bind_text(stmt, idx, *md5sum, -1, NULL);
 	if (rc != SQLITE_OK) {
-		warnx("%s", sqlite3_errmsg(db));
+		if (mflags.verbosity)
+			warnx("%s", sqlite3_errmsg(db));
 		sqlite3_finalize(stmt);
 		free(sqlstr);
 		free(*md5sum);
@@ -1819,13 +1850,14 @@
 	const char *sqlstr;
 	char *errmsg = NULL;
 
-	if (mflags.verbosity)
+	if (mflags.verbosity == 2)
 		printf("Optimizing the database index\n");
 	sqlstr = "INSERT INTO mandb(mandb) VALUES (\'optimize\');"
 		 "VACUUM";
 	sqlite3_exec(db, sqlstr, NULL, NULL, &errmsg);
 	if (errmsg != NULL) {
-		warnx("%s", errmsg);
+		if (mflags.verbosity)
+			warnx("%s", errmsg);
 		free(errmsg);
 		return;
 	}
@@ -2036,6 +2068,6 @@
 static void
 usage(void)
 {
-	fprintf(stderr, "Usage: %s [-flo]\n", getprogname());
+	fprintf(stderr, "Usage: %s [-floQqv] [-C path]\n", getprogname());
 	exit(1);
 }