Skip to contentSkip to conversation

PATCH: make lm_sensors init script return values LSB

lm-sensors Hans de Goede 2 participants 5 messages Feb 11, 2008 – Feb 26, 2008

lore
Share & tools
lore
#0 lore raw

Hi All,

I've received the attached patch through Fedora's bugzilla. It fixes the return values of the various error exit cases to match the LSB spec:
http://refspecs.linux-foundation.org/LSB_3.2.0/LSB-Core-generic/LSB-Core-generic/iniscrptact.html

It looks sane to me, if there are no objections I'll commit it to svn.

Thanks & Regards,

Hans

lm_sensors renamed from lm_sensors.orig +4 -4
@@ -40,15 +40,15 @@
 
 	# Don't bother if /proc/sensors still doesn't exist, kernel doesn't have
 	# support for sensors.
-	[ -e /proc/sys/dev/sensors ] || exit 0
+	[ -e /proc/sys/dev/sensors ] || exit 6
 
 	# If sensors was not already running, unload the module...
 	[ -e /var/lock/subsys/lm_sensors ] || /sbin/modprobe -r i2c-proc >/dev/null 2>&1
 fi
 
 CONFIG=/etc/sysconfig/lm_sensors
-[ -r "$CONFIG" ] || exit 0
-grep '^MODULE_' $CONFIG >/dev/null 2>&1 || exit 0
+[ -r "$CONFIG" ] || exit 6
+grep '^MODULE_' $CONFIG >/dev/null 2>&1 || exit 6
 
 # Load config file
 . "$CONFIG"
@@ -147,7 +147,7 @@
 	;;
   *)
 	echo "Usage: $0 {start|stop|status|restart|reload|condrestart}"
-	exit 1
+	exit 3
 esac
 
 exit $RETVAL

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

#1 lore raw

Re: [lm-sensors] PATCH: make lm_sensors init script return values

Hi Hans,

Quoted 9 lines · Hans de Goede

I've received the attached patch through Fedora's bugzilla. It fixes the return values of the various error exit cases to match the LSB spec:
http://refspecs.linux-foundation.org/LSB_3.2.0/LSB-Core-generic/LSB-Core-generic/iniscrptact.html

It looks sane to me, if there are no objections I'll commit it to svn.

lm_sensors line 43

Quoted 5 lines
lm_sensors renamed from lm_sensors.orig +1 -1
@@ -40,15 +40,15 @@
 
 	# Don't bother if /proc/sensors still doesn't exist, kernel doesn't have
 	# support for sensors.
-	[ -e /proc/sys/dev/sensors ] || exit 0
+	[ -e /proc/sys/dev/sensors ] || exit 6

Note that this doesn't work with a 2.6 kernel anyway, which makes me wonder whether it's worth keeping these init files in the lm-sensors tree. Obviously no distribution uses them as-is.

lm_sensors line 51

Quoted 10 lines
lm_sensors renamed from lm_sensors.orig +2 -2
 	# If sensors was not already running, unload the module...
 	[ -e /var/lock/subsys/lm_sensors ] || /sbin/modprobe -r i2c-proc >/dev/null 2>&1
 fi
 
 CONFIG=/etc/sysconfig/lm_sensors
-[ -r "$CONFIG" ] || exit 0
-grep '^MODULE_' $CONFIG >/dev/null 2>&1 || exit 0
+[ -r "$CONFIG" ] || exit 6
+grep '^MODULE_' $CONFIG >/dev/null 2>&1 || exit 6

I am worried that this error check (and the one above) is done independently of the command, i.e. also for command "status", while the document you mentioned above states that the error codes are different for this command, and "6" isn't valid there. So I think that the configuration file check and loading should be moved to the specific commands that need it (start and stop as far as I can see) before you can return 6 on missing configuration file.

lm_sensors line 150

Quoted 9 lines
lm_sensors renamed from lm_sensors.orig +1 -1
 # Load config file
 . "$CONFIG"
@@ -147,7 +147,7 @@
 	;;
   *)
 	echo "Usage: $0 {start|stop|status|restart|reload|condrestart}"
-	exit 1
+	exit 3

None of the init scripts in openSuse does this. They all use "exit 1", and that sounds reasonable to me. If the user runs "lm_sensors blah", it will fail, not because it is an "unimplemented feature" (3) but because the user typed a command that doesn't exist. So I wouldn't change it, but if you really don't like 1, then 2 ("invalid or excess argument(s)") would be a better choice (we have one openSuse script that does this.)

Quoted 3 lines
lm_sensors renamed from lm_sensors.orig +0 -0
 esac
 
 exit $RETVAL
Signature · 6 lines
Jean Delvare

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
#2 lore raw

Re: [lm-sensors] PATCH: make lm_sensors init script return values

In reply to Hans de Goede
Quoted 2 lines · Jean Delvare

Hi Hans,

Hi Jean,

Thanks for the thorough review!

Quoted 11 lines · Hans de Goede
Quoted 10 lines

I've received the attached patch through Fedora's bugzilla. It fixes the return values of the various error exit cases to match the LSB spec:
http://refspecs.linux-foundation.org/LSB_3.2.0/LSB-Core-generic/LSB-Core-generic/iniscrptact.html

It looks sane to me, if there are no objections I'll commit it to svn.

lm_sensors renamed from lm_sensors.orig +0 -0
@@ -40,15 +40,15 @@
 
Quoted 9 lines

lm_sensors line 43

Quoted 4 lines
lm_sensors renamed from lm_sensors.orig +1 -1
 	# Don't bother if /proc/sensors still doesn't exist, kernel doesn't have
 	# support for sensors.
-	[ -e /proc/sys/dev/sensors ] || exit 0
+	[ -e /proc/sys/dev/sensors ] || exit 6

Note that this doesn't work with a 2.6 kernel anyway, which makes me wonder whether it's worth keeping these init files in the lm-sensors tree. Obviously no distribution uses them as-is.

It helps to read the whole script before jumping to conclusions like this, above this is:
if grep -q sysfs /proc/mounts; then
WITHSYS=1
else
WITHSYS=0
fi

if [ $WITHSYS = "0" ]; then

So this piece of code doesn't get executed on 2.6 kernels with sysfs enabled. And actually atleast one distro (Fedora) is using the scrip as is.

Quoted 5 lines
Quoted 5 lines
lm_sensors renamed from lm_sensors.orig +0 -0
 	# If sensors was not already running, unload the module...
 	[ -e /var/lock/subsys/lm_sensors ] || /sbin/modprobe -r i2c-proc >/dev/null 2>&1
 fi
 
Quoted 14 lines

lm_sensors line 51

Quoted 5 lines
lm_sensors renamed from lm_sensors.orig +2 -2
 CONFIG=/etc/sysconfig/lm_sensors
-[ -r "$CONFIG" ] || exit 0
-grep '^MODULE_' $CONFIG >/dev/null 2>&1 || exit 0
+[ -r "$CONFIG" ] || exit 6
+grep '^MODULE_' $CONFIG >/dev/null 2>&1 || exit 6

I am worried that this error check (and the one above) is done independently of the command, i.e. also for command "status", while the document you mentioned above states that the error codes are different for this command, and "6" isn't valid there. So I think that the configuration file check and loading should be moved to the specific commands that need it (start and stop as far as I can see) before you can return 6 on missing configuration file.

Good point I'll do a new version of the patch where all these checks are put in a function and that function only gets called from the relevant commands.

Quoted 18 lines

lm_sensors line 150

Quoted 9 lines
lm_sensors renamed from lm_sensors.orig +1 -1
 # Load config file
 . "$CONFIG"
@@ -147,7 +147,7 @@
 	;;
   *)
 	echo "Usage: $0 {start|stop|status|restart|reload|condrestart}"
-	exit 1
+	exit 3

None of the init scripts in openSuse does this. They all use "exit 1", and that sounds reasonable to me. If the user runs "lm_sensors blah", it will fail, not because it is an "unimplemented feature" (3) but because the user typed a command that doesn't exist. So I wouldn't change it, but if you really don't like 1, then 2 ("invalid or excess argument(s)") would be a better choice (we have one openSuse script that does this.)

Okay, I'll change things to keep exit 1 in this case.

Regards,

Hans

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

#3 lore raw

Re: [lm-sensors] PATCH: make lm_sensors init script return values

In reply to Hans de Goede

Hi Hans,

Quoted 30 lines · Hans de Goede
Quoted 11 lines · Jean Delvare
Quoted 10 lines · Hans de Goede

I've received the attached patch through Fedora's bugzilla. It fixes the return values of the various error exit cases to match the LSB spec:
http://refspecs.linux-foundation.org/LSB_3.2.0/LSB-Core-generic/LSB-Core-generic/iniscrptact.html

It looks sane to me, if there are no objections I'll commit it to svn.

lm_sensors renamed from lm_sensors.orig +0 -0
@@ -40,15 +40,15 @@
 
Quoted 9 lines

lm_sensors line 43

Quoted 4 lines
lm_sensors renamed from lm_sensors.orig +1 -1
 	# Don't bother if /proc/sensors still doesn't exist, kernel doesn't have
 	# support for sensors.
-	[ -e /proc/sys/dev/sensors ] || exit 0
+	[ -e /proc/sys/dev/sensors ] || exit 6

Note that this doesn't work with a 2.6 kernel anyway, which makes me wonder whether it's worth keeping these init files in the lm-sensors tree. Obviously no distribution uses them as-is.

It helps to read the whole script before jumping to conclusions like this, above this is:
if grep -q sysfs /proc/mounts; then
WITHSYS=1
else
WITHSYS=0
fi

Quoted 3 lines

if [ $WITHSYS = "0" ]; then

So this piece of code doesn't get executed on 2.6 kernels with sysfs enabled.

Oops, you're right, I totally missed that, probably because lm_sensors.init.suse doesn't have this conditional.

Quoted 1 line

And actually atleast one distro (Fedora) is using the scrip as is.

The script we ship in openSuse is based on lm_sensors.init.suse, but it's heavily patched. In fact the patch is bigger than the script itself. My impression is that lm_sensors.init.suse has not been updated in parallel with lm_sensors.init and is totally lagging behind by now. So I'd rather delete it, and let openSuse base their patch on lm_sensors.init (which is certainly a saner base) or even just maintain their own init script.

Signature · 6 lines
Jean Delvare

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
#4 lore raw

Re: [lm-sensors] PATCH: make lm_sensors init script return values

In reply to Hans de Goede
Quoted 7 lines · Jean Delvare

Hi Hans,

Quoted 5 lines
(quoted diff) +0 -0
 	# If sensors was not already running, unload the module...
 	[ -e /var/lock/subsys/lm_sensors ] || /sbin/modprobe -r i2c-proc >/dev/null 2>&1
 fi
Quoted 14 lines

Review

Quoted 5 lines

CONFIG=/etc/sysconfig/lm_sensors
-[ -r "$CONFIG" ] || exit 0

(quoted diff) +2 -1
-grep '^MODULE_' $CONFIG >/dev/null 2>&1 || exit 0
+[ -r "$CONFIG" ] || exit 6
+grep '^MODULE_' $CONFIG >/dev/null 2>&1 || exit 6

I am worried that this error check (and the one above) is done independently of the command, i.e. also for command "status", while the document you mentioned above states that the error codes are different for this command, and "6" isn't valid there. So I think that the configuration file check and loading should be moved to the specific commands that need it (start and stop as far as I can see) before you can return 6 on missing configuration file.

Fixed, new version attached.

Quoted 18 lines

Review line 150

Quoted 9 lines

# Load config file
. "$CONFIG"

(quoted diff) +1 -1
@@ -147,7 +147,7 @@
 	;;
   *)
 	echo "Usage: $0 {start|stop|status|restart|reload|condrestart}"
-	exit 1
+	exit 3

None of the init scripts in openSuse does this. They all use "exit 1", and that sounds reasonable to me. If the user runs "lm_sensors blah", it will fail, not because it is an "unimplemented feature" (3) but because the user typed a command that doesn't exist. So I wouldn't change it, but if you really don't like 1, then 2 ("invalid or excess argument(s)") would be a better choice (we have one openSuse script that does this.)

I've kept the exit 3, this patch was submitted to make the initscripts work with some gui service configuration tools, these will never pass a non existing command, but might pass a not supported one, in which case exit 3 is correct. I don't think any non automated tools will care, and for the automated ones exit 3 is the best return code I believe.

New proposed patch attached.

Thanks & Regards,

Hans

prog/init/lm_sensors.init +46 -27
@@ -28,31 +28,6 @@
 # in order as normal shell variables with the special names:
 #    MODULE_1, MODULE_2, MODULE_3, etc.
 
-if grep -q sysfs /proc/mounts; then
-	WITHSYS=1
-else
-	WITHSYS=0
-fi
-
-if [ $WITHSYS == "0" ]; then
-	# If sensors isn't supported by the kernel, try loading the module...
-	[ -e /proc/sys/dev/sensors ] || /sbin/modprobe i2c-proc >/dev/null 2>&1
-
-	# Don't bother if /proc/sensors still doesn't exist, kernel doesn't have
-	# support for sensors.
-	[ -e /proc/sys/dev/sensors ] || exit 0
-
-	# If sensors was not already running, unload the module...
-	[ -e /var/lock/subsys/lm_sensors ] || /sbin/modprobe -r i2c-proc >/dev/null 2>&1
-fi
-
-CONFIG=/etc/sysconfig/lm_sensors
-[ -r "$CONFIG" ] || exit 0
-grep '^MODULE_' $CONFIG >/dev/null 2>&1 || exit 0
-
-# Load config file
-. "$CONFIG"
-
 PSENSORS=/usr/local/bin/sensors
 
 if [ ! -x $PSENSORS ]; then
@@ -65,7 +40,47 @@
 RETVAL=0
 prog="lm_sensors"
 
+# This functions checks if sensor support is compiled into the kernel, if
+# sensors are configured, and loads the config file
+check_sensors() {
+	if grep -q sysfs /proc/mounts; then
+		WITHSYS=1
+	else
+		WITHSYS=0
+	fi
+
+	if [ $WITHSYS == "0" ]; then
+		# If sensors isn't supported by the kernel, try loading the module...
+		[ -e /proc/sys/dev/sensors ] || /sbin/modprobe i2c-proc >/dev/null 2>&1
+
+		# Don't bother if /proc/sensors still doesn't exist, kernel doesn't have
+		# support for sensors.
+		if ! [ -e /proc/sys/dev/sensors ]; then
+			echo -n "Starting $prog: kernel does not have sensors support"
+			echo_failure
+			echo
+			exit 5
+		fi
+
+		# If sensors was not already running, unload the module...
+		[ -e /var/lock/subsys/lm_sensors ] || /sbin/modprobe -r i2c-proc >/dev/null 2>&1
+	fi
+
+	CONFIG=/etc/sysconfig/lm_sensors
+	if ! [ -r "$CONFIG" ] || ! grep '^MODULE_' $CONFIG >/dev/null 2>&1; then
+		echo -n "Starting $prog: not configured, run sensors-detect"
+		echo_warning
+		echo
+		exit 6
+	fi
+
+	# Load config file
+	. "$CONFIG"
+}
+
 start() {
+	check_sensors
+
 	echo -n "Starting $prog: loading module "
 
 	modules=`grep \^MODULE_ $CONFIG | wc -l | tr -d ' '`
@@ -89,6 +104,8 @@
 }
 
 stop() {
+	check_sensors
+
 	echo -n "Stopping $prog: "
 
 	modules=`grep \^MODULE_ $CONFIG | wc -l | tr -d ' '`
@@ -116,12 +133,14 @@
 dostatus() {
 	$PSENSORS
 	RETVAL=$?
+	if [ $RETVAL -ne 0 ]; then
+		RETVAL=3
+	fi
 }
 
 restart() {
 	stop
 	start
-	RETVAL=$?
 }
 
 condrestart() {
@@ -147,7 +166,7 @@
 	;;
   *)
 	echo "Usage: $0 {start|stop|status|restart|reload|condrestart}"
-	exit 1
+	exit 3
 esac
 
 exit $RETVAL

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors