[CRIU] [PATCH 3/3] img-cache/proxy: Close sockets on failure
Radostin Stoyanov
rstoyanov1 at gmail.com
Tue Jan 29 20:37:47 MSK 2019
Signed-off-by: Radostin Stoyanov <rstoyanov1 at gmail.com>
---
criu/img-cache.c | 13 +++++++++----
criu/img-proxy.c | 3 ++-
2 files changed, 11 insertions(+), 5 deletions(-)
diff --git a/criu/img-cache.c b/criu/img-cache.c
index 1e6f79ad0..5d7b90ce6 100644
--- a/criu/img-cache.c
+++ b/criu/img-cache.c
@@ -10,6 +10,8 @@
int image_cache(bool background, char *local_cache_path, unsigned short cache_write_port)
{
+ int tmp;
+
pr_info("Proxy to Cache Port %d, CRIU to Cache Path %s\n",
cache_write_port, local_cache_path);
restoring = true;
@@ -24,12 +26,14 @@ int image_cache(bool background, char *local_cache_path, unsigned short cache_wr
return -1;
}
// Wait to accept connection from proxy.
- proxy_to_cache_fd = accept(proxy_to_cache_fd, NULL, 0);
- if (proxy_to_cache_fd < 0) {
+ tmp = accept(proxy_to_cache_fd, NULL, 0);
+ if (tmp < 0) {
pr_perror("Unable to accept remote image connection"
" from image proxy");
- return -1; // TODO - should close other sockets.
+ close(proxy_to_cache_fd);
+ return -1;
}
+ proxy_to_cache_fd = tmp;
}
pr_info("Cache is connected to Proxy through fd %d\n", proxy_to_cache_fd);
@@ -37,7 +41,8 @@ int image_cache(bool background, char *local_cache_path, unsigned short cache_wr
local_req_fd = setup_UNIX_server_socket(local_cache_path);
if (local_req_fd < 0) {
pr_perror("Unable to open cache to proxy UNIX socket");
- return -1; // TODO - should close other sockets.
+ close(proxy_to_cache_fd);
+ return -1;
}
diff --git a/criu/img-proxy.c b/criu/img-proxy.c
index e73620cdb..7737de069 100644
--- a/criu/img-proxy.c
+++ b/criu/img-proxy.c
@@ -26,7 +26,8 @@ int image_proxy(bool background, char *local_proxy_path, char *fwd_host, unsigne
proxy_to_cache_fd = setup_tcp_client(fwd_host, fwd_port);
if (proxy_to_cache_fd < 0) {
pr_perror("Unable to open proxy to cache TCP socket");
- return -1; // TODO - should close other sockets.
+ close(local_req_fd);
+ return -1;
}
}
--
2.20.1
More information about the CRIU
mailing list