summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorQuentin Armitage <quentin@armitage.org.uk>2021-11-19 18:33:49 +0000
committerLucas De Marchi <lucas.de.marchi@gmail.com>2022-06-30 09:59:38 -0700
commitc1fb98a30dae051ab69d23624d1e062d0527527e (patch)
tree2e5ade5bcb4e314804c2d9a9394a167d2aeb4d93
parent09ad8605520c87e799cb89e2bcdf2f36e21f77ba (diff)
downloadkmod-c1fb98a30dae051ab69d23624d1e062d0527527e.tar.gz
modprobe: Write error messages to syslog if stderr is unavailable
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.
-rw-r--r--tools/modprobe.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/tools/modprobe.c b/tools/modprobe.c
index 2a2ae21..3240c2b 100644
--- a/tools/modprobe.c
+++ b/tools/modprobe.c
@@ -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) {