Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.sbin/makemandb makemandb.c: fail sooner if man page dirs...



details:   https://anonhg.NetBSD.org/src/rev/0cae926f475c
branches:  trunk
changeset: 364674:0cae926f475c
user:      gutteridge <gutteridge%NetBSD.org@localhost>
date:      Wed Apr 06 03:23:38 2022 +0000

description:
makemandb.c: fail sooner if man page dirs can't be found

There's no point initializing database state if we're then going to
fail to locate any man page sources. Make all the initial state checks
contiguous for simplicity and readability. Also, free the variable
"command" on the error path, and correct the error message.

diffstat:

 usr.sbin/makemandb/makemandb.c |  19 +++++++++----------
 1 files changed, 9 insertions(+), 10 deletions(-)

diffs (47 lines):

diff -r dee5722f7134 -r 0cae926f475c usr.sbin/makemandb/makemandb.c
--- a/usr.sbin/makemandb/makemandb.c    Tue Apr 05 23:13:56 2022 +0000
+++ b/usr.sbin/makemandb/makemandb.c    Wed Apr 06 03:23:38 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: makemandb.c,v 1.61 2021/12/05 08:18:18 msaitoh Exp $   */
+/*     $NetBSD: makemandb.c,v 1.62 2022/04/06 03:23:38 gutteridge Exp $        */
 /*
  * Copyright (c) 2011 Abhinav Upadhyay <er.abhinav.upadhyay%gmail.com@localhost>
  * Copyright (c) 2011 Kristaps Dzonsons <kristaps%bsd.lv@localhost>
@@ -17,7 +17,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: makemandb.c,v 1.61 2021/12/05 08:18:18 msaitoh Exp $");
+__RCSID("$NetBSD: makemandb.c,v 1.62 2022/04/06 03:23:38 gutteridge Exp $");
 
 #include <sys/stat.h>
 #include <sys/types.h>
@@ -351,6 +351,13 @@
                manconf = MANCONF;
        }
 
+       /* Call man -p to get the list of man page dirs */
+       if ((file = popen(command, "r")) == NULL) {
+               free(command);
+               err(EXIT_FAILURE, "popen failed");
+       }
+       free(command);
+
        if (mflags.recreate) {
                char *dbp = get_dbpath(manconf);
                /* No error here, it will fail in init_db in the same call */
@@ -378,14 +385,6 @@
                exit(EXIT_FAILURE);
        }
 
-
-       /* Call man -p to get the list of man page dirs */
-       if ((file = popen(command, "r")) == NULL) {
-               close_db(db);
-               err(EXIT_FAILURE, "fopen failed");
-       }
-       free(command);
-
        /* Begin the transaction for indexing the pages */
        sqlite3_exec(db, "BEGIN", NULL, NULL, &errmsg);
        if (errmsg != NULL) {



Home | Main Index | Thread Index | Old Index