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
72c94ff9
Unverified
Commit
72c94ff9
authored
Dec 16, 2017
by
Christian Brauner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tools: add UNPRIVILEGED field in fancy output mode
Signed-off-by:
Christian Brauner
<
christian.brauner@ubuntu.com
>
parent
e4446530
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 @
72c94ff9
...
...
@@ -71,6 +71,7 @@ struct ls {
double
swap
;
bool
autostart
;
bool
running
;
bool
unprivileged
;
};
/* Keep track of field widths for printing. */
...
...
@@ -85,6 +86,7 @@ struct lengths {
unsigned
int
ram_length
;
unsigned
int
swap_length
;
unsigned
int
autostart_length
;
unsigned
int
unprivileged_length
;
};
static
int
ls_deserialize
(
int
rpipefd
,
struct
ls
**
m
,
size_t
*
len
);
...
...
@@ -187,7 +189,7 @@ Options :\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
\
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
\
--running list only running containers
\n
\
--frozen list only frozen containers
\n
\
...
...
@@ -236,16 +238,17 @@ int main(int argc, char *argv[])
struct
lengths
max_len
=
{
/* default header length */
.
name_length
=
4
,
/* NAME */
.
state_length
=
5
,
/* STATE */
.
groups_length
=
6
,
/* GROUPS */
.
interface_length
=
9
,
/* INTERFACE */
.
ipv4_length
=
4
,
/* IPV4 */
.
ipv6_length
=
4
,
/* IPV6 */
.
init_length
=
3
,
/* PID */
.
ram_length
=
3
,
/* RAM */
.
swap_length
=
4
,
/* SWAP */
.
autostart_length
=
9
,
/* AUTOSTART */
.
name_length
=
4
,
/* NAME */
.
state_length
=
5
,
/* STATE */
.
groups_length
=
6
,
/* GROUPS */
.
interface_length
=
9
,
/* INTERFACE */
.
ipv4_length
=
4
,
/* IPV4 */
.
ipv6_length
=
4
,
/* IPV6 */
.
init_length
=
3
,
/* PID */
.
ram_length
=
3
,
/* RAM */
.
swap_length
=
4
,
/* SWAP */
.
autostart_length
=
9
,
/* AUTOSTART */
.
unprivileged_length
=
12
,
/* UNPRIVILEGED */
};
char
**
grps
=
NULL
;
...
...
@@ -481,7 +484,11 @@ static int ls_get(struct ls **m, size_t *size, const struct lxc_arguments *args,
free
(
tmp
);
if
(
running
)
{
char
*
val
;
l
->
init
=
c
->
init_pid
(
c
);
if
(
l
->
init
<=
0
)
goto
put_and_next
;
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,
}
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,
/* Check for invalid keys. */
for
(
s
=
tmp
;
s
&&
*
s
;
s
++
)
{
if
(
strcasecmp
(
*
s
,
"NAME"
)
&&
strcasecmp
(
*
s
,
"STATE"
)
&&
strcasecmp
(
*
s
,
"PID"
)
&&
strcasecmp
(
*
s
,
"RAM"
)
&&
strcasecmp
(
*
s
,
"SWAP"
)
&&
strcasecmp
(
*
s
,
"AUTOSTART"
)
&&
strcasecmp
(
*
s
,
"GROUPS"
)
&&
strcasecmp
(
*
s
,
"INTERFACE"
)
&&
strcasecmp
(
*
s
,
"IPV4"
)
&&
strcasecmp
(
*
s
,
"IPV6"
))
{
strcasecmp
(
*
s
,
"PID"
)
&&
strcasecmp
(
*
s
,
"RAM"
)
&&
strcasecmp
(
*
s
,
"SWAP"
)
&&
strcasecmp
(
*
s
,
"AUTOSTART"
)
&&
strcasecmp
(
*
s
,
"GROUPS"
)
&&
strcasecmp
(
*
s
,
"INTERFACE"
)
&&
strcasecmp
(
*
s
,
"IPV4"
)
&&
strcasecmp
(
*
s
,
"IPV6"
)
&&
strcasecmp
(
*
s
,
"UNPRIVILEGED"
))
{
fprintf
(
stderr
,
"Invalid key: %s
\n
"
,
*
s
);
return
;
}
...
...
@@ -844,6 +861,8 @@ static void ls_print_fancy_format(struct ls *l, struct lengths *lht,
printf
(
"%-*s "
,
lht
->
ipv4_length
,
"IPV4"
);
else
if
(
strcasecmp
(
*
s
,
"IPV6"
)
==
0
)
printf
(
"%-*s "
,
lht
->
ipv6_length
,
"IPV6"
);
else
if
(
strcasecmp
(
*
s
,
"UNPRIVILEGED"
)
==
0
)
printf
(
"%-*s "
,
lht
->
unprivileged_length
,
"UNPRIVILEGED"
);
}
printf
(
"
\n
"
);
...
...
@@ -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
:
"-"
);
}
else
if
(
strcasecmp
(
*
s
,
"IPV6"
)
==
0
)
{
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
"
);
...
...
@@ -907,6 +928,7 @@ static void ls_print_table(struct ls *l, struct lengths *lht,
printf
(
"%-*s "
,
lht
->
groups_length
,
"GROUPS"
);
printf
(
"%-*s "
,
lht
->
ipv4_length
,
"IPV4"
);
printf
(
"%-*s "
,
lht
->
ipv6_length
,
"IPV6"
);
printf
(
"%-*s "
,
lht
->
unprivileged_length
,
"UNPRIVILEGED"
);
printf
(
"
\n
"
);
size_t
i
;
...
...
@@ -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
->
ipv4_length
,
m
->
ipv4
?
m
->
ipv4
:
"-"
);
printf
(
"%-*s "
,
lht
->
ipv6_length
,
m
->
ipv6
?
m
->
ipv6
:
"-"
);
printf
(
"%-*s "
,
lht
->
unprivileged_length
,
m
->
unprivileged
?
"true"
:
"false"
);
printf
(
"
\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
)
return
-
1
;
nbytes
=
sizeof
(
n
->
unprivileged
);
if
(
lxc_write_nointr
(
wpipefd
,
&
n
->
unprivileged
,
(
size_t
)
nbytes
)
!=
nbytes
)
return
-
1
;
nbytes
=
sizeof
(
n
->
nestlvl
);
if
(
lxc_write_nointr
(
wpipefd
,
&
n
->
nestlvl
,
(
size_t
)
nbytes
)
!=
nbytes
)
return
-
1
;
...
...
@@ -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
)
return
-
1
;
nbytes
=
sizeof
(
n
->
unprivileged
);
if
(
lxc_read_nointr
(
rpipefd
,
&
n
->
unprivileged
,
(
size_t
)
nbytes
)
!=
nbytes
)
return
-
1
;
nbytes
=
sizeof
(
n
->
nestlvl
);
if
(
lxc_read_nointr
(
rpipefd
,
&
n
->
nestlvl
,
(
size_t
)
nbytes
)
!=
nbytes
)
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