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
d8eb058d
Unverified
Commit
d8eb058d
authored
Feb 06, 2018
by
Serge Hallyn
Committed by
GitHub
Feb 06, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2044 from brauner/2017-12-16/lxc_ls_add_unprivileged_field
tools: add UNPRIVILEGED field in fancy output mode
parents
af3f9cc9
72c94ff9
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
46 additions
and
15 deletions
+46
-15
lxc_ls.c
src/lxc/tools/lxc_ls.c
+46
-15
No files found.
src/lxc/tools/lxc_ls.c
View file @
d8eb058d
...
@@ -71,6 +71,7 @@ struct ls {
...
@@ -71,6 +71,7 @@ struct ls {
double
swap
;
double
swap
;
bool
autostart
;
bool
autostart
;
bool
running
;
bool
running
;
bool
unprivileged
;
};
};
/* Keep track of field widths for printing. */
/* Keep track of field widths for printing. */
...
@@ -85,6 +86,7 @@ struct lengths {
...
@@ -85,6 +86,7 @@ struct lengths {
unsigned
int
ram_length
;
unsigned
int
ram_length
;
unsigned
int
swap_length
;
unsigned
int
swap_length
;
unsigned
int
autostart_length
;
unsigned
int
autostart_length
;
unsigned
int
unprivileged_length
;
};
};
static
int
ls_deserialize
(
int
rpipefd
,
struct
ls
**
m
,
size_t
*
len
);
static
int
ls_deserialize
(
int
rpipefd
,
struct
ls
**
m
,
size_t
*
len
);
...
@@ -187,7 +189,7 @@ Options :\n\
...
@@ -187,7 +189,7 @@ Options :\n\
-f, --fancy use a fancy, column-based output
\n
\
-f, --fancy use a fancy, column-based output
\n
\
-F, --fancy-format comma separated list of columns to show in the fancy output
\n
\
-F, --fancy-format comma separated list of columns to show in the fancy output
\n
\
valid columns are: NAME, STATE, PID, RAM, SWAP, AUTOSTART,
\n
\
valid columns are: NAME, STATE, PID, RAM, SWAP, AUTOSTART,
\n
\
GROUPS, INTERFACE, IPV4 and IPV6
\n
\
GROUPS, INTERFACE, IPV4 and IPV6
, UNPRIVILEGED
\n
\
--active list only active containers
\n
\
--active list only active containers
\n
\
--running list only running containers
\n
\
--running list only running containers
\n
\
--frozen list only frozen containers
\n
\
--frozen list only frozen containers
\n
\
...
@@ -236,16 +238,17 @@ int main(int argc, char *argv[])
...
@@ -236,16 +238,17 @@ int main(int argc, char *argv[])
struct
lengths
max_len
=
{
struct
lengths
max_len
=
{
/* default header length */
/* default header length */
.
name_length
=
4
,
/* NAME */
.
name_length
=
4
,
/* NAME */
.
state_length
=
5
,
/* STATE */
.
state_length
=
5
,
/* STATE */
.
groups_length
=
6
,
/* GROUPS */
.
groups_length
=
6
,
/* GROUPS */
.
interface_length
=
9
,
/* INTERFACE */
.
interface_length
=
9
,
/* INTERFACE */
.
ipv4_length
=
4
,
/* IPV4 */
.
ipv4_length
=
4
,
/* IPV4 */
.
ipv6_length
=
4
,
/* IPV6 */
.
ipv6_length
=
4
,
/* IPV6 */
.
init_length
=
3
,
/* PID */
.
init_length
=
3
,
/* PID */
.
ram_length
=
3
,
/* RAM */
.
ram_length
=
3
,
/* RAM */
.
swap_length
=
4
,
/* SWAP */
.
swap_length
=
4
,
/* SWAP */
.
autostart_length
=
9
,
/* AUTOSTART */
.
autostart_length
=
9
,
/* AUTOSTART */
.
unprivileged_length
=
12
,
/* UNPRIVILEGED */
};
};
char
**
grps
=
NULL
;
char
**
grps
=
NULL
;
...
@@ -481,7 +484,11 @@ static int ls_get(struct ls **m, size_t *size, const struct lxc_arguments *args,
...
@@ -481,7 +484,11 @@ static int ls_get(struct ls **m, size_t *size, const struct lxc_arguments *args,
free
(
tmp
);
free
(
tmp
);
if
(
running
)
{
if
(
running
)
{
char
*
val
;
l
->
init
=
c
->
init_pid
(
c
);
l
->
init
=
c
->
init_pid
(
c
);
if
(
l
->
init
<=
0
)
goto
put_and_next
;
l
->
interface
=
ls_get_interface
(
c
);
l
->
interface
=
ls_get_interface
(
c
);
...
@@ -497,6 +504,15 @@ static int ls_get(struct ls **m, size_t *size, const struct lxc_arguments *args,
...
@@ -497,6 +504,15 @@ static int ls_get(struct ls **m, size_t *size, const struct lxc_arguments *args,
}
}
l
->
swap
=
ls_get_swap
(
c
);
l
->
swap
=
ls_get_swap
(
c
);
val
=
c
->
get_running_config_item
(
c
,
"lxc.idmap"
);
l
->
unprivileged
=
(
val
==
NULL
);
free
(
val
);
}
else
{
int
ret
;
ret
=
c
->
get_config_item
(
c
,
"lxc.idmap"
,
NULL
,
0
);
l
->
unprivileged
=
(
ret
==
0
);
}
}
}
}
...
@@ -813,10 +829,11 @@ static void ls_print_fancy_format(struct ls *l, struct lengths *lht,
...
@@ -813,10 +829,11 @@ static void ls_print_fancy_format(struct ls *l, struct lengths *lht,
/* Check for invalid keys. */
/* Check for invalid keys. */
for
(
s
=
tmp
;
s
&&
*
s
;
s
++
)
{
for
(
s
=
tmp
;
s
&&
*
s
;
s
++
)
{
if
(
strcasecmp
(
*
s
,
"NAME"
)
&&
strcasecmp
(
*
s
,
"STATE"
)
&&
if
(
strcasecmp
(
*
s
,
"NAME"
)
&&
strcasecmp
(
*
s
,
"STATE"
)
&&
strcasecmp
(
*
s
,
"PID"
)
&&
strcasecmp
(
*
s
,
"RAM"
)
&&
strcasecmp
(
*
s
,
"PID"
)
&&
strcasecmp
(
*
s
,
"RAM"
)
&&
strcasecmp
(
*
s
,
"SWAP"
)
&&
strcasecmp
(
*
s
,
"AUTOSTART"
)
&&
strcasecmp
(
*
s
,
"SWAP"
)
&&
strcasecmp
(
*
s
,
"AUTOSTART"
)
&&
strcasecmp
(
*
s
,
"GROUPS"
)
&&
strcasecmp
(
*
s
,
"INTERFACE"
)
&&
strcasecmp
(
*
s
,
"GROUPS"
)
&&
strcasecmp
(
*
s
,
"INTERFACE"
)
&&
strcasecmp
(
*
s
,
"IPV4"
)
&&
strcasecmp
(
*
s
,
"IPV6"
))
{
strcasecmp
(
*
s
,
"IPV4"
)
&&
strcasecmp
(
*
s
,
"IPV6"
)
&&
strcasecmp
(
*
s
,
"UNPRIVILEGED"
))
{
fprintf
(
stderr
,
"Invalid key: %s
\n
"
,
*
s
);
fprintf
(
stderr
,
"Invalid key: %s
\n
"
,
*
s
);
return
;
return
;
}
}
...
@@ -844,6 +861,8 @@ static void ls_print_fancy_format(struct ls *l, struct lengths *lht,
...
@@ -844,6 +861,8 @@ static void ls_print_fancy_format(struct ls *l, struct lengths *lht,
printf
(
"%-*s "
,
lht
->
ipv4_length
,
"IPV4"
);
printf
(
"%-*s "
,
lht
->
ipv4_length
,
"IPV4"
);
else
if
(
strcasecmp
(
*
s
,
"IPV6"
)
==
0
)
else
if
(
strcasecmp
(
*
s
,
"IPV6"
)
==
0
)
printf
(
"%-*s "
,
lht
->
ipv6_length
,
"IPV6"
);
printf
(
"%-*s "
,
lht
->
ipv6_length
,
"IPV6"
);
else
if
(
strcasecmp
(
*
s
,
"UNPRIVILEGED"
)
==
0
)
printf
(
"%-*s "
,
lht
->
unprivileged_length
,
"UNPRIVILEGED"
);
}
}
printf
(
"
\n
"
);
printf
(
"
\n
"
);
...
@@ -885,6 +904,8 @@ static void ls_print_fancy_format(struct ls *l, struct lengths *lht,
...
@@ -885,6 +904,8 @@ static void ls_print_fancy_format(struct ls *l, struct lengths *lht,
printf
(
"%-*s "
,
lht
->
ipv4_length
,
m
->
ipv4
?
m
->
ipv4
:
"-"
);
printf
(
"%-*s "
,
lht
->
ipv4_length
,
m
->
ipv4
?
m
->
ipv4
:
"-"
);
}
else
if
(
strcasecmp
(
*
s
,
"IPV6"
)
==
0
)
{
}
else
if
(
strcasecmp
(
*
s
,
"IPV6"
)
==
0
)
{
printf
(
"%-*s "
,
lht
->
ipv6_length
,
m
->
ipv6
?
m
->
ipv6
:
"-"
);
printf
(
"%-*s "
,
lht
->
ipv6_length
,
m
->
ipv6
?
m
->
ipv6
:
"-"
);
}
else
if
(
strcasecmp
(
*
s
,
"UNPRIVILEGED"
)
==
0
)
{
printf
(
"%-*s "
,
lht
->
unprivileged_length
,
m
->
unprivileged
?
"true"
:
"false"
);
}
}
}
}
printf
(
"
\n
"
);
printf
(
"
\n
"
);
...
@@ -907,6 +928,7 @@ static void ls_print_table(struct ls *l, struct lengths *lht,
...
@@ -907,6 +928,7 @@ static void ls_print_table(struct ls *l, struct lengths *lht,
printf
(
"%-*s "
,
lht
->
groups_length
,
"GROUPS"
);
printf
(
"%-*s "
,
lht
->
groups_length
,
"GROUPS"
);
printf
(
"%-*s "
,
lht
->
ipv4_length
,
"IPV4"
);
printf
(
"%-*s "
,
lht
->
ipv4_length
,
"IPV4"
);
printf
(
"%-*s "
,
lht
->
ipv6_length
,
"IPV6"
);
printf
(
"%-*s "
,
lht
->
ipv6_length
,
"IPV6"
);
printf
(
"%-*s "
,
lht
->
unprivileged_length
,
"UNPRIVILEGED"
);
printf
(
"
\n
"
);
printf
(
"
\n
"
);
size_t
i
;
size_t
i
;
...
@@ -922,6 +944,7 @@ static void ls_print_table(struct ls *l, struct lengths *lht,
...
@@ -922,6 +944,7 @@ static void ls_print_table(struct ls *l, struct lengths *lht,
printf
(
"%-*s "
,
lht
->
groups_length
,
m
->
groups
?
m
->
groups
:
"-"
);
printf
(
"%-*s "
,
lht
->
groups_length
,
m
->
groups
?
m
->
groups
:
"-"
);
printf
(
"%-*s "
,
lht
->
ipv4_length
,
m
->
ipv4
?
m
->
ipv4
:
"-"
);
printf
(
"%-*s "
,
lht
->
ipv4_length
,
m
->
ipv4
?
m
->
ipv4
:
"-"
);
printf
(
"%-*s "
,
lht
->
ipv6_length
,
m
->
ipv6
?
m
->
ipv6
:
"-"
);
printf
(
"%-*s "
,
lht
->
ipv6_length
,
m
->
ipv6
?
m
->
ipv6
:
"-"
);
printf
(
"%-*s "
,
lht
->
unprivileged_length
,
m
->
unprivileged
?
"true"
:
"false"
);
printf
(
"
\n
"
);
printf
(
"
\n
"
);
}
}
}
}
...
@@ -1093,6 +1116,10 @@ static int ls_serialize(int wpipefd, struct ls *n)
...
@@ -1093,6 +1116,10 @@ static int ls_serialize(int wpipefd, struct ls *n)
if
(
lxc_write_nointr
(
wpipefd
,
&
n
->
running
,
(
size_t
)
nbytes
)
!=
nbytes
)
if
(
lxc_write_nointr
(
wpipefd
,
&
n
->
running
,
(
size_t
)
nbytes
)
!=
nbytes
)
return
-
1
;
return
-
1
;
nbytes
=
sizeof
(
n
->
unprivileged
);
if
(
lxc_write_nointr
(
wpipefd
,
&
n
->
unprivileged
,
(
size_t
)
nbytes
)
!=
nbytes
)
return
-
1
;
nbytes
=
sizeof
(
n
->
nestlvl
);
nbytes
=
sizeof
(
n
->
nestlvl
);
if
(
lxc_write_nointr
(
wpipefd
,
&
n
->
nestlvl
,
(
size_t
)
nbytes
)
!=
nbytes
)
if
(
lxc_write_nointr
(
wpipefd
,
&
n
->
nestlvl
,
(
size_t
)
nbytes
)
!=
nbytes
)
return
-
1
;
return
-
1
;
...
@@ -1176,6 +1203,10 @@ static int ls_deserialize(int rpipefd, struct ls **m, size_t *len)
...
@@ -1176,6 +1203,10 @@ static int ls_deserialize(int rpipefd, struct ls **m, size_t *len)
if
(
lxc_read_nointr
(
rpipefd
,
&
n
->
running
,
(
size_t
)
nbytes
)
!=
nbytes
)
if
(
lxc_read_nointr
(
rpipefd
,
&
n
->
running
,
(
size_t
)
nbytes
)
!=
nbytes
)
return
-
1
;
return
-
1
;
nbytes
=
sizeof
(
n
->
unprivileged
);
if
(
lxc_read_nointr
(
rpipefd
,
&
n
->
unprivileged
,
(
size_t
)
nbytes
)
!=
nbytes
)
return
-
1
;
nbytes
=
sizeof
(
n
->
nestlvl
);
nbytes
=
sizeof
(
n
->
nestlvl
);
if
(
lxc_read_nointr
(
rpipefd
,
&
n
->
nestlvl
,
(
size_t
)
nbytes
)
!=
nbytes
)
if
(
lxc_read_nointr
(
rpipefd
,
&
n
->
nestlvl
,
(
size_t
)
nbytes
)
!=
nbytes
)
return
-
1
;
return
-
1
;
...
...
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