~yolanda.robla/ubuntu/saucy/squid3/dep-8-tests

« back to all changes in this revision

Viewing changes to src/helper.cc

  • Committer: Package Import Robot
  • Author(s): Stefan Bader
  • Date: 2012-06-22 14:18:00 UTC
  • mfrom: (21.2.12 sid)
  • Revision ID: package-import@ubuntu.com-20120622141800-c0e3p4wjxekxp1qh
Tags: 3.1.20-1ubuntu1
* Merge from Debian testing (LP: #1016560).  Remaining changes:
  + debian/control:
    - Update maintainer.
    - Suggests apparmor (>= 2.3)
    - Depends on ssl-cert ((>= 1.0-11ubuntu1)
    - Add transitional dummy packages
  + debian/squid3.upstart
    - Move ulimit command to script section so that it applies
      to the started squid daemon. Thanks to Timur Irmatov (LP: 986159)
    - Work around squid not handling SIGHUP by adding respawn to
      upstart job. (LP: 978356)
  + debian/NEWS.Debian: Rename NEWS.debian, add note regarding squid3
    transition in 12.04 (LP: 924739) 
  + debian/rules
    - Re-enable all hardening options lost in the squid->squid3
      transition (LP: 986314)
  + squid3.resolvconf, debian/squid3.postinst, debian/squid3.postrm,
    debian/squid3.preinst, debian/squid3.prerm:
    - Convert init script to upstart
  + debian/patches/99-ubuntu-ssl-cert-snakeoil:
    - Use snakeoil certificates.
  + debian/logrotate
    - Use sar-reports rather than sarg-maint. (LP: 26616)
  + debian/patches/90-cf.data.ubuntu.dpatch:
    - Add an example refresh pattern for debs.
      (foundations-lucid-local-report spec)
  + Add disabled by default AppArmor profile (LP: 497790)
    - debian/squid3.upstart: load profile in pre-start stanza
    - add debian/usr.sbin.squid3 profile
    - debian/rules:
      + install debian/usr.sbin.squid3, etc/apparmor.d/force-complain and
        etc/apparmor.d/disable into $(INSTALLDIR)
      + use dh_apparmor
    - debian/squid3.install: install etc/apparmor.d/disable, force-complain
      and usr.sbin.squid3
    - debian/squid3.preinst: disable profile on clean install or upgrades
      from earlier than when we shipped the profile

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
1
2
/*
2
3
 * $Id$
3
4
 *
43
44
 
44
45
#define HELPER_MAX_ARGS 64
45
46
 
46
 
/* size of helper read buffer (maximum?). no reason given for this size */
47
 
/* though it has been seen to be too short for some requests */
48
 
/* it is dynamic, so increasng should not have side effects */
49
 
#define BUF_8KB 8192
 
47
 
 
48
/** Initial Squid input buffer size. Helper responses may exceed this, and
 
49
 * Squid will grow the input buffer as needed, up to ReadBufMaxSize.
 
50
 */
 
51
const size_t ReadBufMinSize(4*1024);
 
52
 
 
53
/** Maximum safe size of a helper-to-Squid response message plus one.
 
54
 * Squid will warn and close the stream if a helper sends a too-big response.
 
55
 * ssl_crtd helper is known to produce responses of at least 10KB in size.
 
56
 * Some undocumented helpers are known to produce responses exceeding 8KB.
 
57
 */
 
58
const size_t ReadBufMaxSize(32*1024);
50
59
 
51
60
static IOCB helperHandleRead;
52
61
static IOCB helperStatefulHandleRead;
150
159
        srv->addr = hlp->addr;
151
160
        srv->rfd = rfd;
152
161
        srv->wfd = wfd;
153
 
        srv->rbuf = (char *)memAllocBuf(BUF_8KB, &srv->rbuf_sz);
 
162
        srv->rbuf = (char *)memAllocBuf(ReadBufMinSize, &srv->rbuf_sz);
154
163
        srv->wqueue = new MemBuf;
155
164
        srv->roffset = 0;
156
165
        srv->requests = (helper_request **)xcalloc(hlp->concurrency ? hlp->concurrency : 1, sizeof(*srv->requests));
262
271
        srv->addr = hlp->addr;
263
272
        srv->rfd = rfd;
264
273
        srv->wfd = wfd;
265
 
        srv->rbuf = (char *)memAllocBuf(BUF_8KB, &srv->rbuf_sz);
 
274
        srv->rbuf = (char *)memAllocBuf(ReadBufMinSize, &srv->rbuf_sz);
266
275
        srv->roffset = 0;
267
276
        srv->parent = cbdataReference(hlp);
268
277
 
948
957
        helperReturnBuffer(i, srv, hlp, msg, t);
949
958
    }
950
959
 
951
 
    if (srv->rfd != -1)
952
 
        comm_read(fd, srv->rbuf + srv->roffset, srv->rbuf_sz - srv->roffset - 1, helperHandleRead, srv);
 
960
    if (srv->rfd != -1) {
 
961
        int spaceSize = srv->rbuf_sz - srv->roffset - 1;
 
962
        assert(spaceSize >= 0);
 
963
 
 
964
        // grow the input buffer if needed and possible
 
965
        if (!spaceSize && srv->rbuf_sz + 4096 <= ReadBufMaxSize) {
 
966
            srv->rbuf = (char *)memReallocBuf(srv->rbuf, srv->rbuf_sz + 4096, &srv->rbuf_sz);
 
967
            debugs(84, 3, HERE << "Grew read buffer to " << srv->rbuf_sz);
 
968
            spaceSize = srv->rbuf_sz - srv->roffset - 1;
 
969
            assert(spaceSize >= 0);
 
970
        }
 
971
 
 
972
        // quit reading if there is no space left
 
973
        if (!spaceSize) {
 
974
            debugs(84, DBG_IMPORTANT, "ERROR: Disconnecting from a " <<
 
975
                   "helper that overflowed " << srv->rbuf_sz << "-byte " <<
 
976
                   "Squid input buffer: " << hlp->id_name << " #" <<
 
977
                   (srv->index + 1));
 
978
 
 
979
            int wfd = srv->wfd;
 
980
            srv->wfd = -1;
 
981
            if (srv->rfd == wfd)
 
982
                srv->rfd = -1;
 
983
            srv->flags.closing=1;
 
984
            comm_close(wfd);
 
985
 
 
986
#if _SQUID_MSWIN_
 
987
            if (srv->hIpc) {
 
988
                if (WaitForSingleObject(srv->hIpc, 5000) != WAIT_OBJECT_0) {
 
989
                    getCurrentTime();
 
990
                    debugs(84, 1, "helperShutdown: WARNING: " << hlp->id_name <<
 
991
                           " #" << no << " (" << hlp->cmdline->key << "," <<
 
992
                           (long int)srv->pid << ") didn't exit in 5 seconds");
 
993
                }
 
994
                CloseHandle(srv->hIpc);
 
995
            }
 
996
#endif
 
997
            return;
 
998
        }
 
999
 
 
1000
        comm_read(fd, srv->rbuf + srv->roffset, spaceSize, helperHandleRead, srv);
 
1001
    }
953
1002
}
954
1003
 
955
1004
static void
1025
1074
            helperStatefulReleaseServer(srv);
1026
1075
    }
1027
1076
 
1028
 
    if (srv->rfd != -1)
1029
 
        comm_read(srv->rfd, srv->rbuf + srv->roffset, srv->rbuf_sz - srv->roffset - 1,
1030
 
                  helperStatefulHandleRead, srv);
 
1077
    if (srv->rfd != -1) {
 
1078
        int spaceSize = srv->rbuf_sz - srv->roffset - 1;
 
1079
        assert(spaceSize >= 0);
 
1080
 
 
1081
        // grow the input buffer if needed and possible
 
1082
        if (!spaceSize && srv->rbuf_sz + 4096 <= ReadBufMaxSize) {
 
1083
            srv->rbuf = (char *)memReallocBuf(srv->rbuf, srv->rbuf_sz + 4096, &srv->rbuf_sz);
 
1084
            debugs(84, 3, HERE << "Grew read buffer to " << srv->rbuf_sz);
 
1085
            spaceSize = srv->rbuf_sz - srv->roffset - 1;
 
1086
            assert(spaceSize >= 0);
 
1087
        }
 
1088
 
 
1089
        // quit reading if there is no space left
 
1090
        if (!spaceSize) {
 
1091
            debugs(84, DBG_IMPORTANT, "ERROR: Disconnecting from a " <<
 
1092
                   "helper that overflowed " << srv->rbuf_sz << "-byte " <<
 
1093
                   "Squid input buffer: " << hlp->id_name << " #" <<
 
1094
                   (srv->index + 1));
 
1095
            int wfd = srv->wfd;
 
1096
            srv->wfd = -1;
 
1097
            if (srv->rfd == wfd)
 
1098
                srv->rfd = -1;
 
1099
            srv->flags.closing=1;
 
1100
            comm_close(wfd);
 
1101
 
 
1102
#if _SQUID_MSWIN_
 
1103
            if (srv->hIpc) {
 
1104
                if (WaitForSingleObject(srv->hIpc, 5000) != WAIT_OBJECT_0) {
 
1105
                    getCurrentTime();
 
1106
                    debugs(84, 1, "helperShutdown: WARNING: " << hlp->id_name <<
 
1107
                           " #" << no << " (" << hlp->cmdline->key << "," <<
 
1108
                           (long int)srv->pid << ") didn't exit in 5 seconds");
 
1109
                }
 
1110
                CloseHandle(srv->hIpc);
 
1111
            }
 
1112
#endif
 
1113
            return;
 
1114
        }
 
1115
 
 
1116
        comm_read(srv->rfd, srv->rbuf + srv->roffset, spaceSize, helperStatefulHandleRead, srv);
 
1117
    }
1031
1118
}
1032
1119
 
1033
1120
static void