[CRIU] [PATCH 9/9] unix: split dump_external_sockets() for readability
Andrei Vagin
avagin at virtuozzo.com
Fri Mar 16 20:24:30 MSK 2018
Signed-off-by: Andrei Vagin <avagin at virtuozzo.com>
---
criu/sk-unix.c | 75 +++++++++++++++++++++++++++++++++++-----------------------
1 file changed, 45 insertions(+), 30 deletions(-)
diff --git a/criu/sk-unix.c b/criu/sk-unix.c
index a4e8c5630..67c238855 100644
--- a/criu/sk-unix.c
+++ b/criu/sk-unix.c
@@ -768,48 +768,63 @@ int unix_receive_one(struct nlmsghdr *h, struct ns_id *ns, void *arg)
return unix_collect_one(m, tb, ns);
}
+static int __dump_external_socket(struct unix_sk_desc *sk,
+ struct unix_sk_desc *peer)
+{
+ int ret;
+
+ ret = run_plugins(DUMP_UNIX_SK, sk->fd, sk->sd.ino);
+ if (ret < 0 && ret != -ENOTSUP)
+ return -1;
+
+ if (ret == 0) {
+ sk->ue->uflags |= USK_CALLBACK;
+ return 0;
+ }
+
+ if (unix_sk_exception_lookup_id(sk->sd.ino)) {
+ pr_debug("found exception for unix name-less external socket.\n");
+ return 0;
+ }
+
+ /* Legacy -x|--ext-unix-sk option handling */
+ if (!opts.ext_unix_sk) {
+ show_one_unix("Runaway socket", peer);
+ pr_err("External socket is used. "
+ "Consider using --" USK_EXT_PARAM " option.\n");
+ return -1;
+ }
+
+ if (peer->type != SOCK_DGRAM) {
+ show_one_unix("Ext stream not supported", peer);
+ pr_err("Can't dump half of stream unix connection.\n");
+ return -1;
+ }
+
+ if (!peer->name) {
+ show_one_unix("Ext dgram w/o name", peer);
+ pr_err("Can't dump name-less external socket.\n");
+ pr_err("%d\n", sk->fd);
+ return -1;
+ }
+
+ return 0;
+}
+
static int dump_external_sockets(struct unix_sk_desc *peer)
{
struct unix_sk_desc *sk;
- int ret;
while (!list_empty(&peer->peer_list)) {
sk = list_first_entry(&peer->peer_list, struct unix_sk_desc, peer_node);
- ret = run_plugins(DUMP_UNIX_SK, sk->fd, sk->sd.ino);
- if (ret == -ENOTSUP) {
- if (unix_sk_exception_lookup_id(sk->sd.ino)) {
- pr_debug("found exception for unix name-less external socket.\n");
- } else {
- /* Legacy -x|--ext-unix-sk option handling */
- if (!opts.ext_unix_sk) {
- show_one_unix("Runaway socket", peer);
- pr_err("External socket is used. "
- "Consider using --" USK_EXT_PARAM " option.\n");
- return -1;
- }
-
- if (peer->type != SOCK_DGRAM) {
- show_one_unix("Ext stream not supported", peer);
- pr_err("Can't dump half of stream unix connection.\n");
- return -1;
- }
-
- if (!peer->name) {
- show_one_unix("Ext dgram w/o name", peer);
- pr_err("Can't dump name-less external socket.\n");
- pr_err("%d\n", sk->fd);
- return -1;
- }
- }
- } else if (ret < 0)
+ if (__dump_external_socket(sk, peer))
return -1;
- else
- sk->ue->uflags |= USK_CALLBACK;
if (write_unix_entry(sk))
return -1;
close_safe(&sk->fd);
+
list_del_init(&sk->peer_node);
}
--
2.13.6
More information about the CRIU
mailing list