mirror of
http://git.haproxy.org/git/haproxy.git/
synced 2024-12-19 10:14:41 +00:00
f12f32a0fa
Instead of using existing fields and having to put keyword-specific contexts in the applet definition, let's have the appctx provide a generic storage area that's currently large enough for existing CLI commands and small applets, and a function to allocate that storage. The function will be responsible for verifying that the requested size fits in the area so that the caller doesn't need to add specific checks; it is validated during development as this size is static and will not change at runtime. In addition the caller doesn't even need to free() the area since it's part of an existing context. For the caller's convenience, a context pointer "svcctx" for the command is also provided so that the allocated area can be placed there (or possibly any other one in case a larger area is needed). The struct's layout has been temporarily complicated by adding one level of anonymous union on top of the "ctx" one. This will allow us to preserve "ctx" during 2.6 for compatibility with possible external code and get rid of it in 2.7. This explains why the diff extends to the whole "ctx" union, but a "git show -b" shows that only one extra layer was added. In order to make both the svcctx pointer and its storage accessible without further enlarging the appctx structure, both svcctx and the storage share the same storage as the ctx part. This is done by having them placed in the union with a protected overlapping area for svcctx, for which a shadow member is also present in the storage area: union { void* svcctx; // variable accessed by services struct { void *shadow; // shadow of svcctx; char storage[]; // where most services store their data }; union { // older commands store here and ignore svcctx ... } ctx; }; I.e. new applications will use appctx->svcctx while older ones will be able to continue to use appctx->ctx.* The whole area (including the pointer's context) is zeroed before any applet is initialized, and before CLI keyword processor's first invocation, as it is an important part of the existing keyword processors, which makes CLI keywords effectively behave like applets. |
||
---|---|---|
.. | ||
haproxy | ||
import |