File: 04_liblockfile.dpatch

package info (click to toggle)
solid-pop3d 0.15-23
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 896 kB
  • ctags: 448
  • sloc: ansic: 6,085; sh: 4,682; makefile: 527
file content (135 lines) | stat: -rw-r--r-- 3,325 bytes parent folder | download | duplicates (4)
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#!/bin/sh -e
## 04_liblockfile.dpatch by Robert Luberda <robert@debian.org>
##
## All lines beginning with `## DP:' are a description of the patch.
## DP: mailbox.c: Use liblockfile's maillock (bug#83376).

if [ $# -lt 1 ]; then
    echo >&2 "`basename $0`: script expects -patch|-unpatch as argument"
    exit 1
fi

[ -f debian/patches/00patch-opts ] && . debian/patches/00patch-opts
patch_opts="${patch_opts:--f --no-backup-if-mismatch}"

case "$1" in
       -patch) patch $patch_opts -p1 < $0;;
       -unpatch) patch $patch_opts -p1 -R < $0;;
        *)
                echo >&2 "`basename $0`: script expects -patch|-unpatch as argument"
                exit 1;;
esac

exit 0

@DPATCH@
diff -Nur solid-pop3d-0.15/src/mailbox.c solid-pop3d-0.15-5/src/mailbox.c
--- solid-pop3d-0.15/src/mailbox.c	2000-05-13 15:18:33.000000000 +0200
+++ solid-pop3d-0.15-5/src/mailbox.c	2004-01-25 17:13:32.000000000 +0100
@@ -31,6 +31,14 @@
 #include <sys/file.h>
 #include <fcntl.h>
 #include <errno.h>
+
+#ifdef DEBIAN
+# include <lockfile.h>
+# include <malloc.h>
+# undef HAVE_FLOCK
+# undef MAILOCK
+#endif /* DEBIAN */
+
 #ifdef MAILOCK
 #include <maillock.h>
 #endif
@@ -76,15 +84,31 @@
 #endif
 };
 
+#ifdef DEBIAN
+static char * lockfilename = NULL;
+#define LOCK_SUFFIX ".lock"
+#endif /* DEBIAN */
+
 int unlock_mailbox(void) {
 	int retcode;
+#if defined(F_SETLK) && defined(F_SETLKW) && !defined(HAVE_FLOCK)
+	struct flock arg;
+#endif
+	
+#ifdef DEBIAN
+	if (lockfilename) {
+		lockfile_remove(lockfilename);
+		free(lockfilename);
+		lockfilename = NULL;
+	}		
+#endif /* DEBIAN */
+	
 #ifdef HAVE_FLOCK
 #define MLNAME "mailbox: flock"
 	retcode = flock(mailboxfd, LOCK_UN);
 #else
 #if defined(F_SETLK) && defined(F_SETLKW)
 #define MLNAME "mailbox: fcntl"
-	struct flock arg;
 	
 	arg.l_type = F_UNLCK;
 	arg.l_whence = arg.l_start = arg.l_len = arg.l_pid = 0;	
@@ -94,16 +118,19 @@
 	retcode = lockf(mailboxfd, F_ULOCK, 0);
 #endif /* defined(F_SETLK) && defined(F_SETLKW) */
 #endif /* HAVE_FLOCK */
+
 #ifdef MAILOCK
 	mailunlock();
 #endif
 	return retcode;
 }
 
+
 int lock_mailbox(void) {
 #if defined(F_SETLK) && defined(F_SETLKW) && !defined(HAVE_FLOCK)
 	struct flock arg;
 #endif
+	int retcode;
 
 #ifdef MAILOCK
 	if (maillock(username, 1) != 0) {
@@ -113,16 +140,35 @@
 #endif
 
 #ifdef HAVE_FLOCK
-	return flock(mailboxfd, LOCK_EX);
+	retcode = flock(mailboxfd, LOCK_EX);
 #else
 #if defined(F_SETLK) && defined(F_SETLKW)
 	arg.l_type = F_WRLCK;
 	arg.l_whence = arg.l_start = arg.l_len = arg.l_pid = 0;	
-	return fcntl(mailboxfd, F_SETLKW, &arg);
+	retcode = fcntl(mailboxfd, F_SETLKW, &arg);
 #else
-	return lockf(mailboxfd, F_LOCK, 0);
+	retcode = lockf(mailboxfd, F_LOCK, 0);
 #endif /* defined(F_SETLK) && defined(F_SETLKW) */
 #endif /* HAVE_FLOCK */
+	
+#ifdef DEBIAN
+	if (retcode != 0)
+		return retcode;
+	lockfilename = (char *) malloc( strlen(maildrop_name) + sizeof(LOCK_SUFFIX) );
+	if (!lockfilename) {
+		pop_log(pop_priority, "mailbox: no memory available");
+		return -1;
+	}
+	sprintf(lockfilename, "%s" LOCK_SUFFIX, maildrop_name);
+	if (lockfile_create(lockfilename, 1, 0) != L_SUCCESS) {
+		free(lockfilename);
+		lockfilename = NULL;
+		pop_error("mailbox: lockfile_create");
+		return -1;
+	};
+	retcode = 0;
+#endif /* DEBIAN */
+	return retcode;
 }
 
 long int mb_dec(char *in) {