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
ea0eb48b
Unverified
Commit
ea0eb48b
authored
Aug 25, 2017
by
Christian Brauner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
arguments: non-functional changes
Signed-off-by:
Christian Brauner
<
christian.brauner@ubuntu.com
>
parent
77b0073a
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
72 additions
and
52 deletions
+72
-52
arguments.c
src/lxc/arguments.c
+48
-30
arguments.h
src/lxc/arguments.h
+24
-22
No files found.
src/lxc/arguments.c
View file @
ea0eb48b
...
@@ -21,26 +21,26 @@
...
@@ -21,26 +21,26 @@
* License along with this library; if not, write to the Free Software
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
*/
#include <ctype.h>
#include <errno.h>
#include <limits.h>
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdlib.h>
#include <limits.h>
#include <string.h>
#include <string.h>
#include <ctype.h>
/* for isprint() */
#include <unistd.h>
#include <errno.h>
#include <sys/stat.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/types.h>
#include <unistd.h>
#include "arguments.h"
#include "arguments.h"
#include "utils.h"
#include "utils.h"
#include "version.h"
#include "version.h"
/*---------------------------------------------------------------------------*/
static
int
build_shortopts
(
const
struct
option
*
a_options
,
char
*
a_shortopts
,
static
int
build_shortopts
(
const
struct
option
*
a_options
,
size_t
a_size
)
char
*
a_shortopts
,
size_t
a_size
)
{
{
const
struct
option
*
opt
;
size_t
i
=
0
;
size_t
i
=
0
;
const
struct
option
*
opt
;
if
(
!
a_options
||
!
a_shortopts
||
!
a_size
)
if
(
!
a_options
||
!
a_shortopts
||
!
a_size
)
return
-
1
;
return
-
1
;
...
@@ -79,12 +79,11 @@ static int build_shortopts(const struct option *a_options,
...
@@ -79,12 +79,11 @@ static int build_shortopts(const struct option *a_options,
return
0
;
return
0
;
is2big:
is2big:
errno
=
E2BIG
;
errno
=
E2BIG
;
return
-
1
;
return
-
1
;
}
}
/*---------------------------------------------------------------------------*/
static
void
print_usage
(
const
struct
option
longopts
[],
static
void
print_usage
(
const
struct
option
longopts
[],
const
struct
lxc_arguments
*
a_args
)
const
struct
lxc_arguments
*
a_args
)
...
@@ -96,8 +95,9 @@ static void print_usage(const struct option longopts[],
...
@@ -96,8 +95,9 @@ static void print_usage(const struct option longopts[],
for
(
opt
=
longopts
,
i
=
1
;
opt
->
name
;
opt
++
,
i
++
)
{
for
(
opt
=
longopts
,
i
=
1
;
opt
->
name
;
opt
++
,
i
++
)
{
int
j
;
int
j
;
char
*
uppername
=
strdup
(
opt
->
name
)
;
char
*
uppername
;
uppername
=
strdup
(
opt
->
name
);
if
(
!
uppername
)
if
(
!
uppername
)
exit
(
-
ENOMEM
);
exit
(
-
ENOMEM
);
...
@@ -129,7 +129,8 @@ static void print_usage(const struct option longopts[],
...
@@ -129,7 +129,8 @@ static void print_usage(const struct option longopts[],
exit
(
0
);
exit
(
0
);
}
}
static
void
print_version
()
{
static
void
print_version
()
{
printf
(
"%s
\n
"
,
LXC_VERSION
);
printf
(
"%s
\n
"
,
LXC_VERSION
);
exit
(
0
);
exit
(
0
);
}
}
...
@@ -164,13 +165,14 @@ static int lxc_arguments_lxcpath_add(struct lxc_arguments *args,
...
@@ -164,13 +165,14 @@ static int lxc_arguments_lxcpath_add(struct lxc_arguments *args,
{
{
if
(
args
->
lxcpath_additional
!=
-
1
&&
if
(
args
->
lxcpath_additional
!=
-
1
&&
args
->
lxcpath_cnt
>
args
->
lxcpath_additional
)
{
args
->
lxcpath_cnt
>
args
->
lxcpath_additional
)
{
fprintf
(
stderr
,
"This command only accepts %d -P,--lxcpath arguments
\n
"
,
fprintf
(
stderr
,
"This command only accepts %d -P,--lxcpath arguments
\n
"
,
args
->
lxcpath_additional
+
1
);
args
->
lxcpath_additional
+
1
);
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
}
}
args
->
lxcpath
=
realloc
(
args
->
lxcpath
,
(
args
->
lxcpath_cnt
+
1
)
*
args
->
lxcpath
=
realloc
(
sizeof
(
args
->
lxcpath
[
0
]));
args
->
lxcpath
,
(
args
->
lxcpath_cnt
+
1
)
*
sizeof
(
args
->
lxcpath
[
0
]));
if
(
args
->
lxcpath
==
NULL
)
{
if
(
args
->
lxcpath
==
NULL
)
{
lxc_error
(
args
,
"no memory"
);
lxc_error
(
args
,
"no memory"
);
return
-
ENOMEM
;
return
-
ENOMEM
;
...
@@ -179,11 +181,11 @@ static int lxc_arguments_lxcpath_add(struct lxc_arguments *args,
...
@@ -179,11 +181,11 @@ static int lxc_arguments_lxcpath_add(struct lxc_arguments *args,
return
0
;
return
0
;
}
}
extern
int
lxc_arguments_parse
(
struct
lxc_arguments
*
args
,
extern
int
lxc_arguments_parse
(
struct
lxc_arguments
*
args
,
int
argc
,
int
argc
,
char
*
const
argv
[])
char
*
const
argv
[])
{
{
char
shortopts
[
256
];
int
ret
=
0
;
int
ret
=
0
;
char
shortopts
[
256
];
ret
=
build_shortopts
(
args
->
options
,
shortopts
,
sizeof
(
shortopts
));
ret
=
build_shortopts
(
args
->
options
,
shortopts
,
sizeof
(
shortopts
));
if
(
ret
<
0
)
{
if
(
ret
<
0
)
{
...
@@ -192,28 +194,43 @@ extern int lxc_arguments_parse(struct lxc_arguments *args,
...
@@ -192,28 +194,43 @@ extern int lxc_arguments_parse(struct lxc_arguments *args,
return
ret
;
return
ret
;
}
}
while
(
1
)
{
while
(
true
)
{
int
c
,
index
=
0
;
int
c
;
int
index
=
0
;
c
=
getopt_long
(
argc
,
argv
,
shortopts
,
args
->
options
,
&
index
);
c
=
getopt_long
(
argc
,
argv
,
shortopts
,
args
->
options
,
&
index
);
if
(
c
==
-
1
)
if
(
c
==
-
1
)
break
;
break
;
switch
(
c
)
{
switch
(
c
)
{
case
'n'
:
args
->
name
=
optarg
;
break
;
case
'n'
:
case
'o'
:
args
->
log_file
=
optarg
;
break
;
args
->
name
=
optarg
;
case
'l'
:
args
->
log_priority
=
optarg
;
break
;
break
;
case
'q'
:
args
->
quiet
=
1
;
break
;
case
'o'
:
case
OPT_RCFILE
:
args
->
rcfile
=
optarg
;
break
;
args
->
log_file
=
optarg
;
break
;
case
'l'
:
args
->
log_priority
=
optarg
;
break
;
case
'q'
:
args
->
quiet
=
1
;
break
;
case
OPT_RCFILE
:
args
->
rcfile
=
optarg
;
break
;
case
'P'
:
case
'P'
:
remove_trailing_slashes
(
optarg
);
remove_trailing_slashes
(
optarg
);
ret
=
lxc_arguments_lxcpath_add
(
args
,
optarg
);
ret
=
lxc_arguments_lxcpath_add
(
args
,
optarg
);
if
(
ret
<
0
)
if
(
ret
<
0
)
return
ret
;
return
ret
;
break
;
break
;
case
OPT_USAGE
:
print_usage
(
args
->
options
,
args
);
case
OPT_USAGE
:
case
OPT_VERSION
:
print_version
();
print_usage
(
args
->
options
,
args
);
case
'?'
:
print_help
(
args
,
1
);
case
OPT_VERSION
:
case
'h'
:
print_help
(
args
,
0
);
print_version
();
case
'?'
:
print_help
(
args
,
1
);
case
'h'
:
print_help
(
args
,
0
);
default:
default:
if
(
args
->
parser
)
{
if
(
args
->
parser
)
{
ret
=
args
->
parser
(
args
,
c
,
optarg
);
ret
=
args
->
parser
(
args
,
c
,
optarg
);
...
@@ -231,7 +248,8 @@ extern int lxc_arguments_parse(struct lxc_arguments *args,
...
@@ -231,7 +248,8 @@ extern int lxc_arguments_parse(struct lxc_arguments *args,
/* If no lxcpaths were given, use default */
/* If no lxcpaths were given, use default */
if
(
!
args
->
lxcpath_cnt
)
{
if
(
!
args
->
lxcpath_cnt
)
{
ret
=
lxc_arguments_lxcpath_add
(
args
,
lxc_global_config_value
(
"lxc.lxcpath"
));
ret
=
lxc_arguments_lxcpath_add
(
args
,
lxc_global_config_value
(
"lxc.lxcpath"
));
if
(
ret
<
0
)
if
(
ret
<
0
)
return
ret
;
return
ret
;
}
}
...
...
src/lxc/arguments.h
View file @
ea0eb48b
...
@@ -32,14 +32,14 @@
...
@@ -32,14 +32,14 @@
struct
lxc_arguments
;
struct
lxc_arguments
;
typedef
int
(
*
lxc_arguments_parser_t
)
(
struct
lxc_arguments
*
,
int
,
char
*
);
typedef
int
(
*
lxc_arguments_parser_t
)
(
struct
lxc_arguments
*
,
int
,
char
*
);
typedef
int
(
*
lxc_arguments_checker_t
)
(
const
struct
lxc_arguments
*
);
typedef
int
(
*
lxc_arguments_checker_t
)(
const
struct
lxc_arguments
*
);
struct
lxc_arguments
{
struct
lxc_arguments
{
const
char
*
help
;
const
char
*
help
;
void
(
*
helpfn
)(
const
struct
lxc_arguments
*
);
void
(
*
helpfn
)(
const
struct
lxc_arguments
*
);
const
char
*
progname
;
const
char
*
progname
;
const
struct
option
*
options
;
const
struct
option
*
options
;
lxc_arguments_parser_t
parser
;
lxc_arguments_parser_t
parser
;
lxc_arguments_checker_t
checker
;
lxc_arguments_checker_t
checker
;
...
@@ -144,28 +144,30 @@ struct lxc_arguments {
...
@@ -144,28 +144,30 @@ struct lxc_arguments {
};
};
#define LXC_COMMON_OPTIONS \
#define LXC_COMMON_OPTIONS \
{"name", required_argument, 0, 'n'},
\
{ "name", required_argument, 0, 'n' },
\
{"help", no_argument, 0, 'h'},
\
{ "help", no_argument, 0, 'h' },
\
{"usage", no_argument, 0, OPT_USAGE},
\
{ "usage", no_argument, 0, OPT_USAGE },
\
{"version", no_argument, 0, OPT_VERSION},
\
{ "version", no_argument, 0, OPT_VERSION },
\
{"quiet", no_argument, 0, 'q'},
\
{ "quiet", no_argument, 0, 'q' },
\
{"logfile", required_argument, 0, 'o'},
\
{ "logfile", required_argument, 0, 'o' },
\
{"logpriority", required_argument, 0, 'l'},
\
{ "logpriority", required_argument, 0, 'l' },
\
{"lxcpath", required_argument, 0, 'P'},
\
{ "lxcpath", required_argument, 0, 'P' },
\
{"rcfile", required_argument, 0, OPT_RCFILE},
\
{ "rcfile", required_argument, 0, OPT_RCFILE },
\
{0, 0, 0, 0
}
{ 0, 0, 0, 0
}
/* option keys for long only options */
/* option keys for long only options */
#define OPT_USAGE 0x1000
#define OPT_USAGE 0x1000
#define
OPT_VERSION OPT_USAGE-
1
#define
OPT_VERSION OPT_USAGE -
1
#define
OPT_RCFILE OPT_USAGE-
2
#define
OPT_RCFILE OPT_USAGE -
2
extern
int
lxc_arguments_parse
(
struct
lxc_arguments
*
args
,
extern
int
lxc_arguments_parse
(
struct
lxc_arguments
*
args
,
int
argc
,
int
argc
,
char
*
const
argv
[]);
char
*
const
argv
[]);
extern
int
lxc_arguments_str_to_int
(
struct
lxc_arguments
*
args
,
const
char
*
str
);
extern
int
lxc_arguments_str_to_int
(
struct
lxc_arguments
*
args
,
const
char
*
str
);
#define lxc_error(arg, fmt, args...) if (!(arg)->quiet) \
#define lxc_error(arg, fmt, args...) \
fprintf(stderr, "%s: " fmt "\n", (arg)->progname, ## args)
if (!(arg)->quiet) \
fprintf(stderr, "%s: " fmt "\n", (arg)->progname, ##args)
#endif
#endif
/* __LXC_ARGUMENTS_H */
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