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
bf7e2093
Unverified
Commit
bf7e2093
authored
Mar 10, 2020
by
Stéphane Graber
Committed by
GitHub
Mar 10, 2020
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3283 from brauner/2020-03-10/fixes
bugfixes
parents
44512eee
2580145f
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
77 additions
and
25 deletions
+77
-25
configure.ac
configure.ac
+4
-0
cgfsng.c
src/lxc/cgroups/cgfsng.c
+0
-0
file_utils.c
src/lxc/file_utils.c
+23
-1
Makefile.am
src/tests/Makefile.am
+6
-2
share_ns.c
src/tests/share_ns.c
+42
-20
state_server.c
src/tests/state_server.c
+2
-2
No files found.
configure.ac
View file @
bf7e2093
...
@@ -701,6 +701,10 @@ AC_CHECK_FUNCS([strlcat],
...
@@ -701,6 +701,10 @@ AC_CHECK_FUNCS([strlcat],
AM_CONDITIONAL(HAVE_STRLCAT, true)
AM_CONDITIONAL(HAVE_STRLCAT, true)
AC_DEFINE(HAVE_STRLCAT,1,[Have strlcat]),
AC_DEFINE(HAVE_STRLCAT,1,[Have strlcat]),
AM_CONDITIONAL(HAVE_STRLCAT, false))
AM_CONDITIONAL(HAVE_STRLCAT, false))
AC_CHECK_FUNCS([fmemopen],
AM_CONDITIONAL(HAVE_FMEMOPEN, true)
AC_DEFINE(HAVE_FMEMOPEN,1,[Have fmemopen]),
AM_CONDITIONAL(HAVE_FMEMOPEN, false))
# HAVE_STRUCT_RTNL_LINK_STATS64={0,1}
# HAVE_STRUCT_RTNL_LINK_STATS64={0,1}
AC_CHECK_TYPES([struct rtnl_link_stats64], [], [], [[#include <linux/if_link.h>]])
AC_CHECK_TYPES([struct rtnl_link_stats64], [], [], [[#include <linux/if_link.h>]])
...
...
src/lxc/cgroups/cgfsng.c
View file @
bf7e2093
This diff is collapsed.
Click to expand it.
src/lxc/file_utils.c
View file @
bf7e2093
...
@@ -6,6 +6,7 @@
...
@@ -6,6 +6,7 @@
#include <errno.h>
#include <errno.h>
#include <fcntl.h>
#include <fcntl.h>
#include <linux/magic.h>
#include <linux/magic.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <sys/stat.h>
#include <sys/sendfile.h>
#include <sys/sendfile.h>
...
@@ -469,6 +470,7 @@ char *file_to_buf(const char *path, size_t *length)
...
@@ -469,6 +470,7 @@ char *file_to_buf(const char *path, size_t *length)
FILE
*
fopen_cached
(
const
char
*
path
,
const
char
*
mode
,
void
**
caller_freed_buffer
)
FILE
*
fopen_cached
(
const
char
*
path
,
const
char
*
mode
,
void
**
caller_freed_buffer
)
{
{
#ifdef HAVE_FMEMOPEN
__do_free
char
*
buf
=
NULL
;
__do_free
char
*
buf
=
NULL
;
size_t
len
=
0
;
size_t
len
=
0
;
FILE
*
f
;
FILE
*
f
;
...
@@ -482,13 +484,17 @@ FILE *fopen_cached(const char *path, const char *mode, void **caller_freed_buffe
...
@@ -482,13 +484,17 @@ FILE *fopen_cached(const char *path, const char *mode, void **caller_freed_buffe
return
NULL
;
return
NULL
;
*
caller_freed_buffer
=
move_ptr
(
buf
);
*
caller_freed_buffer
=
move_ptr
(
buf
);
return
f
;
return
f
;
#else
return
fopen
(
path
,
mode
);
#endif
}
}
FILE
*
fdopen_cached
(
int
fd
,
const
char
*
mode
,
void
**
caller_freed_buffer
)
FILE
*
fdopen_cached
(
int
fd
,
const
char
*
mode
,
void
**
caller_freed_buffer
)
{
{
FILE
*
f
;
#ifdef HAVE_FMEMOPEN
__do_free
char
*
buf
=
NULL
;
__do_free
char
*
buf
=
NULL
;
size_t
len
=
0
;
size_t
len
=
0
;
FILE
*
f
;
buf
=
fd_to_buf
(
fd
,
&
len
);
buf
=
fd_to_buf
(
fd
,
&
len
);
if
(
!
buf
)
if
(
!
buf
)
...
@@ -499,5 +505,21 @@ FILE *fdopen_cached(int fd, const char *mode, void **caller_freed_buffer)
...
@@ -499,5 +505,21 @@ FILE *fdopen_cached(int fd, const char *mode, void **caller_freed_buffer)
return
NULL
;
return
NULL
;
*
caller_freed_buffer
=
move_ptr
(
buf
);
*
caller_freed_buffer
=
move_ptr
(
buf
);
#else
__do_close_prot_errno
int
dupfd
=
-
EBADF
;
dupfd
=
dup
(
fd
);
if
(
dupfd
<
0
)
return
NULL
;
f
=
fdopen
(
dupfd
,
"re"
);
if
(
!
f
)
return
NULL
;
/* Transfer ownership of fd. */
move_fd
(
dupfd
);
#endif
return
f
;
return
f
;
}
}
src/tests/Makefile.am
View file @
bf7e2093
...
@@ -34,12 +34,16 @@ lxc_test_raw_clone_SOURCES = lxc_raw_clone.c \
...
@@ -34,12 +34,16 @@ lxc_test_raw_clone_SOURCES = lxc_raw_clone.c \
../lxc/utils.c
../lxc/utils.h
../lxc/utils.c
../lxc/utils.h
lxc_test_reboot_SOURCES
=
reboot.c
lxc_test_reboot_SOURCES
=
reboot.c
lxc_test_saveconfig_SOURCES
=
saveconfig.c
lxc_test_saveconfig_SOURCES
=
saveconfig.c
lxc_test_share_ns_SOURCES
=
share_ns.c lxctest.h
lxc_test_share_ns_SOURCES
=
share_ns.c
\
lxctest.h
\
../lxc/compiler.h
lxc_test_shortlived_SOURCES
=
shortlived.c
lxc_test_shortlived_SOURCES
=
shortlived.c
lxc_test_shutdowntest_SOURCES
=
shutdowntest.c
lxc_test_shutdowntest_SOURCES
=
shutdowntest.c
lxc_test_snapshot_SOURCES
=
snapshot.c
lxc_test_snapshot_SOURCES
=
snapshot.c
lxc_test_startone_SOURCES
=
startone.c
lxc_test_startone_SOURCES
=
startone.c
lxc_test_state_server_SOURCES
=
state_server.c lxctest.h
lxc_test_state_server_SOURCES
=
state_server.c
\
lxctest.h
\
../lxc/compiler.h
lxc_test_utils_SOURCES
=
lxc-test-utils.c lxctest.h
lxc_test_utils_SOURCES
=
lxc-test-utils.c lxctest.h
AM_CFLAGS
=
-DLXCROOTFSMOUNT
=
\"
$(LXCROOTFSMOUNT)
\"
\
AM_CFLAGS
=
-DLXCROOTFSMOUNT
=
\"
$(LXCROOTFSMOUNT)
\"
\
...
...
src/tests/share_ns.c
View file @
bf7e2093
...
@@ -16,6 +16,7 @@
...
@@ -16,6 +16,7 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
*/
#define _GNU_SOURCE
#include <alloca.h>
#include <alloca.h>
#include <errno.h>
#include <errno.h>
#include <pthread.h>
#include <pthread.h>
...
@@ -30,23 +31,26 @@
...
@@ -30,23 +31,26 @@
#include "lxc/lxccontainer.h"
#include "lxc/lxccontainer.h"
#include "lxctest.h"
#include "lxctest.h"
#include "../lxc/compiler.h"
#define TEST_DEFAULT_BUF_SIZE 256
struct
thread_args
{
struct
thread_args
{
int
thread_id
;
int
thread_id
;
bool
success
;
bool
success
;
pid_t
init_pid
;
pid_t
init_pid
;
char
inherited_ipc_ns
[
4096
];
char
inherited_ipc_ns
[
TEST_DEFAULT_BUF_SIZE
];
char
inherited_net_ns
[
4096
];
char
inherited_net_ns
[
TEST_DEFAULT_BUF_SIZE
];
};
};
void
*
ns_sharing_wrapper
(
void
*
data
)
__noreturn
static
void
*
ns_sharing_wrapper
(
void
*
data
)
{
{
int
init_pid
;
int
init_pid
;
ssize_t
ret
;
ssize_t
ret
;
char
name
[
100
];
char
name
[
100
];
char
owning_ns_init_pid
[
100
];
char
owning_ns_init_pid
[
100
];
char
proc_ns_path
[
256
];
char
proc_ns_path
[
TEST_DEFAULT_BUF_SIZE
];
char
ns_buf
[
256
];
char
ns_buf
[
TEST_DEFAULT_BUF_SIZE
];
struct
lxc_container
*
c
;
struct
lxc_container
*
c
;
struct
thread_args
*
args
=
data
;
struct
thread_args
*
args
=
data
;
...
@@ -56,7 +60,7 @@ void *ns_sharing_wrapper(void *data)
...
@@ -56,7 +60,7 @@ void *ns_sharing_wrapper(void *data)
c
=
lxc_container_new
(
name
,
NULL
);
c
=
lxc_container_new
(
name
,
NULL
);
if
(
!
c
)
{
if
(
!
c
)
{
lxc_error
(
"Failed to create container
\"
%s
\"\n
"
,
name
);
lxc_error
(
"Failed to create container
\"
%s
\"\n
"
,
name
);
return
NULL
;
goto
out_pthread_exit
;
}
}
if
(
c
->
is_defined
(
c
))
{
if
(
c
->
is_defined
(
c
))
{
...
@@ -74,6 +78,8 @@ void *ns_sharing_wrapper(void *data)
...
@@ -74,6 +78,8 @@ void *ns_sharing_wrapper(void *data)
goto
out
;
goto
out
;
}
}
c
->
clear_config
(
c
);
if
(
!
c
->
load_config
(
c
,
NULL
))
{
if
(
!
c
->
load_config
(
c
,
NULL
))
{
lxc_error
(
"Failed to load config for container
\"
%s
\"\n
"
,
name
);
lxc_error
(
"Failed to load config for container
\"
%s
\"\n
"
,
name
);
goto
out
;
goto
out
;
...
@@ -131,7 +137,7 @@ void *ns_sharing_wrapper(void *data)
...
@@ -131,7 +137,7 @@ void *ns_sharing_wrapper(void *data)
lxc_error
(
"Failed to retrieve ipc namespace for container
\"
%s
\"\n
"
,
name
);
lxc_error
(
"Failed to retrieve ipc namespace for container
\"
%s
\"\n
"
,
name
);
goto
out
;
goto
out
;
}
}
ns_buf
[
ret
]
=
'\0'
;
ns_buf
[
ret
==
0
?
ret
:
ret
-
1
]
=
'\0'
;
if
(
strcmp
(
args
->
inherited_ipc_ns
,
ns_buf
)
!=
0
)
{
if
(
strcmp
(
args
->
inherited_ipc_ns
,
ns_buf
)
!=
0
)
{
lxc_error
(
"Failed to inherit ipc namespace from container
\"
owning-ns
\"
: %s != %s
\n
"
,
args
->
inherited_ipc_ns
,
ns_buf
);
lxc_error
(
"Failed to inherit ipc namespace from container
\"
owning-ns
\"
: %s != %s
\n
"
,
args
->
inherited_ipc_ns
,
ns_buf
);
...
@@ -151,7 +157,7 @@ void *ns_sharing_wrapper(void *data)
...
@@ -151,7 +157,7 @@ void *ns_sharing_wrapper(void *data)
lxc_error
(
"Failed to retrieve ipc namespace for container
\"
%s
\"\n
"
,
name
);
lxc_error
(
"Failed to retrieve ipc namespace for container
\"
%s
\"\n
"
,
name
);
goto
out
;
goto
out
;
}
}
ns_buf
[
ret
]
=
'\0'
;
ns_buf
[
ret
==
0
?
ret
:
ret
-
1
]
=
'\0'
;
if
(
strcmp
(
args
->
inherited_net_ns
,
ns_buf
)
!=
0
)
{
if
(
strcmp
(
args
->
inherited_net_ns
,
ns_buf
)
!=
0
)
{
lxc_error
(
"Failed to inherit net namespace from container
\"
owning-ns
\"
: %s != %s
\n
"
,
args
->
inherited_net_ns
,
ns_buf
);
lxc_error
(
"Failed to inherit net namespace from container
\"
owning-ns
\"
: %s != %s
\n
"
,
args
->
inherited_net_ns
,
ns_buf
);
...
@@ -168,20 +174,22 @@ out:
...
@@ -168,20 +174,22 @@ out:
if
(
!
c
->
destroy
(
c
))
if
(
!
c
->
destroy
(
c
))
lxc_error
(
"Failed to destroy container
\"
%s
\"\n
"
,
name
);
lxc_error
(
"Failed to destroy container
\"
%s
\"\n
"
,
name
);
lxc_container_put
(
c
);
out_pthread_exit:
pthread_exit
(
NULL
);
pthread_exit
(
NULL
);
return
NULL
;
}
}
int
main
(
int
argc
,
char
*
argv
[])
int
main
(
int
argc
,
char
*
argv
[])
{
{
struct
thread_args
*
args
=
NULL
;
struct
thread_args
*
args
=
NULL
;
pthread_t
*
threads
=
NULL
;
size_t
nthreads
=
10
;
size_t
nthreads
=
10
;
int
i
,
init_pid
,
j
;
int
i
,
init_pid
,
j
;
char
proc_ns_path
[
4096
];
char
proc_ns_path
[
TEST_DEFAULT_BUF_SIZE
];
char
ipc_ns_buf
[
4096
];
char
ipc_ns_buf
[
TEST_DEFAULT_BUF_SIZE
];
char
net_ns_buf
[
4096
];
char
net_ns_buf
[
TEST_DEFAULT_BUF_SIZE
];
pthread_attr_t
attr
;
pthread_attr_t
attr
;
pthread_t
threads
[
10
];
struct
lxc_container
*
c
;
struct
lxc_container
*
c
;
int
ret
=
EXIT_FAILURE
;
int
ret
=
EXIT_FAILURE
;
...
@@ -195,17 +203,17 @@ int main(int argc, char *argv[])
...
@@ -195,17 +203,17 @@ int main(int argc, char *argv[])
if
(
c
->
is_defined
(
c
))
{
if
(
c
->
is_defined
(
c
))
{
lxc_error
(
"%s
\n
"
,
"Container
\"
owning-ns
\"
is defined"
);
lxc_error
(
"%s
\n
"
,
"Container
\"
owning-ns
\"
is defined"
);
goto
on_error_
put
;
goto
on_error_
stop
;
}
}
if
(
!
c
->
createl
(
c
,
"busybox"
,
NULL
,
NULL
,
0
,
NULL
))
{
if
(
!
c
->
createl
(
c
,
"busybox"
,
NULL
,
NULL
,
0
,
NULL
))
{
lxc_error
(
"%s
\n
"
,
"Failed to create busybox container
\"
owning-ns
\"
"
);
lxc_error
(
"%s
\n
"
,
"Failed to create busybox container
\"
owning-ns
\"
"
);
goto
on_error_
put
;
goto
on_error_
stop
;
}
}
if
(
!
c
->
is_defined
(
c
))
{
if
(
!
c
->
is_defined
(
c
))
{
lxc_error
(
"%s
\n
"
,
"Container
\"
owning-ns
\"
is not defined"
);
lxc_error
(
"%s
\n
"
,
"Container
\"
owning-ns
\"
is not defined"
);
goto
on_error_
put
;
goto
on_error_
stop
;
}
}
c
->
clear_config
(
c
);
c
->
clear_config
(
c
);
...
@@ -268,15 +276,26 @@ int main(int argc, char *argv[])
...
@@ -268,15 +276,26 @@ int main(int argc, char *argv[])
goto
on_error_stop
;
goto
on_error_stop
;
}
}
threads
=
malloc
(
sizeof
(
pthread_t
)
*
nthreads
);
if
(
!
threads
)
{
lxc_error
(
"%s
\n
"
,
"Failed to allocate memory"
);
goto
on_error_stop
;
}
for
(
j
=
0
;
j
<
10
;
j
++
)
{
for
(
j
=
0
;
j
<
10
;
j
++
)
{
bool
had_error
=
false
;
lxc_debug
(
"Starting namespace sharing test iteration %d
\n
"
,
j
);
lxc_debug
(
"Starting namespace sharing test iteration %d
\n
"
,
j
);
for
(
i
=
0
;
i
<
nthreads
;
i
++
)
{
for
(
i
=
0
;
i
<
nthreads
;
i
++
)
{
memset
(
&
args
[
i
],
0
,
sizeof
(
struct
thread_args
));
memset
(
&
threads
[
i
],
0
,
sizeof
(
pthread_t
));
args
[
i
].
thread_id
=
i
;
args
[
i
].
thread_id
=
i
;
args
[
i
].
success
=
false
;
args
[
i
].
success
=
false
;
args
[
i
].
init_pid
=
init_pid
;
args
[
i
].
init_pid
=
init_pid
;
memcpy
(
args
[
i
].
inherited_ipc_ns
,
ipc_ns_buf
,
sizeof
(
args
[
i
].
inherited_ipc_ns
)
);
snprintf
(
args
[
i
].
inherited_ipc_ns
,
sizeof
(
args
[
i
].
inherited_ipc_ns
),
"%s"
,
ipc_ns_buf
);
memcpy
(
args
[
i
].
inherited_net_ns
,
net_ns_buf
,
sizeof
(
args
[
i
].
inherited_net_ns
)
);
snprintf
(
args
[
i
].
inherited_net_ns
,
sizeof
(
args
[
i
].
inherited_net_ns
),
"%s"
,
net_ns_buf
);
ret
=
pthread_create
(
&
threads
[
i
],
&
attr
,
ns_sharing_wrapper
,
(
void
*
)
&
args
[
i
]);
ret
=
pthread_create
(
&
threads
[
i
],
&
attr
,
ns_sharing_wrapper
,
(
void
*
)
&
args
[
i
]);
if
(
ret
!=
0
)
if
(
ret
!=
0
)
...
@@ -290,15 +309,19 @@ int main(int argc, char *argv[])
...
@@ -290,15 +309,19 @@ int main(int argc, char *argv[])
if
(
!
args
[
i
].
success
)
{
if
(
!
args
[
i
].
success
)
{
lxc_error
(
"ns sharing thread %d failed
\n
"
,
args
[
i
].
thread_id
);
lxc_error
(
"ns sharing thread %d failed
\n
"
,
args
[
i
].
thread_id
);
goto
on_error_stop
;
had_error
=
true
;
}
}
}
}
if
(
had_error
)
goto
on_error_stop
;
}
}
ret
=
EXIT_SUCCESS
;
ret
=
EXIT_SUCCESS
;
on_error_stop:
on_error_stop:
free
(
args
);
free
(
args
);
free
(
threads
);
pthread_attr_destroy
(
&
attr
);
pthread_attr_destroy
(
&
attr
);
if
(
c
->
is_running
(
c
)
&&
!
c
->
stop
(
c
))
if
(
c
->
is_running
(
c
)
&&
!
c
->
stop
(
c
))
...
@@ -307,7 +330,6 @@ on_error_stop:
...
@@ -307,7 +330,6 @@ on_error_stop:
if
(
!
c
->
destroy
(
c
))
if
(
!
c
->
destroy
(
c
))
lxc_error
(
"%s
\n
"
,
"Failed to destroy container
\"
owning-ns
\"
"
);
lxc_error
(
"%s
\n
"
,
"Failed to destroy container
\"
owning-ns
\"
"
);
on_error_put:
lxc_container_put
(
c
);
lxc_container_put
(
c
);
if
(
ret
==
EXIT_SUCCESS
)
if
(
ret
==
EXIT_SUCCESS
)
lxc_debug
(
"%s
\n
"
,
"All state namespace sharing tests passed"
);
lxc_debug
(
"%s
\n
"
,
"All state namespace sharing tests passed"
);
...
...
src/tests/state_server.c
View file @
bf7e2093
...
@@ -30,6 +30,7 @@
...
@@ -30,6 +30,7 @@
#include "lxc/lxccontainer.h"
#include "lxc/lxccontainer.h"
#include "lxctest.h"
#include "lxctest.h"
#include "../lxc/compiler.h"
struct
thread_args
{
struct
thread_args
{
int
thread_id
;
int
thread_id
;
...
@@ -38,7 +39,7 @@ struct thread_args {
...
@@ -38,7 +39,7 @@ struct thread_args {
struct
lxc_container
*
c
;
struct
lxc_container
*
c
;
};
};
static
void
*
state_wrapper
(
void
*
data
)
__noreturn
static
void
*
state_wrapper
(
void
*
data
)
{
{
struct
thread_args
*
args
=
data
;
struct
thread_args
*
args
=
data
;
...
@@ -50,7 +51,6 @@ static void *state_wrapper(void *data)
...
@@ -50,7 +51,6 @@ static void *state_wrapper(void *data)
args
->
thread_id
,
args
->
timeout
,
args
->
success
?
"SUCCESS"
:
"FAILED"
);
args
->
thread_id
,
args
->
timeout
,
args
->
success
?
"SUCCESS"
:
"FAILED"
);
pthread_exit
(
NULL
);
pthread_exit
(
NULL
);
return
NULL
;
}
}
int
main
(
int
argc
,
char
*
argv
[])
int
main
(
int
argc
,
char
*
argv
[])
...
...
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