Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
L
lxc
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chen Yisong
lxc
Commits
b41008b4
Unverified
Commit
b41008b4
authored
Mar 30, 2018
by
Christian Brauner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
lxclock: use thread-safe *_OFD_* fcntl() locks
If they aren't available fallback to BSD flock()s. Closes #2245. Signed-off-by:
Christian Brauner
<
christian.brauner@ubuntu.com
>
parent
2efc4ab7
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
17 deletions
+33
-17
lxclock.c
src/lxc/lxclock.c
+17
-14
lxclock.h
src/lxc/lxclock.h
+16
-3
No files found.
src/lxc/lxclock.c
View file @
b41008b4
...
@@ -54,8 +54,8 @@ static inline void dump_stacktrace(void)
...
@@ -54,8 +54,8 @@ static inline void dump_stacktrace(void)
size
=
backtrace
(
array
,
MAX_STACKDEPTH
);
size
=
backtrace
(
array
,
MAX_STACKDEPTH
);
strings
=
backtrace_symbols
(
array
,
size
);
strings
=
backtrace_symbols
(
array
,
size
);
/
/ Using fprintf here as our logging module is not thread safe
/
* Using fprintf here as our logging module is not thread safe. */
fprintf
(
stderr
,
"
\t
Obtained %zu stack frames
.
\n
"
,
size
);
fprintf
(
stderr
,
"
\t
Obtained %zu stack frames
\n
"
,
size
);
for
(
i
=
0
;
i
<
size
;
i
++
)
for
(
i
=
0
;
i
<
size
;
i
++
)
fprintf
(
stderr
,
"
\t\t
%s
\n
"
,
strings
[
i
]);
fprintf
(
stderr
,
"
\t\t
%s
\n
"
,
strings
[
i
]);
...
@@ -195,7 +195,7 @@ int lxclock(struct lxc_lock *l, int timeout)
...
@@ -195,7 +195,7 @@ int lxclock(struct lxc_lock *l, int timeout)
case
LXC_LOCK_ANON_SEM
:
case
LXC_LOCK_ANON_SEM
:
if
(
!
timeout
)
{
if
(
!
timeout
)
{
ret
=
sem_wait
(
l
->
u
.
sem
);
ret
=
sem_wait
(
l
->
u
.
sem
);
if
(
ret
==
-
1
)
if
(
ret
<
0
)
saved_errno
=
errno
;
saved_errno
=
errno
;
}
else
{
}
else
{
struct
timespec
ts
;
struct
timespec
ts
;
...
@@ -205,7 +205,7 @@ int lxclock(struct lxc_lock *l, int timeout)
...
@@ -205,7 +205,7 @@ int lxclock(struct lxc_lock *l, int timeout)
}
}
ts
.
tv_sec
+=
timeout
;
ts
.
tv_sec
+=
timeout
;
ret
=
sem_timedwait
(
l
->
u
.
sem
,
&
ts
);
ret
=
sem_timedwait
(
l
->
u
.
sem
,
&
ts
);
if
(
ret
==
-
1
)
if
(
ret
<
0
)
saved_errno
=
errno
;
saved_errno
=
errno
;
}
}
break
;
break
;
...
@@ -220,21 +220,22 @@ int lxclock(struct lxc_lock *l, int timeout)
...
@@ -220,21 +220,22 @@ int lxclock(struct lxc_lock *l, int timeout)
goto
out
;
goto
out
;
}
}
if
(
l
->
u
.
f
.
fd
==
-
1
)
{
if
(
l
->
u
.
f
.
fd
==
-
1
)
{
l
->
u
.
f
.
fd
=
open
(
l
->
u
.
f
.
fname
,
O_RDWR
|
O_CREAT
,
l
->
u
.
f
.
fd
=
open
(
l
->
u
.
f
.
fname
,
O_CREAT
|
O_RDWR
|
O_NOFOLLOW
|
O_CLOEXEC
|
O_NOCTTY
,
S_IWUSR
|
S_IRUSR
);
S_IWUSR
|
S_IRUSR
);
if
(
l
->
u
.
f
.
fd
==
-
1
)
{
if
(
l
->
u
.
f
.
fd
==
-
1
)
{
ERROR
(
"Error opening %s"
,
l
->
u
.
f
.
fname
);
ERROR
(
"Error opening %s"
,
l
->
u
.
f
.
fname
);
saved_errno
=
errno
;
saved_errno
=
errno
;
goto
out
;
goto
out
;
}
}
}
}
memset
(
&
lk
,
0
,
sizeof
(
struct
flock
));
lk
.
l_type
=
F_WRLCK
;
lk
.
l_type
=
F_WRLCK
;
lk
.
l_whence
=
SEEK_SET
;
lk
.
l_whence
=
SEEK_SET
;
lk
.
l_start
=
0
;
ret
=
fcntl
(
l
->
u
.
f
.
fd
,
F_OFD_SETLKW
,
&
lk
)
;
lk
.
l_len
=
0
;
if
(
ret
<
0
)
{
ret
=
fcntl
(
l
->
u
.
f
.
fd
,
F_SETLKW
,
&
lk
);
if
(
errno
==
EINVAL
)
if
(
ret
==
-
1
)
ret
=
flock
(
l
->
u
.
f
.
fd
,
LOCK_EX
);
saved_errno
=
errno
;
saved_errno
=
errno
;
}
break
;
break
;
}
}
...
@@ -259,13 +260,15 @@ int lxcunlock(struct lxc_lock *l)
...
@@ -259,13 +260,15 @@ int lxcunlock(struct lxc_lock *l)
break
;
break
;
case
LXC_LOCK_FLOCK
:
case
LXC_LOCK_FLOCK
:
if
(
l
->
u
.
f
.
fd
!=
-
1
)
{
if
(
l
->
u
.
f
.
fd
!=
-
1
)
{
memset
(
&
lk
,
0
,
sizeof
(
struct
flock
));
lk
.
l_type
=
F_UNLCK
;
lk
.
l_type
=
F_UNLCK
;
lk
.
l_whence
=
SEEK_SET
;
lk
.
l_whence
=
SEEK_SET
;
lk
.
l_start
=
0
;
ret
=
fcntl
(
l
->
u
.
f
.
fd
,
F_OFD_SETLK
,
&
lk
)
;
lk
.
l_len
=
0
;
if
(
ret
<
0
)
{
ret
=
fcntl
(
l
->
u
.
f
.
fd
,
F_SETLK
,
&
lk
);
if
(
errno
==
EINVAL
)
if
(
ret
<
0
)
ret
=
flock
(
l
->
u
.
f
.
fd
,
LOCK_EX
|
LOCK_NB
);
saved_errno
=
errno
;
saved_errno
=
errno
;
}
close
(
l
->
u
.
f
.
fd
);
close
(
l
->
u
.
f
.
fd
);
l
->
u
.
f
.
fd
=
-
1
;
l
->
u
.
f
.
fd
=
-
1
;
}
else
}
else
...
...
src/lxc/lxclock.h
View file @
b41008b4
...
@@ -23,12 +23,25 @@
...
@@ -23,12 +23,25 @@
#ifndef __LXC_LXCLOCK_H
#ifndef __LXC_LXCLOCK_H
#define __LXC_LXCLOCK_H
#define __LXC_LXCLOCK_H
#include <fcntl.h>
/* For O_* constants */
#include <fcntl.h>
#include <sys/stat.h>
/* For mode constants */
#include <sys/file.h>
#include <semaphore.h>
#include <semaphore.h>
#include <string.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/file.h>
#include <time.h>
#include <time.h>
#include <unistd.h>
#ifndef F_OFD_GETLK
#define F_OFD_GETLK 36
#endif
#ifndef F_OFD_SETLK
#define F_OFD_SETLK 37
#endif
#ifndef F_OFD_SETLKW
#define F_OFD_SETLKW 38
#endif
#define LXC_LOCK_ANON_SEM 1
/*!< Anonymous semaphore lock */
#define LXC_LOCK_ANON_SEM 1
/*!< Anonymous semaphore lock */
#define LXC_LOCK_FLOCK 2
/*!< flock(2) lock */
#define LXC_LOCK_FLOCK 2
/*!< flock(2) lock */
...
...
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