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-&gt;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="&#39;courier new&#39;, 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= &quot;i&quot;;<br>  const char *keyfile1=&quot;/home/i/.ssh/id_rsa.pub&quot;;<br>  const char *keyfile2=&quot;/home/i/.ssh/id_rsa&quot;;<br>  const char *password= &quot;D0r1nha23&quot;;<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*)(&amp;sin), sizeof(struct sockaddr_in)<br>
            ) != 0 ) {<br>    fprintf(stderr, &quot;failed to connect!\n&quot;);<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>                  , &quot;Failure establishing SSH session&quot; );<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>                  , &quot;\tAuthentication by public key failed!&quot; );<br>    return;<br>  } else {<br>    _libssh2_debug( session, LIBSSH2_TRACE_TRANS<br>                  , &quot;\tAuthentication by public key succeeded.&quot; );<br>
    if(!(channel= libssh2_channel_open_session(session))) {<br>      _libssh2_debug( session, LIBSSH2_TRACE_TRANS<br>                    , &quot;Unable to open a session&quot; );<br>      return;<br>    } else {<br>      libssh2_channel_setenv(channel, &quot;FOO&quot;, &quot;bar&quot;);<br>
      if(libssh2_channel_request_pty(channel, &quot;vanilla&quot;)) {<br>        _libssh2_debug( session, LIBSSH2_TRACE_TRANS<br>                      , &quot;Failed requesting pty&quot; );<br>      } else {<br>        if(libssh2_channel_shell(channel)) {<br>
          _libssh2_debug( session, LIBSSH2_TRACE_TRANS<br>                        , &quot;Unable to request shell on allocated pty&quot; );<br>        } else {<br>          if(channel){<br>            libssh2_channel_free(channel);<br>
            channel= NULL;<br>          }<br>        }<br>      }<br>    }<br>  }<br>  libssh2_session_disconnect( session<br>                            , &quot;Normal Shutdown, Thank you for playing&quot; );<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="&#39;courier new&#39;, monospace">foreign import ccall unsafe &quot;libssh2_test&quot;  <br>
  libssh2Test:: IO ()</font><div><br></div><div>as well as </div><div><br></div><font face="&#39;courier new&#39;, monospace">{# context lib=&quot;ssh2&quot; prefix=&quot;libssh2&quot; #}<br>{# fun test as test { } -&gt; `()&#39; #}</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>