From owner-freebsd-ports-bugs@FreeBSD.ORG Tue Jun 26 21:30:12 2012 Return-Path: Delivered-To: freebsd-ports-bugs@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 7A0D31065675 for ; Tue, 26 Jun 2012 21:30:12 +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 4F1798FC19 for ; Tue, 26 Jun 2012 21:30:12 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.5/8.14.5) with ESMTP id q5QLUC5U014394 for ; Tue, 26 Jun 2012 21:30:12 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.5/8.14.5/Submit) id q5QLUCgF014392; Tue, 26 Jun 2012 21:30:12 GMT (envelope-from gnats) Resent-Date: Tue, 26 Jun 2012 21:30:12 GMT Resent-Message-Id: <201206262130.q5QLUCgF014392@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, freebsd@nagilum.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id CE2C71065672 for ; 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 ; 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 ; 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 ; 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 X-Send-Pr-Version: 3.113 Cc: Subject: ports/169467: update sysutils/swapmon to version 1.5 X-BeenThere: freebsd-ports-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Ports bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 26 Jun 2012 21:30:12 -0000 >Number: 169467 >Category: ports >Synopsis: update sysutils/swapmon to version 1.5 >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-ports-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: maintainer-update >Submitter-Id: current-users >Arrival-Date: Tue Jun 26 21:30:11 UTC 2012 >Closed-Date: >Last-Modified: >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: >Unformatted: