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
bb19d0ab
Unverified
Commit
bb19d0ab
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-execute: add default log priority & cleanups
Signed-off-by:
2xsec
<
dh48.jeong@samsung.com
>
parent
3920d874
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
42 additions
and
42 deletions
+42
-42
lxc_execute.c
src/lxc/tools/lxc_execute.c
+42
-42
No files found.
src/lxc/tools/lxc_execute.c
View file @
bb19d0ab
...
@@ -43,8 +43,46 @@
...
@@ -43,8 +43,46 @@
lxc_log_define
(
lxc_execute
,
lxc
);
lxc_log_define
(
lxc_execute
,
lxc
);
static
int
my_parser
(
struct
lxc_arguments
*
args
,
int
c
,
char
*
arg
);
static
bool
set_argv
(
struct
lxc_container
*
c
,
struct
lxc_arguments
*
args
);
static
struct
lxc_list
defines
;
static
struct
lxc_list
defines
;
static
const
struct
option
my_longopts
[]
=
{
{
"daemon"
,
no_argument
,
0
,
'd'
},
{
"rcfile"
,
required_argument
,
0
,
'f'
},
{
"define"
,
required_argument
,
0
,
's'
},
{
"uid"
,
required_argument
,
0
,
'u'
},
{
"gid"
,
required_argument
,
0
,
'g'
},
{
"share-net"
,
required_argument
,
0
,
OPT_SHARE_NET
},
{
"share-ipc"
,
required_argument
,
0
,
OPT_SHARE_IPC
},
{
"share-uts"
,
required_argument
,
0
,
OPT_SHARE_UTS
},
{
"share-pid"
,
required_argument
,
0
,
OPT_SHARE_PID
},
LXC_COMMON_OPTIONS
};
static
struct
lxc_arguments
my_args
=
{
.
progname
=
"lxc-execute"
,
.
help
=
"\
--name=NAME -- COMMAND
\n
\
\n
\
lxc-execute creates a container with the identifier NAME
\n
\
and execs COMMAND into this container.
\n
\
\n
\
Options :
\n
\
-n, --name=NAME NAME of the container
\n
\
-d, --daemon Daemonize the container
\n
\
-f, --rcfile=FILE Load configuration file FILE
\n
\
-s, --define KEY=VAL Assign VAL to configuration variable KEY
\n
\
-u, --uid=UID Execute COMMAND with UID inside the container
\n
\
-g, --gid=GID Execute COMMAND with GID inside the container
\n
"
,
.
options
=
my_longopts
,
.
parser
=
my_parser
,
.
log_priority
=
"ERROR"
,
.
log_file
=
"none"
,
.
daemonize
=
0
,
};
static
int
my_parser
(
struct
lxc_arguments
*
args
,
int
c
,
char
*
arg
)
static
int
my_parser
(
struct
lxc_arguments
*
args
,
int
c
,
char
*
arg
)
{
{
int
ret
;
int
ret
;
...
@@ -82,43 +120,9 @@ static int my_parser(struct lxc_arguments *args, int c, char *arg)
...
@@ -82,43 +120,9 @@ static int my_parser(struct lxc_arguments *args, int c, char *arg)
args
->
share_ns
[
LXC_NS_PID
]
=
arg
;
args
->
share_ns
[
LXC_NS_PID
]
=
arg
;
break
;
break
;
}
}
return
0
;
return
0
;
}
}
static
const
struct
option
my_longopts
[]
=
{
{
"daemon"
,
no_argument
,
0
,
'd'
},
{
"rcfile"
,
required_argument
,
0
,
'f'
},
{
"define"
,
required_argument
,
0
,
's'
},
{
"uid"
,
required_argument
,
0
,
'u'
},
{
"gid"
,
required_argument
,
0
,
'g'
},
{
"share-net"
,
required_argument
,
0
,
OPT_SHARE_NET
},
{
"share-ipc"
,
required_argument
,
0
,
OPT_SHARE_IPC
},
{
"share-uts"
,
required_argument
,
0
,
OPT_SHARE_UTS
},
{
"share-pid"
,
required_argument
,
0
,
OPT_SHARE_PID
},
LXC_COMMON_OPTIONS
};
static
struct
lxc_arguments
my_args
=
{
.
progname
=
"lxc-execute"
,
.
help
=
"\
--name=NAME -- COMMAND
\n
\
\n
\
lxc-execute creates a container with the identifier NAME
\n
\
and execs COMMAND into this container.
\n
\
\n
\
Options :
\n
\
-n, --name=NAME NAME of the container
\n
\
-d, --daemon Daemonize the container
\n
\
-f, --rcfile=FILE Load configuration file FILE
\n
\
-s, --define KEY=VAL Assign VAL to configuration variable KEY
\n
\
-u, --uid=UID Execute COMMAND with UID inside the container
\n
\
-g, --gid=GID Execute COMMAND with GID inside the container
\n
"
,
.
options
=
my_longopts
,
.
parser
=
my_parser
,
.
daemonize
=
0
,
};
static
bool
set_argv
(
struct
lxc_container
*
c
,
struct
lxc_arguments
*
args
)
static
bool
set_argv
(
struct
lxc_container
*
c
,
struct
lxc_arguments
*
args
)
{
{
int
ret
;
int
ret
;
...
@@ -134,6 +138,7 @@ static bool set_argv(struct lxc_container *c, struct lxc_arguments *args)
...
@@ -134,6 +138,7 @@ static bool set_argv(struct lxc_container *c, struct lxc_arguments *args)
return
false
;
return
false
;
args
->
argv
=
components
;
args
->
argv
=
components
;
for
(
p
=
components
;
*
p
;
p
++
)
for
(
p
=
components
;
*
p
;
p
++
)
args
->
argc
++
;
args
->
argc
++
;
...
@@ -156,8 +161,6 @@ int main(int argc, char *argv[])
...
@@ -156,8 +161,6 @@ int main(int argc, char *argv[])
if
(
lxc_arguments_parse
(
&
my_args
,
argc
,
argv
))
if
(
lxc_arguments_parse
(
&
my_args
,
argc
,
argv
))
exit
(
err
);
exit
(
err
);
/* 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
;
...
@@ -167,7 +170,6 @@ int main(int argc, char *argv[])
...
@@ -167,7 +170,6 @@ int main(int argc, char *argv[])
if
(
lxc_log_init
(
&
log
))
if
(
lxc_log_init
(
&
log
))
exit
(
err
);
exit
(
err
);
}
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
)
{
...
@@ -195,12 +197,11 @@ int main(int argc, char *argv[])
...
@@ -195,12 +197,11 @@ int main(int argc, char *argv[])
goto
out
;
goto
out
;
}
}
if
(
my_args
.
argc
==
0
)
{
if
(
my_args
.
argc
==
0
)
if
(
!
set_argv
(
c
,
&
my_args
))
{
if
(
!
set_argv
(
c
,
&
my_args
))
{
ERROR
(
"Missing command to execute!"
);
ERROR
(
"Missing command to execute!"
);
goto
out
;
goto
out
;
}
}
}
bret
=
lxc_config_define_load
(
&
defines
,
c
);
bret
=
lxc_config_define_load
(
&
defines
,
c
);
if
(
!
bret
)
if
(
!
bret
)
...
@@ -244,13 +245,12 @@ int main(int argc, char *argv[])
...
@@ -244,13 +245,12 @@ int main(int argc, char *argv[])
if
(
c
->
daemonize
)
{
if
(
c
->
daemonize
)
{
err
=
EXIT_SUCCESS
;
err
=
EXIT_SUCCESS
;
}
else
{
}
else
{
if
(
WIFEXITED
(
c
->
error_num
))
{
if
(
WIFEXITED
(
c
->
error_num
))
err
=
WEXITSTATUS
(
c
->
error_num
);
err
=
WEXITSTATUS
(
c
->
error_num
);
}
else
{
else
/* Try to die with the same signal the task did. */
/* Try to die with the same signal the task did. */
kill
(
0
,
WTERMSIG
(
c
->
error_num
));
kill
(
0
,
WTERMSIG
(
c
->
error_num
));
}
}
}
out:
out:
lxc_container_put
(
c
);
lxc_container_put
(
c
);
...
...
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