Dear all,<div><br></div><div>after noticing problems with libssh2, and trying to fix this myself, I ran into a strange experience which I wish to get an explanation for.</div><div><br></div><div>After compiling an OpenSSH server and a raw C libssh2 (for comparison) with debug messaging, I with support of the libssh2 community was able to trace the problem back to a call to poll(3) in session.c::_libssh2_wait_socket(),</div>
<div><br></div><div> rc = poll(sockets, 1, has_timeout?ms_to_next: -1);</div><div><br></div><div>where sockets consists of a single socket, session->socket_fd.</div><div><br></div><div>This is roughly a polling with timeout for the connection – and, with the Haskell FFI, an</div>
<div><br></div><div> error 4 / EINTR / Interrupted system call</div><div><br></div><div>is thrown, and I was explained that this probably is caused by another signal of the same code unit. Not finding anything, I at the end extended libssh2 by a function,</div>
<div><br></div><font face="'courier new', monospace">LIBSSH2_API void libssh2_test(void){<br> struct sockaddr_in sin;<br> LIBSSH2_SESSION *session;<br> const char *fingerprint;<br> LIBSSH2_CHANNEL *channel;<br>
const unsigned long hostaddr= htonl(0x7F000001);<br> const char *username= "i";<br> const char *keyfile1="/home/i/.ssh/id_rsa.pub";<br> const char *keyfile2="/home/i/.ssh/id_rsa";<br> const char *password= "D0r1nha23";<br>
int got= 0;<br> int sock= socket(AF_INET, SOCK_STREAM, 0);<br> sin.sin_family= AF_INET;<br> sin.sin_port= htons(22);<br> sin.sin_addr.s_addr= hostaddr;<br> if(connect( sock, (struct sockaddr*)(&sin), sizeof(struct sockaddr_in)<br>
) != 0 ) {<br> fprintf(stderr, "failed to connect!\n");<br> return;<br> }<br> session= libssh2_session_init();<br> libssh2_trace(session,~0);<br> if(libssh2_session_handshake(session, sock)) {<br>
_libssh2_debug(session, LIBSSH2_TRACE_TRANS<br> , "Failure establishing SSH session" );<br> return;<br> }<br> fingerprint= libssh2_hostkey_hash(session, LIBSSH2_HOSTKEY_HASH_SHA1);<br> libssh2_userauth_list(session, username, strlen(username)); // ??<br>
if(libssh2_userauth_publickey_fromfile( session<br> , username<br> , keyfile1<br> , keyfile2<br> , password )) {<br>
_libssh2_debug(session, LIBSSH2_TRACE_TRANS<br> , "\tAuthentication by public key failed!" );<br> return;<br> } else {<br> _libssh2_debug( session, LIBSSH2_TRACE_TRANS<br> , "\tAuthentication by public key succeeded." );<br>
if(!(channel= libssh2_channel_open_session(session))) {<br> _libssh2_debug( session, LIBSSH2_TRACE_TRANS<br> , "Unable to open a session" );<br> return;<br> } else {<br> libssh2_channel_setenv(channel, "FOO", "bar");<br>
if(libssh2_channel_request_pty(channel, "vanilla")) {<br> _libssh2_debug( session, LIBSSH2_TRACE_TRANS<br> , "Failed requesting pty" );<br> } else {<br> if(libssh2_channel_shell(channel)) {<br>
_libssh2_debug( session, LIBSSH2_TRACE_TRANS<br> , "Unable to request shell on allocated pty" );<br> } else {<br> if(channel){<br> libssh2_channel_free(channel);<br>
channel= NULL;<br> }<br> }<br> }<br> }<br> }<br> libssh2_session_disconnect( session<br> , "Normal Shutdown, Thank you for playing" );<br> libssh2_session_free(session);<br>
close(sock);<br> libssh2_exit();<br> return;<br>}</font><div><br></div><div>and called it by</div><div><br></div><font face="'courier new', monospace">foreign import ccall unsafe "libssh2_test" <br>
libssh2Test:: IO ()</font><div><br></div><div>as well as </div><div><br></div><font face="'courier new', monospace">{# context lib="ssh2" prefix="libssh2" #}<br>{# fun test as test { } -> `()' #}</font><div>
<br></div><div>With both approaches, I still got the same EINTR error, while coalling libssh2_test() from C works completely flawless.</div><div><br></div><div>Is it possible that an interfering signal comes from the FFI? If yes, is there a workaround?</div>
<div><br></div><div>Grateful for any kind of enlightenment... :-)</div><div><br></div><div>Thanks a lot in advance, Nick</div><div><br></div>