[6/7] spfs: return duplicated socket from usernsd

Submitted by Stanislav Kinsburskiy on Dec. 20, 2017, 4:07 p.m.

Details

Message ID 20171220160716.957380.32587.stgit@skinsbursky-vz7.qa.sw.ru
State New
Series "spfs: duplicate socket before sending it from usernsd"
Headers show

Commit Message

Stanislav Kinsburskiy Dec. 20, 2017, 4:07 p.m.
Usernsd closes socket when sent.

https://jira.sw.ru/browse/PSBM-79462

Signed-off-by: Stanislav Kinsburskiy <skinsbursky@virtuozzo.com>
---
 criu/spfs.c |   10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

Patch hide | download patch | download mbox

diff --git a/criu/spfs.c b/criu/spfs.c
index da19179..857a167 100644
--- a/criu/spfs.c
+++ b/criu/spfs.c
@@ -162,11 +162,19 @@  static int start_spfs_manager(void)
 static int get_spfs_mngr_sock(void *start, int fd, pid_t pid)
 {
 	int sock;
+	int sfd;
 
 	sock = get_service_fd(SPFS_MNGR_SK);
 	if (sock < 0 && start)
 		sock = start_spfs_manager();
-	return sock;
+	if (sock < 0)
+		return sock;
+
+	sfd = dup(sock);
+	if (sfd < 0)
+		pr_perror("failed to duplicate socket %d", sock);
+
+	return sfd;
 }
 
 static int request_spfs_mngr_sock(bool *start_mngr)

Comments

Andrey Vagin Dec. 20, 2017, 8:01 p.m.
On Wed, Dec 20, 2017 at 07:07:16PM +0300, Stanislav Kinsburskiy wrote:
> Usernsd closes socket when sent.
> 
> https://jira.sw.ru/browse/PSBM-79462
> 
> Signed-off-by: Stanislav Kinsburskiy <skinsbursky@virtuozzo.com>
> ---
>  criu/spfs.c |   10 +++++++++-
>  1 file changed, 9 insertions(+), 1 deletion(-)
> 
> diff --git a/criu/spfs.c b/criu/spfs.c
> index da19179..857a167 100644
> --- a/criu/spfs.c
> +++ b/criu/spfs.c
> @@ -162,11 +162,19 @@ static int start_spfs_manager(void)
>  static int get_spfs_mngr_sock(void *start, int fd, pid_t pid)
>  {
>  	int sock;
> +	int sfd;
>  
>  	sock = get_service_fd(SPFS_MNGR_SK);
>  	if (sock < 0 && start)
>  		sock = start_spfs_manager();
> -	return sock;
> +	if (sock < 0)
> +		return sock;
> +

start_spfs_manager() returns a descriptor which has to be closed.

You need to dup a descriptor, only if it is a service one.

> +	sfd = dup(sock);
> +	if (sfd < 0)
> +		pr_perror("failed to duplicate socket %d", sock);
> +
> +	return sfd;
>  }
>  
>  static int request_spfs_mngr_sock(bool *start_mngr)
>