From: Christian Brauner Date: Mon, 4 Sep 2017 12:48:37 +0000 (+0200) Subject: start: don't let data_sock users close the fd X-Git-Tag: lxc-2.0.9~48^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=270e9a2a3c007773a871c27ca1d6e8c08c10f54c;p=thirdparty%2Flxc.git start: don't let data_sock users close the fd It is bad style to close an fd inside a function which didn't create it. Let's rather close it transparently in start.c. Signed-off-by: Christian Brauner --- diff --git a/src/lxc/conf.c b/src/lxc/conf.c index 041cc3605..15142f066 100644 --- a/src/lxc/conf.c +++ b/src/lxc/conf.c @@ -3035,8 +3035,6 @@ static int lxc_send_ttys_to_parent(struct lxc_handler *handler) else TRACE("Sent %d ttys to parent", conf->tty); - close(handler->data_sock[0]); - close(handler->data_sock[1]); lxc_delete_tty(tty_info); return ret; diff --git a/src/lxc/network.c b/src/lxc/network.c index 6f87d07a3..c20d5980f 100644 --- a/src/lxc/network.c +++ b/src/lxc/network.c @@ -2975,14 +2975,9 @@ int lxc_network_send_veth_names_to_child(struct lxc_handler *handler) continue; ret = send(data_sock, netdev->name, IFNAMSIZ, 0); - if (ret < 0) { - close(handler->data_sock[0]); - close(handler->data_sock[1]); + if (ret < 0) return -1; - } else { - TRACE("Sent network device name \"%s\" to child", - netdev->name); - } + TRACE("Sent network device name \"%s\" to child", netdev->name); } return 0; @@ -3005,14 +3000,9 @@ int lxc_network_recv_veth_names_from_parent(struct lxc_handler *handler) continue; ret = recv(data_sock, netdev->name, IFNAMSIZ, 0); - if (ret < 0) { - close(handler->data_sock[0]); - close(handler->data_sock[1]); + if (ret < 0) return -1; - } else { - TRACE("Received network device name \"%s\" from parent", - netdev->name); - } + TRACE("Received network device name \"%s\" from parent", netdev->name); } return 0; @@ -3034,23 +3024,18 @@ int lxc_network_send_name_and_ifindex_to_parent(struct lxc_handler *handler) /* Send network device name in the child's namespace to parent. */ ret = send(data_sock, netdev->name, IFNAMSIZ, 0); if (ret < 0) - goto on_error; + return -1; /* Send network device ifindex in the child's namespace to * parent. */ ret = send(data_sock, &netdev->ifindex, sizeof(netdev->ifindex), 0); if (ret < 0) - goto on_error; + return -1; } TRACE("Sent network device names and ifindeces to parent"); return 0; - -on_error: - close(handler->data_sock[0]); - close(handler->data_sock[1]); - return -1; } int lxc_network_recv_name_and_ifindex_from_child(struct lxc_handler *handler) @@ -3071,20 +3056,15 @@ int lxc_network_recv_name_and_ifindex_from_child(struct lxc_handler *handler) */ ret = recv(data_sock, netdev->name, IFNAMSIZ, 0); if (ret < 0) - goto on_error; + return -1; /* Receive network device ifindex in the child's namespace to * parent. */ ret = recv(data_sock, &netdev->ifindex, sizeof(netdev->ifindex), 0); if (ret < 0) - goto on_error; + return -1; } return 0; - -on_error: - close(handler->data_sock[0]); - close(handler->data_sock[1]); - return -1; } diff --git a/src/lxc/start.c b/src/lxc/start.c index 5bb3db431..bfd5827e1 100644 --- a/src/lxc/start.c +++ b/src/lxc/start.c @@ -988,7 +988,10 @@ static int do_start(void *data) } /* Setup the container, ip, names, utsname, ... */ - if (lxc_setup(handler)) { + ret = lxc_setup(handler); + close(handler->data_sock[0]); + close(handler->data_sock[1]); + if (ret < 0) { ERROR("Failed to setup container \"%s\".", handler->name); goto out_warn_father; }