Re: [squid-users] Squid redirect problem

From: Deepa D <deepndharma@dont-contact.us>
Date: Sat, 31 Jan 2004 10:54:08 +0000 (GMT)

Hi,
   Sorry the delay.
   I have pasted the code to this mail.
   Kindly let me know if there is any problem in it.

int sig_hup = 0;

int main (int argc, char *argv[]) {

  int sd, rc;
  struct sockaddr_in localAddr, servAddr;
  struct hostent *h;

  char buff[MAX_BUFF] = "";
  int nread = 0;

  h = gethostbyname("127.0.0.1");
  if(h == NULL) {
            log(LOG_ERROR, " Client - unknown host\n ");
            exit(1);
  }

  servAddr.sin_family = h->h_addrtype;
  memcpy((char *) &servAddr.sin_addr.s_addr,
h->h_addr_list[0], h->h_length);
  servAddr.sin_port = htons(SERVER_PORT);

  while(!sig_hup) {

        if(fgets(buff, MAX_BUFF, stdin) != NULL) {

                /* create socket */
                sd = socket(AF_INET, SOCK_STREAM, 0);
                if(sd < 0) {
                        log(LOG_ERROR, " Client - cannot open socket\n ");
                        exit(1);
                }

                /* bind any port number */
                localAddr.sin_family = AF_INET;
                localAddr.sin_addr.s_addr = htonl(INADDR_ANY);
                localAddr.sin_port = htons(0);

                rc = bind(sd, (struct sockaddr *) &localAddr,
sizeof(localAddr));
                if(rc < 0) {
                        log(LOG_ERROR, " Client - cannot bind to
SERVER_PORT\n ");
                        exit(1);
                }

                
                rc = connect(sd, (struct sockaddr *) &servAddr,
sizeof(servAddr));
                if(rc < 0) {
                        log(LOG_ERROR, " Client - could not connect to the
server\n ");
                        exit(1);
                }

                if(strchr(buff, '\n') == NULL) {
                         /* Append a new line character so that the data
gets flushed. */
                         strcat(buff,"\n");
                }
                if(write(sd , buff , strlen(buff)) < 0) {
                        log(LOG_ERROR," Client - error while writing to
server.\n ");
                } else {
                        logger1(LOG_INFO," Client - wrote to server = ",
buff);
                }

                memset(buff,'\0',MAX_BUFF);
                nread = read(sd, buff, MAX_BUFF);
                puts(buff);
                fflush(stdout);
                close(sd);
        }

        // The client exits when it reads an EOF from stdin.
        exit(0);

  }
  *buff = '\0';
  return 0;

}

void contentfilter_HUP(int signal) {

  /* exciting bit of code this one :-) */
  sig_hup = 1;
  log(LOG_INFO, "sigHUP received.
Reconfiguring....\n");
}

Regards,
   Deepa

 --- Henrik Nordstrom <hno@squid-cache.org> wrote: >
On Mon, 19 Jan 2004, Deepa D wrote:
>
> > FATAL: The redirector helpers are crashing
> too
> > rapidly, need help!
> > But, when I don't do exit(0) in my C code once
> > read from stdin returns null, I don't have this
> > problem.
>
> Then I think you are exiting even if the read does
> not return EOF.
>
> If you want you can post your helper source and we
> take a look.
>
> Regards
> Henrik
>

________________________________________________________________________
Yahoo! India Mobile: Download the latest polyphonic ringtones.
Go to http://in.mobile.yahoo.com
Received on Sat Jan 31 2004 - 06:40:52 MST

This archive was generated by hypermail pre-2.1.9 : Sun Feb 01 2004 - 12:00:10 MST