Re: Cachemgr code: Why write to stdout?

From: Nigel Metheringham <Nigel.Metheringham@dont-contact.us>
Date: Fri, 14 Mar 1997 11:37:40 +0000

[Ccd to squid-users after previous private email with Kate]

Ha... its a bug!

Whats happening is this... relevant pieces of code included, rest dropped

    /* read stuff from stdin for form contents of POST request */
    ...
    close(0);
    ...
    /* Connect to the server */
    if ((conn = socket(PF_INET, SOCK_STREAM, 0)) < 0) {

- this happens to reuse fd 0 (stdin) on all normal Unix varients

    if ((conn = client_comm_connect(conn, hostname, portnum)) < 0) {

- client_comm_connect returns 0 for sucess, which happens to be the
- correct fd number!

I strongly suggest that we change that last if statement to

    if (client_comm_connect(conn, hostname, portnum) < 0) {

to prevent us getting badly caught out by any other changes!

Patch is
=======================
Index: src/cachemgr.c
--- src/cachemgr.c.orig Fri Mar 14 11:45:16 1997
+++ src/cachemgr.c Fri Mar 14 11:45:42 1997
@@ -805,7 +805,7 @@
        perror("client: socket");
        exit(1);
     }
- if ((conn = client_comm_connect(conn, hostname, portnum)) < 0) {
+ if (client_comm_connect(conn, hostname, portnum) < 0) {
        printf("Error: connecting to cache mgr: %s:%d\n", hostname,
portnum);
        printf("%s</PRE></BODY></HTML>\n", xstrerror());
        exit(1);
=======================

        Nigel.

-- 
[ Nigel.Metheringham@theplanet.net   -  Systems Software Engineer ]
[ Tel : +44 113 251 6012                   Fax : +44 113 224 0003 ]
[            Friends don't let friends use sendmail!              ]
Received on Fri Mar 14 1997 - 03:59:47 MST

This archive was generated by hypermail pre-2.1.9 : Tue Dec 09 2003 - 16:34:41 MST