diff mbox series

[kmod,v4,3/4] kmod: Add config command to show compile time configuration as JSON

Message ID eacb691cec6266a22387f6445507de122f5c7afb.1689589902.git.msuchanek@suse.de (mailing list archive)
State New, archived
Headers show
Series kmod /usr support | expand

Commit Message

Michal Suchánek July 17, 2023, 10:39 a.m. UTC
Show prefix (where system configuration files are searched/to be
installed), sysconfdir (where user configuration files are searched),
module compressions, and module signatures supported.

Signed-off-by: Michal Suchanek <msuchanek@suse.de>
---
v2: mention module signature in commit message
v3: add sysconfdir
---
 man/kmod.xml |  6 ++++++
 tools/kmod.c | 40 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 46 insertions(+)
diff mbox series

Patch

diff --git a/man/kmod.xml b/man/kmod.xml
index 0706ad58c2cc..f992a500f836 100644
--- a/man/kmod.xml
+++ b/man/kmod.xml
@@ -71,6 +71,12 @@ 
           <para>Show the help message.</para>
         </listitem>
       </varlistentry>
+      <varlistentry>
+        <term><command>config</command></term>
+        <listitem>
+          <para>Show compile time options in JSON.</para>
+        </listitem>
+      </varlistentry>
       <varlistentry>
         <term><command>list</command></term>
         <listitem>
diff --git a/tools/kmod.c b/tools/kmod.c
index 55689c075ab1..a684c1d24284 100644
--- a/tools/kmod.c
+++ b/tools/kmod.c
@@ -37,9 +37,11 @@  static const struct option options[] = {
 };
 
 static const struct kmod_cmd kmod_cmd_help;
+static const struct kmod_cmd kmod_cmd_config;
 
 static const struct kmod_cmd *kmod_cmds[] = {
 	&kmod_cmd_help,
+	&kmod_cmd_config,
 	&kmod_cmd_list,
 	&kmod_cmd_static_nodes,
 
@@ -95,6 +97,44 @@  static const struct kmod_cmd kmod_cmd_help = {
 	.help = "Show help message",
 };
 
+static const char *compressions[] = {
+#ifdef ENABLE_ZSTD
+			"zstd",
+#endif
+#ifdef ENABLE_XZ
+			"xz",
+#endif
+#ifdef ENABLE_ZLIB
+			"gz",
+#endif
+			NULL
+};
+
+static int kmod_config(int argc, char *argv[])
+{
+	unsigned i;
+	printf("{\"prefix\":\"" PREFIX "\""
+			",\"sysconfdir\":\"" SYSCONFDIR "\""
+			",\"module_signature\":["
+#ifdef ENABLE_OPENSSL
+			"\"PKCS#7\","
+#endif
+			"\"legacy\"]"
+			",\"module_compression\":[");
+	for(i = 0; compressions[i]; i++) {
+		printf("%s\"%s\"", i ? "," : "", compressions[i]);
+	}
+	printf("]}\n");
+
+	return EXIT_SUCCESS;
+}
+
+static const struct kmod_cmd kmod_cmd_config = {
+	.name = "config",
+	.cmd = kmod_config,
+	.help = "Show compile time options in JSON",
+};
+
 static int handle_kmod_commands(int argc, char *argv[])
 {
 	const char *cmd;