cfengine/core — pull request #47 by nyetsche (2012-04-19 16:21:26+00:00)
Title: Pass promise var to ServerConnect

If the readtcp() function is used and the socket cannot be connected (e.g.,
there is nothing listening on that port), this function tries to close the
socket that is never actually opened:

cf3> Couldn't send
cf3> !!! System error for send: "Bad file descriptor"
cf3> !! Could not close socket
cf3> !!! System error for cf_closesocket: "Bad file descriptor"

The root cause appears to be in ServerConnect() function, defined in
src/client_code.c, with the cause at approx line 1103:

if (!connected && pp)
{
cfPS(cf_verbose, CF_FAIL, "connect", pp, attr, " !! Unable to connect to server %s", host);
return false;
}

ServerConnect() is defined as:

int ServerConnect(AgentConnection *conn, char *host, Attributes attr, Promise *pp)

yet (prepatched) function called with pp=NULL - which means that the check above fails
and the function returns 'true', even though the connected variable is (rightly) false.

I've also opened up a bug report here - https://cfengine.com/bugtracker/view.php?id=1085 - I'm not sure where the best place to discuss this is. My patch "works", but I'm not sure what the intended role of the Promise *pp argument to ServerConnect() is. I wonder about unexpected consequences.