- None of swapon(), swapoff(), /sbin/swapon, /sbin/swapoff can handle swapfile directly. Run scripts with mdconfig instead.

- Bump PORTREVISION

Feature safe:   yes
This commit is contained in:
Yen-Ming Lee 2010-06-25 22:38:17 +00:00
parent 73d56dd444
commit efb351f724
Notes: svn2git 2021-03-31 03:12:20 +00:00
svn path=/head/; revision=256974
7 changed files with 184 additions and 0 deletions

View File

@ -7,6 +7,7 @@
PORTNAME= swapd
PORTVERSION= 1.0.3
PORTREVISION= 1
CATEGORIES= sysutils
MASTER_SITES= http://www.rkeene.org/files/oss/swapd/source/
@ -22,4 +23,12 @@ USE_RC_SUBR= swapd
MAN5= swapd.conf.5
MAN8= swapd.8
post-patch:
@${REINPLACE_CMD} -e "s,%%PREFIX%%,${PREFIX},g" ${WRKSRC}/${CONFIGURE_SCRIPT}
post-install:
.for f in swapd_swapon swapd_swapoff
${INSTALL_SCRIPT} ${FILESDIR}/${f} ${PREFIX}/sbin
.endfor
.include <bsd.port.mk>

View File

@ -0,0 +1,36 @@
--- configure.orig 2005-02-18 20:34:16.000000000 -0800
+++ configure 2010-06-25 00:26:06.000000000 -0700
@@ -11435,6 +11435,7 @@
rm -f conftest.err conftest.$ac_objext \
conftest$ac_exeext conftest.$ac_ext
fi
+eval "$as_ac_var=no"
echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_var'}'`" >&5
echo "${ECHO_T}`eval echo '${'$as_ac_var'}'`" >&6
if test `eval echo '${'$as_ac_var'}'` = yes; then
@@ -11535,6 +11536,7 @@
rm -f conftest.err conftest.$ac_objext \
conftest$ac_exeext conftest.$ac_ext
fi
+ac_cv_func_swapon=no
echo "$as_me:$LINENO: result: $ac_cv_func_swapon" >&5
echo "${ECHO_T}$ac_cv_func_swapon" >&6
if test $ac_cv_func_swapon = yes; then
@@ -12170,6 +12172,17 @@
_ACEOF
;;
+ freebsd*)
+
+cat >>confdefs.h <<\_ACEOF
+#define SWAPD_SWAPON_CMDLINE "/usr/local/sbin/swapd_swapon \"%s\""
+_ACEOF
+
+cat >>confdefs.h <<\_ACEOF
+#define SWAPD_SWAPOFF_CMDLINE "/usr/local/sbin/swapd_swapoff \"%s\""
+_ACEOF
+
+ ;;
esac

View File

@ -0,0 +1,94 @@
--- swapd.c.orig 2005-02-18 20:32:30.000000000 -0800
+++ swapd.c 2010-06-25 12:16:07.000000000 -0700
@@ -1,3 +1,6 @@
+#include <syslog.h>
+#include <stdarg.h>
+#include <errno.h>
#include "compat.h"
#ifdef HAVE_STDIO_H
@@ -187,15 +190,18 @@
# ifdef SWAPON_TAKES_2_ARGS
/* Linux */
swaponret = swapon(swapfile, 0);
+ syslog(LOG_NOTICE, "swapon(%s, 0) ret:%d errno:%d", swapfile, swaponret, errno);
# else
/* BSD */
swaponret = swapon(swapfile);
+ syslog(LOG_NOTICE, "swapon(%s) ret:%d errno:%d", swapfile, swaponret, errno);
# endif
#else
# ifdef SWAPD_SWAPON_CMDLINE
char cmdline[1024] = {0};
snprintf(cmdline, sizeof(cmdline) - 1, SWAPD_SWAPON_CMDLINE, swapfile);
swaponret = system(cmdline);
+ syslog(LOG_NOTICE, "swapon: %s ret:%d errno:%d", cmdline, swaponret, errno);
# else
# error Dont know how to swapon() on this platform!
# endif
@@ -286,7 +292,9 @@
int swapd_swapoff(swap_t *swapfile) {
int swapoffret = -1;
+#ifdef SWAPD_SWAPOFF_CMDLINE
char cmdline[1024] = {0};
+#endif
if (swapfile == NULL) {
return(-1);
@@ -299,11 +307,13 @@
/* Prefer the swapoff() system call ... */
#ifdef HAVE_SWAPOFF
swapoffret = swapoff(swapfile->pathname);
+ syslog(LOG_NOTICE, "swapoff(%s) ret:%d errno:%d", swapfile->pathname, swapoffret, errno);
#else
/* ... if that's not available, try some command.. */
# ifdef SWAPD_SWAPOFF_CMDLINE
snprintf(cmdline, sizeof(cmdline) - 1, SWAPD_SWAPOFF_CMDLINE, swapfile->pathname);
swapoffret = system(cmdline);
+ syslog(LOG_NOTICE, "swapoff: %s ret:%d errno:%d", cmdline, swapoffret, errno);
# else
/* ... otherwise, issue a warning since we don't know what to do. */
# warning Dont know how to swapoff on this platform
@@ -444,6 +454,8 @@
int chdirret = 0, statret = 0;
int gfm_errorcount = 0;
+ openlog("swapd", LOG_PID, LOG_DAEMON);
+
if (!swapd_init_stats()) {
return(EXIT_FAILURE);
}
@@ -518,7 +530,7 @@
daemonize();
- dh = opendir(".");
+ dh = opendir(swapdir);
if (dh != NULL) {
inactive_swaps = 0;
@@ -587,7 +599,7 @@
}
}
- swapinfo = swapd_mkswap(".", swapsize, swapfile);
+ swapinfo = swapd_mkswap(swapdir, swapsize, swapfile);
if (swapfile != NULL) {
free(swapfile);
@@ -637,6 +649,7 @@
if (swaps[i]->active == 0 && swaps[i]->pathname != NULL) {
inactive_swaps++;
if (inactive_swaps > max_inactive_swaps) {
+ syslog(LOG_NOTICE, "unlink(%s)", swaps[i]->pathname);
unlink(swaps[i]->pathname);
free(swaps[i]->pathname);
free(swaps[i]);
@@ -658,5 +671,6 @@
}
+ closelog();
return(EXIT_FAILURE);
}

View File

@ -0,0 +1,11 @@
--- swapd.conf.5.in.orig 2010-06-24 16:22:44.000000000 -0700
+++ swapd.conf.5.in 2010-06-24 16:22:57.000000000 -0700
@@ -14,7 +14,7 @@
maxfree 0
swapsize 32m
swapdir /var/tmp
- maxunusedswap 5
+ maxunusedswaps 5
delay 30
include_cache yes
.fi

View File

@ -0,0 +1,16 @@
#!/bin/sh
swapfile=$1
if [ -z "$swapfile" ]; then
echo "usage: $0 swapfile"
exit 1
fi
if [ ! -f $swapfile ]; then
echo "$0: swapfile '$swapfile' not found"
exit 1
fi
mdev=`/sbin/mdconfig -l -v | grep ${swapfile} | awk '{print $1}'`
if [ -z "$mdev" ]; then
echo "$0: swapfile '$swapfile' is not in use"
exit 1
fi
/sbin/swapoff /dev/${mdev} && /sbin/mdconfig -d -u /dev/${mdev}

View File

@ -0,0 +1,16 @@
#!/bin/sh
swapfile=$1
if [ -z "$swapfile" ]; then
echo "usage: $0 swapfile"
exit 1
fi
if [ ! -f $swapfile ]; then
echo "$0: swapfile '$swapfile' not found"
exit 1
fi
mdev=`/sbin/mdconfig -a -t vnode -f ${swapfile}`
if [ -z "$mdev" ]; then
echo "$0: unable to create vnode for swapfile '$swapfile'"
exit 1
fi
/sbin/swapon /dev/${mdev}

View File

@ -1,4 +1,6 @@
sbin/swapd
sbin/swapd_swapon
sbin/swapd_swapoff
@unexec if cmp -s %D/etc/swapd.conf %D/etc/swapd.conf.sample; then rm -f %D/etc/swapd.conf; fi
etc/swapd.conf.sample
@exec [ ! -f %B/swapd.conf ] && cp %B/%f %B/swapd.conf