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
79cda71d
Unverified
Commit
79cda71d
authored
Jul 13, 2018
by
2xsec
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
lxclock: change error log using strerror to SYSERROR
Signed-off-by:
2xsec
<
dh48.jeong@samsung.com
>
parent
74370367
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
2 deletions
+23
-2
lxclock.c
src/lxc/lxclock.c
+23
-2
No files found.
src/lxc/lxclock.c
View file @
79cda71d
...
@@ -75,7 +75,7 @@ static void lock_mutex(pthread_mutex_t *l)
...
@@ -75,7 +75,7 @@ static void lock_mutex(pthread_mutex_t *l)
ret
=
pthread_mutex_lock
(
l
);
ret
=
pthread_mutex_lock
(
l
);
if
(
ret
!=
0
)
{
if
(
ret
!=
0
)
{
fprintf
(
stderr
,
"%s - Failed acquire mutex"
,
strerror
(
ret
)
);
SYSERROR
(
"Failed to acquire mutex"
);
dump_stacktrace
();
dump_stacktrace
();
_exit
(
EXIT_FAILURE
);
_exit
(
EXIT_FAILURE
);
}
}
...
@@ -87,7 +87,7 @@ static void unlock_mutex(pthread_mutex_t *l)
...
@@ -87,7 +87,7 @@ static void unlock_mutex(pthread_mutex_t *l)
ret
=
pthread_mutex_unlock
(
l
);
ret
=
pthread_mutex_unlock
(
l
);
if
(
ret
!=
0
)
{
if
(
ret
!=
0
)
{
fprintf
(
stderr
,
"%s - Failed to release mutex"
,
strerror
(
ret
)
);
SYSERROR
(
"Failed to release mutex"
);
dump_stacktrace
();
dump_stacktrace
();
_exit
(
EXIT_FAILURE
);
_exit
(
EXIT_FAILURE
);
}
}
...
@@ -111,6 +111,7 @@ static char *lxclock_name(const char *p, const char *n)
...
@@ -111,6 +111,7 @@ static char *lxclock_name(const char *p, const char *n)
rundir
=
get_rundir
();
rundir
=
get_rundir
();
if
(
!
rundir
)
if
(
!
rundir
)
return
NULL
;
return
NULL
;
len
+=
strlen
(
rundir
);
len
+=
strlen
(
rundir
);
if
((
dest
=
malloc
(
len
))
==
NULL
)
{
if
((
dest
=
malloc
(
len
))
==
NULL
)
{
...
@@ -124,6 +125,7 @@ static char *lxclock_name(const char *p, const char *n)
...
@@ -124,6 +125,7 @@ static char *lxclock_name(const char *p, const char *n)
free
(
rundir
);
free
(
rundir
);
return
NULL
;
return
NULL
;
}
}
ret
=
mkdir_p
(
dest
,
0755
);
ret
=
mkdir_p
(
dest
,
0755
);
if
(
ret
<
0
)
{
if
(
ret
<
0
)
{
free
(
dest
);
free
(
dest
);
...
@@ -137,6 +139,7 @@ static char *lxclock_name(const char *p, const char *n)
...
@@ -137,6 +139,7 @@ static char *lxclock_name(const char *p, const char *n)
free
(
dest
);
free
(
dest
);
return
NULL
;
return
NULL
;
}
}
return
dest
;
return
dest
;
}
}
...
@@ -148,11 +151,13 @@ static sem_t *lxc_new_unnamed_sem(void)
...
@@ -148,11 +151,13 @@ static sem_t *lxc_new_unnamed_sem(void)
s
=
malloc
(
sizeof
(
*
s
));
s
=
malloc
(
sizeof
(
*
s
));
if
(
!
s
)
if
(
!
s
)
return
NULL
;
return
NULL
;
ret
=
sem_init
(
s
,
0
,
1
);
ret
=
sem_init
(
s
,
0
,
1
);
if
(
ret
)
{
if
(
ret
)
{
free
(
s
);
free
(
s
);
return
NULL
;
return
NULL
;
}
}
return
s
;
return
s
;
}
}
...
@@ -171,6 +176,7 @@ struct lxc_lock *lxc_newlock(const char *lxcpath, const char *name)
...
@@ -171,6 +176,7 @@ struct lxc_lock *lxc_newlock(const char *lxcpath, const char *name)
free
(
l
);
free
(
l
);
l
=
NULL
;
l
=
NULL
;
}
}
goto
out
;
goto
out
;
}
}
...
@@ -181,6 +187,7 @@ struct lxc_lock *lxc_newlock(const char *lxcpath, const char *name)
...
@@ -181,6 +187,7 @@ struct lxc_lock *lxc_newlock(const char *lxcpath, const char *name)
l
=
NULL
;
l
=
NULL
;
goto
out
;
goto
out
;
}
}
l
->
u
.
f
.
fd
=
-
1
;
l
->
u
.
f
.
fd
=
-
1
;
out:
out:
...
@@ -200,10 +207,12 @@ int lxclock(struct lxc_lock *l, int timeout)
...
@@ -200,10 +207,12 @@ int lxclock(struct lxc_lock *l, int timeout)
saved_errno
=
errno
;
saved_errno
=
errno
;
}
else
{
}
else
{
struct
timespec
ts
;
struct
timespec
ts
;
if
(
clock_gettime
(
CLOCK_REALTIME
,
&
ts
)
==
-
1
)
{
if
(
clock_gettime
(
CLOCK_REALTIME
,
&
ts
)
==
-
1
)
{
ret
=
-
2
;
ret
=
-
2
;
goto
out
;
goto
out
;
}
}
ts
.
tv_sec
+=
timeout
;
ts
.
tv_sec
+=
timeout
;
ret
=
sem_timedwait
(
l
->
u
.
sem
,
&
ts
);
ret
=
sem_timedwait
(
l
->
u
.
sem
,
&
ts
);
if
(
ret
<
0
)
if
(
ret
<
0
)
...
@@ -216,10 +225,12 @@ int lxclock(struct lxc_lock *l, int timeout)
...
@@ -216,10 +225,12 @@ int lxclock(struct lxc_lock *l, int timeout)
ERROR
(
"Error: timeout not supported with flock"
);
ERROR
(
"Error: timeout not supported with flock"
);
goto
out
;
goto
out
;
}
}
if
(
!
l
->
u
.
f
.
fname
)
{
if
(
!
l
->
u
.
f
.
fname
)
{
ERROR
(
"Error: filename not set for flock"
);
ERROR
(
"Error: filename not set for flock"
);
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_CREAT
|
O_RDWR
|
O_NOFOLLOW
|
O_CLOEXEC
|
O_NOCTTY
,
S_IWUSR
|
S_IRUSR
);
l
->
u
.
f
.
fd
=
open
(
l
->
u
.
f
.
fname
,
O_CREAT
|
O_RDWR
|
O_NOFOLLOW
|
O_CLOEXEC
|
O_NOCTTY
,
S_IWUSR
|
S_IRUSR
);
if
(
l
->
u
.
f
.
fd
==
-
1
)
{
if
(
l
->
u
.
f
.
fd
==
-
1
)
{
...
@@ -228,9 +239,12 @@ int lxclock(struct lxc_lock *l, int timeout)
...
@@ -228,9 +239,12 @@ int lxclock(struct lxc_lock *l, int timeout)
goto
out
;
goto
out
;
}
}
}
}
memset
(
&
lk
,
0
,
sizeof
(
struct
flock
));
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
;
ret
=
fcntl
(
l
->
u
.
f
.
fd
,
F_OFD_SETLKW
,
&
lk
);
ret
=
fcntl
(
l
->
u
.
f
.
fd
,
F_OFD_SETLKW
,
&
lk
);
if
(
ret
<
0
)
{
if
(
ret
<
0
)
{
if
(
errno
==
EINVAL
)
if
(
errno
==
EINVAL
)
...
@@ -262,14 +276,17 @@ int lxcunlock(struct lxc_lock *l)
...
@@ -262,14 +276,17 @@ int lxcunlock(struct lxc_lock *l)
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
));
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
;
ret
=
fcntl
(
l
->
u
.
f
.
fd
,
F_OFD_SETLK
,
&
lk
);
ret
=
fcntl
(
l
->
u
.
f
.
fd
,
F_OFD_SETLK
,
&
lk
);
if
(
ret
<
0
)
{
if
(
ret
<
0
)
{
if
(
errno
==
EINVAL
)
if
(
errno
==
EINVAL
)
ret
=
flock
(
l
->
u
.
f
.
fd
,
LOCK_EX
|
LOCK_NB
);
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
...
@@ -292,6 +309,7 @@ void lxc_putlock(struct lxc_lock *l)
...
@@ -292,6 +309,7 @@ void lxc_putlock(struct lxc_lock *l)
{
{
if
(
!
l
)
if
(
!
l
)
return
;
return
;
switch
(
l
->
type
)
{
switch
(
l
->
type
)
{
case
LXC_LOCK_ANON_SEM
:
case
LXC_LOCK_ANON_SEM
:
if
(
l
->
u
.
sem
)
{
if
(
l
->
u
.
sem
)
{
...
@@ -305,6 +323,7 @@ void lxc_putlock(struct lxc_lock *l)
...
@@ -305,6 +323,7 @@ void lxc_putlock(struct lxc_lock *l)
close
(
l
->
u
.
f
.
fd
);
close
(
l
->
u
.
f
.
fd
);
l
->
u
.
f
.
fd
=
-
1
;
l
->
u
.
f
.
fd
=
-
1
;
}
}
free
(
l
->
u
.
f
.
fname
);
free
(
l
->
u
.
f
.
fname
);
l
->
u
.
f
.
fname
=
NULL
;
l
->
u
.
f
.
fname
=
NULL
;
break
;
break
;
...
@@ -338,10 +357,12 @@ int container_disk_lock(struct lxc_container *c)
...
@@ -338,10 +357,12 @@ int container_disk_lock(struct lxc_container *c)
if
((
ret
=
lxclock
(
c
->
privlock
,
0
)))
if
((
ret
=
lxclock
(
c
->
privlock
,
0
)))
return
ret
;
return
ret
;
if
((
ret
=
lxclock
(
c
->
slock
,
0
)))
{
if
((
ret
=
lxclock
(
c
->
slock
,
0
)))
{
lxcunlock
(
c
->
privlock
);
lxcunlock
(
c
->
privlock
);
return
ret
;
return
ret
;
}
}
return
0
;
return
0
;
}
}
...
...
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