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
1ef2b5f4
Unverified
Commit
1ef2b5f4
authored
Mar 25, 2020
by
Christian Brauner
Committed by
Stéphane Graber
Mar 26, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
lxc_init: move main() down
Signed-off-by:
Christian Brauner
<
christian.brauner@ubuntu.com
>
parent
a8565bb4
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
93 additions
and
96 deletions
+93
-96
lxc_init.c
src/lxc/cmd/lxc_init.c
+93
-96
No files found.
src/lxc/cmd/lxc_init.c
View file @
1ef2b5f4
...
...
@@ -70,9 +70,6 @@ struct arguments {
int
argc
;
};
static
int
arguments_parse
(
struct
arguments
*
my_args
,
int
argc
,
char
*
const
argv
[]);
static
struct
arguments
my_args
=
{
.
options
=
long_options
,
.
shortopts
=
short_options
...
...
@@ -191,6 +188,99 @@ static void remove_self(void)
return
;
}
__noreturn
static
void
print_usage_exit
(
const
struct
option
longopts
[])
{
fprintf
(
stderr
,
"Usage: lxc-init [-n|--name=NAME] [-h|--help] [--usage] [--version]
\n
\
[-q|--quiet] [-P|--lxcpath=LXCPATH]
\n
"
);
exit
(
EXIT_SUCCESS
);
}
__noreturn
static
void
print_version_exit
(
void
)
{
printf
(
"%s
\n
"
,
LXC_VERSION
);
exit
(
EXIT_SUCCESS
);
}
static
void
print_help
(
void
)
{
fprintf
(
stderr
,
"\
Usage: lxc-init --name=NAME -- COMMAND
\n
\
\n
\
lxc-init start a COMMAND as PID 2 inside a container
\n
\
\n
\
Options :
\n
\
-n, --name=NAME NAME of the container
\n
\
-q, --quiet Don't produce any output
\n
\
-P, --lxcpath=PATH Use specified container path
\n
\
-?, --help Give this help list
\n
\
--usage Give a short usage message
\n
\
--version Print the version number
\n
\
\n
\
Mandatory or optional arguments to long options are also mandatory or optional
\n
\
for any corresponding short options.
\n
\
\n
\
See the lxc-init man page for further information.
\n\n
"
);
}
static
int
arguments_parse
(
struct
arguments
*
args
,
int
argc
,
char
*
const
argv
[])
{
for
(;;)
{
int
c
;
int
index
=
0
;
c
=
getopt_long
(
argc
,
argv
,
args
->
shortopts
,
args
->
options
,
&
index
);
if
(
c
==
-
1
)
break
;
switch
(
c
)
{
case
'n'
:
args
->
name
=
optarg
;
break
;
case
'o'
:
break
;
case
'l'
:
break
;
case
'q'
:
args
->
quiet
=
true
;
break
;
case
'P'
:
remove_trailing_slashes
(
optarg
);
args
->
lxcpath
=
optarg
;
break
;
case
OPT_USAGE
:
print_usage_exit
(
args
->
options
);
case
OPT_VERSION
:
print_version_exit
();
case
'?'
:
print_help
();
exit
(
EXIT_FAILURE
);
case
'h'
:
print_help
();
exit
(
EXIT_SUCCESS
);
}
}
/*
* Reclaim the remaining command arguments
*/
args
->
argv
=
&
argv
[
optind
];
args
->
argc
=
argc
-
optind
;
/* If no lxcpath was given, use default */
if
(
!
args
->
lxcpath
)
args
->
lxcpath
=
lxc_global_config_value
(
"lxc.lxcpath"
);
/* Check the command options */
if
(
!
args
->
name
)
{
if
(
!
args
->
quiet
)
fprintf
(
stderr
,
"lxc-init: missing container name, use --name option
\n
"
);
return
-
1
;
}
return
0
;
}
int
main
(
int
argc
,
char
*
argv
[])
{
int
i
,
logfd
,
ret
;
...
...
@@ -426,96 +516,3 @@ out:
exit
(
EXIT_FAILURE
);
exit
(
exit_with
);
}
__noreturn
static
void
print_usage_exit
(
const
struct
option
longopts
[])
{
fprintf
(
stderr
,
"Usage: lxc-init [-n|--name=NAME] [-h|--help] [--usage] [--version]
\n
\
[-q|--quiet] [-P|--lxcpath=LXCPATH]
\n
"
);
exit
(
EXIT_SUCCESS
);
}
__noreturn
static
void
print_version_exit
(
void
)
{
printf
(
"%s
\n
"
,
LXC_VERSION
);
exit
(
EXIT_SUCCESS
);
}
static
void
print_help
(
void
)
{
fprintf
(
stderr
,
"\
Usage: lxc-init --name=NAME -- COMMAND
\n
\
\n
\
lxc-init start a COMMAND as PID 2 inside a container
\n
\
\n
\
Options :
\n
\
-n, --name=NAME NAME of the container
\n
\
-q, --quiet Don't produce any output
\n
\
-P, --lxcpath=PATH Use specified container path
\n
\
-?, --help Give this help list
\n
\
--usage Give a short usage message
\n
\
--version Print the version number
\n
\
\n
\
Mandatory or optional arguments to long options are also mandatory or optional
\n
\
for any corresponding short options.
\n
\
\n
\
See the lxc-init man page for further information.
\n\n
"
);
}
static
int
arguments_parse
(
struct
arguments
*
args
,
int
argc
,
char
*
const
argv
[])
{
for
(;;)
{
int
c
;
int
index
=
0
;
c
=
getopt_long
(
argc
,
argv
,
args
->
shortopts
,
args
->
options
,
&
index
);
if
(
c
==
-
1
)
break
;
switch
(
c
)
{
case
'n'
:
args
->
name
=
optarg
;
break
;
case
'o'
:
break
;
case
'l'
:
break
;
case
'q'
:
args
->
quiet
=
true
;
break
;
case
'P'
:
remove_trailing_slashes
(
optarg
);
args
->
lxcpath
=
optarg
;
break
;
case
OPT_USAGE
:
print_usage_exit
(
args
->
options
);
case
OPT_VERSION
:
print_version_exit
();
case
'?'
:
print_help
();
exit
(
EXIT_FAILURE
);
case
'h'
:
print_help
();
exit
(
EXIT_SUCCESS
);
}
}
/*
* Reclaim the remaining command arguments
*/
args
->
argv
=
&
argv
[
optind
];
args
->
argc
=
argc
-
optind
;
/* If no lxcpath was given, use default */
if
(
!
args
->
lxcpath
)
args
->
lxcpath
=
lxc_global_config_value
(
"lxc.lxcpath"
);
/* Check the command options */
if
(
!
args
->
name
)
{
if
(
!
args
->
quiet
)
fprintf
(
stderr
,
"lxc-init: missing container name, use --name option
\n
"
);
return
-
1
;
}
return
0
;
}
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