[CRIU] [PATCH 1/7] remote: Move setup_TCP_server_socket to img-cache
Radostin Stoyanov
rstoyanov1 at gmail.com
Sun Jul 8 19:47:05 MSK 2018
The function setup_TCP_server_socket() is used only in img-cache.c
and it makes sense to be stored there. This change will also reduce
the size of img-remote.c
Signed-off-by: Radostin Stoyanov <rstoyanov1 at gmail.com>
---
criu/img-cache.c | 38 +++++++++++++++++++++++++++++++++++++
criu/img-remote.c | 40 ---------------------------------------
criu/include/img-remote.h | 1 -
3 files changed, 38 insertions(+), 41 deletions(-)
diff --git a/criu/img-cache.c b/criu/img-cache.c
index 98fdf80e..1eadb977 100644
--- a/criu/img-cache.c
+++ b/criu/img-cache.c
@@ -22,6 +22,44 @@ int accept_proxy_to_cache(int sockfd)
return proxy_fd;
}
+int setup_TCP_server_socket(int port)
+{
+ struct sockaddr_in serv_addr;
+ int sockopt = 1;
+ int sockfd = socket(AF_INET, SOCK_STREAM, 0);
+
+ if (sockfd < 0) {
+ pr_perror("Unable to open image socket");
+ return -1;
+ }
+
+ bzero((char *) &serv_addr, sizeof(serv_addr));
+ serv_addr.sin_family = AF_INET;
+ serv_addr.sin_addr.s_addr = INADDR_ANY;
+ serv_addr.sin_port = htons(port);
+
+ if (setsockopt(
+ sockfd, SOL_SOCKET, SO_REUSEADDR, &sockopt, sizeof(sockopt)) == -1) {
+ pr_perror("Unable to set SO_REUSEADDR");
+ goto err;
+ }
+
+ if (bind(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0) {
+ pr_perror("Unable to bind image socket");
+ goto err;
+ }
+
+ if (listen(sockfd, DEFAULT_LISTEN)) {
+ pr_perror("Unable to listen image socket");
+ goto err;
+ }
+
+ return sockfd;
+err:
+ close(sockfd);
+ return -1;
+}
+
int image_cache(bool background, char *local_cache_path, unsigned short cache_write_port)
{
pr_info("Proxy to Cache Port %d, CRIU to Cache Path %s\n",
diff --git a/criu/img-remote.c b/criu/img-remote.c
index f148e23f..4593f41f 100644
--- a/criu/img-remote.c
+++ b/criu/img-remote.c
@@ -120,46 +120,6 @@ struct roperation *get_rop_by_name(
return NULL;
}
-int setup_TCP_server_socket(int port)
-{
- struct sockaddr_in serv_addr;
- int sockopt = 1;
- int sockfd = socket(AF_INET, SOCK_STREAM, 0);
-
- if (sockfd < 0) {
- pr_perror("Unable to open image socket");
- return -1;
- }
-
- bzero((char *) &serv_addr, sizeof(serv_addr));
- serv_addr.sin_family = AF_INET;
- serv_addr.sin_addr.s_addr = INADDR_ANY;
- serv_addr.sin_port = htons(port);
-
- if (setsockopt(
- sockfd, SOL_SOCKET, SO_REUSEADDR, &sockopt, sizeof(sockopt)) == -1) {
- pr_perror("Unable to set SO_REUSEADDR");
- goto err;
- }
-
- if (bind(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0) {
- pr_perror("Unable to bind image socket");
- goto err;
- }
-
- if (listen(sockfd, DEFAULT_LISTEN)) {
- pr_perror("Unable to listen image socket");
- goto err;
- }
-
- return sockfd;
-err:
- close(sockfd);
- return -1;
-}
-
-
-
int setup_TCP_client_socket(char *hostname, int port)
{
int sockfd;
diff --git a/criu/include/img-remote.h b/criu/include/img-remote.h
index 15e1bc5d..ac17025d 100644
--- a/criu/include/img-remote.h
+++ b/criu/include/img-remote.h
@@ -85,7 +85,6 @@ int64_t recv_image_async(struct roperation *op);
int64_t read_remote_header(int fd, char *snapshot_id, char *path, int *open_mode, uint64_t *size);
int64_t write_remote_header(int fd, char *snapshot_id, char *path, int open_mode, uint64_t size);
-int setup_TCP_server_socket(int port);
int setup_TCP_client_socket(char *hostname, int port);
int setup_UNIX_server_socket(char *path);
void socket_set_non_blocking(int fd);
--
2.17.1
More information about the CRIU
mailing list