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: 's avatarChristian Brauner <christian.brauner@ubuntu.com>
parent 1f9bbd23
...@@ -3096,8 +3096,6 @@ static int lxc_send_ttys_to_parent(struct lxc_handler *handler) ...@@ -3096,8 +3096,6 @@ static int lxc_send_ttys_to_parent(struct lxc_handler *handler)
else else
TRACE("Sent %d ttys to parent", conf->tty); TRACE("Sent %d ttys to parent", conf->tty);
close(handler->data_sock[0]);
close(handler->data_sock[1]);
lxc_delete_tty(tty_info); lxc_delete_tty(tty_info);
return ret; return ret;
......
...@@ -3003,14 +3003,9 @@ int lxc_network_send_veth_names_to_child(struct lxc_handler *handler) ...@@ -3003,14 +3003,9 @@ int lxc_network_send_veth_names_to_child(struct lxc_handler *handler)
continue; continue;
ret = send(data_sock, netdev->name, IFNAMSIZ, 0); ret = send(data_sock, netdev->name, IFNAMSIZ, 0);
if (ret < 0) { if (ret < 0)
close(handler->data_sock[0]);
close(handler->data_sock[1]);
return -1; 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; return 0;
...@@ -3033,14 +3028,9 @@ int lxc_network_recv_veth_names_from_parent(struct lxc_handler *handler) ...@@ -3033,14 +3028,9 @@ int lxc_network_recv_veth_names_from_parent(struct lxc_handler *handler)
continue; continue;
ret = recv(data_sock, netdev->name, IFNAMSIZ, 0); ret = recv(data_sock, netdev->name, IFNAMSIZ, 0);
if (ret < 0) { if (ret < 0)
close(handler->data_sock[0]);
close(handler->data_sock[1]);
return -1; 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; return 0;
...@@ -3062,23 +3052,18 @@ int lxc_network_send_name_and_ifindex_to_parent(struct lxc_handler *handler) ...@@ -3062,23 +3052,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. */ /* Send network device name in the child's namespace to parent. */
ret = send(data_sock, netdev->name, IFNAMSIZ, 0); ret = send(data_sock, netdev->name, IFNAMSIZ, 0);
if (ret < 0) if (ret < 0)
goto on_error; return -1;
/* Send network device ifindex in the child's namespace to /* Send network device ifindex in the child's namespace to
* parent. * parent.
*/ */
ret = send(data_sock, &netdev->ifindex, sizeof(netdev->ifindex), 0); ret = send(data_sock, &netdev->ifindex, sizeof(netdev->ifindex), 0);
if (ret < 0) if (ret < 0)
goto on_error; return -1;
} }
TRACE("Sent network device names and ifindeces to parent"); TRACE("Sent network device names and ifindeces to parent");
return 0; 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) int lxc_network_recv_name_and_ifindex_from_child(struct lxc_handler *handler)
...@@ -3099,20 +3084,15 @@ int lxc_network_recv_name_and_ifindex_from_child(struct lxc_handler *handler) ...@@ -3099,20 +3084,15 @@ int lxc_network_recv_name_and_ifindex_from_child(struct lxc_handler *handler)
*/ */
ret = recv(data_sock, netdev->name, IFNAMSIZ, 0); ret = recv(data_sock, netdev->name, IFNAMSIZ, 0);
if (ret < 0) if (ret < 0)
goto on_error; return -1;
/* Receive network device ifindex in the child's namespace to /* Receive network device ifindex in the child's namespace to
* parent. * parent.
*/ */
ret = recv(data_sock, &netdev->ifindex, sizeof(netdev->ifindex), 0); ret = recv(data_sock, &netdev->ifindex, sizeof(netdev->ifindex), 0);
if (ret < 0) if (ret < 0)
goto on_error; return -1;
} }
return 0; return 0;
on_error:
close(handler->data_sock[0]);
close(handler->data_sock[1]);
return -1;
} }
...@@ -912,7 +912,10 @@ static int do_start(void *data) ...@@ -912,7 +912,10 @@ static int do_start(void *data)
} }
/* Setup the container, ip, names, utsname, ... */ /* 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); ERROR("Failed to setup container \"%s\".", handler->name);
goto out_warn_father; goto out_warn_father;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment