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
|
$NetBSD: patch-aa,v 1.1.1.1 2007/07/29 06:58:59 obache Exp $
--- config.c.orig 2006-05-05 20:25:41.000000000 +0100
+++ config.c
@@ -301,6 +301,15 @@ int config_close(void) {
SpreadConfiguration *sc;
LogFacility *lf;
int i;
+#ifdef HAVE_FCNTL_H
+ struct flock fl;
+
+ fl.l_type = F_UNLCK; /* tell it to unlock the region */
+ fl.l_whence = SEEK_SET; /* SEEK_SET, SEEK_CUR, SEEK_END */
+ fl.l_start = 0; /* Offset from l_whence */
+ fl.l_len = 0; /* length, 0 = to EOF */
+ fl.l_pid = getpid(); /* our PID */
+#endif
sciter = sl_getlist(&spreaddaemons);
if(!sciter) return 0;
sc = (SpreadConfiguration *)sciter->data;
@@ -314,13 +323,23 @@ int config_close(void) {
if(lf->vhostdir) {
for (i=0;i< FHASH_SIZE;i++) {
if(lf->hash[i].fd>0) {
- if(!skiplocking) flock(lf->hash[i].fd, LOCK_UN);
+ if(!skiplocking)
+#ifdef HAVE_FCNTL_H
+ fcntl(lf->hash[i].fd, F_SETLK, &fl);
+#else
+ flock(lf->hash[i].fd, LOCK_UN);
+#endif
close(lf->hash[i].fd);
lf->hash[i].fd = -1;
}
}
} else if(lf->logfile && lf->logfile->fd>0) {
- if(!skiplocking) flock(lf->logfile->fd, LOCK_UN);
+ if(!skiplocking)
+#ifdef HAVE_FCNTL_H
+ fcntl(lf->logfile->fd, F_SETLK, &fl);
+#else
+ flock(lf->logfile->fd, LOCK_UN);
+#endif
close(lf->logfile->fd);
lf->logfile->fd = -1;
}
@@ -356,6 +375,15 @@ int config_start(void) {
struct skiplistnode *sciter, *lfiter;
SpreadConfiguration *sc;
LogFacility *lf;
+#ifdef HAVE_FCNTL_H
+ struct flock fl;
+
+ fl.l_type = F_WRLCK; /* F_RDLCK, F_WRLCK, F_UNLCK */
+ fl.l_whence = SEEK_SET; /* SEEK_SET, SEEK_CUR, SEEK_END */
+ fl.l_start = 0; /* Offset from l_whence */
+ fl.l_len = 0; /* length, 0 = to EOF */
+ fl.l_pid = getpid(); /* our PID */
+#endif
sciter = sl_getlist(&spreaddaemons);
if(!sciter) return 0;
sc = (SpreadConfiguration *)sciter->data;
@@ -381,7 +409,11 @@ int config_start(void) {
}
}
if(!skiplocking) {
- if(flock(lf->logfile->fd, LOCK_NB|LOCK_EX)==-1) {
+#ifdef HAVE_FCNTL_H
+ if(fcntl(lf->logfile->fd, F_SETLK, &fl)==-1) {
+#else
+ if(flock(lf->logfile->fd, LOCK_NB|LOCK_EX)==-1) {
+#endif
fprintf(stderr, "Cannot lock %s, is another spreadlogd running?\n",
lf->logfile->filename);
exit(1);
@@ -441,6 +473,15 @@ int config_get_fd(SpreadConfiguration *s
hash_element temp;
char *cp;
char fullpath[MAXPATHLEN];
+#ifdef HAVE_FCNTL_H
+ struct flock fl;
+
+ fl.l_type = F_WRLCK; /* F_RDLCK, F_WRLCK, F_UNLCK */
+ fl.l_whence = SEEK_SET; /* SEEK_SET, SEEK_CUR, SEEK_END */
+ fl.l_start = 0; /* Offset from l_whence */
+ fl.l_len = 0; /* length, 0 = to EOF */
+ fl.l_pid = getpid(); /* our PID */
+#endif
lf = sl_find(sc->logfacilities, group, NULL);
if(!lf || !lf->logfile || !lf->logfile->filename) return -1;
if(lf->vhostdir) {
@@ -457,7 +498,11 @@ int config_get_fd(SpreadConfiguration *s
O_CREAT|O_APPEND|O_WRONLY,
00644);
if(!skiplocking) {
- if(flock(temp.fd, LOCK_NB|LOCK_EX)==-1) {
+#ifdef HAVE_FCNTL_H
+ if(fcntl(temp.fd, F_SETLK, &fl)==-1) {
+#else
+ if(flock(temp.fd, LOCK_NB|LOCK_EX)==-1) {
+#endif
fprintf(stderr, "Cannot lock %s, is another spreadlogd running?\n",
fullpath);
exit(1);
|