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
f8f1069a
Unverified
Commit
f8f1069a
authored
Oct 22, 2018
by
Serge Hallyn
Committed by
GitHub
Oct 22, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2707 from brauner/2018-10-20/code_quality
tree-wide: bugfixes
parents
2a083985
6d61f17d
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
111 additions
and
132 deletions
+111
-132
netns_ifaddrs.c
src/include/netns_ifaddrs.c
+26
-35
cgfsng.c
src/lxc/cgroups/cgfsng.c
+2
-1
lxc_init.c
src/lxc/cmd/lxc_init.c
+4
-4
lxc_monitord.c
src/lxc/cmd/lxc_monitord.c
+11
-11
commands.c
src/lxc/commands.c
+7
-12
conf.c
src/lxc/conf.c
+7
-10
confile.c
src/lxc/confile.c
+10
-8
criu.c
src/lxc/criu.c
+1
-1
lxccontainer.c
src/lxc/lxccontainer.c
+1
-2
start.c
src/lxc/start.c
+2
-2
state.c
src/lxc/state.c
+0
-5
lxc_copy.c
src/lxc/tools/lxc_copy.c
+2
-2
lxc_info.c
src/lxc/tools/lxc_info.c
+8
-8
lxc_stop.c
src/lxc/tools/lxc_stop.c
+1
-2
lxc_top.c
src/lxc/tools/lxc_top.c
+29
-29
No files found.
src/include/netns_ifaddrs.c
View file @
f8f1069a
...
...
@@ -373,12 +373,7 @@ static int __ifaddrs_netlink_recv(int fd, unsigned int seq, int type, int af,
struct
nlmsghdr
*
h
),
void
*
ctx
)
{
char
getlink_buf
[
__NETLINK_ALIGN
(
sizeof
(
struct
nlmsghdr
))
+
__NETLINK_ALIGN
(
sizeof
(
struct
ifinfomsg
))
+
__NETLINK_ALIGN
(
1024
)];
char
getaddr_buf
[
__NETLINK_ALIGN
(
sizeof
(
struct
nlmsghdr
))
+
__NETLINK_ALIGN
(
sizeof
(
struct
ifaddrmsg
))
+
__NETLINK_ALIGN
(
1024
)];
int
r
,
property
,
ret
;
char
*
buf
;
struct
nlmsghdr
*
hdr
;
struct
ifinfomsg
*
ifi_msg
;
...
...
@@ -391,47 +386,43 @@ static int __ifaddrs_netlink_recv(int fd, unsigned int seq, int type, int af,
}
req
;
struct
nlmsghdr
reply
;
}
u
;
int
r
,
property
,
ret
;
if
(
type
==
RTM_GETLINK
)
buf
=
getlink_buf
;
else
if
(
type
==
RTM_GETADDR
)
buf
=
getaddr_buf
;
else
return
-
1
;
memset
(
buf
,
0
,
sizeof
(
*
buf
));
char
getlink_buf
[
__NETLINK_ALIGN
(
sizeof
(
struct
nlmsghdr
))
+
__NETLINK_ALIGN
(
sizeof
(
struct
ifinfomsg
))
+
__NETLINK_ALIGN
(
1024
)]
=
{
0
};
char
getaddr_buf
[
__NETLINK_ALIGN
(
sizeof
(
struct
nlmsghdr
))
+
__NETLINK_ALIGN
(
sizeof
(
struct
ifaddrmsg
))
+
__NETLINK_ALIGN
(
1024
)]
=
{
0
};
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wcast-align"
hdr
=
(
struct
nlmsghdr
*
)
buf
;
if
(
type
==
RTM_GETLINK
)
if
(
type
==
RTM_GETLINK
)
{
buf
=
getlink_buf
;
hdr
=
(
struct
nlmsghdr
*
)
buf
;
hdr
->
nlmsg_len
=
NLMSG_LENGTH
(
sizeof
(
*
ifi_msg
));
ifi_msg
=
(
struct
ifinfomsg
*
)
__NLMSG_DATA
(
hdr
);
else
ifa_msg
=
(
struct
ifaddrmsg
*
)
__NLMSG_DATA
(
hdr
);
ifi_msg
->
ifi_family
=
af
;
if
(
type
==
RTM_GETLINK
)
hdr
->
nlmsg_len
=
NLMSG_LENGTH
(
sizeof
(
*
ifi_msg
));
else
property
=
IFLA_TARGET_NETNSID
;
}
else
if
(
type
==
RTM_GETADDR
)
{
buf
=
getaddr_buf
;
hdr
=
(
struct
nlmsghdr
*
)
buf
;
hdr
->
nlmsg_len
=
NLMSG_LENGTH
(
sizeof
(
*
ifa_msg
));
ifa_msg
=
(
struct
ifaddrmsg
*
)
__NLMSG_DATA
(
hdr
);
ifa_msg
->
ifa_family
=
af
;
property
=
IFA_TARGET_NETNSID
;
}
else
{
errno
=
EINVAL
;
return
-
1
;
}
#pragma GCC diagnostic pop
hdr
->
nlmsg_type
=
type
;
hdr
->
nlmsg_flags
=
NLM_F_DUMP
|
NLM_F_REQUEST
;
hdr
->
nlmsg_pid
=
0
;
hdr
->
nlmsg_seq
=
seq
;
if
(
type
==
RTM_GETLINK
)
ifi_msg
->
ifi_family
=
af
;
else
ifa_msg
->
ifa_family
=
af
;
errno
=
EINVAL
;
if
(
type
==
RTM_GETLINK
)
property
=
IFLA_TARGET_NETNSID
;
else
if
(
type
==
RTM_GETADDR
)
property
=
IFA_TARGET_NETNSID
;
else
return
-
1
;
if
(
netns_id
>=
0
)
addattr
(
hdr
,
1024
,
property
,
&
netns_id
,
sizeof
(
netns_id
));
...
...
src/lxc/cgroups/cgfsng.c
View file @
f8f1069a
...
...
@@ -2133,7 +2133,8 @@ static int __cg_unified_attach(const struct hierarchy *h, const char *name,
if
(
errno
!=
EBUSY
)
goto
on_error
;
}
while
(
++
idx
>
0
&&
idx
<
1000
);
idx
++
;
}
while
(
idx
<
1000
);
on_success:
if
(
idx
<
1000
)
...
...
src/lxc/cmd/lxc_init.c
View file @
f8f1069a
...
...
@@ -182,17 +182,17 @@ static void kill_children(pid_t pid)
}
while
(
!
feof
(
f
))
{
pid_t
pid
;
pid_t
find_
pid
;
if
(
fscanf
(
f
,
"%d "
,
&
pid
)
!=
1
)
{
if
(
fscanf
(
f
,
"%d "
,
&
find_
pid
)
!=
1
)
{
if
(
my_args
.
quiet
)
fprintf
(
stderr
,
"Failed to retrieve pid
\n
"
);
fclose
(
f
);
return
;
}
kill_children
(
pid
);
kill
(
pid
,
SIGKILL
);
(
void
)
kill_children
(
find_
pid
);
(
void
)
kill
(
find_
pid
,
SIGKILL
);
}
fclose
(
f
);
...
...
src/lxc/cmd/lxc_monitord.c
View file @
f8f1069a
...
...
@@ -80,7 +80,7 @@ struct lxc_monitor {
struct
lxc_epoll_descr
descr
;
};
static
struct
lxc_monitor
mon
;
static
struct
lxc_monitor
mon
itor
;
static
int
quit
;
static
int
lxc_monitord_fifo_create
(
struct
lxc_monitor
*
mon
)
...
...
@@ -349,7 +349,7 @@ static int lxc_monitord_mainloop_add(struct lxc_monitor *mon)
static
void
lxc_monitord_cleanup
(
void
)
{
lxc_monitord_delete
(
&
mon
);
lxc_monitord_delete
(
&
mon
itor
);
}
static
void
lxc_monitord_sig_handler
(
int
sig
)
...
...
@@ -415,15 +415,15 @@ int main(int argc, char *argv[])
ret
=
EXIT_FAILURE
;
memset
(
&
mon
,
0
,
sizeof
(
mon
));
mon
.
lxcpath
=
lxcpath
;
if
(
lxc_mainloop_open
(
&
mon
.
descr
))
{
memset
(
&
mon
itor
,
0
,
sizeof
(
monitor
));
mon
itor
.
lxcpath
=
lxcpath
;
if
(
lxc_mainloop_open
(
&
mon
itor
.
descr
))
{
ERROR
(
"Failed to create mainloop"
);
goto
on_error
;
}
mainloop_opened
=
true
;
if
(
lxc_monitord_create
(
&
mon
))
if
(
lxc_monitord_create
(
&
mon
itor
))
goto
on_error
;
monitord_created
=
true
;
...
...
@@ -437,22 +437,22 @@ int main(int argc, char *argv[])
;
close
(
pipefd
);
if
(
lxc_monitord_mainloop_add
(
&
mon
))
{
if
(
lxc_monitord_mainloop_add
(
&
mon
itor
))
{
ERROR
(
"Failed to add mainloop handlers"
);
goto
on_error
;
}
NOTICE
(
"lxc-monitord with pid %d is now monitoring lxcpath %s"
,
lxc_raw_getpid
(),
mon
.
lxcpath
);
lxc_raw_getpid
(),
mon
itor
.
lxcpath
);
for
(;;)
{
ret
=
lxc_mainloop
(
&
mon
.
descr
,
1000
*
30
);
ret
=
lxc_mainloop
(
&
mon
itor
.
descr
,
1000
*
30
);
if
(
ret
)
{
ERROR
(
"mainloop returned an error"
);
break
;
}
if
(
mon
.
clientfds_cnt
<=
0
)
{
if
(
mon
itor
.
clientfds_cnt
<=
0
)
{
NOTICE
(
"No remaining clients. lxc-monitord is exiting"
);
break
;
}
...
...
@@ -471,7 +471,7 @@ on_error:
lxc_monitord_cleanup
();
if
(
mainloop_opened
)
lxc_mainloop_close
(
&
mon
.
descr
);
lxc_mainloop_close
(
&
mon
itor
.
descr
);
exit
(
ret
);
}
src/lxc/commands.c
View file @
f8f1069a
...
...
@@ -299,14 +299,9 @@ static int lxc_cmd(const char *name, struct lxc_cmd_rr *cmd, int *stopped,
SYSTRACE
(
"Command
\"
%s
\"
failed to connect command socket"
,
lxc_cmd_str
(
cmd
->
req
.
cmd
));
if
(
errno
==
ECONNREFUSED
)
if
(
errno
==
ECONNREFUSED
||
errno
==
EPIPE
)
*
stopped
=
1
;
if
(
errno
==
EPIPE
)
{
*
stopped
=
1
;
client_fd
=
0
;
}
return
-
1
;
}
...
...
@@ -314,12 +309,12 @@ static int lxc_cmd(const char *name, struct lxc_cmd_rr *cmd, int *stopped,
if
(
ret
<
0
&&
errno
==
ECONNRESET
)
*
stopped
=
1
;
if
(
!
stay_connected
||
ret
<=
0
)
if
(
client_fd
>=
0
)
{
saved_errno
=
errno
;
close
(
client_fd
)
;
errno
=
saved_errno
;
}
if
(
!
stay_connected
||
ret
<=
0
)
{
saved_errno
=
errno
;
close
(
client_fd
)
;
errno
=
saved_errno
;
return
ret
;
}
if
(
stay_connected
&&
ret
>
0
)
cmd
->
rsp
.
ret
=
client_fd
;
...
...
src/lxc/conf.c
View file @
f8f1069a
...
...
@@ -1494,15 +1494,16 @@ int lxc_chroot(const struct lxc_rootfs *rootfs)
*/
static
int
lxc_pivot_root
(
const
char
*
rootfs
)
{
int
newroot
=
-
1
,
oldroot
=
-
1
,
ret
=
-
1
;
int
oldroot
;
int
newroot
=
-
1
,
ret
=
-
1
;
oldroot
=
open
(
"/"
,
O_DIRECTORY
|
O_RDONLY
);
oldroot
=
open
(
"/"
,
O_DIRECTORY
|
O_RDONLY
|
O_CLOEXEC
);
if
(
oldroot
<
0
)
{
SYSERROR
(
"Failed to open old root directory"
);
return
-
1
;
}
newroot
=
open
(
rootfs
,
O_DIRECTORY
|
O_RDONLY
);
newroot
=
open
(
rootfs
,
O_DIRECTORY
|
O_RDONLY
|
O_CLOEXEC
);
if
(
newroot
<
0
)
{
SYSERROR
(
"Failed to open new root directory"
);
goto
on_error
;
...
...
@@ -1564,9 +1565,9 @@ static int lxc_pivot_root(const char *rootfs)
TRACE
(
"pivot_root(
\"
%s
\"
) successful"
,
rootfs
);
on_error:
if
(
oldroot
!=
-
1
)
close
(
oldroot
);
if
(
newroot
!=
-
1
)
close
(
oldroot
);
if
(
newroot
>=
0
)
close
(
newroot
);
return
ret
;
...
...
@@ -2419,10 +2420,6 @@ FILE *make_anonymous_mount_file(struct lxc_list *mount,
TRACE
(
"Created temporary mount file"
);
}
if
(
fd
<
0
)
{
SYSERROR
(
"Could not create temporary mount file"
);
return
NULL
;
}
lxc_list_for_each
(
iterator
,
mount
)
{
size_t
len
;
...
...
src/lxc/confile.c
View file @
f8f1069a
...
...
@@ -156,7 +156,7 @@ lxc_config_define(uts_name);
lxc_config_define
(
sysctl
);
lxc_config_define
(
proc
);
static
struct
lxc_config_t
config
[]
=
{
static
struct
lxc_config_t
config
_jump_table
[]
=
{
{
"lxc.arch"
,
set_config_personality
,
get_config_personality
,
clr_config_personality
,
},
{
"lxc.apparmor.profile"
,
set_config_apparmor_profile
,
get_config_apparmor_profile
,
clr_config_apparmor_profile
,
},
{
"lxc.apparmor.allow_incomplete"
,
set_config_apparmor_allow_incomplete
,
get_config_apparmor_allow_incomplete
,
clr_config_apparmor_allow_incomplete
,
},
...
...
@@ -246,15 +246,15 @@ static struct lxc_config_t config[] = {
{
"lxc.proc"
,
set_config_proc
,
get_config_proc
,
clr_config_proc
,
},
};
static
const
size_t
config_
size
=
sizeof
(
config
)
/
sizeof
(
struct
lxc_config_t
);
static
const
size_t
config_
jump_table_size
=
sizeof
(
config_jump_table
)
/
sizeof
(
struct
lxc_config_t
);
struct
lxc_config_t
*
lxc_get_config
(
const
char
*
key
)
{
size_t
i
;
for
(
i
=
0
;
i
<
config_size
;
i
++
)
if
(
!
strncmp
(
config
[
i
].
name
,
key
,
strlen
(
config
[
i
].
name
)))
return
&
config
[
i
];
for
(
i
=
0
;
i
<
config_
jump_table_
size
;
i
++
)
if
(
!
strncmp
(
config
_jump_table
[
i
].
name
,
key
,
strlen
(
config_jump_table
[
i
].
name
)))
return
&
config
_jump_table
[
i
];
return
NULL
;
}
...
...
@@ -3489,8 +3489,10 @@ static int get_config_hooks(const char *key, char *retv, int inlen,
return
-
1
;
subkey
=
strchr
(
subkey
+
1
,
'.'
);
if
(
!
subkey
)
return
-
1
;
subkey
++
;
if
(
!*
subkey
)
if
(
*
subkey
==
'\0'
)
return
-
1
;
for
(
i
=
0
;
i
<
NUM_LXC_HOOKS
;
i
++
)
{
...
...
@@ -5190,8 +5192,8 @@ int lxc_list_config_items(char *retv, int inlen)
else
memset
(
retv
,
0
,
inlen
);
for
(
i
=
0
;
i
<
config_size
;
i
++
)
{
char
*
s
=
config
[
i
].
name
;
for
(
i
=
0
;
i
<
config_
jump_table_
size
;
i
++
)
{
char
*
s
=
config
_jump_table
[
i
].
name
;
if
(
s
[
strlen
(
s
)
-
1
]
==
'.'
)
continue
;
...
...
src/lxc/criu.c
View file @
f8f1069a
...
...
@@ -695,7 +695,7 @@ bool __criu_check_feature(uint64_t *features_to_check)
return
false
;
}
while
(
current_bit
<
sizeof
(
uint64_t
)
*
8
)
{
while
(
current_bit
<
(
sizeof
(
uint64_t
)
*
8
-
1
)
)
{
/* only test requested features */
if
(
!
(
features
&
(
1ULL
<<
current_bit
)))
{
/* skip this */
...
...
src/lxc/lxccontainer.c
View file @
f8f1069a
...
...
@@ -1935,8 +1935,7 @@ static bool do_lxcapi_create(struct lxc_container *c, const char *t,
out_unlock
:
umask
(
mask
);
if
(
partial_fd
>=
0
)
remove_partial
(
c
,
partial_fd
);
remove_partial
(
c
,
partial_fd
);
out
:
if
(
!
ret
)
...
...
src/lxc/start.c
View file @
f8f1069a
...
...
@@ -1467,10 +1467,10 @@ int resolve_clone_flags(struct lxc_handler *handler)
struct
lxc_conf
*
conf
=
handler
->
conf
;
for
(
i
=
0
;
i
<
LXC_NS_MAX
;
i
++
)
{
if
(
conf
->
ns_keep
!=
0
)
{
if
(
conf
->
ns_keep
>
0
)
{
if
((
conf
->
ns_keep
&
ns_info
[
i
].
clone_flag
)
==
0
)
handler
->
ns_clone_flags
|=
ns_info
[
i
].
clone_flag
;
}
else
if
(
conf
->
ns_clone
!=
0
)
{
}
else
if
(
conf
->
ns_clone
>
0
)
{
if
((
conf
->
ns_clone
&
ns_info
[
i
].
clone_flag
)
>
0
)
handler
->
ns_clone_flags
|=
ns_info
[
i
].
clone_flag
;
}
else
{
...
...
src/lxc/state.c
View file @
f8f1069a
...
...
@@ -135,11 +135,6 @@ int lxc_wait(const char *lxcname, const char *states, int timeout,
(
void
)
nanosleep
(
&
onesec
,
NULL
);
}
if
(
state
<
0
)
{
ERROR
(
"Failed to retrieve state from monitor"
);
return
-
1
;
}
TRACE
(
"Retrieved state of container %s"
,
lxc_state2str
(
state
));
if
(
!
s
[
state
])
return
-
1
;
...
...
src/lxc/tools/lxc_copy.c
View file @
f8f1069a
...
...
@@ -87,7 +87,7 @@ static const struct option my_longopts[] = {
};
/* mount keys */
static
char
*
const
keys
[]
=
{
static
char
*
const
mount_
keys
[]
=
{
[
LXC_MNT_BIND
]
=
"bind"
,
[
LXC_MNT_OVL
]
=
"overlay"
,
NULL
...
...
@@ -568,7 +568,7 @@ static int my_parser(struct lxc_arguments *args, int c, char *arg)
break
;
case
'm'
:
subopts
=
optarg
;
if
(
parse_mntsubopts
(
subopts
,
keys
,
mntparameters
)
<
0
)
if
(
parse_mntsubopts
(
subopts
,
mount_
keys
,
mntparameters
)
<
0
)
return
-
1
;
break
;
case
'B'
:
...
...
src/lxc/tools/lxc_info.c
View file @
f8f1069a
...
...
@@ -48,7 +48,7 @@ static bool pid;
static
bool
stats
;
static
bool
humanize
=
true
;
static
char
**
key
=
NULL
;
static
int
keys
=
0
;
static
int
nr_
keys
=
0
;
static
int
filter_count
=
0
;
static
int
my_parser
(
struct
lxc_arguments
*
args
,
int
c
,
char
*
arg
)
...
...
@@ -57,13 +57,13 @@ static int my_parser(struct lxc_arguments *args, int c, char *arg)
switch
(
c
)
{
case
'c'
:
newk
=
realloc
(
key
,
(
keys
+
1
)
*
sizeof
(
key
[
0
]));
newk
=
realloc
(
key
,
(
nr_
keys
+
1
)
*
sizeof
(
key
[
0
]));
if
(
!
newk
)
return
-
1
;
key
=
newk
;
key
[
keys
]
=
arg
;
keys
++
;
key
[
nr_
keys
]
=
arg
;
nr_
keys
++
;
break
;
case
'i'
:
ips
=
true
;
filter_count
+=
1
;
break
;
case
's'
:
state
=
true
;
filter_count
+=
1
;
break
;
...
...
@@ -341,7 +341,7 @@ static int print_info(const char *name, const char *lxcpath)
return
-
1
;
}
if
(
!
state
&&
!
pid
&&
!
ips
&&
!
stats
&&
keys
<=
0
)
{
if
(
!
state
&&
!
pid
&&
!
ips
&&
!
stats
&&
nr_
keys
<=
0
)
{
state
=
pid
=
ips
=
stats
=
true
;
print_info_msg_str
(
"Name:"
,
c
->
name
);
}
...
...
@@ -380,7 +380,7 @@ static int print_info(const char *name, const char *lxcpath)
print_net_stats
(
c
);
}
for
(
i
=
0
;
i
<
keys
;
i
++
)
{
for
(
i
=
0
;
i
<
nr_
keys
;
i
++
)
{
int
len
=
c
->
get_config_item
(
c
,
key
[
i
],
NULL
,
0
);
if
(
len
>
0
)
{
...
...
@@ -389,7 +389,7 @@ static int print_info(const char *name, const char *lxcpath)
if
(
c
->
get_config_item
(
c
,
key
[
i
],
val
,
len
+
1
)
!=
len
)
{
fprintf
(
stderr
,
"unable to read %s from configuration
\n
"
,
key
[
i
]);
}
else
{
if
(
!
humanize
&&
keys
==
1
)
if
(
!
humanize
&&
nr_
keys
==
1
)
printf
(
"%s
\n
"
,
val
);
else
printf
(
"%s = %s
\n
"
,
key
[
i
],
val
);
...
...
@@ -397,7 +397,7 @@ static int print_info(const char *name, const char *lxcpath)
free
(
val
);
}
else
if
(
len
==
0
)
{
if
(
!
humanize
&&
keys
==
1
)
if
(
!
humanize
&&
nr_
keys
==
1
)
printf
(
"
\n
"
);
else
printf
(
"%s =
\n
"
,
key
[
i
]);
...
...
src/lxc/tools/lxc_stop.c
View file @
f8f1069a
...
...
@@ -205,8 +205,7 @@ int main(int argc, char *argv[])
/* reboot */
if
(
my_args
.
reboot
)
{
ret
=
c
->
reboot2
(
c
,
my_args
.
timeout
);
if
(
ret
<
0
)
if
(
!
c
->
reboot2
(
c
,
my_args
.
timeout
))
ret
=
EXIT_FAILURE
;
else
ret
=
EXIT_SUCCESS
;
...
...
src/lxc/tools/lxc_top.c
View file @
f8f1069a
...
...
@@ -73,7 +73,7 @@ struct stats {
struct
blkio_stats
io_serviced
;
};
struct
c
t
{
struct
c
ontainer_stats
{
struct
lxc_container
*
c
;
struct
stats
*
stats
;
};
...
...
@@ -84,7 +84,7 @@ static int delay = 3;
static
char
sort_by
=
'n'
;
static
int
sort_reverse
=
0
;
static
struct
termios
oldtios
;
static
struct
c
t
*
ct
=
NULL
;
static
struct
c
ontainer_stats
*
container_stats
=
NULL
;
static
int
ct_alloc_cnt
=
0
;
static
int
my_parser
(
struct
lxc_arguments
*
args
,
int
c
,
char
*
arg
)
...
...
@@ -336,7 +336,7 @@ out:
return
;
}
static
void
stats_get
(
struct
lxc_container
*
c
,
struct
c
t
*
ct
,
struct
stats
*
total
)
static
void
stats_get
(
struct
lxc_container
*
c
,
struct
c
ontainer_stats
*
ct
,
struct
stats
*
total
)
{
ct
->
c
=
c
;
ct
->
stats
->
mem_used
=
stat_get_int
(
c
,
"memory.usage_in_bytes"
);
...
...
@@ -448,8 +448,8 @@ static void stats_print(const char *name, const struct stats *stats,
static
int
cmp_name
(
const
void
*
sct1
,
const
void
*
sct2
)
{
const
struct
c
t
*
ct1
=
sct1
;
const
struct
c
t
*
ct2
=
sct2
;
const
struct
c
ontainer_stats
*
ct1
=
sct1
;
const
struct
c
ontainer_stats
*
ct2
=
sct2
;
if
(
sort_reverse
)
return
strncmp
(
ct2
->
c
->
name
,
ct1
->
c
->
name
,
strlen
(
ct2
->
c
->
name
));
...
...
@@ -459,8 +459,8 @@ static int cmp_name(const void *sct1, const void *sct2)
static
int
cmp_cpuuse
(
const
void
*
sct1
,
const
void
*
sct2
)
{
const
struct
c
t
*
ct1
=
sct1
;
const
struct
c
t
*
ct2
=
sct2
;
const
struct
c
ontainer_stats
*
ct1
=
sct1
;
const
struct
c
ontainer_stats
*
ct2
=
sct2
;
if
(
sort_reverse
)
return
ct2
->
stats
->
cpu_use_nanos
<
ct1
->
stats
->
cpu_use_nanos
;
...
...
@@ -470,8 +470,8 @@ static int cmp_cpuuse(const void *sct1, const void *sct2)
static
int
cmp_blkio
(
const
void
*
sct1
,
const
void
*
sct2
)
{
const
struct
c
t
*
ct1
=
sct1
;
const
struct
c
t
*
ct2
=
sct2
;
const
struct
c
ontainer_stats
*
ct1
=
sct1
;
const
struct
c
ontainer_stats
*
ct2
=
sct2
;
if
(
sort_reverse
)
return
ct2
->
stats
->
io_service_bytes
.
total
<
ct1
->
stats
->
io_service_bytes
.
total
;
...
...
@@ -481,8 +481,8 @@ static int cmp_blkio(const void *sct1, const void *sct2)
static
int
cmp_memory
(
const
void
*
sct1
,
const
void
*
sct2
)
{
const
struct
c
t
*
ct1
=
sct1
;
const
struct
c
t
*
ct2
=
sct2
;
const
struct
c
ontainer_stats
*
ct1
=
sct1
;
const
struct
c
ontainer_stats
*
ct2
=
sct2
;
if
(
sort_reverse
)
return
ct2
->
stats
->
mem_used
<
ct1
->
stats
->
mem_used
;
...
...
@@ -492,8 +492,8 @@ static int cmp_memory(const void *sct1, const void *sct2)
static
int
cmp_memorysw
(
const
void
*
sct1
,
const
void
*
sct2
)
{
const
struct
c
t
*
ct1
=
sct1
;
const
struct
c
t
*
ct2
=
sct2
;
const
struct
c
ontainer_stats
*
ct1
=
sct1
;
const
struct
c
ontainer_stats
*
ct2
=
sct2
;
if
(
sort_reverse
)
return
ct2
->
stats
->
memsw_used
<
ct1
->
stats
->
memsw_used
;
...
...
@@ -503,8 +503,8 @@ static int cmp_memorysw(const void *sct1, const void *sct2)
static
int
cmp_kmemory
(
const
void
*
sct1
,
const
void
*
sct2
)
{
const
struct
c
t
*
ct1
=
sct1
;
const
struct
c
t
*
ct2
=
sct2
;
const
struct
c
ontainer_stats
*
ct1
=
sct1
;
const
struct
c
ontainer_stats
*
ct2
=
sct2
;
if
(
sort_reverse
)
return
ct2
->
stats
->
kmem_used
<
ct1
->
stats
->
kmem_used
;
...
...
@@ -526,7 +526,7 @@ static void ct_sort(int active)
case
'k'
:
cmp_func
=
cmp_kmemory
;
break
;
}
qsort
(
c
t
,
active
,
sizeof
(
*
ct
),
(
int
(
*
)(
const
void
*
,
const
void
*
))
cmp_func
);
qsort
(
c
ontainer_stats
,
active
,
sizeof
(
*
container_stats
),
(
int
(
*
)(
const
void
*
,
const
void
*
))
cmp_func
);
}
static
void
ct_free
(
void
)
...
...
@@ -534,13 +534,13 @@ static void ct_free(void)
int
i
;
for
(
i
=
0
;
i
<
ct_alloc_cnt
;
i
++
)
{
if
(
c
t
[
i
].
c
)
{
lxc_container_put
(
c
t
[
i
].
c
);
c
t
[
i
].
c
=
NULL
;
if
(
c
ontainer_stats
[
i
].
c
)
{
lxc_container_put
(
c
ontainer_stats
[
i
].
c
);
c
ontainer_stats
[
i
].
c
=
NULL
;
}
free
(
c
t
[
i
].
stats
);
c
t
[
i
].
stats
=
NULL
;
free
(
c
ontainer_stats
[
i
].
stats
);
c
ontainer_stats
[
i
].
stats
=
NULL
;
}
}
...
...
@@ -551,15 +551,15 @@ static void ct_realloc(int active_cnt)
ct_free
();
c
t
=
realloc
(
ct
,
sizeof
(
*
ct
)
*
active_cnt
);
if
(
!
c
t
)
{
c
ontainer_stats
=
realloc
(
container_stats
,
sizeof
(
*
container_stats
)
*
active_cnt
);
if
(
!
c
ontainer_stats
)
{
fprintf
(
stderr
,
"Cannot alloc mem
\n
"
);
exit
(
EXIT_FAILURE
);
}
for
(
i
=
0
;
i
<
active_cnt
;
i
++
)
{
c
t
[
i
].
stats
=
malloc
(
sizeof
(
*
ct
[
0
].
stats
));
if
(
!
c
t
[
i
].
stats
)
{
c
ontainer_stats
[
i
].
stats
=
malloc
(
sizeof
(
*
container_stats
[
0
].
stats
));
if
(
!
c
ontainer_stats
[
i
].
stats
)
{
fprintf
(
stderr
,
"Cannot alloc mem
\n
"
);
exit
(
EXIT_FAILURE
);
}
...
...
@@ -640,7 +640,7 @@ int main(int argc, char *argv[])
memset
(
&
total
,
0
,
sizeof
(
total
));
for
(
i
=
0
;
i
<
active_cnt
;
i
++
)
stats_get
(
active
[
i
],
&
c
t
[
i
],
&
total
);
stats_get
(
active
[
i
],
&
c
ontainer_stats
[
i
],
&
total
);
ct_sort
(
active_cnt
);
...
...
@@ -650,7 +650,7 @@ int main(int argc, char *argv[])
}
for
(
i
=
0
;
i
<
active_cnt
&&
i
<
ct_print_cnt
;
i
++
)
{
stats_print
(
c
t
[
i
].
c
->
name
,
ct
[
i
].
stats
,
&
total
);
stats_print
(
c
ontainer_stats
[
i
].
c
->
name
,
container_stats
[
i
].
stats
,
&
total
);
printf
(
"
\n
"
);
}
...
...
@@ -661,8 +661,8 @@ int main(int argc, char *argv[])
fflush
(
stdout
);
for
(
i
=
0
;
i
<
active_cnt
;
i
++
)
{
lxc_container_put
(
c
t
[
i
].
c
);
c
t
[
i
].
c
=
NULL
;
lxc_container_put
(
c
ontainer_stats
[
i
].
c
);
c
ontainer_stats
[
i
].
c
=
NULL
;
}
in_char
=
'\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