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
3920d874
Unverified
Commit
3920d874
authored
Aug 18, 2018
by
2xsec
Committed by
Christian Brauner
Aug 19, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tools: lxc-device: add default log priority & cleanups
Signed-off-by:
2xsec
<
dh48.jeong@samsung.com
>
parent
a1fe06d6
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
25 deletions
+21
-25
lxc_device.c
src/lxc/tools/lxc_device.c
+21
-25
No files found.
src/lxc/tools/lxc_device.c
View file @
3920d874
...
@@ -33,14 +33,16 @@
...
@@ -33,14 +33,16 @@
#include "log.h"
#include "log.h"
#include "utils.h"
#include "utils.h"
lxc_log_define
(
lxc_device
,
lxc
);
#if HAVE_IFADDRS_H
#if HAVE_IFADDRS_H
#include <ifaddrs.h>
#include <ifaddrs.h>
#else
#else
#include "include/ifaddrs.h"
#include "include/ifaddrs.h"
#endif
#endif
lxc_log_define
(
lxc_device
,
lxc
);
static
bool
is_interface
(
const
char
*
dev_name
,
pid_t
pid
);
static
const
struct
option
my_longopts
[]
=
{
static
const
struct
option
my_longopts
[]
=
{
LXC_COMMON_OPTIONS
LXC_COMMON_OPTIONS
};
};
...
@@ -58,6 +60,8 @@ Options :\n\
...
@@ -58,6 +60,8 @@ Options :\n\
.
options
=
my_longopts
,
.
options
=
my_longopts
,
.
parser
=
NULL
,
.
parser
=
NULL
,
.
checker
=
NULL
,
.
checker
=
NULL
,
.
log_priority
=
"ERROR"
,
.
log_file
=
"none"
,
};
};
static
bool
is_interface
(
const
char
*
dev_name
,
pid_t
pid
)
static
bool
is_interface
(
const
char
*
dev_name
,
pid_t
pid
)
...
@@ -110,10 +114,8 @@ int main(int argc, char *argv[])
...
@@ -110,10 +114,8 @@ int main(int argc, char *argv[])
}
}
if
(
lxc_arguments_parse
(
&
my_args
,
argc
,
argv
))
if
(
lxc_arguments_parse
(
&
my_args
,
argc
,
argv
))
goto
err
;
exit
(
EXIT_FAILURE
)
;
/* Only create log if explicitly instructed */
if
(
my_args
.
log_file
||
my_args
.
log_priority
)
{
log
.
name
=
my_args
.
name
;
log
.
name
=
my_args
.
name
;
log
.
file
=
my_args
.
log_file
;
log
.
file
=
my_args
.
log_file
;
log
.
level
=
my_args
.
log_priority
;
log
.
level
=
my_args
.
log_priority
;
...
@@ -123,12 +125,11 @@ int main(int argc, char *argv[])
...
@@ -123,12 +125,11 @@ int main(int argc, char *argv[])
if
(
lxc_log_init
(
&
log
))
if
(
lxc_log_init
(
&
log
))
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
}
c
=
lxc_container_new
(
my_args
.
name
,
my_args
.
lxcpath
[
0
]);
c
=
lxc_container_new
(
my_args
.
name
,
my_args
.
lxcpath
[
0
]);
if
(
!
c
)
{
if
(
!
c
)
{
ERROR
(
"%s doesn't exist"
,
my_args
.
name
);
ERROR
(
"%s doesn't exist"
,
my_args
.
name
);
goto
err
;
exit
(
EXIT_FAILURE
)
;
}
}
if
(
my_args
.
rcfile
)
{
if
(
my_args
.
rcfile
)
{
...
@@ -136,65 +137,60 @@ int main(int argc, char *argv[])
...
@@ -136,65 +137,60 @@ int main(int argc, char *argv[])
if
(
!
c
->
load_config
(
c
,
my_args
.
rcfile
))
{
if
(
!
c
->
load_config
(
c
,
my_args
.
rcfile
))
{
ERROR
(
"Failed to load rcfile"
);
ERROR
(
"Failed to load rcfile"
);
goto
err
1
;
goto
err
;
}
}
c
->
configfile
=
strdup
(
my_args
.
rcfile
);
c
->
configfile
=
strdup
(
my_args
.
rcfile
);
if
(
!
c
->
configfile
)
{
if
(
!
c
->
configfile
)
{
ERROR
(
"Out of memory setting new config filename"
);
ERROR
(
"Out of memory setting new config filename"
);
goto
err
1
;
goto
err
;
}
}
}
}
if
(
!
c
->
is_running
(
c
))
{
if
(
!
c
->
is_running
(
c
))
{
ERROR
(
"Container %s is not running"
,
c
->
name
);
ERROR
(
"Container %s is not running"
,
c
->
name
);
goto
err
1
;
goto
err
;
}
}
if
(
my_args
.
argc
<
2
)
{
if
(
my_args
.
argc
<
2
)
{
ERROR
(
"Error: no command given (Please see --help output)"
);
ERROR
(
"Error: no command given (Please see --help output)"
);
goto
err
1
;
goto
err
;
}
}
cmd
=
my_args
.
argv
[
0
];
cmd
=
my_args
.
argv
[
0
];
dev_name
=
my_args
.
argv
[
1
];
dev_name
=
my_args
.
argv
[
1
];
if
(
my_args
.
argc
<
3
)
if
(
my_args
.
argc
<
3
)
dst_name
=
dev_name
;
dst_name
=
dev_name
;
else
else
dst_name
=
my_args
.
argv
[
2
];
dst_name
=
my_args
.
argv
[
2
];
if
(
strncmp
(
cmd
,
"add"
,
strlen
(
cmd
))
==
0
)
{
if
(
strncmp
(
cmd
,
"add"
,
strlen
(
cmd
))
==
0
)
{
if
(
is_interface
(
dev_name
,
1
))
{
if
(
is_interface
(
dev_name
,
1
))
ret
=
c
->
attach_interface
(
c
,
dev_name
,
dst_name
);
ret
=
c
->
attach_interface
(
c
,
dev_name
,
dst_name
);
}
else
{
else
ret
=
c
->
add_device_node
(
c
,
dev_name
,
dst_name
);
ret
=
c
->
add_device_node
(
c
,
dev_name
,
dst_name
);
}
if
(
ret
!=
true
)
{
if
(
ret
!=
true
)
{
ERROR
(
"Failed to add %s to %s"
,
dev_name
,
c
->
name
);
ERROR
(
"Failed to add %s to %s"
,
dev_name
,
c
->
name
);
goto
err
1
;
goto
err
;
}
}
}
else
if
(
strncmp
(
cmd
,
"del"
,
strlen
(
cmd
))
==
0
)
{
}
else
if
(
strncmp
(
cmd
,
"del"
,
strlen
(
cmd
))
==
0
)
{
if
(
is_interface
(
dev_name
,
c
->
init_pid
(
c
)))
{
if
(
is_interface
(
dev_name
,
c
->
init_pid
(
c
)))
ret
=
c
->
detach_interface
(
c
,
dev_name
,
dst_name
);
ret
=
c
->
detach_interface
(
c
,
dev_name
,
dst_name
);
}
else
{
else
ret
=
c
->
remove_device_node
(
c
,
dev_name
,
dst_name
);
ret
=
c
->
remove_device_node
(
c
,
dev_name
,
dst_name
);
}
if
(
ret
!=
true
)
{
if
(
ret
!=
true
)
{
ERROR
(
"Failed to del %s from %s"
,
dev_name
,
c
->
name
);
ERROR
(
"Failed to del %s from %s"
,
dev_name
,
c
->
name
);
goto
err
1
;
goto
err
;
}
}
}
else
{
}
else
{
ERROR
(
"Error: Please use add or del (Please see --help output)"
);
ERROR
(
"Error: Please use add or del (Please see --help output)"
);
goto
err
1
;
goto
err
;
}
}
exit
(
EXIT_SUCCESS
);
exit
(
EXIT_SUCCESS
);
err1:
lxc_container_put
(
c
);
err:
err:
lxc_container_put
(
c
);
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
}
}
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