From root@cakebox.homeunix.net  Tue Jun 26 21:23:35 2012
Return-Path: <root@cakebox.homeunix.net>
Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52])
	by hub.freebsd.org (Postfix) with ESMTP id CE2C71065672
	for <FreeBSD-gnats-submit@freebsd.org>; Tue, 26 Jun 2012 21:23:35 +0000 (UTC)
	(envelope-from root@cakebox.homeunix.net)
Received: from mo6-p05-ob.rzone.de (mo6-p05-ob.rzone.de [IPv6:2a01:238:20a:202:5305::1])
	by mx1.freebsd.org (Postfix) with ESMTP id 328918FC0A
	for <FreeBSD-gnats-submit@freebsd.org>; Tue, 26 Jun 2012 21:23:35 +0000 (UTC)
Received: from cakebox.homeunix.net
	(ip-2-205-89-245.web.vodafone.de [2.205.89.245])
	by smtp.strato.de (josoe mo65) (RZmta 29.19 DYNA|AUTH)
	with (DHE-RSA-AES256-SHA encrypted) ESMTPA id k01e87o5QIYmIX
	for <FreeBSD-gnats-submit@freebsd.org>;
	Tue, 26 Jun 2012 23:23:32 +0200 (CEST)
Received: from cakebox.homeunix.net (localhost [127.0.0.1])
	by cakebox.homeunix.net (Postfix) with ESMTP id AD6D368083
	for <FreeBSD-gnats-submit@freebsd.org>; Tue, 26 Jun 2012 23:23:11 +0200 (CEST)
Received: by cakebox.homeunix.net (Postfix, from userid 0)
	id 5864468082; Tue, 26 Jun 2012 23:23:10 +0200 (CEST)
Message-Id: <20120626212310.5864468082@cakebox.homeunix.net>
Date: Tue, 26 Jun 2012 23:23:10 +0200 (CEST)
From: freebsd@nagilum.org
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: update sysutils/swapmon to version 1.5
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         169467
>Category:       ports
>Synopsis:       update sysutils/swapmon to version 1.5
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    gjb
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          maintainer-update
>Submitter-Id:   current-users
>Arrival-Date:   Tue Jun 26 21:30:11 UTC 2012
>Closed-Date:    Wed Jun 27 13:32:18 UTC 2012
>Last-Modified:  Wed Jun 27 13:40:07 UTC 2012
>Originator:     Charlie &
>Release:        FreeBSD 10.0-CURRENT i386
>Organization:
>Environment:
System: FreeBSD cakebox.tis 10.0-CURRENT FreeBSD 10.0-CURRENT #0: Sat Jun 23 23:48:21 CEST 2012 root@cakebox.tis:/usr/obj/export/src/sys/net5501 i386


>Description:
	update sysutils/swapmon to version 1.5

Changes:
	- clean up leftover swapfiles after unexpected reboots
	- also works if no swap is configured

>How-To-Repeat:
>Fix:

	apply attached patch

--- swapmon.patch begins here ---
diff -Naur swapmon.old/Makefile swapmon/Makefile
--- swapmon.old/Makefile	2010-08-23 04:40:15.000000000 +0200
+++ swapmon/Makefile	2012-06-26 23:01:29.000000000 +0200
@@ -6,7 +6,7 @@
 #
 
 PORTNAME=	swapmon
-PORTVERSION=	1.4
+PORTVERSION=	1.5
 CATEGORIES=	sysutils
 MASTER_SITES=	# none
 DISTFILES=	# none
diff -Naur swapmon.old/files/swapmon.sh.in swapmon/files/swapmon.sh.in
--- swapmon.old/files/swapmon.sh.in	2010-08-23 04:40:15.000000000 +0200
+++ swapmon/files/swapmon.sh.in	2012-06-26 23:00:53.000000000 +0200
@@ -27,7 +27,7 @@
 # 
 
 CONFIG=%%PREFIX%%/etc/swapmonrc
-VERSION="1.4"
+VERSION="1.5"
 
 if [ -r "${CONFIG}" ]
 then	. "${CONFIG}"
@@ -47,10 +47,13 @@
 : ${LOGGER=/usr/bin/logger}
 # if running as daemon where to put pidfile
 : ${PIDFILE=/var/run/swapmon.pid}
+# if no swap is configured create a swapfile with this size
+: ${SWAP_MIN=256}
 
 LOCKF=$SM_HOME/lock
 SWAPFILE=$SM_HOME/swap.XXXX
 SWAPLIST=$SM_HOME/swapfiles
+SWAPDEF=$SM_HOME/swap.def
 MKTEMP=/usr/bin/mktemp
 TRUNCATE=/usr/bin/truncate
 TOUCH=/usr/bin/touch
@@ -61,9 +64,13 @@
 SWAPCTL=/sbin/swapctl
 RM=/bin/rm
 SED=/usr/bin/sed
+PERM=600
+UID=$(/usr/bin/id -u)
+GID=$(/usr/bin/id -g)
 umask 0077
 
-if [ $(/usr/bin/id -u) -gt 0 ]
+# a few sanity checks to see if we can do our work
+if [ $UID -gt 0 ]
 then	echo "I'm not running as root (uid=0) this probably wont work."
 #	exit 1
 fi
@@ -75,7 +82,7 @@
 # add a 1MB swapfile to check if we have the permissions to do so
 NSWAP=$($MKTEMP ${SWAPFILE})
 $TRUNCATE -s 1M "${NSWAP}" || { echo "Error creating swapfile ${NSWAP}, aborting." ; exit 1; }
-$CHMOD 600 "${NSWAP}"
+$CHMOD ${PERM} "${NSWAP}"
 MDEV=$($MDCONFIG -a -t vnode -f "${NSWAP}")
 if [ -n "$MDEV" ]
 then
@@ -88,6 +95,9 @@
 	$RM -f "${NSWAP}"
 	exit
 fi
+# delete leftover swapfiles
+find $SM_HOME -maxdepth 1 -name $(echo ${SWAPFILE##*/}|tr X \?) -type f \
+	-perm ${PERM} -user $UID -group $GID -exec $RM -fv "{}" \;
 
 if [ ${SWAP_LOW} -ge $(( $(($SWAP_HIGH * 100)) / $((100 + $SWAP_STEP)) )) ]
 then	echo "SWAP_LOW(${SWAP_LOW}) schould be lower than $(( $(($SWAP_HIGH * 100)) / $((100 + $SWAP_STEP)) )) to be useful."
@@ -95,6 +105,41 @@
 		exit 1
 fi
 
+# if there is no swap configured, add some
+add_def_swap()
+{
+	SWAPCTLSK=$($SWAPCTL -sk)
+	SWAPTOTAL=${SWAPCTLSK#* }
+	SWAPTOTAL=${SWAPTOTAL% *}
+	if [ "$SWAPTOTAL" -eq 0 ]
+	then
+		if [ "${SWAP_MIN}" -gt 0 ]
+		then
+			if [ -e "${SWAPDEF}" ]	# if the file already exists
+			then	if [ -f "${SWAPDEF}" -a \! -h "${SWAPDEF}"]	# is it a regular file and no symlink?
+					then	$RM -f "${SWAPDEF}"
+					else	echo "Error: swapfile ${SWAPDEF} is not a regular file, aborting." ; exit 1;
+					fi
+			fi
+			$TRUNCATE -s ${SWAP_MIN}M "${SWAPDEF}" || { echo "Error creating swapfile ${SWAPDEF}, aborting." ; exit 1; }
+			$CHMOD $PERM "${SWAPDEF}"
+			MDEV=$($MDCONFIG -a -t vnode -f "${SWAPDEF}")
+			if [ -n "$MDEV" ]
+			then
+				$SWAPON /dev/${MDEV} || { echo "error activating swapdevice /dev/${MDEV}."; exit 1; }
+				echo "swapmon$VERSION[$$] Activated swapfile ${SWAPDEF} as there was no swap configured!"|$LOGGER
+			else
+				echo "error configuring memory disk ($MDCONFIG -a -t vnode -f \"${SWAPDEF}\")"
+				$RM -f "${SWAPDEF}"
+				exit 1
+			fi
+		else
+			echo "No swap configured, SWAP_MIN set to $SWAP_MIN - aborting."
+			exit 1
+		fi
+	fi
+}
+
 check_swap()
 {
 	SWAPCTLSK=$($SWAPCTL -sk)
@@ -107,7 +152,7 @@
 		# make sure we can write to the swaplist
 		$TOUCH "${SWAPLIST}" || { echo "swapmon$VERSION[$$] Error modifying ${SWAPLIST} exiting."|$LOGGER; exit 1; }
 		$TRUNCATE -s ${BLOCKS}M "${NSWAP}"
-		$CHMOD 0600 "${NSWAP}"
+		$CHMOD $PERM "${NSWAP}"
 		if [ -s "${NSWAP}" ]
 		then	MDEV=$($MDCONFIG -a -t vnode -f "${NSWAP}")
 			printf "${MDEV} ${NSWAP}\n" >>"${SWAPLIST}"
@@ -146,6 +191,8 @@
 	done
 }
 
+add_def_swap	# this will check if there is some swap configured
+				# we can't work without
 case "$1" in
 	start)
 		$0 -F <&- 2>&1 >/dev/null &
@@ -176,7 +223,8 @@
 			exit 1;
 		else
 			echo $$ >"${LOCKF}"
-			LOGGER="|/bin/cat"
+			# w
+			LOGGER="/bin/cat"
 			check_swap
 		fi
 		$RM -f "${LOCKF}"
--- swapmon.patch ends here ---
>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-ports-bugs->gjb 
Responsible-Changed-By: gjb 
Responsible-Changed-When: Wed Jun 27 00:15:23 UTC 2012 
Responsible-Changed-Why:  
I'll take it. 


http://www.freebsd.org/cgi/query-pr.cgi?pr=169467 
State-Changed-From-To: open->closed 
State-Changed-By: gjb 
State-Changed-When: Wed Jun 27 13:32:07 UTC 2012 
State-Changed-Why:  
Committed, thanks! 


http://www.freebsd.org/cgi/query-pr.cgi?pr=169467 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: ports/169467: commit references a PR
Date: Wed, 27 Jun 2012 13:31:21 +0000 (UTC)

 gjb         2012-06-27 13:31:10 UTC
 
   FreeBSD ports repository
 
   Modified files:
     sysutils/swapmon     Makefile 
     sysutils/swapmon/files swapmon.sh.in 
   Log:
   update sysutils/swapmon to version 1.5
   
   Changes:
   - clean up leftover swapfiles after unexpected reboots
   - also works if no swap is configured
   
   PR:             ports/169467
   Submitted by:   freebsd@nagilum.org (maintainer)
   Approved by:    crees (mentor)
   
   Revision  Changes    Path
   1.2       +1 -1      ports/sysutils/swapmon/Makefile
   1.2       +52 -5     ports/sysutils/swapmon/files/swapmon.sh.in
 _______________________________________________
 cvs-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/cvs-all
 To unsubscribe, send any mail to "cvs-all-unsubscribe@freebsd.org"
 
>Unformatted:
