[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Closure of socket by shutdown function
[Thread Prev] | [Thread Next]
- Subject: Closure of socket by shutdown function
- From: Aarthi <aarthit2014@xxxxxxxxx>
- Reply-to: libssh@xxxxxxxxxx
- Date: Fri, 30 May 2014 06:20:18 +0000 (UTC)
- To: libssh@xxxxxxxxxx
Hi All, 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. Thanks Aarthi
Re: Closure of socket by shutdown function | Andreas Schneider <asn@xxxxxxxxxxxxxx> |