]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
modprobe: Write error messages to syslog if stderr is unavailable
authorQuentin Armitage <quentin@armitage.org.uk>
Fri, 19 Nov 2021 18:33:49 +0000 (18:33 +0000)
committerLucas De Marchi <lucas.de.marchi@gmail.com>
Thu, 30 Jun 2022 16:59:38 +0000 (09:59 -0700)
The man page modprobe(8) states for the --syslog option:
"This is also automatically enabled when stderr is unavailable."
but it wasn't happening.

This commit now makes modprobe write to syslog if stderr is closed.

tools/modprobe.c

index 2a2ae21f537051cab47f433106277dec63583d9d..3240c2b72edd2a996a905918f090f4f05c9f888c 100644 (file)
@@ -819,6 +819,7 @@ static int do_modprobe(int argc, char **orig_argv)
        int do_show_modversions = 0;
        int do_show_exports = 0;
        int err;
+       struct stat stat_buf;
 
        argv = prepend_options_from_env(&argc, orig_argv);
        if (argv == NULL) {
@@ -947,6 +948,12 @@ static int do_modprobe(int argc, char **orig_argv)
        args = argv + optind;
        nargs = argc - optind;
 
+       if (!use_syslog &&
+           (!stderr ||
+            fileno(stderr) == -1 ||
+            fstat(fileno(stderr), &stat_buf)))
+               use_syslog = 1;
+
        log_open(use_syslog);
 
        if (!do_show_config) {