tree-wide: fix list_entry()

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
This commit is contained in:
Christian Brauner 2021-08-30 13:52:51 +02:00
parent 1f7dd3d5a0
commit d696c45e73
No known key found for this signature in database
GPG Key ID: 8EB056D53EECB12D
4 changed files with 20 additions and 19 deletions

View File

@ -3569,7 +3569,7 @@ int lxc_map_ids(struct list_head *idmap, pid_t pid)
/* Check if we really need to use newuidmap and newgidmap.
* If the user is only remapping their own {g,u}id, we don't need it.
*/
if (use_shadow && list_len(idmap) == 2) {
if (use_shadow && list_len(map, idmap, head) == 2) {
use_shadow = false;
list_for_each_entry(map, idmap, head) {
if (map->idtype == ID_TYPE_UID && map->range == 1 &&

View File

@ -4029,7 +4029,7 @@ static int get_config_idmaps(const char *key, char *retv, int inlen,
else
memset(retv, 0, inlen);
listlen = list_len(&c->id_map);
listlen = list_len(map, &c->id_map, head);
list_for_each_entry(map, &c->id_map, head) {
ret = strnprintf(buf, sizeof(buf), "%c %lu %lu %lu",
(map->idtype == ID_TYPE_UID) ? 'u' : 'g',
@ -6293,7 +6293,7 @@ static int get_config_net_ipv4_address(const char *key, char *retv, int inlen,
else
memset(retv, 0, inlen);
listlen = list_len(&netdev->ipv4_addresses);
listlen = list_len(inetdev, &netdev->ipv4_addresses, head);
list_for_each_entry(inetdev, &netdev->ipv4_addresses, head) {
if (!inet_ntop(AF_INET, &inetdev->addr, buf, sizeof(buf)))
@ -6326,7 +6326,7 @@ static int get_config_net_veth_ipv4_route(const char *key, char *retv, int inlen
else
memset(retv, 0, inlen);
listlen = list_len(&netdev->priv.veth_attr.ipv4_routes);
listlen = list_len(inetdev, &netdev->priv.veth_attr.ipv4_routes, head);
list_for_each_entry(inetdev, &netdev->priv.veth_attr.ipv4_routes, head) {
if (!inet_ntop(AF_INET, &inetdev->addr, buf, sizeof(buf)))
return -errno;
@ -6384,7 +6384,7 @@ static int get_config_net_ipv6_address(const char *key, char *retv, int inlen,
else
memset(retv, 0, inlen);
listlen = list_len(&netdev->ipv6_addresses);
listlen = list_len(inet6dev, &netdev->ipv6_addresses, head);
list_for_each_entry(inet6dev, &netdev->ipv6_addresses, head) {
if (!inet_ntop(AF_INET6, &inet6dev->addr, buf, sizeof(buf)))
return -errno;
@ -6416,7 +6416,7 @@ static int get_config_net_veth_ipv6_route(const char *key, char *retv, int inlen
else
memset(retv, 0, inlen);
listlen = list_len(&netdev->priv.veth_attr.ipv6_routes);
listlen = list_len(inet6dev, &netdev->priv.veth_attr.ipv6_routes, head);
list_for_each_entry(inet6dev, &netdev->priv.veth_attr.ipv6_routes, head) {
if (!inet_ntop(AF_INET6, &inet6dev->addr, buf, sizeof(buf)))
return -errno;

View File

@ -169,6 +169,8 @@ static int exec_criu(struct cgroup_ops *cgroup_ops, struct lxc_conf *conf,
int static_args = 23, ret;
int netnr = 0;
struct mntent mntent;
struct lxc_netdev *netdev;
struct string_entry *strentry;
char buf[4096], ttys[32];
@ -232,7 +234,7 @@ static int exec_criu(struct cgroup_ops *cgroup_ops, struct lxc_conf *conf,
if (ttys[0])
static_args += 2;
static_args += list_len(&opts->c->lxc_conf->netdevs) * 2;
static_args += list_len(netdev, &opts->c->lxc_conf->netdevs, head) * 2;
} else {
return log_error_errno(-EINVAL, EINVAL, "Invalid criu operation specified");
}
@ -246,7 +248,7 @@ static int exec_criu(struct cgroup_ops *cgroup_ops, struct lxc_conf *conf,
if (opts->user->action_script)
static_args += 2;
static_args += 2 * list_len(&opts->c->lxc_conf->mount_entries);
static_args += 2 * list_len(strentry, &opts->c->lxc_conf->mount_entries, head);
ret = strnprintf(log, sizeof(log), "%s/%s.log", opts->user->directory, opts->action);
if (ret < 0)
@ -453,7 +455,6 @@ static int exec_criu(struct cgroup_ops *cgroup_ops, struct lxc_conf *conf,
DECLARE_ARG("--leave-running");
} else if (strequal(opts->action, "restore")) {
struct lxc_conf *lxc_conf = opts->c->lxc_conf;
struct lxc_netdev *netdev;
DECLARE_ARG("--root");
DECLARE_ARG(opts->c->lxc_conf->rootfs.mount);

View File

@ -961,15 +961,15 @@ static inline void hlist_move_list(struct hlist_head *old,
pos && ({ n = pos->member.next; 1; }); \
pos = hlist_entry_safe(n, typeof(*pos), member))
static inline size_t list_len(struct list_head *list)
{
size_t i = 0;
list_for_each(list, list) {
i++;
}
return i;
}
#define list_len(pos, head, member) \
({ \
size_t __list_len__ = 0; \
\
list_for_each_entry(pos, head, member) { \
(__list_len__)++; \
} \
\
__list_len__; \
})
#endif /* __LXC_HLIST_H */