git: f6d6c6688900 - main - grep: remove tautological condition

From: Kyle Evans <kevans_at_FreeBSD.org>
Date: Thu, 09 Mar 2023 05:35:12 UTC
The branch main has been updated by kevans:

URL: https://cgit.FreeBSD.org/src/commit/?id=f6d6c66889001208aee7b0c46efe1c8ddffda57c

commit f6d6c66889001208aee7b0c46efe1c8ddffda57c
Author:     Kyle Evans <kevans@FreeBSD.org>
AuthorDate: 2023-03-09 05:29:30 +0000
Commit:     Kyle Evans <kevans@FreeBSD.org>
CommitDate: 2023-03-09 05:34:22 +0000

    grep: remove tautological condition
    
    st_size is an off_t, it cannot hold values larger than OFF_MAX.
    
    CID:            1008931
---
 usr.bin/grep/file.c   |  3 +--
 usr.sbin/pkg/config.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++
 usr.sbin/pkg/config.h |  1 +
 usr.sbin/pkg/pkg.c    |  5 +++++
 4 files changed, 62 insertions(+), 2 deletions(-)

diff --git a/usr.bin/grep/file.c b/usr.bin/grep/file.c
index 8577572c2887..787e8fbe03bb 100644
--- a/usr.bin/grep/file.c
+++ b/usr.bin/grep/file.c
@@ -186,8 +186,7 @@ grep_open(const char *path)
 	if (filebehave == FILE_MMAP) {
 		struct stat st;
 
-		if ((fstat(f->fd, &st) == -1) || (st.st_size > OFF_MAX) ||
-		    (!S_ISREG(st.st_mode)))
+		if (fstat(f->fd, &st) == -1 || !S_ISREG(st.st_mode))
 			filebehave = FILE_STDIO;
 		else {
 			int flags = MAP_PRIVATE | MAP_NOCORE | MAP_NOSYNC;
diff --git a/usr.sbin/pkg/config.c b/usr.sbin/pkg/config.c
index 08e206b93511..6902cfe41b7c 100644
--- a/usr.sbin/pkg/config.c
+++ b/usr.sbin/pkg/config.c
@@ -567,3 +567,58 @@ config_finish(void) {
 	for (i = 0; i < CONFIG_SIZE; i++)
 		free(c[i].value);
 }
+
+
+static int
+config_value(const char *key)
+{
+	const struct config_entry *cp;
+
+	for (size_t i = 0; i < nitems(c); i++) {
+		cp = &c[i];
+
+		if (strcmp(cp->key, key) == 0) {
+			switch (cp->type) {
+			case PKG_CONFIG_STRING: {
+				const char *val;
+
+				(void)config_string(i, &val);
+				printf("%s\n", val);
+				break;
+			}
+			case PKG_CONFIG_BOOL: {
+				bool val;
+
+				(void)config_bool(i, &val);
+				printf("%s\n", val ? "yes" : "no");
+				break;
+			}
+			}
+
+			return (0);
+		}
+	}
+
+	return (ENOENT);
+}
+
+int
+config_show(int argc, char *argv[])
+{
+	int error;
+
+	if (argc != 1) {
+		fprintf(stderr, "Usage: pkg -N config <name>\n");
+		return (1);
+	}
+
+	config_init(NULL);
+	error = config_value(argv[0]);
+	config_finish();
+
+	if (error == ENOENT) {
+		fprintf(stderr, "pkg: No such configuration options: %s\n",
+		    argv[0]);
+	}
+	return (error);
+}
diff --git a/usr.sbin/pkg/config.h b/usr.sbin/pkg/config.h
index 87efd3c29e94..8cb878291a7e 100644
--- a/usr.sbin/pkg/config.h
+++ b/usr.sbin/pkg/config.h
@@ -62,6 +62,7 @@ typedef enum {
 
 int config_init(const char *);
 void config_finish(void);
+int config_show(int, char *[]);
 int config_string(pkg_config_key, const char **);
 int config_bool(pkg_config_key, bool *);
 
diff --git a/usr.sbin/pkg/pkg.c b/usr.sbin/pkg/pkg.c
index 7b574dc42db2..3d4119d85bf8 100644
--- a/usr.sbin/pkg/pkg.c
+++ b/usr.sbin/pkg/pkg.c
@@ -1195,6 +1195,11 @@ main(int argc, char *argv[])
 				else if (strcmp(command, "bootstrap") == 0) {
 					bootstrap_only = true;
 				}
+				else if (strcmp(command, "config") == 0 &&
+				    activation_test) {
+					exit(config_show(argc - optind,
+					    argv + optind));
+				}
 			}
 			// bootstrap doesn't accept other arguments
 			else if (bootstrap_only) {