From: Emil Velikov Date: Sat, 18 Jul 2026 22:11:46 +0000 (+0100) Subject: modinfo: flesh out and reuse print_line helper X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5aa0a602f80c61b578af246743dbfa976e5da06e;p=thirdparty%2Fkmod.git modinfo: flesh out and reuse print_line helper Thus using the correct format when `--null` is specified. In particular, the both name + filename use the correct format, when --null (mode) is requested. Signed-off-by: Emil Velikov Link: https://github.com/kmod-project/kmod/pull/451 Signed-off-by: Lucas De Marchi --- diff --git a/tools/modinfo.c b/tools/modinfo.c index 3f013ecf..92df6802 100644 --- a/tools/modinfo.c +++ b/tools/modinfo.c @@ -110,6 +110,23 @@ static int process_parm(enum parm_info parm_info, const char *value, struct para return 0; } +static void print_line(const char *key, const char *value) +{ + if (key == NULL) { + printf("%s%c", value, separator); + return; + } + + if (separator == '\0') { + printf("%s=%s%c", key, value, separator); + } else { + size_t keylen = strlen(key); + if (keylen > 15) + keylen = 15; + printf("%s:%-*s%s%c", key, 15 - (int)keylen, "", value, separator); + } +} + static int modinfo_params_do(const struct kmod_list *list) { const struct kmod_list *l; @@ -168,17 +185,18 @@ static int modinfo_do(struct kmod_module *mod) /* TODO: align builtin vs not wrt listing "name:" via kmod_module_get_info() */ if (is_builtin) { + const char *name = kmod_module_get_name(mod); if (field == NULL) - printf("%-16s%s%c", "name:", kmod_module_get_name(mod), separator); + print_line("name", name); else if (field != NULL && streq(field, "name")) - printf("%s%c", kmod_module_get_name(mod), separator); + print_line(NULL, name); } if (field != NULL && streq(field, "filename")) { - printf("%s%c", filename, separator); + print_line(NULL, filename); return 0; } else if (field == NULL) { - printf("%-16s%s%c", "filename:", filename, separator); + print_line("filename", filename); } err = kmod_module_get_info(mod, &list); @@ -206,8 +224,7 @@ static int modinfo_do(struct kmod_module *mod) if (field != NULL) { if (streq(field, key)) { - /* filtered output contains no key, just value */ - printf("%s%c", value, separator); + print_line(NULL, value); } } else if (streq(key, "parm")) { err = process_parm(parm_desc, value, ¶ms); @@ -217,13 +234,8 @@ static int modinfo_do(struct kmod_module *mod) err = process_parm(parm_type, value, ¶ms); if (err < 0) goto end; - } else if (separator == '\0') { - printf("%s=%s%c", key, value, separator); } else { - size_t keylen = strlen(key); - if (keylen > 15) - keylen = 15; - printf("%s:%-*s%s%c", key, 15 - (int)keylen, "", value, separator); + print_line(key, value); } }