From owner-freebsd-ports-bugs@FreeBSD.ORG  Sun Dec 28 03:30:01 2008
Return-Path: <owner-freebsd-ports-bugs@FreeBSD.ORG>
Delivered-To: freebsd-ports-bugs@hub.freebsd.org
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id 4FBF11065676
	for <freebsd-ports-bugs@hub.freebsd.org>;
	Sun, 28 Dec 2008 03:30:01 +0000 (UTC)
	(envelope-from gnats@FreeBSD.org)
Received: from freefall.freebsd.org (freefall.freebsd.org
	[IPv6:2001:4f8:fff6::28])
	by mx1.freebsd.org (Postfix) with ESMTP id 2D4BB8FC18
	for <freebsd-ports-bugs@hub.freebsd.org>;
	Sun, 28 Dec 2008 03:30:01 +0000 (UTC)
	(envelope-from gnats@FreeBSD.org)
Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1])
	by freefall.freebsd.org (8.14.3/8.14.3) with ESMTP id mBS3U1HL096195
	for <freebsd-ports-bugs@freefall.freebsd.org>;
	Sun, 28 Dec 2008 03:30:01 GMT
	(envelope-from gnats@freefall.freebsd.org)
Received: (from gnats@localhost)
	by freefall.freebsd.org (8.14.3/8.14.3/Submit) id mBS3U1EQ096194;
	Sun, 28 Dec 2008 03:30:01 GMT (envelope-from gnats)
Resent-Date: Sun, 28 Dec 2008 03:30:01 GMT
Resent-Message-Id: <200812280330.mBS3U1EQ096194@freefall.freebsd.org>
Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer)
Resent-To: freebsd-ports-bugs@FreeBSD.org
Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org,
	Alex Kozlov <spam@rm-rf.kiev.ua>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id B2606106564A
	for <freebsd-gnats-submit@FreeBSD.org>;
	Sun, 28 Dec 2008 03:22:34 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [IPv6:2001:4f8:fff6::21])
	by mx1.freebsd.org (Postfix) with ESMTP id A21CD8FC19
	for <freebsd-gnats-submit@FreeBSD.org>;
	Sun, 28 Dec 2008 03:22:34 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.14.3/8.14.3) with ESMTP id mBS3MYOv053354
	for <freebsd-gnats-submit@FreeBSD.org>; Sun, 28 Dec 2008 03:22:34 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.14.3/8.14.3/Submit) id mBS3MYZm053329;
	Sun, 28 Dec 2008 03:22:34 GMT (envelope-from nobody)
Message-Id: <200812280322.mBS3MYZm053329@www.freebsd.org>
Date: Sun, 28 Dec 2008 03:22:34 GMT
From: Alex Kozlov <spam@rm-rf.kiev.ua>
To: freebsd-gnats-submit@FreeBSD.org
X-Send-Pr-Version: www-3.1
Cc: 
Subject: ports/129985: [patch] sysutils/smartmontools fixes to periodic
	script
X-BeenThere: freebsd-ports-bugs@freebsd.org
X-Mailman-Version: 2.1.5
Precedence: list
List-Id: Ports bug reports <freebsd-ports-bugs.freebsd.org>
List-Unsubscribe: <http://lists.freebsd.org/mailman/listinfo/freebsd-ports-bugs>, 
	<mailto:freebsd-ports-bugs-request@freebsd.org?subject=unsubscribe>
List-Archive: <http://lists.freebsd.org/pipermail/freebsd-ports-bugs>
List-Post: <mailto:freebsd-ports-bugs@freebsd.org>
List-Help: <mailto:freebsd-ports-bugs-request@freebsd.org?subject=help>
List-Subscribe: <http://lists.freebsd.org/mailman/listinfo/freebsd-ports-bugs>, 
	<mailto:freebsd-ports-bugs-request@freebsd.org?subject=subscribe>
X-List-Received-Date: Sun, 28 Dec 2008 03:30:01 -0000


>Number:         129985
>Category:       ports
>Synopsis:       [patch] sysutils/smartmontools fixes to periodic script
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-ports-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sun Dec 28 03:30:00 UTC 2008
>Closed-Date:
>Last-Modified:
>Originator:     Alex Kozlov
>Release:        FreeBSD 7.1
>Organization:
private
>Environment:
>Description:
Some fixes for periodic script:
- Remove use of temporary file.
- Remove daily_status_smart_enable as it alway true if daily_status_smart_devices set.
- Fix return status handling. Change bitmask to 8 (as described in man smartctl)
  and change rc from 2 (bad config) to 3 (must not be masked) in case of disk failing.
- Rename script to 343.smart for consistency with other periodic scripts.
>How-To-Repeat:

>Fix:


Patch attached with submission follows:

Index: sysutils/smartmontools/files/smart.in
@@ -4,6 +4,43 @@
 # $FreeBSD: ports/sysutils/smartmontools/files/smart.in,v 1.1 2008/12/19 13:14:29 pav Exp $
 #
 
+#
+# Stolen from comp.unix.shell FAQ Q11
+# (http://cfaj.freeshell.org/shell/cus-faq-2.html#11)
+#
+run_status() {
+		local j com k l a
+		j=1
+		while eval "\${pipestatus_$j+:} false"; do
+			unset pipestatus_$j
+			j=$(($j+1))
+		done
+		j=1 com= k=1 l=
+	    for a; do
+			if [ "x$a" = 'x|' ]; then
+				com="$com { $l "'3>&-
+							echo "pipestatus_'$j'=$?" >&3
+						  } 4>&- |'
+				j=$(($j+1)) l=
+			else
+				l="$l \"\$$k\""
+			fi
+		k=$(($k+1))
+		done
+		com="$com $l"' 3>&- >&4 4>&-
+			echo "pipestatus_'$j'=$?"'
+		exec 4>&1
+		eval "$(exec 3>&1; eval "$com")"
+		exec 4>&-
+		j=1
+		while eval "\${pipestatus_$j+:} false"; do
+			eval "[ \$pipestatus_$j -eq 0 ]" || return 1
+			j=$(($j+1))
+		done
+		return 0
+}
+
+
 if [ -r /etc/defaults/periodic.conf ]; then
     . /etc/defaults/periodic.conf
     source_periodic_confs
@@ -12,41 +49,26 @@
 smartctl=%%PREFIX%%/sbin/smartctl
 : ${daily_status_smartctl_flags="-H"}
 : ${daily_status_smartctl_extra_status_flags="-a"}
-# no default for ${daily_status_smart_devices}
-if [ -z "${daily_status_smart_devices}" ]; then
-	: ${daily_status_smart_enabled="NO"}
-else
-	: ${daily_status_smart_enabled="YES"}
-fi
-trim_junk="tail -n +4"
+rc=0
 
-tmpfile="$(mktemp /var/run/daily.XXXXXXXX)"
-trap "rm -f ${tmpfile}" 0 1 3 15
+# no default for ${daily_status_smart_devices}
+if [ -n "${daily_status_smart_devices}" ]; then
+	trim_junk="tail -n +4"
 
-rc=0
-case "${daily_status_smart_enable}" in
-	[Nn][Oo])
-		;;
-	*)
-		for device in ${daily_status_smart_devices}; do
-			if [ -e ${device} ]; then
-				echo 
-				echo "Checking health of ${device}:"
-				echo
-				${smartctl} ${daily_status_smartctl_flags} ${device} > "${tmpfile}"
-				status=$?
-				if [ $((status & 3)) -ne 0 ]; then
-					rc=2
-					${trim_junk} "${tmpfile}"
-				elif [ $status -ne 0 ]; then
-					rc=1
-					${smartctl} ${daily_status_smartctl_extra_status_flags} ${device} | ${trim_junk}
-				else
-					${trim_junk} "${tmpfile}"
-				fi
+	for device in ${daily_status_smart_devices}; do
+		if [ -e ${device} ]; then
+			echo 
+			echo "Checking health of ${device}:"
+			echo
+			run_status ${smartctl} ${daily_status_smartctl_flags} ${device} \| ${trim_junk}
+			if [ $((pipestatus_1 & 8)) -ne 0 ]; then
+				rc=3
+			elif [ $pipestatus_1 -ne 0 ]; then
+				rc=1
+				${smartctl} ${daily_status_smartctl_extra_status_flags} ${device} | ${trim_junk}
 			fi
-		done
-		;;
-esac
+		fi
+	done
+fi
 
 exit "$rc"


>Release-Note:
>Audit-Trail:
>Unformatted: