1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
--- swapd.c.orig 2013-10-06 16:09:13 UTC
+++ swapd.c
@@ -1,3 +1,6 @@
+#include <syslog.h>
+#include <stdarg.h>
+#include <errno.h>
#include "compat.h"
#ifdef HAVE_STDIO_H
@@ -188,15 +191,18 @@ int swapd_swapon(const char *swapfile) {
# 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
@@ -287,7 +293,9 @@ swap_t *swapd_mkswap(const char *swapdir
int swapd_swapoff(swap_t *swapfile) {
int swapoffret = -1;
+#ifdef SWAPD_SWAPOFF_CMDLINE
char cmdline[1024] = {0};
+#endif
if (swapfile == NULL) {
return(-1);
@@ -300,11 +308,13 @@ int swapd_swapoff(swap_t *swapfile) {
/* 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
@@ -445,6 +455,8 @@ int main(int argc, char **argv) {
int chdirret = 0, statret = 0;
int gfm_errorcount = 0;
+ openlog("swapd", LOG_PID, LOG_DAEMON);
+
if (!swapd_init_stats()) {
return(EXIT_FAILURE);
}
@@ -519,7 +531,7 @@ int main(int argc, char **argv) {
daemonize();
- dh = opendir(".");
+ dh = opendir(swapdir);
if (dh != NULL) {
inactive_swaps = 0;
@@ -588,7 +600,7 @@ int main(int argc, char **argv) {
}
}
- swapinfo = swapd_mkswap(".", swapsize, swapfile);
+ swapinfo = swapd_mkswap(swapdir, swapsize, swapfile);
if (swapfile != NULL) {
free(swapfile);
@@ -638,6 +650,7 @@ int main(int argc, char **argv) {
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]);
@@ -659,5 +672,6 @@ int main(int argc, char **argv) {
}
+ closelog();
return(EXIT_FAILURE);
}
|