File: dlopen_templates.c

package info (click to toggle)
prayer 1.3.5-dfsg1-6
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 6,576 kB
  • sloc: ansic: 43,161; makefile: 817; sh: 445; perl: 166
file content (34 lines) | stat: -rw-r--r-- 1,043 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <dlfcn.h>
#include "shared.h"

struct template_map_index template_map_index[] = {
    {NIL, NIL, NIL},
    {NIL, NIL, NIL}
};

struct template_map_index *
dlopen_templates(const char *set, const char *suffix)
{
    struct template_map_index *tmi = &template_map_index[0];
    static void *handle = 0;

    if (!handle || strcmp(tmi->name, set)) {
        char *filename = pool_printf(NIL, "/usr/lib/prayer/templates/%s%s.so",
                                     set, suffix);

        if (handle) {
            dlclose(handle);
            free(tmi->name);
        }
        tmi->name = pool_strdup(NIL, set);
        if (!(handle = dlopen(filename, RTLD_NOW))
            || !(tmi->template_map = dlsym(handle, "template_map"))
            || !(tmi->count = dlsym(handle, "template_map_count"))) {
            log_fatal("Failed to load template library: %s",
                      dlerror());
        }
        log_debug("Loaded library %s with %d templates", filename, *tmi->count);
        free(filename);
    }
    return tmi;
}