[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Closure of socket by shutdown function
[Thread Prev] | [Thread Next]
- Subject: Re: Closure of socket by shutdown function
- From: Andreas Schneider <asn@xxxxxxxxxxxxxx>
- Reply-to: libssh@xxxxxxxxxx
- Date: Fri, 30 May 2014 12:33:36 +0200
- To: libssh@xxxxxxxxxx
- Cc: Aarthi <aarthit2014@xxxxxxxxx>
On Friday 30 May 2014 06:20:18 Aarthi wrote:
> Hi All,
Hi,
> We are facing an issue while using libssh 0.6.3 integrated with an
> application, say app A. app A runs as a process and libssh is linked to it.
> The app A disables SSH by closing the existing SSH sessions using
> ssh_disconnect(session) and doing ssh_free() and ssh_bind_free(). SSH is
> enabled by ssh_new () ,ssh_bind_listen(),and ssh_bind_accept().
>
>
> The application A forks some processes during its execution. The issue
> occurs when SSH is enabled a session is established, process app B is
> forked, SSH is disabled and enabled.
>
> 1) Initially SSH is enbaled
> 2) Fork process B
> 3) Disable SSH
> 4) Enable SSH
> In the above process during step 2 the “app B” process inherits the ports
> created by “app A” process. In step 3 the port is closed by “app A” process
> but since the “app B” process is running the port 22 remains open (its kept
> in this way by the Operating System)). At step4 when port 22 is bound again
> it returns error as the port is kept open by the Operating System (app B
> process is still running).
> This is a standard system issue with forking of processes. This issue could
> occur when “application A” forks any process during SSH disable and that
> process lives for a while. To solve it the socket has to be “shutdown”
> before “closing”.
>
> the following patch can be applied to bind.c to overcome the issue.
>
> Libssh -> src/bind.c
> void ssh_bind_free(ssh_bind sshbind){
> int i;
> if (sshbind == NULL) {
> return;
> }
> if (sshbind->bindfd >= 0) {
> #ifdef _WIN32
> closesocket(sshbind->bindfd);
> #else
> + shutdown(sshbind->bindfd,2);
> close(sshbind->bindfd);
> #endif
> }
> sshbind->bindfd = SSH_INVALID_SOCKET;
>
> Please let us know your thoughts on this patch, and the release where this
> patch could be integrated to the main line.
I don't think this is a common problem. It is a special case for how you
implemented forking and handling of SSH.
So you should call
fd = ssh_bind_getfd(bind);
shutdown(fd, 2)
ssh_bind_free(bind);
Cheers,
-- andreas
--
Andreas Schneider GPG-ID: CC014E3D
www.cryptomilk.org asn@xxxxxxxxxxxxxx
| Closure of socket by shutdown function | Aarthi <aarthit2014@xxxxxxxxx> |