From 9e482430e03495444950a0bf0eda5232118132a5 Mon Sep 17 00:00:00 2001 From: Jean Delvare Date: Wed, 26 Nov 2008 14:52:07 +0000 Subject: [PATCH] Unload kernel drivers which we loaded ourselves when we are done with them. git-svn-id: http://lm-sensors.org/svn/lm-sensors/branches/lm-sensors-3.0.0@5433 7894878c-1315-0410-8ee3-d5d059ff63e0 --- CHANGES | 1 + prog/detect/sensors-detect | 34 +++++++++++++++++++++++++++++++++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/CHANGES b/CHANGES index a7fe9525..15f5bd04 100644 --- a/CHANGES +++ b/CHANGES @@ -25,6 +25,7 @@ SVN-HEAD Complete GL520SM detection Improve GL525SM detection a bit Let kernel 2.6.28 and later handle chips aliases + Unload kernel drivers when we are done with them (#2329) 3.0.3 (2008-09-28) libsensors: Avoid namespace pollution diff --git a/prog/detect/sensors-detect b/prog/detect/sensors-detect index 32c8fc2c..0da79302 100755 --- a/prog/detect/sensors-detect +++ b/prog/detect/sensors-detect @@ -2290,7 +2290,7 @@ sub initialize_i2c_adapters_list # MODULES # ########### -use vars qw(%modules_list %modules_supported); +use vars qw(%modules_list %modules_supported @modules_we_loaded); sub initialize_modules_list { @@ -2309,6 +2309,23 @@ sub initialize_modules_supported } } +sub unload_modules +{ + return unless @modules_we_loaded; + + # Attempt to unload all kernel drivers we loaded ourselves + while (my $module = pop @modules_we_loaded) { + print "Unloading $module... "; + system("modprobe -r $module 2> /dev/null"); + if (($? >> 8) == 0) { + print "OK\n"; + } else { + print "failed\n"; + } + } + print "\n"; +} + ################# # SYSFS HELPERS # ################# @@ -5337,6 +5354,8 @@ sub main print "Loading failed... skipping.\n"; } else { print "Module loaded successfully.\n"; + push @modules_we_loaded, $adapter; + $modules_list{$adapter} = 1; } } } @@ -5356,6 +5375,8 @@ sub main print "Loading failed, expect problems later on.\n"; } else { print "Module loaded successfully.\n"; + push @modules_we_loaded, "i2c-dev"; + $modules_list{"i2c-dev"} = 1; } print "\n"; } @@ -5589,6 +5610,17 @@ EOT "working properly. Monitoring programs won't work until the needed\n". "modules are loaded.\n\n"; } + + unload_modules(); } +sub cleanup_on_int +{ + print "\n"; + unload_modules(); + exit; +} + +$SIG{INT} = \&cleanup_on_int; + main;