-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

Eric,

On 4/10/20 14:45, Eric Covener wrote:
> On Fri, Apr 10, 2020 at 2:36 PM Christopher Schultz
> <[email protected]> wrote:
>>
>> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256
>>
>> All,
>>
>> First-time httpd hacker, here. I'm looking at:
>> https://bz.apache.org/bugzilla/show_bug.cgi?id=64338
>>
>> I've found that around line 637 of mod_proxy_balancer.c it looks
>> like I just need to poke a value into the r->subprocess_env like
>> this:
>>
>> apt_table_setn(r->subprocess_env, "BALANCER_WORKER_STATUS",
>> XXX);
>>
>> The question is what "XXX" should be. I need to convert
>> (*worker)->s->status (an unsigned int) into a char*.
>>
>> I can manually malloc a char*, stick it in there, and deallocate
>> it each time back through, but that will leak memory when the
>> pool is recycled and I don't get a chance to free my char*.
>>
>> I can use apt_table_set instead of apt_table_setn but that will
>> make performance suck even more than a single allocation each
>> time mod_proxy handles a request.
>>
>> I can also use something like apr_itoa/apr_ltoa which will
>> allocate from the pool which presumably will be cleaned-up at
>> some point, but... when? I don't know anything about how
>> APR/httpd handle memory management and I'm afraid I'll much it
>> all up if I don't ask this question.
>>
>> So ... what's the right way to do this?
>>
>> A performance optimization is likely to be that most workers (a)
>> have all the same "everything is fine" status and (b) the status
>> doesn't change very often. So maybe having a table of predefined
>> status strings sitting around wouldn't be the worth possible
>> thing in the world; that would avoid many needless memory
>> (re)allocations.
>
> Hi Chris.  You have access to a request_rec then you can allocate
> from r->pool. Allocations from there are automatically returned at
> the end of the request.

Ooh, okay. At least that's (a) safe and (b) more APR-ish than using
malloc/free.

> You could also just test the value in that status field and "setn"
> the variable to a constant character or string.

Right; there are no existing places (that I can find) where such a set
of constants already lives. I can add one if it makes sense to do so.
There are only so many combinations of statuses.

> Note: If you move to r->notes (also a table) you can use
> apr_table_setn to pass a casted pointer and retrieve the pointer
> on the other side.  But this is probably a last resort.

I'm not sure I follow, other than mechanically. Why might I want to do
that, exactly?

- -chris
-----BEGIN PGP SIGNATURE-----
Comment: Using GnuPG with Thunderbird - https://www.enigmail.net/

iQIzBAEBCAAdFiEEMmKgYcQvxMe7tcJcHPApP6U8pFgFAl6QygEACgkQHPApP6U8
pFh8JBAAyIhR4TJ0khZ2agTC1CaYlYxwB1yvxyNrg4x8Lgd0meR75jf8jbcw9/uC
3wVDuF678fe0fSkbFst2NPpp/BCb15NYCwqUSPaK93njI3jO/dANEdeHXl4yp32n
wE+y3RwMZ4BRiqZ0VqGM2bRI9wkMMgQSkeTyckW94BbUNKZpg2yYTD/PnPkj9a8I
irgPZ+kyv9b0M0EHUtBb5I9Mzv1kuU5dGnMvs3b4IaKiUf5PrHTAoOnc/Lc3NFr4
4Bdq6Z5wyciBxEnWMN+CGD5GUCp6MX6LT9jpTn8kIyDjdwxesixv87S2jvVZwK41
KDKQcUKLaQLUQ+3lCJmZefb0IG1cB07D6H/9tO9o89MyEVpih6743S743YtfLgLp
09ea46wzr5lOkkS8aMje8v+3uMDbUT9AX8od65N2MwlSEvyhKs0BOE8VK0Z4jD0L
+7syigere0xOYLs1aTDznocp6l6mb3A7GK+er8WRfL8CKAoX+smUk2dm/HkIG4Q5
h0xT4YFB2iEHT7GvdNoxyHpjeXCCVpfLTmy/UZvuBFtGn8ILAXEuksxw1Da/grNx
9SVj8Wu7Sd0oXjoeXila3N55T02iFIW4MWQlRAWdRc2Tr5+wu9y5Y5iLwPZ1Npef
YVXGSCurSrv2rVB61zzWEcKc0GZILKVnArKxbUC+65HdTfUB5CY=
=FY7e
-----END PGP SIGNATURE-----

Reply via email to