Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/netbsd-9]: src/usr.sbin/makemandb Pull up following revision(s) (request...
details: https://anonhg.NetBSD.org/src/rev/a27a9ced8559
branches: netbsd-9
changeset: 366630:a27a9ced8559
user: martin <martin%NetBSD.org@localhost>
date: Fri Jun 03 12:25:14 2022 +0000
description:
Pull up following revision(s) (requested by gutteridge in ticket #1461):
usr.sbin/makemandb/apropos.1: revision 1.19
usr.sbin/makemandb/apropos.c: revision 1.25
usr.sbin/makemandb/apropos.c: revision 1.26
usr.sbin/makemandb/apropos.1: revision 1.20
usr.sbin/makemandb/apropos.1: revision 1.21
usr.sbin/makemandb/apropos.1: revision 1.22
usr.sbin/makemandb/apropos.1: revision 1.23
usr.sbin/makemandb/apropos-utils.c: revision 1.46
usr.sbin/makemandb/apropos-utils.c: revision 1.47
usr.sbin/makemandb/apropos-utils.c: revision 1.49
PR/54343: Prevent NULL pointers in callback strings; use "*?*" for now to
identify them.
PR bin/54343: We want the callback_args.machine to be NULL if it is not
present in the DB.
The previous commit fixed the problem of allowing apropos to not crash and
produce output even if the database is missing values for certain mandatory
fields, such as name, section etc. Normally we don't expect those values
to be missing in the database but in case of parsing errors it can happen.
However, the machine architecture is an optional field since not all man pages
are hardware specific so that should be allowed to be set to NULL if not
present in the database.
apropos.c: fix pager functionality
Issue reported by Rocky Hotas on NetBSD-Users, patch input from RVP on
same, adjustments by me.
apropos.1: document the PAGER environment variable
apropos(1): use proper -width
apropos(1): use proper -width for the list of options too
apropos(1): Tweak the description of -1, ... -9, and -s
-s is not for compatibility only, because section names can be
anything. E.g. we have 3lua and 9lua in base. We have rudiments of
3f (for FORTRAN libs). Some packages in pkgsrc also use suffixed 1
and 3 sections.
apropos(1): Use the official spelling for "SQLite".
While here, use .Bx to refer to 3BSD.
apropos(1): improve error handling in edge cases
Patch from RVP on NetBSD-Users, with an additional comment tweak by me.
Summary from RVP:
1. Ignore SIGPIPE so that we're not killed in the middle of some
DB operation by a botched $PAGER:
$ env PAGER=3D/non-existent apropos -p ...
2. Return proper exit status in case of write errors:
$ apropos ... >/dev/full || echo fail
diffstat:
usr.sbin/makemandb/apropos-utils.c | 51 +++++++++++++++++++++----------------
usr.sbin/makemandb/apropos.1 | 45 ++++++++++++++++++++------------
usr.sbin/makemandb/apropos.c | 27 ++++++++++++++-----
3 files changed, 77 insertions(+), 46 deletions(-)
diffs (truncated from 322 to 300 lines):
diff -r 9eb397c5e46b -r a27a9ced8559 usr.sbin/makemandb/apropos-utils.c
--- a/usr.sbin/makemandb/apropos-utils.c Fri Jun 03 04:01:38 2022 +0000
+++ b/usr.sbin/makemandb/apropos-utils.c Fri Jun 03 12:25:14 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: apropos-utils.c,v 1.45 2019/06/07 16:43:58 leot Exp $ */
+/* $NetBSD: apropos-utils.c,v 1.45.2.1 2022/06/03 12:25:14 martin Exp $ */
/*-
* Copyright (c) 2011 Abhinav Upadhyay <er.abhinav.upadhyay%gmail.com@localhost>
* All rights reserved.
@@ -31,7 +31,7 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: apropos-utils.c,v 1.45 2019/06/07 16:43:58 leot Exp $");
+__RCSID("$NetBSD: apropos-utils.c,v 1.45.2.1 2022/06/03 12:25:14 martin Exp $");
#include <sys/queue.h>
#include <sys/stat.h>
@@ -654,11 +654,18 @@
return query;
}
+static const char *
+get_stmt_col_text(sqlite3_stmt *stmt, int col)
+{
+ const char *t = (const char *) sqlite3_column_text(stmt, col);
+ return t == NULL ? "*?*" : t;
+}
+
/*
* Execute the full text search query and return the number of results
* obtained.
*/
-static unsigned int
+static int
execute_search_query(sqlite3 *db, char *query, query_args *args)
{
sqlite3_stmt *stmt;
@@ -692,16 +699,17 @@
return -1;
}
- unsigned int nresults = 0;
- while (sqlite3_step(stmt) == SQLITE_ROW) {
+ int nresults = rc = 0;
+ while (rc == 0 && sqlite3_step(stmt) == SQLITE_ROW) {
nresults++;
- callback_args.section = (const char *) sqlite3_column_text(stmt, 0);
- name_temp = (const char *) sqlite3_column_text(stmt, 1);
- callback_args.name_desc = (const char *) sqlite3_column_text(stmt, 2);
+ callback_args.section = get_stmt_col_text(stmt, 0);
+ name_temp = get_stmt_col_text(stmt, 1);
+ callback_args.name_desc = get_stmt_col_text(stmt, 2);
callback_args.machine = (const char *) sqlite3_column_text(stmt, 3);
if (!args->legacy) {
- callback_args.snippet = (const char *) sqlite3_column_text(stmt, 4);
- callback_args.snippet_length = strlen(callback_args.snippet);
+ callback_args.snippet = get_stmt_col_text(stmt, 4);
+ callback_args.snippet_length =
+ strlen(callback_args.snippet);
} else {
callback_args.snippet = "";
callback_args.snippet_length = 1;
@@ -713,16 +721,15 @@
easprintf(&name, "%s/%s", lower(m), name_temp);
free(m);
} else {
- name = estrdup((const char *)
- sqlite3_column_text(stmt, 1));
+ name = estrdup(get_stmt_col_text(stmt, 1));
}
callback_args.name = name;
callback_args.other_data = args->callback_data;
- (args->callback)(&callback_args);
+ rc = (args->callback)(&callback_args);
free(name);
}
sqlite3_finalize(stmt);
- return nresults;
+ return (rc < 0) ? rc : nresults;
}
@@ -745,9 +752,9 @@
return -1;
}
- execute_search_query(db, query, args);
+ int rc = execute_search_query(db, query, args);
sqlite3_free(query);
- return *(args->errmsg) == NULL ? 0 : -1;
+ return (rc < 0 || *(args->errmsg) != NULL) ? -1 : 0;
}
static char *
@@ -838,10 +845,10 @@
callback_args->snippet = qsnippet;
callback_args->snippet_length = length;
callback_args->other_data = orig_data->data;
- (*callback)(callback_args);
+ int rc = (*callback)(callback_args);
free(qsnippet);
free(qname_description);
- return 0;
+ return rc;
}
/*
@@ -961,12 +968,12 @@
callback_args->snippet = psnippet;
callback_args->snippet_length = psnippet_length;
callback_args->other_data = orig_data->data;
- (orig_data->callback)(callback_args);
+ int rc = (orig_data->callback)(callback_args);
free(ul_section);
free(ul_name);
free(ul_name_desc);
free(psnippet);
- return 0;
+ return rc;
}
struct term_args {
@@ -1006,11 +1013,11 @@
callback_args->name = ul_name;
callback_args->name_desc = ul_name_desc;
callback_args->other_data = orig_data->data;
- (orig_data->callback)(callback_args);
+ int rc = (orig_data->callback)(callback_args);
free(ul_section);
free(ul_name);
free(ul_name_desc);
- return 0;
+ return rc;
}
/*
diff -r 9eb397c5e46b -r a27a9ced8559 usr.sbin/makemandb/apropos.1
--- a/usr.sbin/makemandb/apropos.1 Fri Jun 03 04:01:38 2022 +0000
+++ b/usr.sbin/makemandb/apropos.1 Fri Jun 03 12:25:14 2022 +0000
@@ -1,4 +1,4 @@
-.\" $NetBSD: apropos.1,v 1.18 2016/06/17 18:48:07 abhinav Exp $
+.\" $NetBSD: apropos.1,v 1.18.18.1 2022/06/03 12:25:14 martin Exp $
.\"
.\" Copyright (c) 2011 Abhinav Upadhyay <er.abhinav.upadhyay%gmail.com@localhost>
.\" All rights reserved.
@@ -29,7 +29,7 @@
.\" OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.Dd June 16, 2016
+.Dd May 17, 2022
.Dt APROPOS 1
.Os
.Sh NAME
@@ -47,7 +47,7 @@
The
.Nm
utility performs a full text search over the complete content of all man pages.
-It uses the FTS engine of Sqlite to perform the search.
+It uses the FTS engine of SQLite to perform the search.
The database is created with the help of the
.Xr makemandb 8
utility.
@@ -62,9 +62,13 @@
Quotes are optional for specifying multiword queries.
.Pp
It supports the following options:
-.Bl -tag -width indent
-.It Fl [1-9]
-Search only within the specified section of manual pages.
+.Bl -tag -width Fl
+.It Fl 1 , No \&... , Fl 9
+Limit the search to the specified section of the manual.
+By default, pages from all sections are shown.
+These options are abbreviations for the
+.Fl s
+option for single digit sections.
.It Fl C Ar path
Use different
.Xr man 1
@@ -95,26 +99,32 @@
Limit the search to the pages for the specified machine architecture.
By default pages for all architectures are shown in the search results.
.It Fl s Ar section
-Restrict the search to the specified section of the manual.
+Limit the search to the specified section of the manual.
By default, pages from all sections are shown.
-This option is for backwards compatibility with the classic version of apropos,
-using it is equivalent to using the
-.Op 123456789
-options directly.
+For single digit sections you can use abbreviations:
+.Fl 1 , No \&... , Fl 9 .
.El
.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
+The location of the SQLite FTS database can be configured using the
.Cd _mandb
tag.
.El
.Sh ENVIRONMENT VARIABLES
-The
-.Ev APROPOS
-environment variable is white-space tokenized as an argument vector
+.Bl -tag -width Ev
+.It Ev APROPOS
+This environment variable is white-space tokenized as an argument vector
and the options in it are parsed and set.
Command line options override the environment options.
+.It Ev PAGER
+The pagination command used for writing the output, should this be requested.
+If the
+.Ev PAGER
+environment variable is null or not set, the standard pagination program
+.Xr more 1
+will be used.
+.El
.Sh SEE ALSO
.Xr man 1 ,
.Xr whatis 1 ,
@@ -123,9 +133,10 @@
.Sh HISTORY
The
.Nm
-command appeared in 3.0BSD.
+command appeared in
+.Bx 3 .
It was rewritten in
.Nx 6.0
-to support full text search using Sqlite.
+to support full text search using SQLite.
.Sh AUTHORS
.An Abhinav Upadhyay
diff -r 9eb397c5e46b -r a27a9ced8559 usr.sbin/makemandb/apropos.c
--- a/usr.sbin/makemandb/apropos.c Fri Jun 03 04:01:38 2022 +0000
+++ b/usr.sbin/makemandb/apropos.c Fri Jun 03 12:25:14 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: apropos.c,v 1.24 2017/11/25 14:29:38 abhinav Exp $ */
+/* $NetBSD: apropos.c,v 1.24.6.1 2022/06/03 12:25:14 martin Exp $ */
/*-
* Copyright (c) 2011 Abhinav Upadhyay <er.abhinav.upadhyay%gmail.com@localhost>
* All rights reserved.
@@ -31,9 +31,10 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: apropos.c,v 1.24 2017/11/25 14:29:38 abhinav Exp $");
+__RCSID("$NetBSD: apropos.c,v 1.24.6.1 2022/06/03 12:25:14 martin Exp $");
#include <err.h>
+#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -157,6 +158,7 @@
char *query = NULL; // the user query
char *errmsg = NULL;
char *str;
+ int pc = 0;
int rc = 0;
size_t i;
int s;
@@ -222,6 +224,10 @@
const char *pager = getenv("PAGER");
if (pager == NULL)
pager = _PATH_PAGER;
+
+ /* Don't get killed by a broken pipe */
+ signal(SIGPIPE, SIG_IGN);
+
/* Open a pipe to the pager */
if ((cbdata.out = popen(pager, "w")) == NULL) {
close_db(db);
@@ -249,6 +255,8 @@
if (aflags.format == APROPOS_HTML)
fprintf(cbdata.out, "</table>\n</body>\n</html>\n");
+ if (aflags.pager)
+ pc = pclose(cbdata.out);
free(query);
if (aflags.sections) {
@@ -264,10 +272,15 @@
exit(EXIT_FAILURE);
}
- if (rc < 0) {
- /* Something wrong with the database. Exit */
+ if (pc == -1)
+ err(EXIT_FAILURE, "pclose error");
+
+ /*
+ * Something wrong with the database, writing output, or a non-existent
+ * pager.
+ */
+ if (rc < 0)
exit(EXIT_FAILURE);
Home |
Main Index |
Thread Index |
Old Index