The following pull request was submitted through Github.
It can be accessed and reviewed at: https://github.com/lxc/lxc/pull/3216

This e-mail was sent by the LXC bot, direct replies will not reach the author
unless they happen to be subscribed to this list.

=== Description (from pull-request) ===
Signed-off-by: Christian Brauner <christian.brau...@ubuntu.com>
From 2b0c584613bcc75c25f0491c4622fa9169196959 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brau...@ubuntu.com>
Date: Sat, 7 Dec 2019 17:21:18 +0100
Subject: [PATCH 01/19] log: rearrange

Signed-off-by: Christian Brauner <christian.brau...@ubuntu.com>
---
 src/lxc/log.h | 32 ++++++++++++++++++++------------
 1 file changed, 20 insertions(+), 12 deletions(-)

diff --git a/src/lxc/log.h b/src/lxc/log.h
index 951eaba318..553bc2a120 100644
--- a/src/lxc/log.h
+++ b/src/lxc/log.h
@@ -491,12 +491,6 @@ ATTR_UNUSED static inline void LXC_##LEVEL(struct 
lxc_log_locinfo* locinfo,        \
                -1;                              \
        })
 
-#define log_trace(__ret__, format, ...)              \
-       ({                                    \
-               TRACE(format, ##__VA_ARGS__); \
-               __ret__;                      \
-       })
-
 #define log_error_errno(__ret__, __errno__, format, ...) \
        ({                                               \
                errno = __errno__;                       \
@@ -510,6 +504,19 @@ ATTR_UNUSED static inline void LXC_##LEVEL(struct 
lxc_log_locinfo* locinfo,        \
                __ret__;                      \
        })
 
+#define log_trace_errno(__ret__, __errno__, format, ...) \
+       ({                                               \
+               errno = __errno__;                       \
+               SYSTRACE(format, ##__VA_ARGS__);         \
+               __ret__;                                 \
+       })
+
+#define log_trace(__ret__, format, ...)              \
+       ({                                    \
+               TRACE(format, ##__VA_ARGS__); \
+               __ret__;                      \
+       })
+
 #define log_warn_errno(__ret__, __errno__, format, ...) \
        ({                                              \
                errno = __errno__;                      \
@@ -517,18 +524,19 @@ ATTR_UNUSED static inline void LXC_##LEVEL(struct 
lxc_log_locinfo* locinfo,       \
                __ret__;                                \
        })
 
-#define log_debug(__ret__, format, ...)              \
-       ({                                    \
-               DEBUG(format, ##__VA_ARGS__); \
-               __ret__;                      \
-       })
-
 #define log_debug_errno(__ret__, __errno__, format, ...) \
        ({                                               \
+               errno = __errno__;                      \
                SYSDEBUG(format, ##__VA_ARGS__);         \
                __ret__;                                 \
        })
 
+#define log_debug(__ret__, format, ...)              \
+       ({                                    \
+               DEBUG(format, ##__VA_ARGS__); \
+               __ret__;                      \
+       })
+
 extern int lxc_log_fd;
 
 extern int lxc_log_syslog(int facility);

From 9958e6fe7f69871a8452cebf48e9e8da019fa6a0 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brau...@ubuntu.com>
Date: Sat, 7 Dec 2019 17:21:53 +0100
Subject: [PATCH 02/19] macro: add ret_errno()

Signed-off-by: Christian Brauner <christian.brau...@ubuntu.com>
---
 src/lxc/macro.h | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/src/lxc/macro.h b/src/lxc/macro.h
index e011596d21..b4c9f4e7c6 100644
--- a/src/lxc/macro.h
+++ b/src/lxc/macro.h
@@ -454,6 +454,12 @@ enum {
                __ret__;                  \
        })
 
+#define ret_errno(__errno__)       \
+       ({                         \
+               errno = __errno__; \
+               -__errno__;        \
+       })
+
 #define free_replace_move_ptr(a, b) \
        ({                          \
                free(a);            \

From db1b8b0f5ef3d24760587a1a56b7ea0fa5c0c712 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brau...@ubuntu.com>
Date: Sat, 7 Dec 2019 17:22:14 +0100
Subject: [PATCH 03/19] af_unix: s/minus_one_set_errno(/ret_set_errno(-1, /g

Signed-off-by: Christian Brauner <christian.brau...@ubuntu.com>
---
 src/lxc/af_unix.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/lxc/af_unix.c b/src/lxc/af_unix.c
index 061d1c3176..7f8c88b1a2 100644
--- a/src/lxc/af_unix.c
+++ b/src/lxc/af_unix.c
@@ -335,14 +335,14 @@ int lxc_unix_sockaddr(struct sockaddr_un *ret, const char 
*path)
 
        len = strlen(path);
        if (len == 0)
-               return minus_one_set_errno(EINVAL);
+               return ret_set_errno(-1, EINVAL);
        if (path[0] != '/' && path[0] != '@')
-               return minus_one_set_errno(EINVAL);
+               return ret_set_errno(-1, EINVAL);
        if (path[1] == '\0')
-               return minus_one_set_errno(EINVAL);
+               return ret_set_errno(-1, EINVAL);
 
        if (len + 1 > sizeof(ret->sun_path))
-               return minus_one_set_errno(EINVAL);
+               return ret_set_errno(-1, EINVAL);
 
        *ret = (struct sockaddr_un){
            .sun_family = AF_UNIX,

From 540a2f7092605c586ad1f1c8e4231c3a53655099 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brau...@ubuntu.com>
Date: Sat, 7 Dec 2019 17:22:53 +0100
Subject: [PATCH 04/19] attach: s/minus_one_set_errno(/ret_set_errno(-1, /g

Signed-off-by: Christian Brauner <christian.brau...@ubuntu.com>
---
 src/lxc/attach.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/lxc/attach.c b/src/lxc/attach.c
index 7976d464ce..3dd56ccb3a 100644
--- a/src/lxc/attach.c
+++ b/src/lxc/attach.c
@@ -1009,10 +1009,10 @@ int lxc_attach(struct lxc_container *container, 
lxc_attach_exec_t exec_function,
        }
 
        if (!container)
-               return minus_one_set_errno(EINVAL);
+               return ret_set_errno(-1, EINVAL);
 
        if (!lxc_container_get(container))
-               return minus_one_set_errno(EINVAL);
+               return ret_set_errno(-1, EINVAL);
 
        name = container->name;
        lxcpath = container->config_path;

From 3d0327ed245ff14e8a33659ec82ef13b6b54fc55 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brau...@ubuntu.com>
Date: Sat, 7 Dec 2019 17:23:24 +0100
Subject: [PATCH 05/19] commands: replace logging helpers

s/error_log_errno(/log_error_errno(-1, /g
s/minus_one_set_errno(/ret_set_errno(-1, /g

Signed-off-by: Christian Brauner <christian.brau...@ubuntu.com>
---
 src/lxc/commands.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/src/lxc/commands.c b/src/lxc/commands.c
index 9bbc206096..c46a4106d5 100644
--- a/src/lxc/commands.c
+++ b/src/lxc/commands.c
@@ -913,16 +913,16 @@ int lxc_cmd_add_bpf_device_cgroup(const char *name, const 
char *lxcpath,
        int ret;
 
        if (strlen(device->access) > STRLITERALLEN("rwm"))
-               return error_log_errno(EINVAL, "Invalid access mode specified 
%s",
+               return log_error_errno(-1, EINVAL, "Invalid access mode 
specified %s",
                                       device->access);
 
        ret = lxc_cmd(name, &cmd, &stopped, lxcpath, NULL);
        if (ret < 0 || cmd.rsp.ret < 0)
-               return error_log_errno(errno, "Failed to add new bpf device 
cgroup rule");
+               return log_error_errno(-1, errno, "Failed to add new bpf device 
cgroup rule");
 
        return 0;
 #else
-       return minus_one_set_errno(ENOSYS);
+       return ret_set_errno(-1, ENOSYS);
 #endif
 }
 
@@ -1006,7 +1006,7 @@ static int lxc_cmd_add_bpf_device_cgroup_callback(int fd, 
struct lxc_cmd_req *re
         */
        return 1;
 #else
-       return minus_one_set_errno(ENOSYS);
+       return ret_set_errno(-1, ENOSYS);
 #endif
 }
 
@@ -1155,7 +1155,7 @@ int lxc_cmd_seccomp_notify_add_listener(const char *name, 
const char *lxcpath,
 
        return cmd.rsp.ret;
 #else
-       return minus_one_set_errno(ENOSYS);
+       return ret_set_errno(-1, ENOSYS);
 #endif
 }
 
@@ -1211,7 +1211,7 @@ int lxc_cmd_freeze(const char *name, const char *lxcpath, 
int timeout)
 
        ret = lxc_cmd(name, &cmd, &stopped, lxcpath, NULL);
        if (ret <= 0 || cmd.rsp.ret < 0)
-               return error_log_errno(errno, "Failed to freeze container");
+               return log_error_errno(-1, errno, "Failed to freeze container");
 
        return cmd.rsp.ret;
 }
@@ -1244,7 +1244,7 @@ int lxc_cmd_unfreeze(const char *name, const char 
*lxcpath, int timeout)
 
        ret = lxc_cmd(name, &cmd, &stopped, lxcpath, NULL);
        if (ret <= 0 || cmd.rsp.ret < 0)
-               return error_log_errno(errno, "Failed to unfreeze container");
+               return log_error_errno(-1, errno, "Failed to unfreeze 
container");
 
        return cmd.rsp.ret;
 }

From 596a002c6846cc977c45e0fff595ed58278169b0 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brau...@ubuntu.com>
Date: Sat, 7 Dec 2019 17:24:29 +0100
Subject: [PATCH 06/19] network: replace logging helpers

s/error_log_errno(/log_error_errno(-1, /g
s/minus_one_set_errno(/ret_set_errno(-1, /g

Signed-off-by: Christian Brauner <christian.brau...@ubuntu.com>
---
 src/lxc/network.c | 88 +++++++++++++++++++++++------------------------
 1 file changed, 44 insertions(+), 44 deletions(-)

diff --git a/src/lxc/network.c b/src/lxc/network.c
index 9faa2e6a93..65eca60e83 100644
--- a/src/lxc/network.c
+++ b/src/lxc/network.c
@@ -131,7 +131,7 @@ static int lxc_setup_ipv4_routes(struct lxc_list *ip, int 
ifindex)
                if (err) {
                        SYSERROR("Failed to setup ipv4 route for network device 
"
                                 "with ifindex %d", ifindex);
-                       return minus_one_set_errno(-err);
+                       return ret_set_errno(-1, -err);
                }
        }
 
@@ -150,7 +150,7 @@ static int lxc_setup_ipv6_routes(struct lxc_list *ip, int 
ifindex)
                if (err) {
                        SYSERROR("Failed to setup ipv6 route for network device 
"
                                 "with ifindex %d", ifindex);
-                       return minus_one_set_errno(-err);
+                       return ret_set_errno(-1, -err);
                }
        }
 
@@ -168,7 +168,7 @@ static int setup_ipv4_addr_routes(struct lxc_list *ip, int 
ifindex)
                err = lxc_ipv4_dest_add(ifindex, &inetdev->addr, 32);
 
                if (err)
-                       return error_log_errno(err,
+                       return log_error_errno(-1, err,
                                "Failed to setup ipv4 address route for network 
device with eifindex %d",
                                ifindex);
        }
@@ -186,7 +186,7 @@ static int setup_ipv6_addr_routes(struct lxc_list *ip, int 
ifindex)
 
                err = lxc_ipv6_dest_add(ifindex, &inet6dev->addr, 128);
                if (err)
-                       return error_log_errno(err,
+                       return log_error_errno(-1, err,
                                "Failed to setup ipv6 address route for network 
device with eifindex %d",
                                ifindex);
        }
@@ -258,13 +258,13 @@ static int lxc_is_ip_forwarding_enabled(const char 
*ifname, int family)
        char buf[1] = "";
 
        if (family != AF_INET && family != AF_INET6)
-               return minus_one_set_errno(EINVAL);
+               return ret_set_errno(-1, EINVAL);
 
        ret = snprintf(path, PATH_MAX, "/proc/sys/net/%s/conf/%s/%s",
                       family == AF_INET ? "ipv4" : "ipv6", ifname,
                       "forwarding");
        if (ret < 0 || (size_t)ret >= PATH_MAX)
-               return minus_one_set_errno(E2BIG);
+               return ret_set_errno(-1, E2BIG);
 
        return lxc_read_file_expect(path, buf, 1, "1");
 }
@@ -401,19 +401,19 @@ static int instantiate_veth(struct lxc_handler *handler, 
struct lxc_netdev *netd
                if (netdev->ipv4_gateway) {
                        char bufinet4[INET_ADDRSTRLEN];
                        if (!inet_ntop(AF_INET, netdev->ipv4_gateway, bufinet4, 
sizeof(bufinet4))) {
-                               error_log_errno(-errno, "Failed to convert 
gateway ipv4 address on \"%s\"", veth1);
+                               log_error_errno(-1, -errno, "Failed to convert 
gateway ipv4 address on \"%s\"", veth1);
                                goto out_delete;
                        }
 
                        err = lxc_ip_forwarding_on(veth1, AF_INET);
                        if (err) {
-                               error_log_errno(err, "Failed to activate ipv4 
forwarding on \"%s\"", veth1);
+                               log_error_errno(-1, err, "Failed to activate 
ipv4 forwarding on \"%s\"", veth1);
                                goto out_delete;
                        }
 
                        err = lxc_add_ip_neigh_proxy(bufinet4, veth1);
                        if (err) {
-                               error_log_errno(err, "Failed to add gateway 
ipv4 proxy on \"%s\"", veth1);
+                               log_error_errno(-1, err, "Failed to add gateway 
ipv4 proxy on \"%s\"", veth1);
                                goto out_delete;
                        }
                }
@@ -422,7 +422,7 @@ static int instantiate_veth(struct lxc_handler *handler, 
struct lxc_netdev *netd
                        char bufinet6[INET6_ADDRSTRLEN];
 
                        if (!inet_ntop(AF_INET6, netdev->ipv6_gateway, 
bufinet6, sizeof(bufinet6))) {
-                               error_log_errno(-errno, "Failed to convert 
gateway ipv6 address on \"%s\"", veth1);
+                               log_error_errno(-1, -errno, "Failed to convert 
gateway ipv6 address on \"%s\"", veth1);
                                goto out_delete;
                        }
 
@@ -431,25 +431,25 @@ static int instantiate_veth(struct lxc_handler *handler, 
struct lxc_netdev *netd
                        */
                        err = lxc_is_ip_forwarding_enabled("all", AF_INET6);
                        if (err) {
-                               error_log_errno(err, "Requires sysctl 
net.ipv6.conf.all.forwarding=1");
+                               log_error_errno(-1, err, "Requires sysctl 
net.ipv6.conf.all.forwarding=1");
                                goto out_delete;
                        }
 
                        err = lxc_ip_forwarding_on(veth1, AF_INET6);
                        if (err) {
-                               error_log_errno(err, "Failed to activate ipv6 
forwarding on \"%s\"", veth1);
+                               log_error_errno(-1, err, "Failed to activate 
ipv6 forwarding on \"%s\"", veth1);
                                goto out_delete;
                        }
 
                        err = lxc_neigh_proxy_on(veth1, AF_INET6);
                        if (err) {
-                               error_log_errno(err, "Failed to activate proxy 
ndp on \"%s\"", veth1);
+                               log_error_errno(-1, err, "Failed to activate 
proxy ndp on \"%s\"", veth1);
                                goto out_delete;
                        }
 
                        err = lxc_add_ip_neigh_proxy(bufinet6, veth1);
                        if (err) {
-                               error_log_errno(err, "Failed to add gateway 
ipv6 proxy on \"%s\"", veth1);
+                               log_error_errno(-1, err, "Failed to add gateway 
ipv6 proxy on \"%s\"", veth1);
                                goto out_delete;
                        }
                }
@@ -457,14 +457,14 @@ static int instantiate_veth(struct lxc_handler *handler, 
struct lxc_netdev *netd
                /* setup ipv4 address routes on the host interface */
                err = setup_ipv4_addr_routes(&netdev->ipv4, 
netdev->priv.veth_attr.ifindex);
                if (err) {
-                       error_log_errno(err, "Failed to setup ip address routes 
for network device \"%s\"", veth1);
+                       log_error_errno(-1, err, "Failed to setup ip address 
routes for network device \"%s\"", veth1);
                        goto out_delete;
                }
 
                /* setup ipv6 address routes on the host interface */
                err = setup_ipv6_addr_routes(&netdev->ipv6, 
netdev->priv.veth_attr.ifindex);
                if (err) {
-                       error_log_errno(err, "Failed to setup ip address routes 
for network device \"%s\"", veth1);
+                       log_error_errno(-1, err, "Failed to setup ip address 
routes for network device \"%s\"", veth1);
                        goto out_delete;
                }
        }
@@ -580,19 +580,19 @@ static int lxc_ipvlan_create(const char *master, const 
char *name, int mode, int
 
        len = strlen(master);
        if (len == 1 || len >= IFNAMSIZ)
-               return minus_one_set_errno(EINVAL);
+               return ret_set_errno(-1, EINVAL);
 
        len = strlen(name);
        if (len == 1 || len >= IFNAMSIZ)
-               return minus_one_set_errno(EINVAL);
+               return ret_set_errno(-1, EINVAL);
 
        index = if_nametoindex(master);
        if (!index)
-               return minus_one_set_errno(EINVAL);
+               return ret_set_errno(-1, EINVAL);
 
        err = netlink_open(&nlh, NETLINK_ROUTE);
        if (err)
-               return minus_one_set_errno(-err);
+               return ret_set_errno(-1, -err);
 
        err = -ENOMEM;
        nlmsg = nlmsg_alloc(NLMSG_GOOD_SIZE);
@@ -653,7 +653,7 @@ static int lxc_ipvlan_create(const char *master, const char 
*name, int mode, int
        nlmsg_free(answer);
        nlmsg_free(nlmsg);
        if (err < 0)
-               return minus_one_set_errno(-err);
+               return ret_set_errno(-1, -err);
        return 0;
 }
 
@@ -846,7 +846,7 @@ static int instantiate_phys(struct lxc_handler *handler, 
struct lxc_netdev *netd
        mtu_orig = netdev_get_mtu(netdev->ifindex);
        if (mtu_orig < 0) {
                SYSERROR("Failed to get original mtu for interface \"%s\"", 
netdev->link);
-               return minus_one_set_errno(-mtu_orig);
+               return ret_set_errno(-1, -mtu_orig);
        }
 
        netdev->priv.phys_attr.mtu = mtu_orig;
@@ -2007,13 +2007,13 @@ static int lxc_is_ip_neigh_proxy_enabled(const char 
*ifname, int family)
        char buf[1] = "";
 
        if (family != AF_INET && family != AF_INET6)
-               return minus_one_set_errno(EINVAL);
+               return ret_set_errno(-1, EINVAL);
 
        ret = snprintf(path, PATH_MAX, "/proc/sys/net/%s/conf/%s/%s",
                       family == AF_INET ? "ipv4" : "ipv6", ifname,
                       family == AF_INET ? "proxy_arp" : "proxy_ndp");
        if (ret < 0 || (size_t)ret >= PATH_MAX)
-               return minus_one_set_errno(E2BIG);
+               return ret_set_errno(-1, E2BIG);
 
        return lxc_read_file_expect(path, buf, 1, "1");
 }
@@ -3047,7 +3047,7 @@ static int lxc_setup_l2proxy(struct lxc_netdev *netdev) {
                /* Check for net.ipv4.conf.[link].forwarding=1 */
                if (lxc_is_ip_forwarding_enabled(netdev->link, AF_INET) < 0) {
                        ERROR("Requires sysctl net.ipv4.conf.%s.forwarding=1", 
netdev->link);
-                       return minus_one_set_errno(EINVAL);
+                       return ret_set_errno(-1, EINVAL);
                }
        }
 
@@ -3056,13 +3056,13 @@ static int lxc_setup_l2proxy(struct lxc_netdev *netdev) 
{
                /* Check for net.ipv6.conf.[link].proxy_ndp=1 */
                if (lxc_is_ip_neigh_proxy_enabled(netdev->link, AF_INET6) < 0) {
                        ERROR("Requires sysctl net.ipv6.conf.%s.proxy_ndp=1", 
netdev->link);
-                       return minus_one_set_errno(EINVAL);
+                       return ret_set_errno(-1, EINVAL);
                }
 
                /* Check for net.ipv6.conf.[link].forwarding=1 */
                if (lxc_is_ip_forwarding_enabled(netdev->link, AF_INET6) < 0) {
                        ERROR("Requires sysctl net.ipv6.conf.%s.forwarding=1", 
netdev->link);
-                       return minus_one_set_errno(EINVAL);
+                       return ret_set_errno(-1, EINVAL);
                }
        }
 
@@ -3071,31 +3071,31 @@ static int lxc_setup_l2proxy(struct lxc_netdev *netdev) 
{
                /* Check mode is l3s as other modes do not work with l2proxy. */
                if (netdev->priv.ipvlan_attr.mode != IPVLAN_MODE_L3S) {
                        ERROR("Requires ipvlan mode on dev \"%s\" be l3s when 
used with l2proxy", netdev->link);
-                       return minus_one_set_errno(EINVAL);
+                       return ret_set_errno(-1, EINVAL);
                }
 
                /* Retrieve local-loopback interface index for use with IPVLAN 
static routes. */
                lo_ifindex = if_nametoindex(loop_device);
                if (lo_ifindex == 0) {
                        ERROR("Failed to retrieve ifindex for \"%s\" routing 
cleanup", loop_device);
-                       return minus_one_set_errno(EINVAL);
+                       return ret_set_errno(-1, EINVAL);
                }
        }
 
        lxc_list_for_each_safe(cur, &netdev->ipv4, next) {
                inet4dev = cur->elem;
                if (!inet_ntop(AF_INET, &inet4dev->addr, bufinet4, 
sizeof(bufinet4)))
-                       return minus_one_set_errno(-errno);
+                       return ret_set_errno(-1, -errno);
 
                if (lxc_add_ip_neigh_proxy(bufinet4, netdev->link) < 0)
-                       return minus_one_set_errno(EINVAL);
+                       return ret_set_errno(-1, EINVAL);
 
                /* IPVLAN requires a route to local-loopback to trigger 
l2proxy. */
                if (netdev->type == LXC_NET_IPVLAN) {
                        err = lxc_ipv4_dest_add(lo_ifindex, &inet4dev->addr, 
32);
                        if (err < 0) {
                                ERROR("Failed to add ipv4 dest \"%s\" for 
network device \"%s\"", bufinet4, loop_device);
-                               return minus_one_set_errno(-err);
+                               return ret_set_errno(-1, -err);
                        }
                }
        }
@@ -3103,17 +3103,17 @@ static int lxc_setup_l2proxy(struct lxc_netdev *netdev) 
{
        lxc_list_for_each_safe(cur, &netdev->ipv6, next) {
                inet6dev = cur->elem;
                if (!inet_ntop(AF_INET6, &inet6dev->addr, bufinet6, 
sizeof(bufinet6)))
-                       return minus_one_set_errno(-errno);
+                       return ret_set_errno(-1, -errno);
 
                if (lxc_add_ip_neigh_proxy(bufinet6, netdev->link) < 0)
-                       return minus_one_set_errno(EINVAL);
+                       return ret_set_errno(-1, EINVAL);
 
                /* IPVLAN requires a route to local-loopback to trigger 
l2proxy. */
                if (netdev->type == LXC_NET_IPVLAN) {
                        err = lxc_ipv6_dest_add(lo_ifindex, &inet6dev->addr, 
128);
                        if (err < 0) {
                                ERROR("Failed to add ipv6 dest \"%s\" for 
network device \"%s\"", bufinet6, loop_device);
-                               return minus_one_set_errno(-err);
+                               return ret_set_errno(-1, -err);
                        }
                }
        }
@@ -3127,7 +3127,7 @@ static int lxc_delete_ipv4_l2proxy(struct in_addr *ip, 
char *link, unsigned int
 
        if (!inet_ntop(AF_INET, ip, bufinet4, sizeof(bufinet4))) {
                SYSERROR("Failed to convert IP for l2proxy ipv4 removal on dev 
\"%s\"", link);
-               return minus_one_set_errno(EINVAL);
+               return ret_set_errno(-1, EINVAL);
        }
 
        /* If a local-loopback ifindex supplied remove the static route to the 
lo device. */
@@ -3145,7 +3145,7 @@ static int lxc_delete_ipv4_l2proxy(struct in_addr *ip, 
char *link, unsigned int
        }
 
        if (errCount > 0)
-               return minus_one_set_errno(EINVAL);
+               return ret_set_errno(-1, EINVAL);
 
        return 0;
 }
@@ -3156,7 +3156,7 @@ static int lxc_delete_ipv6_l2proxy(struct in6_addr *ip, 
char *link, unsigned int
 
        if (!inet_ntop(AF_INET6, ip, bufinet6, sizeof(bufinet6))) {
                SYSERROR("Failed to convert IP for l2proxy ipv6 removal on dev 
\"%s\"", link);
-               return minus_one_set_errno(EINVAL);
+               return ret_set_errno(-1, EINVAL);
        }
 
        /* If a local-loopback ifindex supplied remove the static route to the 
lo device. */
@@ -3174,7 +3174,7 @@ static int lxc_delete_ipv6_l2proxy(struct in6_addr *ip, 
char *link, unsigned int
        }
 
        if (errCount > 0)
-               return minus_one_set_errno(EINVAL);
+               return ret_set_errno(-1, EINVAL);
 
        return 0;
 }
@@ -3209,7 +3209,7 @@ static int lxc_delete_l2proxy(struct lxc_netdev *netdev) {
        }
 
        if (errCount > 0)
-               return minus_one_set_errno(EINVAL);
+               return ret_set_errno(-1, EINVAL);
 
        return 0;
 }
@@ -3766,12 +3766,12 @@ static int lxc_setup_netdev_in_child_namespaces(struct 
lxc_netdev *netdev)
                        if (err < 0) {
                                SYSERROR("Failed to setup ipv4 gateway to 
network device \"%s\"",
                                         current_ifname);
-                               return minus_one_set_errno(-err);
+                               return ret_set_errno(-1, -err);
                        }
                } else {
                        /* Check the gateway address is valid */
                        if (!inet_ntop(AF_INET, netdev->ipv4_gateway, bufinet4, 
sizeof(bufinet4)))
-                               return minus_one_set_errno(errno);
+                               return ret_set_errno(-1, errno);
 
                        /* Try adding a default route to the gateway address */
                        err = lxc_ipv4_gateway_add(netdev->ifindex, 
netdev->ipv4_gateway);
@@ -3820,12 +3820,12 @@ static int lxc_setup_netdev_in_child_namespaces(struct 
lxc_netdev *netdev)
                        if (err < 0) {
                                SYSERROR("Failed to setup ipv6 gateway to 
network device \"%s\"",
                                         current_ifname);
-                               return minus_one_set_errno(-err);
+                               return ret_set_errno(-1, -err);
                        }
                } else {
                        /* Check the gateway address is valid */
                        if (!inet_ntop(AF_INET6, netdev->ipv6_gateway, 
bufinet6, sizeof(bufinet6)))
-                               return minus_one_set_errno(errno);
+                               return ret_set_errno(-1, errno);
 
                        /* Try adding a default route to the gateway address */
                        err = lxc_ipv6_gateway_add(netdev->ifindex, 
netdev->ipv6_gateway);

From 21fce08cb69ab6c912c68fb8aefcdfa1a6fbe166 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brau...@ubuntu.com>
Date: Sat, 7 Dec 2019 17:25:28 +0100
Subject: [PATCH 07/19] confile: replace logging helpers

Signed-off-by: Christian Brauner <christian.brau...@ubuntu.com>
---
 src/lxc/confile.c | 72 +++++++++++++++++++++++------------------------
 1 file changed, 36 insertions(+), 36 deletions(-)

diff --git a/src/lxc/confile.c b/src/lxc/confile.c
index 79fef103ab..c27d432d81 100644
--- a/src/lxc/confile.c
+++ b/src/lxc/confile.c
@@ -401,11 +401,11 @@ static int set_config_net_l2proxy(const char *key, const 
char *value,
                return clr_config_net_l2proxy(key, lxc_conf, data);
 
        if (!netdev)
-               return minus_one_set_errno(EINVAL);
+               return ret_set_errno(-1, EINVAL);
 
        ret = lxc_safe_uint(value, &val);
        if (ret < 0)
-               return minus_one_set_errno(-ret);
+               return ret_set_errno(-1, -ret);
 
        switch (val) {
        case 0:
@@ -416,7 +416,7 @@ static int set_config_net_l2proxy(const char *key, const 
char *value,
                return 0;
        }
 
-       return minus_one_set_errno(EINVAL);
+       return ret_set_errno(-1, EINVAL);
 }
 
 static int set_config_net_name(const char *key, const char *value,
@@ -485,11 +485,11 @@ static int set_config_net_ipvlan_mode(const char *key, 
const char *value,
                return clr_config_net_ipvlan_mode(key, lxc_conf, data);
 
        if (!netdev)
-               return minus_one_set_errno(EINVAL);
+               return ret_set_errno(-1, EINVAL);
 
        if (netdev->type != LXC_NET_IPVLAN) {
                SYSERROR("Invalid ipvlan mode \"%s\", can only be used with 
ipvlan network", value);
-               return minus_one_set_errno(EINVAL);
+               return ret_set_errno(-1, EINVAL);
        }
 
        return lxc_ipvlan_mode_to_flag(&netdev->priv.ipvlan_attr.mode, value);
@@ -504,11 +504,11 @@ static int set_config_net_ipvlan_isolation(const char 
*key, const char *value,
                return clr_config_net_ipvlan_isolation(key, lxc_conf, data);
 
        if (!netdev)
-               return minus_one_set_errno(EINVAL);
+               return ret_set_errno(-1, EINVAL);
 
        if (netdev->type != LXC_NET_IPVLAN) {
                SYSERROR("Invalid ipvlan isolation \"%s\", can only be used 
with ipvlan network", value);
-               return minus_one_set_errno(EINVAL);
+               return ret_set_errno(-1, EINVAL);
        }
 
        return 
lxc_ipvlan_isolation_to_flag(&netdev->priv.ipvlan_attr.isolation, value);
@@ -729,11 +729,11 @@ static int set_config_net_veth_ipv4_route(const char 
*key, const char *value,
                return clr_config_net_veth_ipv4_route(key, lxc_conf, data);
 
        if (!netdev)
-               return minus_one_set_errno(EINVAL);
+               return ret_set_errno(-1, EINVAL);
 
        if (netdev->type != LXC_NET_VETH) {
                SYSERROR("Invalid ipv4 route \"%s\", can only be used with veth 
network", value);
-               return minus_one_set_errno(EINVAL);
+               return ret_set_errno(-1, EINVAL);
        }
 
        inetdev = malloc(sizeof(*inetdev));
@@ -754,22 +754,22 @@ static int set_config_net_veth_ipv4_route(const char 
*key, const char *value,
 
        slash = strchr(valdup, '/');
        if (!slash)
-               return minus_one_set_errno(EINVAL);
+               return ret_set_errno(-1, EINVAL);
 
        *slash = '\0';
        slash++;
        if (*slash == '\0')
-               return minus_one_set_errno(EINVAL);
+               return ret_set_errno(-1, EINVAL);
 
        netmask = slash;
 
        ret = lxc_safe_uint(netmask, &inetdev->prefix);
        if (ret < 0 || inetdev->prefix > 32)
-               return minus_one_set_errno(EINVAL);
+               return ret_set_errno(-1, EINVAL);
 
        ret = inet_pton(AF_INET, valdup, &inetdev->addr);
        if (!ret || ret < 0)
-               return minus_one_set_errno(EINVAL);
+               return ret_set_errno(-1, EINVAL);
 
        lxc_list_add_tail(&netdev->priv.veth_attr.ipv4_routes, list);
        move_ptr(inetdev);
@@ -900,11 +900,11 @@ static int set_config_net_veth_ipv6_route(const char 
*key, const char *value,
                return clr_config_net_veth_ipv6_route(key, lxc_conf, data);
 
        if (!netdev)
-               return minus_one_set_errno(EINVAL);
+               return ret_set_errno(-1, EINVAL);
 
        if (netdev->type != LXC_NET_VETH) {
                SYSERROR("Invalid ipv6 route \"%s\", can only be used with veth 
network", value);
-               return minus_one_set_errno(EINVAL);
+               return ret_set_errno(-1, EINVAL);
        }
 
        inet6dev = malloc(sizeof(*inet6dev));
@@ -925,22 +925,22 @@ static int set_config_net_veth_ipv6_route(const char 
*key, const char *value,
 
        slash = strchr(valdup, '/');
        if (!slash)
-               return minus_one_set_errno(EINVAL);
+               return ret_set_errno(-1, EINVAL);
 
        *slash = '\0';
        slash++;
        if (*slash == '\0')
-               return minus_one_set_errno(EINVAL);
+               return ret_set_errno(-1, EINVAL);
 
        netmask = slash;
 
        ret = lxc_safe_uint(netmask, &inet6dev->prefix);
        if (ret < 0 || inet6dev->prefix > 128)
-               return minus_one_set_errno(EINVAL);
+               return ret_set_errno(-1, EINVAL);
 
        ret = inet_pton(AF_INET6, valdup, &inet6dev->addr);
        if (!ret || ret < 0)
-               return minus_one_set_errno(EINVAL);
+               return ret_set_errno(-1, EINVAL);
 
        lxc_list_add_tail(&netdev->priv.veth_attr.ipv6_routes, list);
        move_ptr(inet6dev);
@@ -1004,7 +1004,7 @@ static int set_config_seccomp_allow_nesting(const char 
*key, const char *value,
                return -1;
 
        if (lxc_conf->seccomp.allow_nesting > 1)
-               return minus_one_set_errno(EINVAL);
+               return ret_set_errno(-1, EINVAL);
 
        return 0;
 #else
@@ -1019,7 +1019,7 @@ static int set_config_seccomp_notify_cookie(const char 
*key, const char *value,
 #ifdef HAVE_SECCOMP_NOTIFY
        return set_config_string_item(&lxc_conf->seccomp.notifier.cookie, 
value);
 #else
-       return minus_one_set_errno(ENOSYS);
+       return ret_set_errno(-1, ENOSYS);
 #endif
 }
 
@@ -1033,7 +1033,7 @@ static int set_config_seccomp_notify_proxy(const char 
*key, const char *value,
                return clr_config_seccomp_notify_proxy(key, lxc_conf, NULL);
 
        if (strncmp(value, "unix:", 5) != 0)
-               return minus_one_set_errno(EINVAL);
+               return ret_set_errno(-1, EINVAL);
 
        offset = value + 5;
        if (lxc_unix_sockaddr(&lxc_conf->seccomp.notifier.proxy_addr, offset) < 
0)
@@ -1041,7 +1041,7 @@ static int set_config_seccomp_notify_proxy(const char 
*key, const char *value,
 
        return 0;
 #else
-       return minus_one_set_errno(ENOSYS);
+       return ret_set_errno(-1, ENOSYS);
 #endif
 }
 
@@ -3985,7 +3985,7 @@ static int get_config_seccomp_notify_cookie(const char 
*key, char *retv, int inl
 #ifdef HAVE_SECCOMP_NOTIFY
        return lxc_get_conf_str(retv, inlen, c->seccomp.notifier.cookie);
 #else
-       return minus_one_set_errno(ENOSYS);
+       return ret_set_errno(-1, ENOSYS);
 #endif
 }
 
@@ -3998,7 +3998,7 @@ static int get_config_seccomp_notify_proxy(const char 
*key, char *retv, int inle
                                    ? 
&c->seccomp.notifier.proxy_addr.sun_path[0]
                                    : 
&c->seccomp.notifier.proxy_addr.sun_path[1]);
 #else
-       return minus_one_set_errno(ENOSYS);
+       return ret_set_errno(-1, ENOSYS);
 #endif
 }
 
@@ -4611,7 +4611,7 @@ static inline int clr_config_seccomp_notify_cookie(const 
char *key,
        c->seccomp.notifier.cookie = NULL;
        return 0;
 #else
-       return minus_one_set_errno(ENOSYS);
+       return ret_set_errno(-1, ENOSYS);
 #endif
 }
 
@@ -4623,7 +4623,7 @@ static inline int clr_config_seccomp_notify_proxy(const 
char *key,
               sizeof(c->seccomp.notifier.proxy_addr));
        return 0;
 #else
-       return minus_one_set_errno(ENOSYS);
+       return ret_set_errno(-1, ENOSYS);
 #endif
 }
 
@@ -5064,7 +5064,7 @@ static int clr_config_net_l2proxy(const char *key, struct 
lxc_conf *lxc_conf,
        struct lxc_netdev *netdev = data;
 
        if (!netdev)
-               return minus_one_set_errno(EINVAL);
+               return ret_set_errno(-1, EINVAL);
 
        netdev->l2proxy = false;
 
@@ -5093,7 +5093,7 @@ static int clr_config_net_ipvlan_mode(const char *key,
        struct lxc_netdev *netdev = data;
 
        if (!netdev)
-               return minus_one_set_errno(EINVAL);
+               return ret_set_errno(-1, EINVAL);
 
        if (netdev->type != LXC_NET_IPVLAN)
                return 0;
@@ -5109,7 +5109,7 @@ static int clr_config_net_ipvlan_isolation(const char 
*key,
        struct lxc_netdev *netdev = data;
 
        if (!netdev)
-               return minus_one_set_errno(EINVAL);
+               return ret_set_errno(-1, EINVAL);
 
        if (netdev->type != LXC_NET_IPVLAN)
                return 0;
@@ -5125,7 +5125,7 @@ static int clr_config_net_veth_mode(const char *key,
        struct lxc_netdev *netdev = data;
 
        if (!netdev)
-               return minus_one_set_errno(EINVAL);
+               return ret_set_errno(-1, EINVAL);
 
        if (netdev->type != LXC_NET_VETH)
                return 0;
@@ -5493,7 +5493,7 @@ static int get_config_net_ipvlan_mode(const char *key, 
char *retv, int inlen,
                memset(retv, 0, inlen);
 
        if (!netdev)
-               return minus_one_set_errno(EINVAL);
+               return ret_set_errno(-1, EINVAL);
 
        if (netdev->type != LXC_NET_IPVLAN)
                return 0;
@@ -5532,7 +5532,7 @@ static int get_config_net_ipvlan_isolation(const char 
*key, char *retv, int inle
                memset(retv, 0, inlen);
 
        if (!netdev)
-               return minus_one_set_errno(EINVAL);
+               return ret_set_errno(-1, EINVAL);
 
        if (netdev->type != LXC_NET_IPVLAN)
                return 0;
@@ -5571,7 +5571,7 @@ static int get_config_net_veth_mode(const char *key, char 
*retv, int inlen,
                memset(retv, 0, inlen);
 
        if (!netdev)
-               return minus_one_set_errno(EINVAL);
+               return ret_set_errno(-1, EINVAL);
 
        if (netdev->type != LXC_NET_VETH)
                return 0;
@@ -5800,7 +5800,7 @@ static int get_config_net_veth_ipv4_route(const char 
*key, char *retv, int inlen
                memset(retv, 0, inlen);
 
        if (!netdev)
-               return minus_one_set_errno(EINVAL);
+               return ret_set_errno(-1, EINVAL);
 
        if (netdev->type != LXC_NET_VETH)
                return 0;
@@ -5891,7 +5891,7 @@ static int get_config_net_veth_ipv6_route(const char 
*key, char *retv, int inlen
                memset(retv, 0, inlen);
 
        if (!netdev)
-               return minus_one_set_errno(EINVAL);
+               return ret_set_errno(-1, EINVAL);
 
        if (netdev->type != LXC_NET_VETH)
                return 0;

From d220323012d3bc176461018cc1743ac05e789cb7 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brau...@ubuntu.com>
Date: Sat, 7 Dec 2019 17:28:06 +0100
Subject: [PATCH 08/19] cgroups/cgfsng: replace logging functions

Signed-off-by: Christian Brauner <christian.brau...@ubuntu.com>
---
 src/lxc/cgroups/cgfsng.c | 50 ++++++++++++++++++++--------------------
 1 file changed, 25 insertions(+), 25 deletions(-)

diff --git a/src/lxc/cgroups/cgfsng.c b/src/lxc/cgroups/cgfsng.c
index d5ddc8388d..e88e158d0a 100644
--- a/src/lxc/cgroups/cgfsng.c
+++ b/src/lxc/cgroups/cgfsng.c
@@ -1941,7 +1941,7 @@ static bool cg_legacy_freeze(struct cgroup_ops *ops)
 
        h = get_hierarchy(ops, "freezer");
        if (!h)
-               return minus_one_set_errno(ENOENT);
+               return ret_set_errno(-1, ENOENT);
 
        path = must_make_path(h->container_full_path, "freezer.state", NULL);
        return lxc_write_to_file(path, "FROZEN", STRLITERALLEN("FROZEN"), 
false, 0666);
@@ -1992,10 +1992,10 @@ static int cg_unified_freeze(struct cgroup_ops *ops, 
int timeout)
 
        h = ops->unified;
        if (!h)
-               return minus_one_set_errno(ENOENT);
+               return ret_set_errno(-1, ENOENT);
 
        if (!h->container_full_path)
-               return minus_one_set_errno(EEXIST);
+               return ret_set_errno(-1, EEXIST);
 
        if (timeout != 0) {
                __do_free char *events_file = NULL;
@@ -2003,27 +2003,27 @@ static int cg_unified_freeze(struct cgroup_ops *ops, 
int timeout)
                events_file = must_make_path(h->container_full_path, 
"cgroup.events", NULL);
                fd = open(events_file, O_RDONLY | O_CLOEXEC);
                if (fd < 0)
-                       return error_log_errno(errno, "Failed to open 
cgroup.events file");
+                       return log_error_errno(-1, errno, "Failed to open 
cgroup.events file");
 
                ret = lxc_mainloop_open(&descr);
                if (ret)
-                       return error_log_errno(errno, "Failed to create epoll 
instance to wait for container freeze");
+                       return log_error_errno(-1, errno, "Failed to create 
epoll instance to wait for container freeze");
 
                /* automatically cleaned up now */
                descr_ptr = &descr;
 
                ret = lxc_mainloop_add_handler(&descr, fd, 
freezer_cgroup_events_cb, INT_TO_PTR((int){1}));
                if (ret < 0)
-                       return error_log_errno(errno, "Failed to add 
cgroup.events fd handler to mainloop");
+                       return log_error_errno(-1, errno, "Failed to add 
cgroup.events fd handler to mainloop");
        }
 
        path = must_make_path(h->container_full_path, "cgroup.freeze", NULL);
        ret = lxc_write_to_file(path, "1", 1, false, 0666);
        if (ret < 0)
-               return error_log_errno(errno, "Failed to open cgroup.freeze 
file");
+               return log_error_errno(-1, errno, "Failed to open cgroup.freeze 
file");
 
        if (timeout != 0 && lxc_mainloop(&descr, timeout))
-               return error_log_errno(errno, "Failed to wait for container to 
be frozen");
+               return log_error_errno(-1, errno, "Failed to wait for container 
to be frozen");
 
        return 0;
 }
@@ -2031,7 +2031,7 @@ static int cg_unified_freeze(struct cgroup_ops *ops, int 
timeout)
 __cgfsng_ops static int cgfsng_freeze(struct cgroup_ops *ops, int timeout)
 {
        if (!ops->hierarchies)
-               return minus_one_set_errno(ENOENT);
+               return ret_set_errno(-1, ENOENT);
 
        if (ops->cgroup_layout != CGROUP_LAYOUT_UNIFIED)
                return cg_legacy_freeze(ops);
@@ -2046,7 +2046,7 @@ static int cg_legacy_unfreeze(struct cgroup_ops *ops)
 
        h = get_hierarchy(ops, "freezer");
        if (!h)
-               return minus_one_set_errno(ENOENT);
+               return ret_set_errno(-1, ENOENT);
 
        path = must_make_path(h->container_full_path, "freezer.state", NULL);
        return lxc_write_to_file(path, "THAWED", STRLITERALLEN("THAWED"), 
false, 0666);
@@ -2063,10 +2063,10 @@ static int cg_unified_unfreeze(struct cgroup_ops *ops, 
int timeout)
 
        h = ops->unified;
        if (!h)
-               return minus_one_set_errno(ENOENT);
+               return ret_set_errno(-1, ENOENT);
 
        if (!h->container_full_path)
-               return minus_one_set_errno(EEXIST);
+               return ret_set_errno(-1, EEXIST);
 
        if (timeout != 0) {
                __do_free char *events_file = NULL;
@@ -2074,27 +2074,27 @@ static int cg_unified_unfreeze(struct cgroup_ops *ops, 
int timeout)
                events_file = must_make_path(h->container_full_path, 
"cgroup.events", NULL);
                fd = open(events_file, O_RDONLY | O_CLOEXEC);
                if (fd < 0)
-                       return error_log_errno(errno, "Failed to open 
cgroup.events file");
+                       return log_error_errno(-1, errno, "Failed to open 
cgroup.events file");
 
                ret = lxc_mainloop_open(&descr);
                if (ret)
-                       return error_log_errno(errno, "Failed to create epoll 
instance to wait for container unfreeze");
+                       return log_error_errno(-1, errno, "Failed to create 
epoll instance to wait for container unfreeze");
 
                /* automatically cleaned up now */
                descr_ptr = &descr;
 
                ret = lxc_mainloop_add_handler(&descr, fd, 
freezer_cgroup_events_cb, INT_TO_PTR((int){0}));
                if (ret < 0)
-                       return error_log_errno(errno, "Failed to add 
cgroup.events fd handler to mainloop");
+                       return log_error_errno(-1, errno, "Failed to add 
cgroup.events fd handler to mainloop");
        }
 
        path = must_make_path(h->container_full_path, "cgroup.freeze", NULL);
        ret = lxc_write_to_file(path, "0", 1, false, 0666);
        if (ret < 0)
-               return error_log_errno(errno, "Failed to open cgroup.freeze 
file");
+               return log_error_errno(-1, errno, "Failed to open cgroup.freeze 
file");
 
        if (timeout != 0 && lxc_mainloop(&descr, timeout))
-               return error_log_errno(errno, "Failed to wait for container to 
be unfrozen");
+               return log_error_errno(-1, errno, "Failed to wait for container 
to be unfrozen");
 
        return 0;
 }
@@ -2102,7 +2102,7 @@ static int cg_unified_unfreeze(struct cgroup_ops *ops, 
int timeout)
 __cgfsng_ops static int cgfsng_unfreeze(struct cgroup_ops *ops, int timeout)
 {
        if (!ops->hierarchies)
-               return minus_one_set_errno(ENOENT);
+               return ret_set_errno(-1, ENOENT);
 
        if (ops->cgroup_layout != CGROUP_LAYOUT_UNIFIED)
                return cg_legacy_unfreeze(ops);
@@ -2148,7 +2148,7 @@ static int cgroup_attach_leaf(int unified_fd, int64_t pid)
                return 0;
        /* this is a non-leaf node */
        if (errno != EBUSY)
-               return error_log_errno(errno, "Failed to attach to unified 
cgroup");
+               return log_error_errno(-1, errno, "Failed to attach to unified 
cgroup");
 
        do {
                char *slash;
@@ -2167,7 +2167,7 @@ static int cgroup_attach_leaf(int unified_fd, int64_t pid)
                *slash = '\0';
                ret = mkdirat(unified_fd, attach_cgroup, 0755);
                if (ret < 0 && errno != EEXIST)
-                       return error_log_errno(errno, "Failed to create cgroup 
%s", attach_cgroup);
+                       return log_error_errno(-1, errno, "Failed to create 
cgroup %s", attach_cgroup);
 
                *slash = '/';
                ret = lxc_writeat(unified_fd, attach_cgroup, pidstr, 
pidstr_len);
@@ -2176,7 +2176,7 @@ static int cgroup_attach_leaf(int unified_fd, int64_t pid)
 
                /* this is a non-leaf node */
                if (errno != EBUSY)
-                       return error_log_errno(errno, "Failed to attach to 
unified cgroup");
+                       return log_error_errno(-1, errno, "Failed to attach to 
unified cgroup");
 
                idx++;
        } while (idx < 1000);
@@ -2435,7 +2435,7 @@ __cgfsng_ops static int cgfsng_set(struct cgroup_ops *ops,
 
                ret = device_cgroup_rule_parse(&device, key, value);
                if (ret < 0)
-                       return error_log_errno(EINVAL, "Failed to parse device 
string %s=%s",
+                       return log_error_errno(-1, EINVAL, "Failed to parse 
device string %s=%s",
                                               key, value);
 
                ret = lxc_cmd_add_bpf_device_cgroup(name, lxcpath, &device);
@@ -2644,7 +2644,7 @@ static int bpf_device_cgroup_prepare(struct cgroup_ops 
*ops,
 
        ret = device_cgroup_rule_parse(&device_item, key, val);
        if (ret < 0)
-               return error_log_errno(EINVAL,
+               return log_error_errno(-1, EINVAL,
                                       "Failed to parse device string %s=%s",
                                       key, val);
 
@@ -3072,14 +3072,14 @@ static int cg_unified_init(struct cgroup_ops *ops, bool 
relative,
 
        ret = unified_cgroup_hierarchy();
        if (ret == -ENOMEDIUM)
-               return -ENOMEDIUM;
+               return ret_errno(ENOMEDIUM);
 
        if (ret != CGROUP2_SUPER_MAGIC)
                return 0;
 
        base_cgroup = cg_unified_get_current_cgroup(relative);
        if (!base_cgroup)
-               return -EINVAL;
+               return ret_errno(EINVAL);
        if (!relative)
                prune_init_scope(base_cgroup);
 

From 102dca262246efa419058f14f56717b44b85dec2 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brau...@ubuntu.com>
Date: Sat, 7 Dec 2019 17:29:12 +0100
Subject: [PATCH 09/19] cgroups/cgroup: replace logging functions

Signed-off-by: Christian Brauner <christian.brau...@ubuntu.com>
---
 src/lxc/cgroups/cgroup.c | 17 +++++++----------
 1 file changed, 7 insertions(+), 10 deletions(-)

diff --git a/src/lxc/cgroups/cgroup.c b/src/lxc/cgroups/cgroup.c
index 8804d59ac3..84171c18d9 100644
--- a/src/lxc/cgroups/cgroup.c
+++ b/src/lxc/cgroups/cgroup.c
@@ -24,19 +24,16 @@ struct cgroup_ops *cgroup_init(struct lxc_conf *conf)
 {
        struct cgroup_ops *cgroup_ops;
 
-       if (!conf) {
-               ERROR("No valid conf given");
-               return NULL;
-       }
+       if (!conf)
+               return log_error_errno(NULL, EINVAL, "No valid conf given");
 
        cgroup_ops = cgfsng_ops_init(conf);
-       if (!cgroup_ops) {
-               ERROR("Failed to initialize cgroup driver");
-               return NULL;
-       }
+       if (!cgroup_ops)
+               return log_error_errno(NULL, errno, "Failed to initialize 
cgroup driver");
 
-       if (!cgroup_ops->data_init(cgroup_ops))
-               return NULL;
+       if (cgroup_ops->data_init(cgroup_ops))
+               return log_error_errno(NULL, errno,
+                                      "Failed to initialize cgroup data");
 
        TRACE("Initialized cgroup driver %s", cgroup_ops->driver);
 

From 55cc1116857df23d76eec0b6a2241c7aa3e0f5f3 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brau...@ubuntu.com>
Date: Sat, 7 Dec 2019 17:30:07 +0100
Subject: [PATCH 10/19] cgroups/cgroup2_devices: replace logging functions

Signed-off-by: Christian Brauner <christian.brau...@ubuntu.com>
---
 src/lxc/cgroups/cgroup2_devices.c | 48 +++++++++++++++----------------
 1 file changed, 24 insertions(+), 24 deletions(-)

diff --git a/src/lxc/cgroups/cgroup2_devices.c 
b/src/lxc/cgroups/cgroup2_devices.c
index cb6f76abc1..7df8112422 100644
--- a/src/lxc/cgroups/cgroup2_devices.c
+++ b/src/lxc/cgroups/cgroup2_devices.c
@@ -35,11 +35,11 @@ static int bpf_program_add_instructions(struct bpf_program 
*prog,
        struct bpf_insn *new_insn;
 
        if (prog->kernel_fd >= 0)
-               return error_log_errno(EBUSY, "Refusing to update bpf cgroup 
program that's already loaded");
+               return log_error_errno(-1, EBUSY, "Refusing to update bpf 
cgroup program that's already loaded");
 
        new_insn = realloc(prog->instructions, sizeof(struct bpf_insn) * (count 
+ prog->n_instructions));
        if (!new_insn)
-               return error_log_errno(ENOMEM, "Failed to reallocate bpf cgroup 
program");
+               return log_error_errno(-1, ENOMEM, "Failed to reallocate bpf 
cgroup program");
 
        prog->instructions = new_insn;
        memcpy(prog->instructions + prog->n_instructions, instructions,
@@ -184,7 +184,7 @@ struct bpf_program *bpf_program_new(uint32_t prog_type)
 int bpf_program_init(struct bpf_program *prog)
 {
        if (!prog)
-               return minus_one_set_errno(EINVAL);
+               return ret_set_errno(-1, EINVAL);
 
        const struct bpf_insn pre_insn[] = {
            /* load device type to r2 */
@@ -217,7 +217,7 @@ int bpf_program_append_device(struct bpf_program *prog, 
struct device_item *devi
        int device_type;
 
        if (!prog || !device)
-               return minus_one_set_errno(EINVAL);
+               return ret_set_errno(-1, EINVAL);
 
        /* This is a global rule so no need to append anything. */
        if (device->global_rule > LXC_BPF_DEVICE_CGROUP_LOCAL_RULE) {
@@ -227,7 +227,7 @@ int bpf_program_append_device(struct bpf_program *prog, 
struct device_item *devi
 
        device_type = bpf_device_type(device->type);
        if (device_type < 0)
-               return error_log_errno(EINVAL, "Invalid bpf cgroup device type 
%c", device->type);
+               return log_error_errno(-1, EINVAL, "Invalid bpf cgroup device 
type %c", device->type);
 
        if (device_type > 0)
                jump_nr++;
@@ -249,7 +249,7 @@ int bpf_program_append_device(struct bpf_program *prog, 
struct device_item *devi
 
                ret = bpf_program_add_instructions(prog, ins, ARRAY_SIZE(ins));
                if (ret)
-                       return error_log_errno(errno, "Failed to add 
instructions to bpf cgroup program");
+                       return log_error_errno(-1, errno, "Failed to add 
instructions to bpf cgroup program");
        }
 
        if (!bpf_device_all_access(access_mask)) {
@@ -262,7 +262,7 @@ int bpf_program_append_device(struct bpf_program *prog, 
struct device_item *devi
                jump_nr -= 3;
                ret = bpf_program_add_instructions(prog, ins, ARRAY_SIZE(ins));
                if (ret)
-                       return error_log_errno(errno, "Failed to add 
instructions to bpf cgroup program");
+                       return log_error_errno(-1, errno, "Failed to add 
instructions to bpf cgroup program");
        }
 
        if (device->major >= 0) {
@@ -272,7 +272,7 @@ int bpf_program_append_device(struct bpf_program *prog, 
struct device_item *devi
 
                ret = bpf_program_add_instructions(prog, ins, ARRAY_SIZE(ins));
                if (ret)
-                       return error_log_errno(errno, "Failed to add 
instructions to bpf cgroup program");
+                       return log_error_errno(-1, errno, "Failed to add 
instructions to bpf cgroup program");
        }
 
        if (device->minor >= 0) {
@@ -282,13 +282,13 @@ int bpf_program_append_device(struct bpf_program *prog, 
struct device_item *devi
 
                ret = bpf_program_add_instructions(prog, ins, ARRAY_SIZE(ins));
                if (ret)
-                       return error_log_errno(errno, "Failed to add 
instructions to bpf cgroup program");
+                       return log_error_errno(-1, errno, "Failed to add 
instructions to bpf cgroup program");
        }
 
        ret = bpf_program_add_instructions(prog, bpf_access_decision,
                                            ARRAY_SIZE(bpf_access_decision));
        if (ret)
-               return error_log_errno(errno, "Failed to add instructions to 
bpf cgroup program");
+               return log_error_errno(-1, errno, "Failed to add instructions 
to bpf cgroup program");
 
        return 0;
 }
@@ -301,7 +301,7 @@ int bpf_program_finalize(struct bpf_program *prog)
        };
 
        if (!prog)
-               return minus_one_set_errno(EINVAL);
+               return ret_set_errno(-1, EINVAL);
 
        TRACE("Implementing %s bpf device cgroup program",
              prog->device_list_type == LXC_BPF_DEVICE_CGROUP_BLACKLIST
@@ -332,7 +332,7 @@ static int bpf_program_load_kernel(struct bpf_program 
*prog, char *log_buf,
 
        prog->kernel_fd = bpf(BPF_PROG_LOAD, &attr, sizeof(attr));
        if (prog->kernel_fd < 0)
-               return error_log_errno(errno, "Failed to load bpf program");
+               return log_error_errno(-1, errno, "Failed to load bpf program");
 
        return 0;
 }
@@ -346,17 +346,17 @@ int bpf_program_cgroup_attach(struct bpf_program *prog, 
int type,
        int ret;
 
        if (!prog)
-               return minus_one_set_errno(EINVAL);
+               return ret_set_errno(-1, EINVAL);
 
        if (flags & ~(BPF_F_ALLOW_OVERRIDE, BPF_F_ALLOW_MULTI))
-               return error_log_errno(EINVAL, "Invalid flags for bpf program");
+               return log_error_errno(-1, EINVAL, "Invalid flags for bpf 
program");
 
        if (prog->attached_path) {
                if (prog->attached_type != type)
-                       return error_log_errno(EBUSY, "Wrong type for bpf 
program");
+                       return log_error_errno(-1, EBUSY, "Wrong type for bpf 
program");
 
                if (prog->attached_flags != flags)
-                       return error_log_errno(EBUSY, "Wrong flags for bpf 
program");
+                       return log_error_errno(-1, EBUSY, "Wrong flags for bpf 
program");
 
                if (flags != BPF_F_ALLOW_OVERRIDE)
                        return true;
@@ -364,15 +364,15 @@ int bpf_program_cgroup_attach(struct bpf_program *prog, 
int type,
 
        ret = bpf_program_load_kernel(prog, NULL, 0);
        if (ret < 0)
-               return error_log_errno(ret, "Failed to load bpf program");
+               return log_error_errno(-1, ret, "Failed to load bpf program");
 
        copy = strdup(path);
        if (!copy)
-               return error_log_errno(ENOMEM, "Failed to duplicate cgroup path 
%s", path);
+               return log_error_errno(-1, ENOMEM, "Failed to duplicate cgroup 
path %s", path);
 
        fd = open(path, O_DIRECTORY | O_RDONLY | O_CLOEXEC);
        if (fd < 0)
-               return error_log_errno(errno, "Failed to open cgroup path %s", 
path);
+               return log_error_errno(-1, errno, "Failed to open cgroup path 
%s", path);
 
        attr = (union bpf_attr){
            .attach_type        = type,
@@ -383,7 +383,7 @@ int bpf_program_cgroup_attach(struct bpf_program *prog, int 
type,
 
        ret = bpf(BPF_PROG_ATTACH, &attr, sizeof(attr));
        if (ret < 0)
-               return error_log_errno(errno, "Failed to attach bpf program");
+               return log_error_errno(-1, errno, "Failed to attach bpf 
program");
 
        free_replace_move_ptr(prog->attached_path, copy);
        prog->attached_type = type;
@@ -407,7 +407,7 @@ int bpf_program_cgroup_detach(struct bpf_program *prog)
        fd = open(prog->attached_path, O_DIRECTORY | O_RDONLY | O_CLOEXEC);
        if (fd < 0) {
                if (errno != ENOENT)
-                       return error_log_errno(errno, "Failed to open attach 
cgroup %s",
+                       return log_error_errno(-1, errno, "Failed to open 
attach cgroup %s",
                                               prog->attached_path);
        } else {
                union bpf_attr attr;
@@ -420,7 +420,7 @@ int bpf_program_cgroup_detach(struct bpf_program *prog)
 
                ret = bpf(BPF_PROG_DETACH, &attr, sizeof(attr));
                if (ret < 0)
-                       return error_log_errno(errno, "Failed to detach bpf 
program from cgroup %s",
+                       return log_error_errno(-1, errno, "Failed to detach bpf 
program from cgroup %s",
                                               prog->attached_path);
        }
 
@@ -488,11 +488,11 @@ int bpf_list_add_device(struct lxc_conf *conf, struct 
device_item *device)
 
        list_elem = malloc(sizeof(*list_elem));
        if (!list_elem)
-               return error_log_errno(ENOMEM, "Failed to allocate new device 
list");
+               return log_error_errno(-1, ENOMEM, "Failed to allocate new 
device list");
 
        new_device = memdup(device, sizeof(struct device_item));
        if (!new_device)
-               return error_log_errno(ENOMEM, "Failed to allocate new device 
item");
+               return log_error_errno(-1, ENOMEM, "Failed to allocate new 
device item");
 
        lxc_list_add_elem(list_elem, move_ptr(new_device));
        lxc_list_add_tail(&conf->devices, move_ptr(list_elem));

From 341e6516f255753cf4e1d35f75647e4896bf919c Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brau...@ubuntu.com>
Date: Sat, 7 Dec 2019 17:30:57 +0100
Subject: [PATCH 11/19] cgroups: rework return values of some functions

Signed-off-by: Christian Brauner <christian.brau...@ubuntu.com>
---
 src/lxc/cgroups/cgfsng.c | 58 ++++++++++++++++++----------------------
 src/lxc/cgroups/cgroup.h |  2 +-
 2 files changed, 27 insertions(+), 33 deletions(-)

diff --git a/src/lxc/cgroups/cgfsng.c b/src/lxc/cgroups/cgfsng.c
index e88e158d0a..d981708114 100644
--- a/src/lxc/cgroups/cgfsng.c
+++ b/src/lxc/cgroups/cgfsng.c
@@ -2887,8 +2887,7 @@ static void cg_unified_delegate(char ***delegate)
 /* At startup, parse_hierarchies finds all the info we need about cgroup
  * mountpoints and current cgroups, and stores it in @d.
  */
-static bool cg_hybrid_init(struct cgroup_ops *ops, bool relative,
-                          bool unprivileged)
+static int cg_hybrid_init(struct cgroup_ops *ops, bool relative, bool 
unprivileged)
 {
        __do_free char *basecginfo = NULL;
        __do_free char *line = NULL;
@@ -2905,19 +2904,15 @@ static bool cg_hybrid_init(struct cgroup_ops *ops, bool 
relative,
        else
                basecginfo = read_file("/proc/self/cgroup");
        if (!basecginfo)
-               return false;
+               return ret_set_errno(-1, ENOMEM);
 
        ret = get_existing_subsystems(&klist, &nlist);
-       if (ret < 0) {
-               ERROR("Failed to retrieve available legacy cgroup controllers");
-               return false;
-       }
+       if (ret < 0)
+               return log_error_errno(-1, errno, "Failed to retrieve available 
legacy cgroup controllers");
 
        f = fopen("/proc/self/mountinfo", "r");
-       if (!f) {
-               ERROR("Failed to open \"/proc/self/mountinfo\"");
-               return false;
-       }
+       if (!f)
+               return log_error_errno(-1, errno, "Failed to open 
\"/proc/self/mountinfo\"");
 
        lxc_cgfsng_print_basecg_debuginfo(basecginfo, klist, nlist);
 
@@ -2954,22 +2949,18 @@ static bool cg_hybrid_init(struct cgroup_ops *ops, bool 
relative,
 
                if (type == CGROUP_SUPER_MAGIC)
                        if (controller_list_is_dup(ops->hierarchies, 
controller_list))
-                               goto next;
+                               log_trace_errno(goto next, EEXIST, "Skipping 
duplicating controller");
 
                mountpoint = cg_hybrid_get_mountpoint(line);
-               if (!mountpoint) {
-                       ERROR("Failed parsing mountpoint from \"%s\"", line);
-                       goto next;
-               }
+               if (!mountpoint)
+                       log_error_errno(goto next, EINVAL, "Failed parsing 
mountpoint from \"%s\"", line);
 
                if (type == CGROUP_SUPER_MAGIC)
                        base_cgroup = cg_hybrid_get_current_cgroup(basecginfo, 
controller_list[0], CGROUP_SUPER_MAGIC);
                else
                        base_cgroup = cg_hybrid_get_current_cgroup(basecginfo, 
NULL, CGROUP2_SUPER_MAGIC);
-               if (!base_cgroup) {
-                       ERROR("Failed to find current cgroup");
-                       goto next;
-               }
+               if (!base_cgroup)
+                       log_error_errno(goto next, EINVAL, "Failed to find 
current cgroup");
 
                trim(base_cgroup);
                prune_init_scope(base_cgroup);
@@ -2978,7 +2969,7 @@ static bool cg_hybrid_init(struct cgroup_ops *ops, bool 
relative,
                else
                        writeable = test_writeable_v1(mountpoint, base_cgroup);
                if (!writeable)
-                       goto next;
+                       log_trace_errno(goto next, EROFS, "The %s group is not 
writeable", base_cgroup);
 
                if (type == CGROUP2_SUPER_MAGIC) {
                        char *cgv2_ctrl_path;
@@ -2998,7 +2989,7 @@ static bool cg_hybrid_init(struct cgroup_ops *ops, bool 
relative,
 
                /* Exclude all controllers that cgroup use does not want. */
                if (!cgroup_use_wants_controllers(ops, controller_list))
-                       goto next;
+                       log_trace_errno(goto next, EINVAL, "Skipping 
controller");
 
                new = add_hierarchy(&ops->hierarchies, controller_list, 
mountpoint, base_cgroup, type);
                if (type == CGROUP2_SUPER_MAGIC && !ops->unified) {
@@ -3025,9 +3016,9 @@ static bool cg_hybrid_init(struct cgroup_ops *ops, bool 
relative,
         * controllers are accounted for
         */
        if (!all_controllers_found(ops))
-               return false;
+               return log_error_errno(-1, ENOENT, "Failed to find all required 
controllers");
 
-       return true;
+       return 0;
 }
 
 /* Get current cgroup from /proc/self/cgroup for the cgroupfs v2 hierarchy. */
@@ -3114,7 +3105,7 @@ static int cg_unified_init(struct cgroup_ops *ops, bool 
relative,
        return CGROUP2_SUPER_MAGIC;
 }
 
-static bool cg_init(struct cgroup_ops *ops, struct lxc_conf *conf)
+static int cg_init(struct cgroup_ops *ops, struct lxc_conf *conf)
 {
        int ret;
        const char *tmp;
@@ -3134,29 +3125,32 @@ static bool cg_init(struct cgroup_ops *ops, struct 
lxc_conf *conf)
 
        ret = cg_unified_init(ops, relative, !lxc_list_empty(&conf->id_map));
        if (ret < 0)
-               return false;
+               return -1;
 
        if (ret == CGROUP2_SUPER_MAGIC)
-               return true;
+               return 0;
 
        return cg_hybrid_init(ops, relative, !lxc_list_empty(&conf->id_map));
 }
 
-__cgfsng_ops static bool cgfsng_data_init(struct cgroup_ops *ops)
+__cgfsng_ops static int cgfsng_data_init(struct cgroup_ops *ops)
 {
        const char *cgroup_pattern;
 
+       if (!ops)
+               return ret_set_errno(-1, ENOENT);
+
        /* copy system-wide cgroup information */
        cgroup_pattern = lxc_global_config_value("lxc.cgroup.pattern");
        if (!cgroup_pattern) {
                /* lxc.cgroup.pattern is only NULL on error. */
                ERROR("Failed to retrieve cgroup pattern");
-               return false;
+               return ret_set_errno(-1, ENOMEM);
        }
        ops->cgroup_pattern = must_copy_string(cgroup_pattern);
        ops->monitor_pattern = MONITOR_CGROUP;
 
-       return true;
+       return 0;
 }
 
 struct cgroup_ops *cgfsng_ops_init(struct lxc_conf *conf)
@@ -3165,12 +3159,12 @@ struct cgroup_ops *cgfsng_ops_init(struct lxc_conf 
*conf)
 
        cgfsng_ops = malloc(sizeof(struct cgroup_ops));
        if (!cgfsng_ops)
-               return NULL;
+               return ret_set_errno(NULL, ENOMEM);
 
        memset(cgfsng_ops, 0, sizeof(struct cgroup_ops));
        cgfsng_ops->cgroup_layout = CGROUP_LAYOUT_UNKNOWN;
 
-       if (!cg_init(cgfsng_ops, conf))
+       if (cg_init(cgfsng_ops, conf))
                return NULL;
 
        cgfsng_ops->unified_fd = -EBADF;
diff --git a/src/lxc/cgroups/cgroup.h b/src/lxc/cgroups/cgroup.h
index 80d2c315a3..dce506aa20 100644
--- a/src/lxc/cgroups/cgroup.h
+++ b/src/lxc/cgroups/cgroup.h
@@ -132,7 +132,7 @@ struct cgroup_ops {
         */
        cgroup_layout_t cgroup_layout;
 
-       bool (*data_init)(struct cgroup_ops *ops);
+       int (*data_init)(struct cgroup_ops *ops);
        void (*payload_destroy)(struct cgroup_ops *ops, struct lxc_handler 
*handler);
        void (*monitor_destroy)(struct cgroup_ops *ops, struct lxc_handler 
*handler);
        bool (*monitor_create)(struct cgroup_ops *ops, struct lxc_handler 
*handler);

From bf39128d818fcdf8248a029e711ae00e2e803329 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brau...@ubuntu.com>
Date: Sat, 7 Dec 2019 17:31:21 +0100
Subject: [PATCH 12/19] confile_utils: replace logging functions

Signed-off-by: Christian Brauner <christian.brau...@ubuntu.com>
---
 src/lxc/confile_utils.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/lxc/confile_utils.c b/src/lxc/confile_utils.c
index fe62d74d51..b5a9f1c1ee 100644
--- a/src/lxc/confile_utils.c
+++ b/src/lxc/confile_utils.c
@@ -503,7 +503,7 @@ int lxc_veth_mode_to_flag(int *mode, const char *value)
                return 0;
        }
 
-       return minus_one_set_errno(EINVAL);
+       return ret_set_errno(-1, EINVAL);
 }
 
 static struct lxc_macvlan_mode {

From b18f6aac91dab359e43821b22ae46eb259ca5050 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brau...@ubuntu.com>
Date: Sat, 7 Dec 2019 17:31:36 +0100
Subject: [PATCH 13/19] lxccontainer: replace logging functions

Signed-off-by: Christian Brauner <christian.brau...@ubuntu.com>
---
 src/lxc/lxccontainer.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/lxc/lxccontainer.c b/src/lxc/lxccontainer.c
index b97b58ec6a..dc977f57b0 100644
--- a/src/lxc/lxccontainer.c
+++ b/src/lxc/lxccontainer.c
@@ -5262,7 +5262,7 @@ static int lxcapi_attach_run_waitl(struct lxc_container 
*c, lxc_attach_options_t
 static int do_lxcapi_seccomp_notify_fd(struct lxc_container *c)
 {
        if (!c || !c->lxc_conf)
-               return minus_one_set_errno(-EINVAL);
+               return ret_set_errno(-1, -EINVAL);
 
        return lxc_seccomp_get_notify_fd(&c->lxc_conf->seccomp);
 }

From 08e8091de8218dfa0ba67be25a639587913259d7 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brau...@ubuntu.com>
Date: Sat, 7 Dec 2019 17:31:50 +0100
Subject: [PATCH 14/19] {log, macro}: remove unused logging functions

Signed-off-by: Christian Brauner <christian.brau...@ubuntu.com>
---
 src/lxc/log.h   | 7 -------
 src/lxc/macro.h | 6 ------
 2 files changed, 13 deletions(-)

diff --git a/src/lxc/log.h b/src/lxc/log.h
index 553bc2a120..d5bfd42e97 100644
--- a/src/lxc/log.h
+++ b/src/lxc/log.h
@@ -484,13 +484,6 @@ ATTR_UNUSED static inline void LXC_##LEVEL(struct 
lxc_log_locinfo* locinfo,        \
        } while (0)
 #endif
 
-#define error_log_errno(__errno__, format, ...)  \
-       ({                                       \
-               errno = __errno__;               \
-               SYSERROR(format, ##__VA_ARGS__); \
-               -1;                              \
-       })
-
 #define log_error_errno(__ret__, __errno__, format, ...) \
        ({                                               \
                errno = __errno__;                       \
diff --git a/src/lxc/macro.h b/src/lxc/macro.h
index b4c9f4e7c6..68bd6ca844 100644
--- a/src/lxc/macro.h
+++ b/src/lxc/macro.h
@@ -442,12 +442,6 @@ enum {
                __internal_fd__;            \
        })
 
-#define minus_one_set_errno(__errno__) \
-       ({                             \
-               errno = __errno__;     \
-               -1;                    \
-       })
-
 #define ret_set_errno(__ret__, __errno__) \
        ({                                \
                errno = __errno__;        \

From 1a080cd740c4fc4a6a9dd6136b2acc2dfa1c4802 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brau...@ubuntu.com>
Date: Sat, 7 Dec 2019 17:38:42 +0100
Subject: [PATCH 15/19] compiler: add __unused attribute

Signed-off-by: Christian Brauner <christian.brau...@ubuntu.com>
---
 src/lxc/compiler.h | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/src/lxc/compiler.h b/src/lxc/compiler.h
index e8adf37c47..2774c6334d 100644
--- a/src/lxc/compiler.h
+++ b/src/lxc/compiler.h
@@ -45,6 +45,13 @@
 #define __returns_twice __attribute__((returns_twice))
 #endif
 
+/* This attribute is required to silence clang warnings */
+#if defined(__GNUC__)
+#define __unused __attribute__ ((unused))
+#else
+#define __unused
+#endif
+
 #define __cgfsng_ops
 
 #endif /* __LXC_COMPILER_H */

From 81102768102dc5f539bf21287433614da608808b Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brau...@ubuntu.com>
Date: Sat, 7 Dec 2019 17:39:03 +0100
Subject: [PATCH 16/19] attach: replace closing helpers

Signed-off-by: Christian Brauner <christian.brau...@ubuntu.com>
---
 src/lxc/attach.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/src/lxc/attach.c b/src/lxc/attach.c
index 3dd56ccb3a..5c50e1a109 100644
--- a/src/lxc/attach.c
+++ b/src/lxc/attach.c
@@ -104,9 +104,8 @@ static struct lxc_proc_context_info 
*lxc_proc_get_context_info(pid_t pid)
 
 static inline void lxc_proc_close_ns_fd(struct lxc_proc_context_info *ctx)
 {
-       for (int i = 0; i < LXC_NS_MAX; i++) {
-               __do_close_prot_errno int fd ATTR_UNUSED = 
move_fd(ctx->ns_fd[i]);
-       }
+       for (int i = 0; i < LXC_NS_MAX; i++)
+               close_prot_errno_disarm(ctx->ns_fd[i]);
 }
 
 static void lxc_proc_put_context_info(struct lxc_proc_context_info *ctx)
@@ -668,9 +667,8 @@ struct attach_clone_payload {
 
 static void lxc_put_attach_clone_payload(struct attach_clone_payload *p)
 {
-       __do_close_prot_errno int ipc_socket ATTR_UNUSED = p->ipc_socket;
-       __do_close_prot_errno int terminal_slave_fd ATTR_UNUSED = 
p->terminal_slave_fd;
-
+       close_prot_errno_disarm(p->ipc_socket);
+       close_prot_errno_disarm(p->terminal_slave_fd);
        if (p->init_ctx) {
                lxc_proc_put_context_info(p->init_ctx);
                p->init_ctx = NULL;

From 47d8afa2a6c49e3053a8c249a6c497d0f13cc03b Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brau...@ubuntu.com>
Date: Sat, 7 Dec 2019 17:39:49 +0100
Subject: [PATCH 17/19] log: replace compiler attributes

Signed-off-by: Christian Brauner <christian.brau...@ubuntu.com>
---
 src/lxc/log.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/lxc/log.h b/src/lxc/log.h
index d5bfd42e97..99cc4680b6 100644
--- a/src/lxc/log.h
+++ b/src/lxc/log.h
@@ -245,10 +245,10 @@ static inline void __lxc_log(const struct 
lxc_log_category *category,
  */
 #define lxc_log_priority_define(acategory, LEVEL)                              
\
                                                                                
\
-ATTR_UNUSED __attribute__ ((format (printf, 2, 3)))                            
\
+__unused __attribute__ ((format (printf, 2, 3)))                               
\
 static inline void LXC_##LEVEL(struct lxc_log_locinfo *, const char *, ...);   
\
                                                                                
\
-ATTR_UNUSED static inline void LXC_##LEVEL(struct lxc_log_locinfo* locinfo,    
\
+__unused static inline void LXC_##LEVEL(struct lxc_log_locinfo* locinfo,       
\
                                           const char* format, ...)             
\
 {                                                                              
\
        if (lxc_log_priority_is_enabled(acategory, LXC_LOG_LEVEL_##LEVEL)) {    
\

From 9ff57a59182521e50126c333f84a1d9d6e4615e6 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brau...@ubuntu.com>
Date: Sat, 7 Dec 2019 17:40:05 +0100
Subject: [PATCH 18/19] start: replace compiler attributes

Signed-off-by: Christian Brauner <christian.brau...@ubuntu.com>
---
 src/lxc/start.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/lxc/start.c b/src/lxc/start.c
index db57600b00..3dd96bc354 100644
--- a/src/lxc/start.c
+++ b/src/lxc/start.c
@@ -1119,8 +1119,8 @@ void lxc_abort(const char *name, struct lxc_handler 
*handler)
 static int do_start(void *data)
 {
        struct lxc_handler *handler = data;
-       ATTR_UNUSED __do_close_prot_errno int data_sock0 = 
handler->data_sock[0],
-                                             data_sock1 = 
handler->data_sock[1];
+       __unused __do_close_prot_errno int data_sock0 = handler->data_sock[0],
+                                          data_sock1 = handler->data_sock[1];
        __do_close_prot_errno int status_fd = -EBADF;
        int ret;
        uid_t new_uid;
@@ -1132,7 +1132,7 @@ static int do_start(void *data)
 
        lxc_sync_fini_parent(handler);
 
-       if (lxc_abstract_unix_recv_fds(handler->data_sock[1], &status_fd, 1, 
NULL, 0) < 0) {
+       if (lxc_abstract_unix_recv_fds(data_sock1, &status_fd, 1, NULL, 0) < 0) 
{
                ERROR("Failed to receive status file descriptor to child 
process");
                goto out_warn_father;
        }

From 41ad3c906826f1e7b123a6fc5b3cb7e17694d2bd Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brau...@ubuntu.com>
Date: Sat, 7 Dec 2019 17:40:32 +0100
Subject: [PATCH 19/19] log: remove unused compiler attribute

Signed-off-by: Christian Brauner <christian.brau...@ubuntu.com>
---
 src/lxc/log.h | 7 -------
 1 file changed, 7 deletions(-)

diff --git a/src/lxc/log.h b/src/lxc/log.h
index 99cc4680b6..1d5d444b4e 100644
--- a/src/lxc/log.h
+++ b/src/lxc/log.h
@@ -26,13 +26,6 @@
 #define LXC_LOG_PREFIX_SIZE    32
 #define LXC_LOG_BUFFER_SIZE    4096
 
-/* This attribute is required to silence clang warnings */
-#if defined(__GNUC__)
-#define ATTR_UNUSED __attribute__ ((unused))
-#else
-#define ATTR_UNUSED
-#endif
-
 /* predefined lxc log priorities. */
 enum lxc_loglevel {
        LXC_LOG_LEVEL_TRACE,
_______________________________________________
lxc-devel mailing list
lxc-devel@lists.linuxcontainers.org
http://lists.linuxcontainers.org/listinfo/lxc-devel

Reply via email to