The problem seems to be in liblogging-0.7.1/src/socketsUnix.c:
"Normal" debug output to file only works in debug mode:
- Code: Select all
sbSockObj* sbSockInitEx(int iAF, int iSockType)
{
struct sbSockObject *pThis;
assert((iSockType == SOCK_STREAM) || (iSockType == SOCK_DGRAM));
pThis = (struct sbSockObject*) calloc(1, sizeof(struct sbSockObject));
if(pThis != NULL)
{ /* initialize class members */
! FILE *fp; fp = fopen("/tmp/liblogging.log", "a"); fprintf(fp, "socket(%d, %d, 0) => ", iAF, iSockType); fclose(fp);
if((pThis->sock = socket(iAF, iSockType, 0)) == INVALID_SOCKET)
{
! fp = fopen("/tmp/liblogging.log", "a"); fprintf(fp, "INVALID_SOCKET\n"); fclose(fp);
free(pThis);
return(NULL);
}
! fp = fopen("/tmp/liblogging.log", "a"); fprintf(fp, "%d\n", pThis->sock); fclose(fp);
/* rest of initialization */
pThis->bIsInError = FALSE;
pThis->OID = OIDsbSock;
pThis->iCurInBufPos = 0;
pThis->iInBufLen = 0;
}
return(pThis);
}
"Optimized" debug output to file works every time:
- Code: Select all
sbSockObj* sbSockInitEx(int iAF, int iSockType)
{
struct sbSockObject *pThis;
assert((iSockType == SOCK_STREAM) || (iSockType == SOCK_DGRAM));
pThis = (struct sbSockObject*) calloc(1, sizeof(struct sbSockObject));
if(pThis != NULL)
{ /* initialize class members */
! FILE *fp; fp = fopen("/tmp/liblogging.log", "a"); fprintf(fp, "socket(%d, %d, 0) => ", iAF, iSockType);
if((pThis->sock = socket(iAF, iSockType, 0)) == INVALID_SOCKET)
{
! fprintf(fp, "INVALID_SOCKET\n"); fclose(fp);
free(pThis);
return(NULL);
}
! fprintf(fp, "%d\n", pThis->sock); fclose(fp);
/* rest of initialization */
pThis->bIsInError = FALSE;
pThis->OID = OIDsbSock;
pThis->iCurInBufPos = 0;
pThis->iInBufLen = 0;
}
return(pThis);
}
So keeping another file descriptor open "fixes" the code. Something seems to wrong with fd 6 (using the extra open file I get socket fd 7). At least it is this fd when using my full blown configuration file (UDP, TCP, RELP and RFC3195).
Also, when running under "strace -ff", the socket call succeeds. I don't really have an idea what could possibly be wrong there (maybe some problem due to cloning the process?)...