[v5,09/11] sk-queue: Use sendto() to restore socket queue

Submitted by Kirill Tkhai on June 16, 2016, 1:54 p.m.

Details

Message ID 146608526507.15781.12374696977980426088.stgit@pro
State Rejected
Series "Support for packet's msg_name in receive queue of promiscous DGRAM sockets"
Headers show

Commit Message

Kirill Tkhai June 16, 2016, 1:54 p.m.
v5: New. This was split from:
"allow to use several file descriptors to restore a queue"

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
---
 criu/include/sk-queue.h |    7 ++++++-
 criu/sk-queue.c         |    9 +++++----
 2 files changed, 11 insertions(+), 5 deletions(-)

Patch hide | download patch | download mbox

diff --git a/criu/include/sk-queue.h b/criu/include/sk-queue.h
index e3d8dff..a16edc6 100644
--- a/criu/include/sk-queue.h
+++ b/criu/include/sk-queue.h
@@ -16,6 +16,11 @@  extern struct list_head packets_list;
 
 extern struct collect_image_info sk_queues_cinfo;
 extern int dump_sk_queue(int sock_fd, int sock_id, u64 (*get_sender)(const char *, int));
-extern int restore_sk_queue(int fd, unsigned int peer_id);
+extern int __restore_sk_queue(int queuer_fd, unsigned int peer_id,
+			      struct sockaddr *dst_addr, socklen_t dst_addrlen);
+static inline int restore_sk_queue(int queuer_fd, unsigned int peer_id)
+{
+	return __restore_sk_queue(queuer_fd, peer_id, NULL, 0);
+}
 
 #endif /* __CR_SK_QUEUE_H__ */
diff --git a/criu/sk-queue.c b/criu/sk-queue.c
index 8e6556a..9e9a484 100644
--- a/criu/sk-queue.c
+++ b/criu/sk-queue.c
@@ -188,15 +188,15 @@  int dump_sk_queue(int sock_fd, int sock_id, u64 (*get_sender)(const char *, int)
 	return ret;
 }
 
-int restore_sk_queue(int fd, unsigned int peer_id)
+int __restore_sk_queue(int queuer_fd, unsigned int peer_id, struct sockaddr *dst_addr, socklen_t dst_addrlen)
 {
 	struct sk_packet *pkt, *tmp;
-	int ret;
 	struct cr_img *img;
+	int fd, ret;
 
 	pr_info("Trying to restore recv queue for %u\n", peer_id);
 
-	if (restore_prepare_socket(fd))
+	if (restore_prepare_socket(queuer_fd) < 0)
 		return -1;
 
 	img = open_image(CR_FD_SK_QUEUES, O_RSTR);
@@ -235,7 +235,8 @@  int restore_sk_queue(int fd, unsigned int peer_id)
 			goto err;
 		}
 
-		ret = write(fd, buf, entry->length);
+		fd = queuer_fd;
+		ret = sendto(fd, buf, entry->length, 0, dst_addr, dst_addrlen);
 		xfree(buf);
 		if (ret < 0) {
 			pr_perror("Failed to send packet");