Module Name:    src
Committed By:   gutteridge
Date:           Wed Apr  6 03:23:38 UTC 2022

Modified Files:
        src/usr.sbin/makemandb: makemandb.c

Log Message:
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.


To generate a diff of this commit:
cvs rdiff -u -r1.61 -r1.62 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/usr.sbin/makemandb/makemandb.c
diff -u src/usr.sbin/makemandb/makemandb.c:1.61 src/usr.sbin/makemandb/makemandb.c:1.62
--- src/usr.sbin/makemandb/makemandb.c:1.61	Sun Dec  5 08:18:18 2021
+++ src/usr.sbin/makemandb/makemandb.c	Wed Apr  6 03:23:38 2022
@@ -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.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.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 @@ main(int argc, char *argv[])
 		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 @@ main(int argc, char *argv[])
 		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) {

Reply via email to