~ps10gel/ubuntu/xenial/trafficserver/6.2.0

« back to all changes in this revision

Viewing changes to proxy/Plugin.cc

  • Committer: Package Import Robot
  • Author(s): Aron Xu
  • Date: 2013-05-09 01:00:04 UTC
  • mto: (1.1.11) (5.3.3 experimental)
  • mto: This revision was merged to the branch mainline in revision 15.
  • Revision ID: package-import@ubuntu.com-20130509010004-9fqq9n0adseg3f8w
Tags: upstream-3.3.2
ImportĀ upstreamĀ versionĀ 3.3.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
#include "InkAPIInternal.h"
36
36
#include "Main.h"
37
37
#include "Plugin.h"
38
 
#include "PluginDB.h"
39
38
 
40
39
// HPUX:
41
40
//   LD_SHAREDCMD=ld -b
48
47
 
49
48
 
50
49
static const char *plugin_dir = ".";
51
 
static const char *extensions_dir = ".";
52
 
static PluginDB *plugin_db = NULL;
53
50
 
54
51
typedef void (*init_func_t) (int argc, char *argv[]);
55
 
typedef void (*init_func_w_handle_t) (void *handle, int argc, char *argv[]);
56
 
typedef int (*lic_req_func_t) (void);
57
52
 
58
53
// Plugin registration vars
59
54
//
75
70
{ }
76
71
 
77
72
static void *
78
 
dll_open(char *fn, bool global)
 
73
dll_open(const char *path)
79
74
{
80
 
  int global_flags = global ? RTLD_GLOBAL : 0;
81
 
 
82
 
  return (void *) dlopen(fn, RTLD_NOW | global_flags);
 
75
  return (void *) dlopen(path, RTLD_NOW);
83
76
}
84
77
 
85
78
static void *
101
94
  dlclose(dlp);
102
95
}
103
96
 
104
 
 
105
97
static void
106
 
plugin_load(int argc, char *argv[], bool internal)
 
98
plugin_load(int argc, char *argv[])
107
99
{
108
100
  char path[PATH_NAME_MAX + 1];
109
101
  void *handle;
110
102
  init_func_t init;
111
 
  lic_req_func_t lic_req;
112
103
  PluginRegInfo *plugin_reg_temp;
113
 
  const char *pdir = internal ? extensions_dir : plugin_dir;
114
104
 
115
105
  if (argc < 1) {
116
106
    return;
117
107
  }
118
 
  ink_filepath_make(path, sizeof(path), pdir, argv[0]);
 
108
  ink_filepath_make(path, sizeof(path), plugin_dir, argv[0]);
119
109
 
120
110
  Note("loading plugin '%s'", path);
121
111
 
128
118
    plugin_reg_temp = (plugin_reg_temp->link).next;
129
119
  }
130
120
 
131
 
  handle = dll_open(path, (internal ? true : false));
 
121
  handle = dll_open(path);
132
122
  if (!handle) {
133
123
    Error("unable to load '%s': %s", path, dll_error(handle));
134
124
    abort();
135
125
  }
136
126
 
137
 
  lic_req = (lic_req_func_t) dll_findsym(handle, "TSPluginLicenseRequired");
138
 
  if (lic_req && lic_req() != 0) {
139
 
    PluginDB::CheckLicenseResult result = plugin_db->CheckLicense(argv[0]);
140
 
    if (result != PluginDB::license_ok) {
141
 
      Error("unable to load '%s': %s", path, PluginDB::CheckLicenseResultStr[result]);
142
 
      dll_close(handle);
143
 
      abort();
144
 
    }
145
 
  }
146
127
  // Allocate a new registration structure for the
147
128
  //    plugin we're starting up
148
129
  ink_assert(plugin_reg_current == NULL);
149
130
  plugin_reg_current = new PluginRegInfo;
150
131
  plugin_reg_current->plugin_path = ats_strdup(path);
151
132
 
152
 
  init_func_w_handle_t inith = (init_func_w_handle_t) dll_findsym(handle, "TSPluginInitwDLLHandle");
153
 
  if (inith) {
154
 
    inith(handle, argc, argv);
155
 
    return;
156
 
  }
157
 
 
158
133
  init = (init_func_t) dll_findsym(handle, "TSPluginInit");
159
134
  if (!init) {
160
135
    Error("unable to find TSPluginInit function '%s': %s", path, dll_error(handle));
268
243
}
269
244
 
270
245
void
271
 
plugin_init(const char *config_dir, bool internal)
 
246
plugin_init(const char *config_dir)
272
247
{
273
248
  char path[PATH_NAME_MAX + 1];
274
249
  char line[1024], *p;
281
256
 
282
257
  if (INIT_ONCE) {
283
258
    api_init();
284
 
    char *cfg = NULL;
285
 
 
286
259
    plugin_dir = TSPluginDirGet();
287
 
 
288
 
    RecGetRecordString_Xmalloc("proxy.config.plugin.extensions_dir", (char**)&cfg);
289
 
    if (cfg != NULL) {
290
 
      extensions_dir = Layout::get()->relative(cfg);
291
 
      ats_free(cfg);
292
 
      cfg = NULL;
293
 
    }
294
 
    ink_filepath_make(path, sizeof(path), config_dir, "plugin.db");
295
 
    plugin_db = new PluginDB(path);
296
260
    INIT_ONCE = false;
297
261
  }
298
262
 
299
 
  ink_assert(plugin_db);
300
 
 
301
 
  if (internal == false) {
302
 
    ink_filepath_make(path, sizeof(path), config_dir, "plugin.config");
303
 
  } else {
304
 
    ink_filepath_make(path, sizeof(path), config_dir, "extensions.config");
305
 
  }
306
 
 
 
263
  ink_filepath_make(path, sizeof(path), config_dir, "plugin.config");
307
264
  fd = open(path, O_RDONLY);
308
265
  if (fd < 0) {
309
 
    /* secret extensions dont complain */
310
 
    if (internal == false) {
311
 
      Warning("unable to open plugin config file '%s': %d, %s", path, errno, strerror(errno));
312
 
    }
 
266
    Warning("unable to open plugin config file '%s': %d, %s", path, errno, strerror(errno));
313
267
    return;
314
268
  }
315
269
 
362
316
      }
363
317
    }
364
318
 
365
 
    plugin_load(argc, argv, internal);
 
319
    plugin_load(argc, argv);
366
320
 
367
321
    for (i = 0; i < argc; i++)
368
322
      ats_free(vars[i]);