[syslog-ng] Problem when getting data from syslog-ng into a socket program

Diluka Moratuwage diluka at wso2.com
Sat Aug 11 16:15:06 CEST 2007


Hi,
    I have a little problem which I need to solve. I wrote a small 
program, which
listens to the syslog-ng. I think I have encountered a problem with the 
timing
I'm connecting and disconnecting to the syslog-ng.

    I almost always get the following msg with other msgs,

<43>Aug 11 19:39:03 diluka-laptop syslog-ng[5084]: Connection broken; 
time_reopen='10'
<43>Aug 11 19:39:13 diluka-laptop syslog-ng[5084]: EOF occurred while 
idle; fd='20'


    Please let me know whether following code snippet has anything 
irrelevent
or unsuitable.

    while(1)
    {
        int len, read = 0;
        new_fd = accept(sockfd, (struct sockaddr *)&their_addr, &sin_size);

        while((len = recv (new_fd, buffer, BUFF_SIZE - 1, MSG_PEEK)) > 0)
        {
            read = recv(sockfd, buffer, BUFF_SIZE - 1, 0);
            buffer[read] = '\0';
            printf(buffer);
            memset(buffer, '\0', BUFF_SIZE * sizeof(char));
            break;
        }
        close(new_fd);
        new_fd = 0;
    }

    I highly appreciate if you can give some help for me to get the 
problem solved.

Thanks,
Diluka.


More information about the syslog-ng mailing list