[strongSwan] why not use gcc extension to facilitate us

Shengju Zhang zhangsju at gmail.com
Wed Oct 17 11:40:48 CEST 2012


Hi Martin,

Thanks for your reply.

is it possible to change the most important three libraries:
libstrongswan, libcharon, libhydra to this mechanism?

Since the code like the following, makes the code readability degree.
And even worse, every process have to write this code if it want to use these
libraries.
>From my point, the library initialization should be taken by library
itself. Not the program who use it.

    /* initialize library */
    if (!library_init(NULL))
    {
        library_deinit();
        exit(XXX);
    }

    if (!libhydra_init(XXX))
    {
        libhydra_deinit();
        library_deinit();
        exit(XXX);
    }

    if (!libcharon_init(XXX))
    {
        goto deinit;
    }

deinit:
    libcharon_deinit();
    libhydra_deinit();
    library_deinit();


On Wed, Oct 17, 2012 at 4:22 PM, Martin Willi <martin at strongswan.org> wrote:
> Hi,
>
>> I find lots of function calls of 'library_init' or 'libhydra_init'
>> etc. in the source code.
>> why don't we just use the GCC extension '__attribute__
>> ((constructor))' and '__attribute__((destructor))' to facilitate our
>> work?
>> Is there any other concerns?
>
> Yes. The order of invocation of these function relies on different
> criteria, including linking order. It is hard to get it correct for all
> cases, hence we switch from constructor/destructor to explicit
> initialization calls a few years ago.
>
> Regards
> Martin
>




More information about the Users mailing list