Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
varnish-cache
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
varnishcache
varnish-cache
Commits
2f535f80
Commit
2f535f80
authored
Jun 20, 2011
by
Poul-Henning Kamp
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of
ssh://git.varnish-cache.org/git/varnish-cache
parents
0b4c6941
78df00d1
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
52 additions
and
11 deletions
+52
-11
mgt_shmem.c
bin/varnishd/mgt_shmem.c
+25
-11
flopen.h
include/flopen.h
+3
-0
flopen.c
lib/libvarnish/flopen.c
+24
-0
No files found.
bin/varnishd/mgt_shmem.c
View file @
2f535f80
...
...
@@ -101,6 +101,7 @@
#include "heritage.h"
#include "vmb.h"
#include "vsm.h"
#include "flopen.h"
#ifndef MAP_HASSEMAPHORE
#define MAP_HASSEMAPHORE 0
/* XXX Linux */
...
...
@@ -125,11 +126,24 @@ vsl_n_check(int fd)
struct
VSM_head
slh
;
int
i
;
struct
stat
st
;
pid_t
pid
;
AZ
(
fstat
(
fd
,
&
st
));
if
(
!
S_ISREG
(
st
.
st_mode
))
ARGV_ERR
(
"
\t
shmlog: Not a file
\n
"
);
/* Test if the SHMFILE is locked by other Varnish */
if
(
fltest
(
fd
,
&
pid
)
>
0
)
{
fprintf
(
stderr
,
"SHMFILE locked by running varnishd master (pid=%jd)
\n
"
,
(
intmax_t
)
pid
);
fprintf
(
stderr
,
"(Use unique -n arguments if you want multiple "
"instances)
\n
"
);
exit
(
2
);
}
/* Read owning pid from SHMFILE */
memset
(
&
slh
,
0
,
sizeof
slh
);
/* XXX: for flexelint */
i
=
read
(
fd
,
&
slh
,
sizeof
slh
);
if
(
i
!=
sizeof
slh
)
...
...
@@ -138,15 +152,11 @@ vsl_n_check(int fd)
return
;
if
(
slh
.
hdrsize
!=
sizeof
slh
)
return
;
if
(
slh
.
master_pid
!=
0
&&
!
kill
(
slh
.
master_pid
,
0
))
{
fprintf
(
stderr
,
"SHMFILE owned by running varnishd master (pid=%jd)
\n
"
,
"WARNING: Taking over SHMFILE marked as owned by "
"running process (pid=%jd)
\n
"
,
(
intmax_t
)
slh
.
master_pid
);
fprintf
(
stderr
,
"(Use unique -n arguments if you want multiple "
"instances.)
\n
"
);
exit
(
2
);
}
}
...
...
@@ -161,14 +171,19 @@ vsl_buildnew(const char *fn, unsigned size, int fill)
int
i
;
unsigned
u
;
char
buf
[
64
*
1024
];
int
flags
;
(
void
)
unlink
(
fn
);
vsl_fd
=
open
(
fn
,
O_RDWR
|
O_CREAT
|
O_EXCL
,
0644
);
vsl_fd
=
flopen
(
fn
,
O_RDWR
|
O_CREAT
|
O_EXCL
|
O_NONBLOCK
,
0644
);
if
(
vsl_fd
<
0
)
{
fprintf
(
stderr
,
"Could not create %s: %s
\n
"
,
fn
,
strerror
(
errno
));
exit
(
1
);
}
flags
=
fcntl
(
vsl_fd
,
F_GETFL
);
assert
(
flags
!=
-
1
);
flags
&=
~
O_NONBLOCK
;
AZ
(
fcntl
(
vsl_fd
,
F_SETFL
,
flags
));
memset
(
&
slh
,
0
,
sizeof
slh
);
slh
.
magic
=
VSM_HEAD_MAGIC
;
...
...
@@ -277,7 +292,6 @@ mgt_SHM_Init(const char *l_arg)
vsl_n_check
(
i
);
(
void
)
close
(
i
);
}
(
void
)
close
(
i
);
vsl_buildnew
(
VSM_FILENAME
,
size
,
fill
);
VSM_head
=
(
void
*
)
mmap
(
NULL
,
size
,
...
...
include/flopen.h
View file @
2f535f80
...
...
@@ -31,6 +31,9 @@
#ifndef FLOPEN_H_INCLUDED
#define FLOPEN_H_INCLUDED
#include <sys/types.h>
int
flopen
(
const
char
*
,
int
,
...);
int
fltest
(
int
fd
,
pid_t
*
pid
);
#endif
lib/libvarnish/flopen.c
View file @
2f535f80
...
...
@@ -107,3 +107,27 @@ flopen(const char *path, int flags, ...)
return
(
fd
);
}
}
/* Tests if the given fd is locked through flopen
* If pid is non-NULL, stores the pid of the process holding the lock there
* Returns 1 if the file is locked
* Returns 0 if the file is unlocked
* Returns -1 on error (and errno)
*/
int
fltest
(
int
fd
,
pid_t
*
pid
)
{
struct
flock
lock
;
memset
(
&
lock
,
0
,
sizeof
lock
);
lock
.
l_type
=
F_WRLCK
;
lock
.
l_whence
=
SEEK_SET
;
if
(
fcntl
(
fd
,
F_GETLK
,
&
lock
)
==
-
1
)
return
(
-
1
);
if
(
lock
.
l_type
==
F_UNLCK
)
return
(
0
);
if
(
pid
!=
NULL
)
*
pid
=
lock
.
l_pid
;
return
(
1
);
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment