summaryrefslogtreecommitdiff
path: root/sysutils/swapd/files/patch-swapd.c
diff options
context:
space:
mode:
authorYen-Ming Lee <leeym@FreeBSD.org>2010-06-25 22:38:17 +0000
committerYen-Ming Lee <leeym@FreeBSD.org>2010-06-25 22:38:17 +0000
commitefb351f724bb7ec9acf6d316ee19ca67fe0092f0 (patch)
tree1db04fdd6d9dedfe422e8fcaf4befb4130497f7c /sysutils/swapd/files/patch-swapd.c
parentVariant of the allgohans script that does locking. This has been in (diff)
- None of swapon(), swapoff(), /sbin/swapon, /sbin/swapoff can handle swapfile directly. Run scripts with mdconfig instead.
- Bump PORTREVISION Feature safe: yes
Diffstat (limited to 'sysutils/swapd/files/patch-swapd.c')
-rw-r--r--sysutils/swapd/files/patch-swapd.c94
1 files changed, 94 insertions, 0 deletions
diff --git a/sysutils/swapd/files/patch-swapd.c b/sysutils/swapd/files/patch-swapd.c
new file mode 100644
index 000000000000..eabf2cd11055
--- /dev/null
+++ b/sysutils/swapd/files/patch-swapd.c
@@ -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);
+ }