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
74cd2949
Unverified
Commit
74cd2949
authored
Jun 23, 2017
by
0x0916
Committed by
Stéphane Graber
Aug 15, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use strerror(errno) instead of %m
Signed-off-by:
0x0916
<
w@laoqinren.net
>
parent
5292b43b
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
31 additions
and
23 deletions
+31
-23
arguments.c
src/lxc/arguments.c
+2
-1
caps.c
src/lxc/caps.c
+16
-11
conf.c
src/lxc/conf.c
+3
-3
lxc_init.c
src/lxc/lxc_init.c
+1
-1
start.c
src/lxc/start.c
+2
-2
sync.c
src/lxc/sync.c
+2
-2
reboot.c
src/tests/reboot.c
+5
-3
No files found.
src/lxc/arguments.c
View file @
74cd2949
...
@@ -258,7 +258,8 @@ int lxc_arguments_str_to_int(struct lxc_arguments *args, const char *str)
...
@@ -258,7 +258,8 @@ int lxc_arguments_str_to_int(struct lxc_arguments *args, const char *str)
errno
=
0
;
errno
=
0
;
val
=
strtol
(
str
,
&
endptr
,
10
);
val
=
strtol
(
str
,
&
endptr
,
10
);
if
(
errno
)
{
if
(
errno
)
{
lxc_error
(
args
,
"invalid statefd '%s' : %m"
,
str
);
lxc_error
(
args
,
"invalid statefd '%s' : %s"
,
str
,
strerror
(
errno
));
return
-
1
;
return
-
1
;
}
}
...
...
src/lxc/caps.c
View file @
74cd2949
...
@@ -53,19 +53,19 @@ int lxc_caps_down(void)
...
@@ -53,19 +53,19 @@ int lxc_caps_down(void)
caps
=
cap_get_proc
();
caps
=
cap_get_proc
();
if
(
!
caps
)
{
if
(
!
caps
)
{
ERROR
(
"failed to cap_get_proc: %
m"
);
ERROR
(
"failed to cap_get_proc: %
s"
,
strerror
(
errno
)
);
return
-
1
;
return
-
1
;
}
}
ret
=
cap_clear_flag
(
caps
,
CAP_EFFECTIVE
);
ret
=
cap_clear_flag
(
caps
,
CAP_EFFECTIVE
);
if
(
ret
)
{
if
(
ret
)
{
ERROR
(
"failed to cap_clear_flag: %
m"
);
ERROR
(
"failed to cap_clear_flag: %
s"
,
strerror
(
errno
)
);
goto
out
;
goto
out
;
}
}
ret
=
cap_set_proc
(
caps
);
ret
=
cap_set_proc
(
caps
);
if
(
ret
)
{
if
(
ret
)
{
ERROR
(
"failed to cap_set_proc: %
m"
);
ERROR
(
"failed to cap_set_proc: %
s"
,
strerror
(
errno
)
);
goto
out
;
goto
out
;
}
}
...
@@ -87,7 +87,7 @@ int lxc_caps_up(void)
...
@@ -87,7 +87,7 @@ int lxc_caps_up(void)
caps
=
cap_get_proc
();
caps
=
cap_get_proc
();
if
(
!
caps
)
{
if
(
!
caps
)
{
ERROR
(
"failed to cap_get_proc: %
m"
);
ERROR
(
"failed to cap_get_proc: %
s"
,
strerror
(
errno
)
);
return
-
1
;
return
-
1
;
}
}
...
@@ -101,21 +101,22 @@ int lxc_caps_up(void)
...
@@ -101,21 +101,22 @@ int lxc_caps_up(void)
INFO
(
"Last supported cap was %d"
,
cap
-
1
);
INFO
(
"Last supported cap was %d"
,
cap
-
1
);
break
;
break
;
}
else
{
}
else
{
ERROR
(
"failed to cap_get_flag: %m"
);
ERROR
(
"failed to cap_get_flag: %s"
,
strerror
(
errno
));
goto
out
;
goto
out
;
}
}
}
}
ret
=
cap_set_flag
(
caps
,
CAP_EFFECTIVE
,
1
,
&
cap
,
flag
);
ret
=
cap_set_flag
(
caps
,
CAP_EFFECTIVE
,
1
,
&
cap
,
flag
);
if
(
ret
)
{
if
(
ret
)
{
ERROR
(
"failed to cap_set_flag: %
m"
);
ERROR
(
"failed to cap_set_flag: %
s"
,
strerror
(
errno
)
);
goto
out
;
goto
out
;
}
}
}
}
ret
=
cap_set_proc
(
caps
);
ret
=
cap_set_proc
(
caps
);
if
(
ret
)
{
if
(
ret
)
{
ERROR
(
"failed to cap_set_proc: %
m"
);
ERROR
(
"failed to cap_set_proc: %
s"
,
strerror
(
errno
)
);
goto
out
;
goto
out
;
}
}
...
@@ -139,22 +140,26 @@ int lxc_caps_init(void)
...
@@ -139,22 +140,26 @@ int lxc_caps_init(void)
INFO
(
"command is run as setuid root (uid : %d)"
,
uid
);
INFO
(
"command is run as setuid root (uid : %d)"
,
uid
);
if
(
prctl
(
PR_SET_KEEPCAPS
,
1
))
{
if
(
prctl
(
PR_SET_KEEPCAPS
,
1
))
{
ERROR
(
"failed to 'PR_SET_KEEPCAPS': %m"
);
ERROR
(
"failed to 'PR_SET_KEEPCAPS': %s"
,
strerror
(
errno
));
return
-
1
;
return
-
1
;
}
}
if
(
setresgid
(
gid
,
gid
,
gid
))
{
if
(
setresgid
(
gid
,
gid
,
gid
))
{
ERROR
(
"failed to change gid to '%d': %m"
,
gid
);
ERROR
(
"failed to change gid to '%d': %s"
,
gid
,
strerror
(
errno
));
return
-
1
;
return
-
1
;
}
}
if
(
setresuid
(
uid
,
uid
,
uid
))
{
if
(
setresuid
(
uid
,
uid
,
uid
))
{
ERROR
(
"failed to change uid to '%d': %m"
,
uid
);
ERROR
(
"failed to change uid to '%d': %s"
,
uid
,
strerror
(
errno
));
return
-
1
;
return
-
1
;
}
}
if
(
lxc_caps_up
())
{
if
(
lxc_caps_up
())
{
ERROR
(
"failed to restore capabilities: %m"
);
ERROR
(
"failed to restore capabilities: %s"
,
strerror
(
errno
));
return
-
1
;
return
-
1
;
}
}
}
}
...
...
src/lxc/conf.c
View file @
74cd2949
...
@@ -3001,9 +3001,9 @@ struct lxc_conf *lxc_conf_init(void)
...
@@ -3001,9 +3001,9 @@ struct lxc_conf *lxc_conf_init(void)
struct
lxc_conf
*
new
;
struct
lxc_conf
*
new
;
int
i
;
int
i
;
new
=
malloc
(
sizeof
(
*
new
));
new
=
malloc
(
sizeof
(
*
new
));
if
(
!
new
)
{
if
(
!
new
)
{
ERROR
(
"lxc_conf_init : %
m"
);
ERROR
(
"lxc_conf_init : %
s"
,
strerror
(
errno
)
);
return
NULL
;
return
NULL
;
}
}
memset
(
new
,
0
,
sizeof
(
*
new
));
memset
(
new
,
0
,
sizeof
(
*
new
));
...
@@ -3024,7 +3024,7 @@ struct lxc_conf *lxc_conf_init(void)
...
@@ -3024,7 +3024,7 @@ struct lxc_conf *lxc_conf_init(void)
new
->
maincmd_fd
=
-
1
;
new
->
maincmd_fd
=
-
1
;
new
->
rootfs
.
mount
=
strdup
(
default_rootfs_mount
);
new
->
rootfs
.
mount
=
strdup
(
default_rootfs_mount
);
if
(
!
new
->
rootfs
.
mount
)
{
if
(
!
new
->
rootfs
.
mount
)
{
ERROR
(
"lxc_conf_init : %
m"
);
ERROR
(
"lxc_conf_init : %
s"
,
strerror
(
errno
)
);
free
(
new
);
free
(
new
);
return
NULL
;
return
NULL
;
}
}
...
...
src/lxc/lxc_init.c
View file @
74cd2949
...
@@ -184,7 +184,7 @@ int main(int argc, char *argv[])
...
@@ -184,7 +184,7 @@ int main(int argc, char *argv[])
NOTICE
(
"about to exec '%s'"
,
aargv
[
0
]);
NOTICE
(
"about to exec '%s'"
,
aargv
[
0
]);
execvp
(
aargv
[
0
],
aargv
);
execvp
(
aargv
[
0
],
aargv
);
ERROR
(
"failed to exec: '%s' : %
m"
,
aargv
[
0
]
);
ERROR
(
"failed to exec: '%s' : %
s"
,
aargv
[
0
],
strerror
(
errno
)
);
exit
(
err
);
exit
(
err
);
}
}
...
...
src/lxc/start.c
View file @
74cd2949
...
@@ -195,7 +195,7 @@ int lxc_check_inherited(struct lxc_conf *conf, int fd_to_ignore)
...
@@ -195,7 +195,7 @@ int lxc_check_inherited(struct lxc_conf *conf, int fd_to_ignore)
restart:
restart:
dir
=
opendir
(
"/proc/self/fd"
);
dir
=
opendir
(
"/proc/self/fd"
);
if
(
!
dir
)
{
if
(
!
dir
)
{
WARN
(
"
failed to open directory: %m"
);
WARN
(
"
Failed to open directory: %s."
,
strerror
(
errno
)
);
return
-
1
;
return
-
1
;
}
}
...
@@ -584,7 +584,7 @@ static int must_drop_cap_sys_boot(struct lxc_conf *conf)
...
@@ -584,7 +584,7 @@ static int must_drop_cap_sys_boot(struct lxc_conf *conf)
return
-
1
;
return
-
1
;
}
}
if
(
wait
(
&
status
)
<
0
)
{
if
(
wait
(
&
status
)
<
0
)
{
SYSERROR
(
"
unexpected wait error: %m"
);
SYSERROR
(
"
Unexpected wait error: %s."
,
strerror
(
errno
)
);
return
-
1
;
return
-
1
;
}
}
...
...
src/lxc/sync.c
View file @
74cd2949
...
@@ -40,7 +40,7 @@ static int __sync_wait(int fd, int sequence)
...
@@ -40,7 +40,7 @@ static int __sync_wait(int fd, int sequence)
ret
=
read
(
fd
,
&
sync
,
sizeof
(
sync
));
ret
=
read
(
fd
,
&
sync
,
sizeof
(
sync
));
if
(
ret
<
0
)
{
if
(
ret
<
0
)
{
ERROR
(
"sync wait failure : %
m"
);
ERROR
(
"sync wait failure : %
s"
,
strerror
(
errno
)
);
return
-
1
;
return
-
1
;
}
}
...
@@ -71,7 +71,7 @@ static int __sync_wake(int fd, int sequence)
...
@@ -71,7 +71,7 @@ static int __sync_wake(int fd, int sequence)
int
sync
=
sequence
;
int
sync
=
sequence
;
if
(
write
(
fd
,
&
sync
,
sizeof
(
sync
))
<
0
)
{
if
(
write
(
fd
,
&
sync
,
sizeof
(
sync
))
<
0
)
{
ERROR
(
"sync wake failure : %
m"
);
ERROR
(
"sync wake failure : %
s"
,
strerror
(
errno
)
);
return
-
1
;
return
-
1
;
}
}
return
0
;
return
0
;
...
...
src/tests/reboot.c
View file @
74cd2949
...
@@ -21,6 +21,8 @@
...
@@ -21,6 +21,8 @@
#include <sched.h>
#include <sched.h>
#include <unistd.h>
#include <unistd.h>
#include <signal.h>
#include <signal.h>
#include <errno.h>
#include <string.h>
#include <sys/reboot.h>
#include <sys/reboot.h>
#include <sys/types.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/wait.h>
...
@@ -38,7 +40,7 @@ static int do_reboot(void *arg)
...
@@ -38,7 +40,7 @@ static int do_reboot(void *arg)
int
*
cmd
=
arg
;
int
*
cmd
=
arg
;
if
(
reboot
(
*
cmd
))
if
(
reboot
(
*
cmd
))
printf
(
"failed to reboot(%d): %
m
\n
"
,
*
cmd
);
printf
(
"failed to reboot(%d): %
s
\n
"
,
*
cmd
,
strerror
(
errno
)
);
return
0
;
return
0
;
}
}
...
@@ -51,12 +53,12 @@ static int test_reboot(int cmd, int sig)
...
@@ -51,12 +53,12 @@ static int test_reboot(int cmd, int sig)
ret
=
clone
(
do_reboot
,
stack
,
CLONE_NEWPID
|
SIGCHLD
,
&
cmd
);
ret
=
clone
(
do_reboot
,
stack
,
CLONE_NEWPID
|
SIGCHLD
,
&
cmd
);
if
(
ret
<
0
)
{
if
(
ret
<
0
)
{
printf
(
"failed to clone: %
m
\n
"
);
printf
(
"failed to clone: %
s
\n
"
,
strerror
(
errno
)
);
return
-
1
;
return
-
1
;
}
}
if
(
wait
(
&
status
)
<
0
)
{
if
(
wait
(
&
status
)
<
0
)
{
printf
(
"unexpected wait error: %
m
\n
"
);
printf
(
"unexpected wait error: %
s
\n
"
,
strerror
(
errno
)
);
return
-
1
;
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