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
a47e327c
Commit
a47e327c
authored
Sep 05, 2016
by
Stéphane Graber
Committed by
GitHub
Sep 05, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1169 from brauner/2016-09-04/fix_syslog
syslog tweaks
parents
e3197b0c
83319023
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
92 additions
and
84 deletions
+92
-84
conf.c
src/lxc/conf.c
+1
-0
conf.h
src/lxc/conf.h
+4
-0
confile.c
src/lxc/confile.c
+11
-30
log.c
src/lxc/log.c
+2
-1
log.h
src/lxc/log.h
+36
-1
get_item.c
src/tests/get_item.c
+29
-52
lxctest.h
src/tests/lxctest.h
+9
-0
No files found.
src/lxc/conf.c
View file @
a47e327c
...
@@ -4168,6 +4168,7 @@ void lxc_conf_free(struct lxc_conf *conf)
...
@@ -4168,6 +4168,7 @@ void lxc_conf_free(struct lxc_conf *conf)
free
(
conf
->
init_cmd
);
free
(
conf
->
init_cmd
);
free
(
conf
->
unexpanded_config
);
free
(
conf
->
unexpanded_config
);
free
(
conf
->
pty_names
);
free
(
conf
->
pty_names
);
free
(
conf
->
syslog
);
lxc_clear_config_network
(
conf
);
lxc_clear_config_network
(
conf
);
free
(
conf
->
lsm_aa_profile
);
free
(
conf
->
lsm_aa_profile
);
free
(
conf
->
lsm_se_context
);
free
(
conf
->
lsm_se_context
);
...
...
src/lxc/conf.h
View file @
a47e327c
...
@@ -378,6 +378,10 @@ struct lxc_conf {
...
@@ -378,6 +378,10 @@ struct lxc_conf {
/* indicator if the container will be destroyed on shutdown */
/* indicator if the container will be destroyed on shutdown */
int
ephemeral
;
int
ephemeral
;
/* The facility to pass to syslog. Let's users establish as what type of
* program liblxc is supposed to write to the syslog. */
char
*
syslog
;
};
};
#ifdef HAVE_TLS
#ifdef HAVE_TLS
...
...
src/lxc/confile.c
View file @
a47e327c
...
@@ -273,23 +273,6 @@ static const struct signame signames[] = {
...
@@ -273,23 +273,6 @@ static const struct signame signames[] = {
#endif
#endif
};
};
struct
syslog_facility
{
const
char
*
name
;
int
facility
;
};
static
const
struct
syslog_facility
syslog_facilities
[]
=
{
{
"daemon"
,
LOG_DAEMON
},
{
"local0"
,
LOG_LOCAL0
},
{
"local1"
,
LOG_LOCAL1
},
{
"local2"
,
LOG_LOCAL2
},
{
"local3"
,
LOG_LOCAL3
},
{
"local4"
,
LOG_LOCAL4
},
{
"local5"
,
LOG_LOCAL5
},
{
"local6"
,
LOG_LOCAL6
},
{
"local7"
,
LOG_LOCAL7
},
};
static
const
size_t
config_size
=
sizeof
(
config
)
/
sizeof
(
struct
lxc_config_t
);
static
const
size_t
config_size
=
sizeof
(
config
)
/
sizeof
(
struct
lxc_config_t
);
extern
struct
lxc_config_t
*
lxc_getconfig
(
const
char
*
key
)
extern
struct
lxc_config_t
*
lxc_getconfig
(
const
char
*
key
)
...
@@ -2027,8 +2010,8 @@ int lxc_config_read(const char *file, struct lxc_conf *conf, bool from_include)
...
@@ -2027,8 +2010,8 @@ int lxc_config_read(const char *file, struct lxc_conf *conf, bool from_include)
}
}
/* Catch only the top level config file name in the structure */
/* Catch only the top level config file name in the structure */
if
(
!
conf
->
rcfile
)
if
(
!
conf
->
rcfile
)
conf
->
rcfile
=
strdup
(
file
);
conf
->
rcfile
=
strdup
(
file
);
return
lxc_file_for_each_line
(
file
,
parse_line
,
&
c
);
return
lxc_file_for_each_line
(
file
,
parse_line
,
&
c
);
}
}
...
@@ -2577,6 +2560,8 @@ int lxc_get_config_item(struct lxc_conf *c, const char *key, char *retv,
...
@@ -2577,6 +2560,8 @@ int lxc_get_config_item(struct lxc_conf *c, const char *key, char *retv,
return
lxc_get_conf_int
(
c
,
retv
,
inlen
,
c
->
init_gid
);
return
lxc_get_conf_int
(
c
,
retv
,
inlen
,
c
->
init_gid
);
else
if
(
strcmp
(
key
,
"lxc.ephemeral"
)
==
0
)
else
if
(
strcmp
(
key
,
"lxc.ephemeral"
)
==
0
)
return
lxc_get_conf_int
(
c
,
retv
,
inlen
,
c
->
ephemeral
);
return
lxc_get_conf_int
(
c
,
retv
,
inlen
,
c
->
ephemeral
);
else
if
(
strcmp
(
key
,
"lxc.syslog"
)
==
0
)
v
=
c
->
syslog
;
else
return
-
1
;
else
return
-
1
;
if
(
!
v
)
if
(
!
v
)
...
@@ -2959,17 +2944,13 @@ static int config_ephemeral(const char *key, const char *value,
...
@@ -2959,17 +2944,13 @@ static int config_ephemeral(const char *key, const char *value,
static
int
config_syslog
(
const
char
*
key
,
const
char
*
value
,
static
int
config_syslog
(
const
char
*
key
,
const
char
*
value
,
struct
lxc_conf
*
lxc_conf
)
struct
lxc_conf
*
lxc_conf
)
{
{
int
n
;
int
facility
;
int
facility
=
-
1
;
facility
=
lxc_syslog_priority_to_int
(
value
);
if
(
facility
==
-
EINVAL
)
{
for
(
n
=
0
;
n
<
sizeof
(
syslog_facilities
)
/
sizeof
((
syslog_facilities
)[
0
]);
n
++
)
{
if
(
strcasecmp
(
syslog_facilities
[
n
].
name
,
value
)
==
0
)
{
facility
=
syslog_facilities
[
n
].
facility
;
lxc_log_syslog
(
facility
);
return
0
;
}
}
ERROR
(
"Wrong value for lxc.syslog"
);
ERROR
(
"Wrong value for lxc.syslog"
);
return
-
1
;
return
-
1
;
}
lxc_log_syslog
(
facility
);
return
config_string_item
(
&
lxc_conf
->
syslog
,
value
);
}
}
src/lxc/log.c
View file @
a47e327c
...
@@ -108,8 +108,9 @@ static int log_append_syslog(const struct lxc_log_appender *appender,
...
@@ -108,8 +108,9 @@ static int log_append_syslog(const struct lxc_log_appender *appender,
}
}
syslog
(
lxc_log_priority_to_syslog
(
event
->
priority
),
syslog
(
lxc_log_priority_to_syslog
(
event
->
priority
),
"%s %s - %s:%s:%d - %s"
,
"%s
%s
%s - %s:%s:%d - %s"
,
log_vmname
?
log_vmname
:
""
,
log_vmname
?
log_vmname
:
""
,
log_vmname
?
":"
:
""
,
event
->
category
,
event
->
category
,
event
->
locinfo
->
file
,
event
->
locinfo
->
func
,
event
->
locinfo
->
file
,
event
->
locinfo
->
func
,
event
->
locinfo
->
line
,
event
->
locinfo
->
line
,
...
...
src/lxc/log.h
View file @
a47e327c
...
@@ -26,12 +26,14 @@
...
@@ -26,12 +26,14 @@
#include "config.h"
#include "config.h"
#include <errno.h>
#include <stdarg.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdio.h>
#include <sys/time.h>
#include <sys/time.h>
#include <string.h>
#include <string.h>
#include <strings.h>
#include <strings.h>
#include <stdbool.h>
#include <stdbool.h>
#include <syslog.h>
#include "conf.h"
#include "conf.h"
...
@@ -53,7 +55,7 @@
...
@@ -53,7 +55,7 @@
#define ATTR_UNUSED
#define ATTR_UNUSED
#endif
#endif
/* predefined priorities. */
/* predefined
lxc log
priorities. */
enum
lxc_loglevel
{
enum
lxc_loglevel
{
LXC_LOG_PRIORITY_TRACE
,
LXC_LOG_PRIORITY_TRACE
,
LXC_LOG_PRIORITY_DEBUG
,
LXC_LOG_PRIORITY_DEBUG
,
...
@@ -151,6 +153,24 @@ static inline const char* lxc_log_priority_to_string(int priority)
...
@@ -151,6 +153,24 @@ static inline const char* lxc_log_priority_to_string(int priority)
return
"NOTSET"
;
return
"NOTSET"
;
}
}
}
}
static
inline
const
char
*
lxc_syslog_priority_to_string
(
int
priority
)
{
switch
(
priority
)
{
case
LOG_DAEMON
:
return
"daemon"
;
case
LOG_LOCAL0
:
return
"local0"
;
case
LOG_LOCAL1
:
return
"local1"
;
case
LOG_LOCAL2
:
return
"local2"
;
case
LOG_LOCAL3
:
return
"local3"
;
case
LOG_LOCAL4
:
return
"local4"
;
case
LOG_LOCAL5
:
return
"local5"
;
case
LOG_LOCAL6
:
return
"local6"
;
case
LOG_LOCAL7
:
return
"local7"
;
default:
return
"NOTSET"
;
}
}
/*
/*
* converts a literal priority to an int
* converts a literal priority to an int
*/
*/
...
@@ -169,6 +189,21 @@ static inline int lxc_log_priority_to_int(const char* name)
...
@@ -169,6 +189,21 @@ static inline int lxc_log_priority_to_int(const char* name)
return
LXC_LOG_PRIORITY_NOTSET
;
return
LXC_LOG_PRIORITY_NOTSET
;
}
}
static
inline
int
lxc_syslog_priority_to_int
(
const
char
*
name
)
{
if
(
!
strcasecmp
(
"daemon"
,
name
))
return
LOG_DAEMON
;
if
(
!
strcasecmp
(
"local0"
,
name
))
return
LOG_LOCAL0
;
if
(
!
strcasecmp
(
"local1"
,
name
))
return
LOG_LOCAL1
;
if
(
!
strcasecmp
(
"local2"
,
name
))
return
LOG_LOCAL2
;
if
(
!
strcasecmp
(
"local3"
,
name
))
return
LOG_LOCAL3
;
if
(
!
strcasecmp
(
"local4"
,
name
))
return
LOG_LOCAL4
;
if
(
!
strcasecmp
(
"local5"
,
name
))
return
LOG_LOCAL5
;
if
(
!
strcasecmp
(
"local6"
,
name
))
return
LOG_LOCAL6
;
if
(
!
strcasecmp
(
"local7"
,
name
))
return
LOG_LOCAL7
;
return
-
EINVAL
;
}
static
inline
void
static
inline
void
__lxc_log_append
(
const
struct
lxc_log_appender
*
appender
,
__lxc_log_append
(
const
struct
lxc_log_appender
*
appender
,
struct
lxc_log_event
*
event
)
struct
lxc_log_event
*
event
)
...
...
src/tests/get_item.c
View file @
a47e327c
...
@@ -26,31 +26,53 @@
...
@@ -26,31 +26,53 @@
#include <stdlib.h>
#include <stdlib.h>
#include <errno.h>
#include <errno.h>
#include <string.h>
#include <string.h>
#include "lxc/state.h"
#include "lxc/state.h"
#include "lxctest.h"
#define MYNAME "lxctest1"
#define MYNAME "lxctest1"
int
main
(
int
argc
,
char
*
argv
[])
int
main
(
int
argc
,
char
*
argv
[])
{
{
int
ret
=
EXIT_FAILURE
;
struct
lxc_container
*
c
;
struct
lxc_container
*
c
;
int
ret
;
char
v1
[
2
],
v2
[
256
],
v3
[
2048
];
char
v1
[
2
],
v2
[
256
],
v3
[
2048
];
if
((
c
=
lxc_container_new
(
"testxyz"
,
NULL
))
==
NULL
)
{
if
((
c
=
lxc_container_new
(
"testxyz"
,
NULL
))
==
NULL
)
{
fprintf
(
stderr
,
"%d: error opening lxc_container %s
\n
"
,
__LINE__
,
MYNAME
);
fprintf
(
stderr
,
"%d: error opening lxc_container %s
\n
"
,
__LINE__
,
MYNAME
);
ret
=
1
;
exit
(
EXIT_FAILURE
);
}
/* EXPECT SUCCESS: lxc.syslog with valid value. */
if
(
!
c
->
set_config_item
(
c
,
"lxc.syslog"
,
"local0"
))
{
lxc_error
(
"%s
\n
"
,
"Failed to set lxc.syslog.
\n
"
);
goto
out
;
}
ret
=
c
->
get_config_item
(
c
,
"lxc.syslog"
,
v2
,
255
);
if
(
ret
<
0
)
{
lxc_error
(
"Failed to retrieve lxc.syslog: %d.
\n
"
,
ret
);
goto
out
;
}
if
(
strcmp
(
v2
,
"local0"
)
!=
0
)
{
lxc_error
(
"Expected: local0 == %s.
\n
"
,
v2
);
goto
out
;
}
lxc_debug
(
"Retrieving value for lxc.syslog correctly returned: %s.
\n
"
,
v2
);
/* EXPECT FAILURE: lxc.syslog with invalid value. */
if
(
c
->
set_config_item
(
c
,
"lxc.syslog"
,
"NONSENSE"
))
{
lxc_error
(
"%s
\n
"
,
"Succeeded int setting lxc.syslog to invalid value
\"
NONSENSE
\"
.
\n
"
);
goto
out
;
goto
out
;
}
}
lxc_debug
(
"%s
\n
"
,
"Successfully failed to set lxc.syslog to invalid value.
\n
"
);
if
(
!
c
->
set_config_item
(
c
,
"lxc.hook.pre-start"
,
"hi there"
))
{
if
(
!
c
->
set_config_item
(
c
,
"lxc.hook.pre-start"
,
"hi there"
))
{
fprintf
(
stderr
,
"%d: failed to set hook.pre-start
\n
"
,
__LINE__
);
fprintf
(
stderr
,
"%d: failed to set hook.pre-start
\n
"
,
__LINE__
);
ret
=
1
;
goto
out
;
goto
out
;
}
}
ret
=
c
->
get_config_item
(
c
,
"lxc.hook.pre-start"
,
v2
,
255
);
ret
=
c
->
get_config_item
(
c
,
"lxc.hook.pre-start"
,
v2
,
255
);
if
(
ret
<
0
)
{
if
(
ret
<
0
)
{
fprintf
(
stderr
,
"%d: get_config_item(lxc.hook.pre-start) returned %d
\n
"
,
__LINE__
,
ret
);
fprintf
(
stderr
,
"%d: get_config_item(lxc.hook.pre-start) returned %d
\n
"
,
__LINE__
,
ret
);
ret
=
1
;
goto
out
;
goto
out
;
}
}
fprintf
(
stderr
,
"lxc.hook.pre-start returned %d %s
\n
"
,
ret
,
v2
);
fprintf
(
stderr
,
"lxc.hook.pre-start returned %d %s
\n
"
,
ret
,
v2
);
...
@@ -58,58 +80,49 @@ int main(int argc, char *argv[])
...
@@ -58,58 +80,49 @@ int main(int argc, char *argv[])
ret
=
c
->
get_config_item
(
c
,
"lxc.network"
,
v2
,
255
);
ret
=
c
->
get_config_item
(
c
,
"lxc.network"
,
v2
,
255
);
if
(
ret
<
0
)
{
if
(
ret
<
0
)
{
fprintf
(
stderr
,
"%d: get_config_item returned %d
\n
"
,
__LINE__
,
ret
);
fprintf
(
stderr
,
"%d: get_config_item returned %d
\n
"
,
__LINE__
,
ret
);
ret
=
1
;
goto
out
;
goto
out
;
}
}
fprintf
(
stderr
,
"%d: get_config_item(lxc.network) returned %d %s
\n
"
,
__LINE__
,
ret
,
v2
);
fprintf
(
stderr
,
"%d: get_config_item(lxc.network) returned %d %s
\n
"
,
__LINE__
,
ret
,
v2
);
if
(
!
c
->
set_config_item
(
c
,
"lxc.tty"
,
"4"
))
{
if
(
!
c
->
set_config_item
(
c
,
"lxc.tty"
,
"4"
))
{
fprintf
(
stderr
,
"%d: failed to set tty
\n
"
,
__LINE__
);
fprintf
(
stderr
,
"%d: failed to set tty
\n
"
,
__LINE__
);
ret
=
1
;
goto
out
;
goto
out
;
}
}
ret
=
c
->
get_config_item
(
c
,
"lxc.tty"
,
v2
,
255
);
ret
=
c
->
get_config_item
(
c
,
"lxc.tty"
,
v2
,
255
);
if
(
ret
<
0
)
{
if
(
ret
<
0
)
{
fprintf
(
stderr
,
"%d: get_config_item(lxc.tty) returned %d
\n
"
,
__LINE__
,
ret
);
fprintf
(
stderr
,
"%d: get_config_item(lxc.tty) returned %d
\n
"
,
__LINE__
,
ret
);
ret
=
1
;
goto
out
;
goto
out
;
}
}
fprintf
(
stderr
,
"lxc.tty returned %d %s
\n
"
,
ret
,
v2
);
fprintf
(
stderr
,
"lxc.tty returned %d %s
\n
"
,
ret
,
v2
);
if
(
!
c
->
set_config_item
(
c
,
"lxc.arch"
,
"x86"
))
{
if
(
!
c
->
set_config_item
(
c
,
"lxc.arch"
,
"x86"
))
{
fprintf
(
stderr
,
"%d: failed to set arch
\n
"
,
__LINE__
);
fprintf
(
stderr
,
"%d: failed to set arch
\n
"
,
__LINE__
);
ret
=
1
;
goto
out
;
goto
out
;
}
}
ret
=
c
->
get_config_item
(
c
,
"lxc.arch"
,
v2
,
255
);
ret
=
c
->
get_config_item
(
c
,
"lxc.arch"
,
v2
,
255
);
if
(
ret
<
0
)
{
if
(
ret
<
0
)
{
fprintf
(
stderr
,
"%d: get_config_item(lxc.arch) returned %d
\n
"
,
__LINE__
,
ret
);
fprintf
(
stderr
,
"%d: get_config_item(lxc.arch) returned %d
\n
"
,
__LINE__
,
ret
);
ret
=
1
;
goto
out
;
goto
out
;
}
}
printf
(
"lxc.arch returned %d %s
\n
"
,
ret
,
v2
);
printf
(
"lxc.arch returned %d %s
\n
"
,
ret
,
v2
);
if
(
!
c
->
set_config_item
(
c
,
"lxc.init_uid"
,
"100"
))
{
if
(
!
c
->
set_config_item
(
c
,
"lxc.init_uid"
,
"100"
))
{
fprintf
(
stderr
,
"%d: failed to set init_uid
\n
"
,
__LINE__
);
fprintf
(
stderr
,
"%d: failed to set init_uid
\n
"
,
__LINE__
);
ret
=
1
;
goto
out
;
goto
out
;
}
}
ret
=
c
->
get_config_item
(
c
,
"lxc.init_uid"
,
v2
,
255
);
ret
=
c
->
get_config_item
(
c
,
"lxc.init_uid"
,
v2
,
255
);
if
(
ret
<
0
)
{
if
(
ret
<
0
)
{
fprintf
(
stderr
,
"%d: get_config_item(lxc.init_uid) returned %d
\n
"
,
__LINE__
,
ret
);
fprintf
(
stderr
,
"%d: get_config_item(lxc.init_uid) returned %d
\n
"
,
__LINE__
,
ret
);
ret
=
1
;
goto
out
;
goto
out
;
}
}
printf
(
"lxc.init_uid returned %d %s
\n
"
,
ret
,
v2
);
printf
(
"lxc.init_uid returned %d %s
\n
"
,
ret
,
v2
);
if
(
!
c
->
set_config_item
(
c
,
"lxc.init_gid"
,
"100"
))
{
if
(
!
c
->
set_config_item
(
c
,
"lxc.init_gid"
,
"100"
))
{
fprintf
(
stderr
,
"%d: failed to set init_gid
\n
"
,
__LINE__
);
fprintf
(
stderr
,
"%d: failed to set init_gid
\n
"
,
__LINE__
);
ret
=
1
;
goto
out
;
goto
out
;
}
}
ret
=
c
->
get_config_item
(
c
,
"lxc.init_gid"
,
v2
,
255
);
ret
=
c
->
get_config_item
(
c
,
"lxc.init_gid"
,
v2
,
255
);
if
(
ret
<
0
)
{
if
(
ret
<
0
)
{
fprintf
(
stderr
,
"%d: get_config_item(lxc.init_gid) returned %d
\n
"
,
__LINE__
,
ret
);
fprintf
(
stderr
,
"%d: get_config_item(lxc.init_gid) returned %d
\n
"
,
__LINE__
,
ret
);
ret
=
1
;
goto
out
;
goto
out
;
}
}
printf
(
"lxc.init_gid returned %d %s
\n
"
,
ret
,
v2
);
printf
(
"lxc.init_gid returned %d %s
\n
"
,
ret
,
v2
);
...
@@ -119,7 +132,6 @@ int main(int argc, char *argv[])
...
@@ -119,7 +132,6 @@ int main(int argc, char *argv[])
char
*
alloced
;
char
*
alloced
;
if
(
!
c
->
set_config_item
(
c
,
"lxc.utsname"
,
HNAME
))
{
if
(
!
c
->
set_config_item
(
c
,
"lxc.utsname"
,
HNAME
))
{
fprintf
(
stderr
,
"%d: failed to set utsname
\n
"
,
__LINE__
);
fprintf
(
stderr
,
"%d: failed to set utsname
\n
"
,
__LINE__
);
ret
=
1
;
goto
out
;
goto
out
;
}
}
...
@@ -127,7 +139,6 @@ int main(int argc, char *argv[])
...
@@ -127,7 +139,6 @@ int main(int argc, char *argv[])
len
=
c
->
get_config_item
(
c
,
"lxc.utsname"
,
NULL
,
0
);
// query the size of the string
len
=
c
->
get_config_item
(
c
,
"lxc.utsname"
,
NULL
,
0
);
// query the size of the string
if
(
len
<
0
)
{
if
(
len
<
0
)
{
fprintf
(
stderr
,
"%d: get_config_item(lxc.utsname) returned %d
\n
"
,
__LINE__
,
len
);
fprintf
(
stderr
,
"%d: get_config_item(lxc.utsname) returned %d
\n
"
,
__LINE__
,
len
);
ret
=
1
;
goto
out
;
goto
out
;
}
}
printf
(
"lxc.utsname returned %d
\n
"
,
len
);
printf
(
"lxc.utsname returned %d
\n
"
,
len
);
...
@@ -136,7 +147,6 @@ int main(int argc, char *argv[])
...
@@ -136,7 +147,6 @@ int main(int argc, char *argv[])
alloced
=
malloc
(
len
+
1
);
alloced
=
malloc
(
len
+
1
);
if
(
!
alloced
)
{
if
(
!
alloced
)
{
fprintf
(
stderr
,
"%d: failed to allocate %d bytes for utsname
\n
"
,
__LINE__
,
len
);
fprintf
(
stderr
,
"%d: failed to allocate %d bytes for utsname
\n
"
,
__LINE__
,
len
);
ret
=
1
;
goto
out
;
goto
out
;
}
}
// now pass in the malloc'd array, and pass in length of string + 1: again
// now pass in the malloc'd array, and pass in length of string + 1: again
...
@@ -144,12 +154,10 @@ int main(int argc, char *argv[])
...
@@ -144,12 +154,10 @@ int main(int argc, char *argv[])
ret
=
c
->
get_config_item
(
c
,
"lxc.utsname"
,
alloced
,
len
+
1
);
ret
=
c
->
get_config_item
(
c
,
"lxc.utsname"
,
alloced
,
len
+
1
);
if
(
ret
<
0
)
{
if
(
ret
<
0
)
{
fprintf
(
stderr
,
"%d: get_config_item(lxc.utsname) returned %d
\n
"
,
__LINE__
,
ret
);
fprintf
(
stderr
,
"%d: get_config_item(lxc.utsname) returned %d
\n
"
,
__LINE__
,
ret
);
ret
=
1
;
goto
out
;
goto
out
;
}
}
if
(
strcmp
(
alloced
,
HNAME
)
!=
0
||
ret
!=
len
)
{
if
(
strcmp
(
alloced
,
HNAME
)
!=
0
||
ret
!=
len
)
{
fprintf
(
stderr
,
"lxc.utsname returned wrong value: %d %s not %d %s
\n
"
,
ret
,
alloced
,
len
,
HNAME
);
fprintf
(
stderr
,
"lxc.utsname returned wrong value: %d %s not %d %s
\n
"
,
ret
,
alloced
,
len
,
HNAME
);
ret
=
1
;
goto
out
;
goto
out
;
}
}
printf
(
"lxc.utsname returned %d %s
\n
"
,
len
,
alloced
);
printf
(
"lxc.utsname returned %d %s
\n
"
,
len
,
alloced
);
...
@@ -157,26 +165,22 @@ int main(int argc, char *argv[])
...
@@ -157,26 +165,22 @@ int main(int argc, char *argv[])
if
(
!
c
->
set_config_item
(
c
,
"lxc.mount.entry"
,
"hi there"
))
{
if
(
!
c
->
set_config_item
(
c
,
"lxc.mount.entry"
,
"hi there"
))
{
fprintf
(
stderr
,
"%d: failed to set mount.entry
\n
"
,
__LINE__
);
fprintf
(
stderr
,
"%d: failed to set mount.entry
\n
"
,
__LINE__
);
ret
=
1
;
goto
out
;
goto
out
;
}
}
ret
=
c
->
get_config_item
(
c
,
"lxc.mount.entry"
,
v2
,
255
);
ret
=
c
->
get_config_item
(
c
,
"lxc.mount.entry"
,
v2
,
255
);
if
(
ret
<
0
)
{
if
(
ret
<
0
)
{
fprintf
(
stderr
,
"%d: get_config_item(lxc.mount.entry) returned %d
\n
"
,
__LINE__
,
ret
);
fprintf
(
stderr
,
"%d: get_config_item(lxc.mount.entry) returned %d
\n
"
,
__LINE__
,
ret
);
ret
=
1
;
goto
out
;
goto
out
;
}
}
printf
(
"lxc.mount.entry returned %d %s
\n
"
,
ret
,
v2
);
printf
(
"lxc.mount.entry returned %d %s
\n
"
,
ret
,
v2
);
if
(
!
c
->
set_config_item
(
c
,
"lxc.aa_profile"
,
"unconfined"
))
{
if
(
!
c
->
set_config_item
(
c
,
"lxc.aa_profile"
,
"unconfined"
))
{
fprintf
(
stderr
,
"%d: failed to set aa_profile
\n
"
,
__LINE__
);
fprintf
(
stderr
,
"%d: failed to set aa_profile
\n
"
,
__LINE__
);
ret
=
1
;
goto
out
;
goto
out
;
}
}
ret
=
c
->
get_config_item
(
c
,
"lxc.aa_profile"
,
v2
,
255
);
ret
=
c
->
get_config_item
(
c
,
"lxc.aa_profile"
,
v2
,
255
);
if
(
ret
<
0
)
{
if
(
ret
<
0
)
{
fprintf
(
stderr
,
"%d: get_config_item(lxc.aa_profile) returned %d
\n
"
,
__LINE__
,
ret
);
fprintf
(
stderr
,
"%d: get_config_item(lxc.aa_profile) returned %d
\n
"
,
__LINE__
,
ret
);
ret
=
1
;
goto
out
;
goto
out
;
}
}
printf
(
"lxc.aa_profile returned %d %s
\n
"
,
ret
,
v2
);
printf
(
"lxc.aa_profile returned %d %s
\n
"
,
ret
,
v2
);
...
@@ -186,7 +190,6 @@ int main(int argc, char *argv[])
...
@@ -186,7 +190,6 @@ int main(int argc, char *argv[])
// new test with real container
// new test with real container
if
((
c
=
lxc_container_new
(
MYNAME
,
NULL
))
==
NULL
)
{
if
((
c
=
lxc_container_new
(
MYNAME
,
NULL
))
==
NULL
)
{
fprintf
(
stderr
,
"%d: error opening lxc_container %s
\n
"
,
__LINE__
,
MYNAME
);
fprintf
(
stderr
,
"%d: error opening lxc_container %s
\n
"
,
__LINE__
,
MYNAME
);
ret
=
1
;
goto
out
;
goto
out
;
}
}
c
->
destroy
(
c
);
c
->
destroy
(
c
);
...
@@ -194,130 +197,109 @@ int main(int argc, char *argv[])
...
@@ -194,130 +197,109 @@ int main(int argc, char *argv[])
if
((
c
=
lxc_container_new
(
MYNAME
,
NULL
))
==
NULL
)
{
if
((
c
=
lxc_container_new
(
MYNAME
,
NULL
))
==
NULL
)
{
fprintf
(
stderr
,
"%d: error opening lxc_container %s
\n
"
,
__LINE__
,
MYNAME
);
fprintf
(
stderr
,
"%d: error opening lxc_container %s
\n
"
,
__LINE__
,
MYNAME
);
ret
=
1
;
goto
out
;
goto
out
;
}
}
if
(
!
c
->
createl
(
c
,
"busybox"
,
NULL
,
NULL
,
0
,
NULL
))
{
if
(
!
c
->
createl
(
c
,
"busybox"
,
NULL
,
NULL
,
0
,
NULL
))
{
fprintf
(
stderr
,
"%d: failed to create a trusty container
\n
"
,
__LINE__
);
fprintf
(
stderr
,
"%d: failed to create a trusty container
\n
"
,
__LINE__
);
ret
=
1
;
goto
out
;
goto
out
;
}
}
lxc_container_put
(
c
);
lxc_container_put
(
c
);
/* XXX TODO load_config needs to clear out any old config first */
/* XXX TODO load_config needs to clear out any old config first */
if
((
c
=
lxc_container_new
(
MYNAME
,
NULL
))
==
NULL
)
{
if
((
c
=
lxc_container_new
(
MYNAME
,
NULL
))
==
NULL
)
{
fprintf
(
stderr
,
"%d: error opening lxc_container %s
\n
"
,
__LINE__
,
MYNAME
);
fprintf
(
stderr
,
"%d: error opening lxc_container %s
\n
"
,
__LINE__
,
MYNAME
);
ret
=
1
;
goto
out
;
goto
out
;
}
}
ret
=
c
->
get_config_item
(
c
,
"lxc.cap.drop"
,
NULL
,
300
);
ret
=
c
->
get_config_item
(
c
,
"lxc.cap.drop"
,
NULL
,
300
);
if
(
ret
<
5
||
ret
>
255
)
{
if
(
ret
<
5
||
ret
>
255
)
{
fprintf
(
stderr
,
"%d: get_config_item(lxc.cap.drop) with NULL returned %d
\n
"
,
__LINE__
,
ret
);
fprintf
(
stderr
,
"%d: get_config_item(lxc.cap.drop) with NULL returned %d
\n
"
,
__LINE__
,
ret
);
ret
=
1
;
goto
out
;
goto
out
;
}
}
ret
=
c
->
get_config_item
(
c
,
"lxc.cap.drop"
,
v1
,
1
);
ret
=
c
->
get_config_item
(
c
,
"lxc.cap.drop"
,
v1
,
1
);
if
(
ret
<
5
||
ret
>
255
)
{
if
(
ret
<
5
||
ret
>
255
)
{
fprintf
(
stderr
,
"%d: get_config_item(lxc.cap.drop) returned %d
\n
"
,
__LINE__
,
ret
);
fprintf
(
stderr
,
"%d: get_config_item(lxc.cap.drop) returned %d
\n
"
,
__LINE__
,
ret
);
ret
=
1
;
goto
out
;
goto
out
;
}
}
ret
=
c
->
get_config_item
(
c
,
"lxc.cap.drop"
,
v2
,
255
);
ret
=
c
->
get_config_item
(
c
,
"lxc.cap.drop"
,
v2
,
255
);
if
(
ret
<
0
)
{
if
(
ret
<
0
)
{
fprintf
(
stderr
,
"%d: get_config_item(lxc.cap.drop) returned %d %s
\n
"
,
__LINE__
,
ret
,
v2
);
fprintf
(
stderr
,
"%d: get_config_item(lxc.cap.drop) returned %d %s
\n
"
,
__LINE__
,
ret
,
v2
);
ret
=
1
;
goto
out
;
goto
out
;
}
}
printf
(
"%d: get_config_item(lxc.cap.drop) returned %d %s
\n
"
,
__LINE__
,
ret
,
v2
);
printf
(
"%d: get_config_item(lxc.cap.drop) returned %d %s
\n
"
,
__LINE__
,
ret
,
v2
);
ret
=
c
->
get_config_item
(
c
,
"lxc.network"
,
v2
,
255
);
ret
=
c
->
get_config_item
(
c
,
"lxc.network"
,
v2
,
255
);
if
(
ret
<
0
)
{
if
(
ret
<
0
)
{
fprintf
(
stderr
,
"%d: get_config_item returned %d
\n
"
,
__LINE__
,
ret
);
fprintf
(
stderr
,
"%d: get_config_item returned %d
\n
"
,
__LINE__
,
ret
);
ret
=
1
;
goto
out
;
goto
out
;
}
}
printf
(
"%d: get_config_item(lxc.network) returned %d %s
\n
"
,
__LINE__
,
ret
,
v2
);
printf
(
"%d: get_config_item(lxc.network) returned %d %s
\n
"
,
__LINE__
,
ret
,
v2
);
if
(
!
c
->
set_config_item
(
c
,
"lxc.network.ipv4"
,
"10.2.3.4"
))
{
if
(
!
c
->
set_config_item
(
c
,
"lxc.network.ipv4"
,
"10.2.3.4"
))
{
fprintf
(
stderr
,
"%d: failed to set ipv4
\n
"
,
__LINE__
);
fprintf
(
stderr
,
"%d: failed to set ipv4
\n
"
,
__LINE__
);
ret
=
1
;
goto
out
;
goto
out
;
}
}
ret
=
c
->
get_config_item
(
c
,
"lxc.network.0.ipv4"
,
v2
,
255
);
ret
=
c
->
get_config_item
(
c
,
"lxc.network.0.ipv4"
,
v2
,
255
);
if
(
ret
<=
0
)
{
if
(
ret
<=
0
)
{
fprintf
(
stderr
,
"%d: lxc.network.0.ipv4 returned %d
\n
"
,
__LINE__
,
ret
);
fprintf
(
stderr
,
"%d: lxc.network.0.ipv4 returned %d
\n
"
,
__LINE__
,
ret
);
ret
=
1
;
goto
out
;
goto
out
;
}
}
if
(
!
c
->
clear_config_item
(
c
,
"lxc.network.0.ipv4"
))
{
if
(
!
c
->
clear_config_item
(
c
,
"lxc.network.0.ipv4"
))
{
fprintf
(
stderr
,
"%d: failed clearing all ipv4 entries
\n
"
,
__LINE__
);
fprintf
(
stderr
,
"%d: failed clearing all ipv4 entries
\n
"
,
__LINE__
);
ret
=
1
;
goto
out
;
goto
out
;
}
}
ret
=
c
->
get_config_item
(
c
,
"lxc.network.0.ipv4"
,
v2
,
255
);
ret
=
c
->
get_config_item
(
c
,
"lxc.network.0.ipv4"
,
v2
,
255
);
if
(
ret
!=
0
)
{
if
(
ret
!=
0
)
{
fprintf
(
stderr
,
"%d: after clearing ipv4 entries get_item(lxc.network.0.ipv4 returned %d
\n
"
,
__LINE__
,
ret
);
fprintf
(
stderr
,
"%d: after clearing ipv4 entries get_item(lxc.network.0.ipv4 returned %d
\n
"
,
__LINE__
,
ret
);
ret
=
1
;
goto
out
;
goto
out
;
}
}
if
(
!
c
->
set_config_item
(
c
,
"lxc.network.ipv4.gateway"
,
"10.2.3.254"
))
{
if
(
!
c
->
set_config_item
(
c
,
"lxc.network.ipv4.gateway"
,
"10.2.3.254"
))
{
fprintf
(
stderr
,
"%d: failed to set ipv4.gateway
\n
"
,
__LINE__
);
fprintf
(
stderr
,
"%d: failed to set ipv4.gateway
\n
"
,
__LINE__
);
ret
=
1
;
goto
out
;
goto
out
;
}
}
ret
=
c
->
get_config_item
(
c
,
"lxc.network.0.ipv4.gateway"
,
v2
,
255
);
ret
=
c
->
get_config_item
(
c
,
"lxc.network.0.ipv4.gateway"
,
v2
,
255
);
if
(
ret
<=
0
)
{
if
(
ret
<=
0
)
{
fprintf
(
stderr
,
"%d: lxc.network.0.ipv4.gateway returned %d
\n
"
,
__LINE__
,
ret
);
fprintf
(
stderr
,
"%d: lxc.network.0.ipv4.gateway returned %d
\n
"
,
__LINE__
,
ret
);
ret
=
1
;
goto
out
;
goto
out
;
}
}
if
(
!
c
->
set_config_item
(
c
,
"lxc.network.0.ipv4.gateway"
,
""
))
{
if
(
!
c
->
set_config_item
(
c
,
"lxc.network.0.ipv4.gateway"
,
""
))
{
fprintf
(
stderr
,
"%d: failed clearing ipv4.gateway
\n
"
,
__LINE__
);
fprintf
(
stderr
,
"%d: failed clearing ipv4.gateway
\n
"
,
__LINE__
);
ret
=
1
;
goto
out
;
goto
out
;
}
}
ret
=
c
->
get_config_item
(
c
,
"lxc.network.0.ipv4.gateway"
,
v2
,
255
);
ret
=
c
->
get_config_item
(
c
,
"lxc.network.0.ipv4.gateway"
,
v2
,
255
);
if
(
ret
!=
0
)
{
if
(
ret
!=
0
)
{
fprintf
(
stderr
,
"%d: after clearing ipv4.gateway get_item(lxc.network.0.ipv4.gateway returned %d
\n
"
,
__LINE__
,
ret
);
fprintf
(
stderr
,
"%d: after clearing ipv4.gateway get_item(lxc.network.0.ipv4.gateway returned %d
\n
"
,
__LINE__
,
ret
);
ret
=
1
;
goto
out
;
goto
out
;
}
}
ret
=
c
->
get_config_item
(
c
,
"lxc.network.0.link"
,
v2
,
255
);
ret
=
c
->
get_config_item
(
c
,
"lxc.network.0.link"
,
v2
,
255
);
if
(
ret
<
0
)
{
if
(
ret
<
0
)
{
fprintf
(
stderr
,
"%d: get_config_item returned %d
\n
"
,
__LINE__
,
ret
);
fprintf
(
stderr
,
"%d: get_config_item returned %d
\n
"
,
__LINE__
,
ret
);
ret
=
1
;
goto
out
;
goto
out
;
}
}
printf
(
"%d: get_config_item (link) returned %d %s
\n
"
,
__LINE__
,
ret
,
v2
);
printf
(
"%d: get_config_item (link) returned %d %s
\n
"
,
__LINE__
,
ret
,
v2
);
ret
=
c
->
get_config_item
(
c
,
"lxc.network.0.name"
,
v2
,
255
);
ret
=
c
->
get_config_item
(
c
,
"lxc.network.0.name"
,
v2
,
255
);
if
(
ret
<
0
)
{
if
(
ret
<
0
)
{
fprintf
(
stderr
,
"%d: get_config_item returned %d
\n
"
,
__LINE__
,
ret
);
fprintf
(
stderr
,
"%d: get_config_item returned %d
\n
"
,
__LINE__
,
ret
);
ret
=
1
;
goto
out
;
goto
out
;
}
}
printf
(
"%d: get_config_item (name) returned %d %s
\n
"
,
__LINE__
,
ret
,
v2
);
printf
(
"%d: get_config_item (name) returned %d %s
\n
"
,
__LINE__
,
ret
,
v2
);
if
(
!
c
->
clear_config_item
(
c
,
"lxc.network"
))
{
if
(
!
c
->
clear_config_item
(
c
,
"lxc.network"
))
{
fprintf
(
stderr
,
"%d: clear_config_item failed
\n
"
,
__LINE__
);
fprintf
(
stderr
,
"%d: clear_config_item failed
\n
"
,
__LINE__
);
ret
=
1
;
goto
out
;
goto
out
;
}
}
ret
=
c
->
get_config_item
(
c
,
"lxc.network"
,
v2
,
255
);
ret
=
c
->
get_config_item
(
c
,
"lxc.network"
,
v2
,
255
);
if
(
ret
!=
0
)
{
if
(
ret
!=
0
)
{
fprintf
(
stderr
,
"%d: network was not actually cleared (get_network returned %d)
\n
"
,
__LINE__
,
ret
);
fprintf
(
stderr
,
"%d: network was not actually cleared (get_network returned %d)
\n
"
,
__LINE__
,
ret
);
ret
=
1
;
goto
out
;
goto
out
;
}
}
ret
=
c
->
get_config_item
(
c
,
"lxc.cgroup"
,
v3
,
2047
);
ret
=
c
->
get_config_item
(
c
,
"lxc.cgroup"
,
v3
,
2047
);
if
(
ret
<
0
)
{
if
(
ret
<
0
)
{
fprintf
(
stderr
,
"%d: get_config_item(cgroup.devices) returned %d
\n
"
,
__LINE__
,
ret
);
fprintf
(
stderr
,
"%d: get_config_item(cgroup.devices) returned %d
\n
"
,
__LINE__
,
ret
);
ret
=
1
;
goto
out
;
goto
out
;
}
}
printf
(
"%d: get_config_item (cgroup.devices) returned %d %s
\n
"
,
__LINE__
,
ret
,
v3
);
printf
(
"%d: get_config_item (cgroup.devices) returned %d %s
\n
"
,
__LINE__
,
ret
,
v3
);
...
@@ -325,35 +307,30 @@ int main(int argc, char *argv[])
...
@@ -325,35 +307,30 @@ int main(int argc, char *argv[])
ret
=
c
->
get_config_item
(
c
,
"lxc.cgroup.devices.allow"
,
v3
,
2047
);
ret
=
c
->
get_config_item
(
c
,
"lxc.cgroup.devices.allow"
,
v3
,
2047
);
if
(
ret
<
0
)
{
if
(
ret
<
0
)
{
fprintf
(
stderr
,
"%d: get_config_item(cgroup.devices.devices.allow) returned %d
\n
"
,
__LINE__
,
ret
);
fprintf
(
stderr
,
"%d: get_config_item(cgroup.devices.devices.allow) returned %d
\n
"
,
__LINE__
,
ret
);
ret
=
1
;
goto
out
;
goto
out
;
}
}
printf
(
"%d: get_config_item (cgroup.devices.devices.allow) returned %d %s
\n
"
,
__LINE__
,
ret
,
v3
);
printf
(
"%d: get_config_item (cgroup.devices.devices.allow) returned %d %s
\n
"
,
__LINE__
,
ret
,
v3
);
if
(
!
c
->
clear_config_item
(
c
,
"lxc.cgroup"
))
{
if
(
!
c
->
clear_config_item
(
c
,
"lxc.cgroup"
))
{
fprintf
(
stderr
,
"%d: failed clearing lxc.cgroup
\n
"
,
__LINE__
);
fprintf
(
stderr
,
"%d: failed clearing lxc.cgroup
\n
"
,
__LINE__
);
ret
=
1
;
goto
out
;
goto
out
;
}
}
if
(
!
c
->
clear_config_item
(
c
,
"lxc.cap.drop"
))
{
if
(
!
c
->
clear_config_item
(
c
,
"lxc.cap.drop"
))
{
fprintf
(
stderr
,
"%d: failed clearing lxc.cap.drop
\n
"
,
__LINE__
);
fprintf
(
stderr
,
"%d: failed clearing lxc.cap.drop
\n
"
,
__LINE__
);
ret
=
1
;
goto
out
;
goto
out
;
}
}
if
(
!
c
->
clear_config_item
(
c
,
"lxc.mount.entry"
))
{
if
(
!
c
->
clear_config_item
(
c
,
"lxc.mount.entry"
))
{
fprintf
(
stderr
,
"%d: failed clearing lxc.mount.entry
\n
"
,
__LINE__
);
fprintf
(
stderr
,
"%d: failed clearing lxc.mount.entry
\n
"
,
__LINE__
);
ret
=
1
;
goto
out
;
goto
out
;
}
}
if
(
!
c
->
clear_config_item
(
c
,
"lxc.hook"
))
{
if
(
!
c
->
clear_config_item
(
c
,
"lxc.hook"
))
{
fprintf
(
stderr
,
"%d: failed clearing lxc.hook
\n
"
,
__LINE__
);
fprintf
(
stderr
,
"%d: failed clearing lxc.hook
\n
"
,
__LINE__
);
ret
=
1
;
goto
out
;
goto
out
;
}
}
c
->
destroy
(
c
);
printf
(
"All get_item tests passed
\n
"
);
printf
(
"All get_item tests passed
\n
"
);
ret
=
0
;
ret
=
EXIT_SUCCESS
;
out:
out:
c
->
destroy
(
c
);
lxc_container_put
(
c
);
lxc_container_put
(
c
);
exit
(
ret
);
exit
(
ret
);
}
;
}
src/tests/lxctest.h
View file @
a47e327c
...
@@ -28,6 +28,15 @@
...
@@ -28,6 +28,15 @@
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdlib.h>
#define lxc_debug_stream(stream, format, ...) \
do { \
fprintf(stream, "%s: %d: %s: " format, __FILE__, __LINE__, \
__func__, __VA_ARGS__); \
} while (false)
#define lxc_error(format, ...) lxc_debug_stream(stderr, format, __VA_ARGS__)
#define lxc_debug(format, ...) lxc_debug_stream(stdout, format, __VA_ARGS__)
#define lxc_test_assert_stringify(expression, stringify_expression) \
#define lxc_test_assert_stringify(expression, stringify_expression) \
do { \
do { \
if (!(expression)) { \
if (!(expression)) { \
...
...
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