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
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
2 deletions
+33
-2
lxc_ls.c
src/lxc/tools/lxc_ls.c
+33
-2
No files found.
src/lxc/tools/lxc_ls.c
View file @
72c94ff9
...
@@ -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
\
...
@@ -246,6 +248,7 @@ int main(int argc, char *argv[])
...
@@ -246,6 +248,7 @@ int main(int argc, char *argv[])
.
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
);
}
}
}
}
...
@@ -816,7 +832,8 @@ static void ls_print_fancy_format(struct ls *l, struct lengths *lht,
...
@@ -816,7 +832,8 @@ static void ls_print_fancy_format(struct ls *l, struct lengths *lht,
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