]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
conf, attach: save errno across call to close
authorWolfgang Bumiller <wry.git@bumiller.com>
Sat, 10 Dec 2016 09:18:27 +0000 (10:18 +0100)
committerStéphane Graber <stgraber@ubuntu.com>
Thu, 15 Dec 2016 18:33:53 +0000 (13:33 -0500)
Save errno across some calls to close() since it can be
interrupted.

Signed-off-by: Wolfgang Bumiller <wry.git@bumiller.com>
src/lxc/attach.c
src/lxc/conf.c

index e16d3d7dcf73e88a50006ada2f9113a054190378..f17a16f56b13a7f254c17c0aecd974de8960ea4d 100644 (file)
@@ -941,7 +941,7 @@ int lxc_attach(const char* name, const char* lxcpath, lxc_attach_exec_t exec_fun
 
                /* Open LSM fd and send it to child. */
                if ((options->namespaces & CLONE_NEWNS) && (options->attach_flags & LXC_ATTACH_LSM) && init_ctx->lsm_label) {
-                       int on_exec;
+                       int on_exec, saved_errno;
                        int labelfd = -1;
                        on_exec = options->attach_flags & LXC_ATTACH_LSM_EXEC ? 1 : 0;
                        /* Open fd for the LSM security module. */
@@ -951,10 +951,10 @@ int lxc_attach(const char* name, const char* lxcpath, lxc_attach_exec_t exec_fun
 
                        /* Send child fd of the LSM security module to write to. */
                        ret = lxc_abstract_unix_send_fd(ipc_sockets[0], labelfd, NULL, 0);
+                       saved_errno = errno;
                        close(labelfd);
                        if (ret <= 0) {
-                               ERROR("Error using IPC to send child LSM fd (4): %s.",
-                                               strerror(errno));
+                               ERROR("Intended to send file descriptor %d: %s.", labelfd, strerror(saved_errno));
                                goto cleanup_error;
                        }
                }
index 20515ef3fa9e3376b74121f6882c976574cacf92..b1d2fa77d8fa7844b9a5820fb79f928ab55ab783 100644 (file)
@@ -2513,7 +2513,10 @@ static int setup_mount_entries(const struct lxc_rootfs *rootfs, struct lxc_list
 
        file = tmpfile();
        if (!file) {
-               ERROR("Could not create temporary file: %s.", strerror(errno));
+               int saved_errno = errno;
+               if (fd != -1)
+                       close(fd);
+               ERROR("Could not create mount entry file: %s.", strerror(saved_errno));
                return -1;
        }
 
@@ -2655,7 +2658,7 @@ static int setup_hw_addr(char *hwaddr, const char *ifname)
 {
        struct sockaddr sockaddr;
        struct ifreq ifr;
-       int ret, fd;
+       int ret, fd, saved_errno;
 
        ret = lxc_convert_mac(hwaddr, &sockaddr);
        if (ret) {
@@ -2675,9 +2678,10 @@ static int setup_hw_addr(char *hwaddr, const char *ifname)
        }
 
        ret = ioctl(fd, SIOCSIFHWADDR, &ifr);
+       saved_errno = errno;
        close(fd);
        if (ret)
-               ERROR("ioctl failure : %s", strerror(errno));
+               ERROR("ioctl failure : %s", strerror(saved_errno));
 
        DEBUG("mac address '%s' on '%s' has been setup", hwaddr, ifr.ifr_name);