~drizzle-trunk/drizzle/development

1 by brian
clean slate
1
/* Copyright (C) 2005 MySQL AB
2
3
   This program is free software; you can redistribute it and/or modify
4
   it under the terms of the GNU General Public License as published by
5
   the Free Software Foundation; version 2 of the License.
6
7
   This program is distributed in the hope that it will be useful,
8
   but WITHOUT ANY WARRANTY; without even the implied warranty of
9
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
   GNU General Public License for more details.
11
12
   You should have received a copy of the GNU General Public License
13
   along with this program; if not, write to the Free Software
1802.10.2 by Monty Taylor
Update all of the copyright headers to include the correct address.
14
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
1 by brian
clean slate
15
2173.2.1 by Monty Taylor
Fixes incorrect usage of include
16
#include <config.h>
499.2.9 by Mark Atwood
fix mistakes
17
1122.2.13 by Monty Taylor
Header cleanup.
18
#include <dlfcn.h>
499.2.9 by Mark Atwood
fix mistakes
19
1502.3.1 by iwamatsu at nigauri
Add cstdio include to files needing it. Fixes the build on some debian
20
#include <cstdio>
534 by Monty Taylor
Removed stxnmov. Also deleted strstr which had already been removed.
21
#include <string>
656.1.1 by Monty Taylor
OOOh doggie. Got rid of my_alloca.
22
#include <vector>
873.2.21 by Monty Taylor
Removed the HASH for plugin_hash.
23
#include <map>
1067.4.4 by Nathan Williams
The rest of the files in the drizzled directory were purged of the cmin macro and replace with std::min (except for the definition in globals.h and 1 usage in stacktrace.cc).
24
#include <algorithm>
1625.1.7 by Monty Taylor
Added support for program_options based commandline argument passing.
25
#include <iostream>
534 by Monty Taylor
Removed stxnmov. Also deleted strstr which had already been removed.
26
1625.1.5 by Monty Taylor
Put in first bits to use program_options for plugin loading in parallel to
27
#include <boost/program_options.hpp>
28
2173.2.1 by Monty Taylor
Fixes incorrect usage of include
29
#include <drizzled/option.h>
30
#include <drizzled/internal/m_string.h>
1122.2.13 by Monty Taylor
Header cleanup.
31
2173.2.1 by Monty Taylor
Fixes incorrect usage of include
32
#include <drizzled/plugin.h>
33
#include <drizzled/module/load_list.h>
34
#include <drizzled/module/library.h>
35
#include <drizzled/module/registry.h>
36
#include <drizzled/module/option_context.h>
37
#include <drizzled/sql_parse.h>
38
#include <drizzled/show.h>
39
#include <drizzled/cursor.h>
40
#include <drizzled/set_var.h>
41
#include <drizzled/session.h>
42
#include <drizzled/item/null.h>
43
#include <drizzled/error.h>
44
#include <drizzled/gettext.h>
45
#include <drizzled/errmsg_print.h>
46
#include <drizzled/pthread_globals.h>
47
#include <drizzled/util/tokenize.h>
2241.3.2 by Olaf van der Spek
Refactor Session::variables
48
#include <drizzled/system_variables.h>
1122.2.13 by Monty Taylor
Header cleanup.
49
1966.2.6 by Brian Aker
This is from the catalog patch (I'm pushing it up as its own little thing
50
#include <boost/foreach.hpp>
51
1122.2.13 by Monty Taylor
Header cleanup.
52
/* FreeBSD 2.2.2 does not define RTLD_NOW) */
53
#ifndef RTLD_NOW
54
#define RTLD_NOW 1
55
#endif
1 by brian
clean slate
56
1625.1.5 by Monty Taylor
Put in first bits to use program_options for plugin loading in parallel to
57
namespace po=boost::program_options;
58
534 by Monty Taylor
Removed stxnmov. Also deleted strstr which had already been removed.
59
using namespace std;
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
60
1530.2.5 by Monty Taylor
Renamed classes that were in drizzled::plugin but which were not meant
61
/** These exist just to prevent symbols from being optimized out */
62
typedef drizzled::module::Manifest drizzled_builtin_list[];
63
extern drizzled_builtin_list PANDORA_BUILTIN_SYMBOLS_LIST;
1885.2.3 by Monty Taylor
Finalized the static/load_by_default split, supporting now an array of
64
extern drizzled_builtin_list PANDORA_BUILTIN_LOAD_SYMBOLS_LIST;
1530.2.5 by Monty Taylor
Renamed classes that were in drizzled::plugin but which were not meant
65
drizzled::module::Manifest *drizzled_builtins[]=
66
{
67
  PANDORA_BUILTIN_SYMBOLS_LIST, NULL
68
};
1885.2.3 by Monty Taylor
Finalized the static/load_by_default split, supporting now an array of
69
drizzled::module::Manifest *drizzled_load_builtins[]=
70
{
71
  PANDORA_BUILTIN_LOAD_SYMBOLS_LIST, NULL
72
};
1530.2.5 by Monty Taylor
Renamed classes that were in drizzled::plugin but which were not meant
73
2207.6.3 by Olaf van der Spek
Refactor
74
namespace drizzled {
992.1.39 by Monty Taylor
Removed the m4-based plugin system.
75
 
1122.2.13 by Monty Taylor
Header cleanup.
76
1776.4.7 by Monty Taylor
Made a typedef for the plugin vector<string>
77
typedef vector<string> PluginOptions;
78
static PluginOptions opt_plugin_load;
79
static PluginOptions opt_plugin_add;
80
static PluginOptions opt_plugin_remove;
1530.2.3 by Monty Taylor
Changed the builtin plugin code path to work exactly the same as dynamic.
81
const char *builtin_plugins= PANDORA_BUILTIN_LIST;
1885.2.3 by Monty Taylor
Finalized the static/load_by_default split, supporting now an array of
82
const char *builtin_load_plugins= PANDORA_BUILTIN_LOAD_LIST;
1 by brian
clean slate
83
84
/* Note that 'int version' must be the first field of every plugin
85
   sub-structure (plugin->info).
86
*/
87
962.1.6 by Brian Aker
Cut down on shutdown loop of plugins (cutting stuff out in order to simplify
88
static bool initialized= false;
1 by brian
clean slate
89
908.2.1 by Monty Taylor
First pass at refactoring plugins - factored out sql_map.
90
1 by brian
clean slate
91
static bool reap_needed= false;
92
93
/*
94
  write-lock on LOCK_system_variables_hash is required before modifying
95
  the following variables/structures
96
*/
1485 by Brian Aker
Updates to confine memroot
97
static memory::Root plugin_mem_root(4096);
482 by Brian Aker
Remove uint.
98
static uint32_t global_variables_dynamic_size= 0;
1 by brian
clean slate
99
100
101
/*
102
  hidden part of opaque value passed to variable check functions.
103
  Used to provide a object-like structure to non C++ consumers.
104
*/
1228.1.5 by Monty Taylor
Merged in some naming things.
105
struct st_item_value_holder : public drizzle_value
1 by brian
clean slate
106
{
107
  Item *item;
108
};
109
110
/* prototypes */
2318.6.27 by Olaf van der Spek
Refactor
111
static void plugin_prune_list(vector<string> &plugin_list, const vector<string> &plugins_to_remove);
1530.2.5 by Monty Taylor
Renamed classes that were in drizzled::plugin but which were not meant
112
static bool plugin_load_list(module::Registry &registry,
1757.2.6 by Monty Taylor
We've gotten further. Now things sometimes work, but some things aren't
113
                             memory::Root *tmp_root,
1530.2.3 by Monty Taylor
Changed the builtin plugin code path to work exactly the same as dynamic.
114
                             const set<string> &plugin_list,
1633.1.1 by Monty Taylor
Added in support for program_options output in --help output.
115
                             po::options_description &long_options,
1530.2.3 by Monty Taylor
Changed the builtin plugin code path to work exactly the same as dynamic.
116
                             bool builtin= false);
2318.6.27 by Olaf van der Spek
Refactor
117
static int test_plugin_options(memory::Root*, module::Module*, po::options_description&long_options);
1878.3.2 by Monty Taylor
Split out show_type into its own header and made sys_var work through
118
static void unlock_variables(Session *session, drizzle_system_variables *vars);
119
static void cleanup_variables(drizzle_system_variables *vars);
1 by brian
clean slate
120
121
122
/****************************************************************************
123
  Plugin support code
124
****************************************************************************/
125
1228.1.3 by Monty Taylor
All of the outstanding plugin loader system cleanups:
126
1 by brian
clean slate
127
128
129
/*
130
  NOTE
131
    Requires that a write-lock is held on LOCK_system_variables_hash
132
*/
1530.2.5 by Monty Taylor
Renamed classes that were in drizzled::plugin but which were not meant
133
static bool plugin_add(module::Registry &registry, memory::Root *tmp_root,
134
                       module::Library *library,
1633.1.1 by Monty Taylor
Added in support for program_options output in --help output.
135
                       po::options_description &long_options)
1 by brian
clean slate
136
{
908.2.1 by Monty Taylor
First pass at refactoring plugins - factored out sql_map.
137
  if (! initialized)
1228.1.3 by Monty Taylor
All of the outstanding plugin loader system cleanups:
138
    return true;
908.2.1 by Monty Taylor
First pass at refactoring plugins - factored out sql_map.
139
1228.1.3 by Monty Taylor
All of the outstanding plugin loader system cleanups:
140
  if (registry.find(library->getName()))
1 by brian
clean slate
141
  {
2126.3.3 by Brian Aker
Merge in error message rework. Many error messages are fixed in this patch.
142
    errmsg_printf(error::WARN, ER(ER_PLUGIN_EXISTS),
1228.1.3 by Monty Taylor
All of the outstanding plugin loader system cleanups:
143
                  library->getName().c_str());
144
    return false;
1 by brian
clean slate
145
  }
1093.3.4 by Monty Taylor
Naming cleanups.
146
1 by brian
clean slate
147
  /* Find plugin by name */
1530.2.5 by Monty Taylor
Renamed classes that were in drizzled::plugin but which were not meant
148
  const module::Manifest *manifest= library->getManifest();
1228.1.3 by Monty Taylor
All of the outstanding plugin loader system cleanups:
149
1284.2.1 by Monty Taylor
Add a fatal error if a plugin has a name which has already been registered.
150
  if (registry.find(manifest->name))
151
  {
2126.3.3 by Brian Aker
Merge in error message rework. Many error messages are fixed in this patch.
152
    errmsg_printf(error::ERROR, 
1284.2.1 by Monty Taylor
Add a fatal error if a plugin has a name which has already been registered.
153
                  _("Plugin '%s' contains the name '%s' in its manifest, which "
154
                    "has already been registered.\n"),
155
                  library->getName().c_str(),
156
                  manifest->name);
157
    return true;
158
  }
159
2246.3.1 by Olaf van der Spek
Remove std::nothrow from new()
160
  module::Module* tmp= new module::Module(manifest, library);
1228.1.3 by Monty Taylor
All of the outstanding plugin loader system cleanups:
161
1757.2.6 by Monty Taylor
We've gotten further. Now things sometimes work, but some things aren't
162
  if (!test_plugin_options(tmp_root, tmp, long_options))
1 by brian
clean slate
163
  {
1228.1.3 by Monty Taylor
All of the outstanding plugin loader system cleanups:
164
    registry.add(tmp);
165
    return false;
1 by brian
clean slate
166
  }
2126.3.3 by Brian Aker
Merge in error message rework. Many error messages are fixed in this patch.
167
  errmsg_printf(error::ERROR, ER(ER_CANT_FIND_DL_ENTRY),
1228.1.3 by Monty Taylor
All of the outstanding plugin loader system cleanups:
168
                library->getName().c_str());
169
  return true;
1 by brian
clean slate
170
}
171
172
1530.2.5 by Monty Taylor
Renamed classes that were in drizzled::plugin but which were not meant
173
static void reap_plugins(module::Registry &registry)
1 by brian
clean slate
174
{
2207.6.3 by Olaf van der Spek
Refactor
175
  BOOST_FOREACH(module::Registry::ModuleMap::const_reference module, registry.getModulesMap())
176
    delete module.second;
1119.1.1 by Monty Taylor
--help doesn't need --datadir to work.
177
}
178
179
1530.2.5 by Monty Taylor
Renamed classes that were in drizzled::plugin but which were not meant
180
static bool plugin_initialize(module::Registry &registry,
181
                              module::Module *module)
1119.1.1 by Monty Taylor
--help doesn't need --datadir to work.
182
{
1192.2.3 by Monty Taylor
Renamed plugin::Handle to plugin::Module for clarity.
183
  assert(module->isInited == false);
1119.1.1 by Monty Taylor
--help doesn't need --datadir to work.
184
1530.2.6 by Monty Taylor
Moved plugin::Context to module::Context.
185
  module::Context loading_context(registry, module);
1192.2.3 by Monty Taylor
Renamed plugin::Handle to plugin::Module for clarity.
186
  if (module->getManifest().init)
1119.1.1 by Monty Taylor
--help doesn't need --datadir to work.
187
  {
1324.2.1 by Monty Taylor
Create a plugin::Context object to carry information about the plugin module
188
    if (module->getManifest().init(loading_context))
1119.1.1 by Monty Taylor
--help doesn't need --datadir to work.
189
    {
2126.3.3 by Brian Aker
Merge in error message rework. Many error messages are fixed in this patch.
190
      errmsg_printf(error::ERROR,
1119.1.1 by Monty Taylor
--help doesn't need --datadir to work.
191
                    _("Plugin '%s' init function returned error.\n"),
1192.2.3 by Monty Taylor
Renamed plugin::Handle to plugin::Module for clarity.
192
                    module->getName().c_str());
1119.1.1 by Monty Taylor
--help doesn't need --datadir to work.
193
      return true;
194
    }
195
  }
1192.2.3 by Monty Taylor
Renamed plugin::Handle to plugin::Module for clarity.
196
  module->isInited= true;
965.1.1 by Brian Aker
Refactor plugin loading to remove mask (one step closer to getting rid of
197
  return false;
1 by brian
clean slate
198
}
199
1776.4.1 by Monty Taylor
Migrates the creation of the plugin lists to have program_options directly
200
static void compose_plugin_options(vector<string> &target,
201
                                   vector<string> options)
202
{
2207.6.2 by Olaf van der Spek
Refactor
203
  BOOST_FOREACH(vector<string>::reference it, options)
204
    tokenize(it, target, ",", true);
205
  BOOST_FOREACH(vector<string>::reference it, target)
206
    std::replace(it.begin(), it.end(), '-', '_');
1776.4.1 by Monty Taylor
Migrates the creation of the plugin lists to have program_options directly
207
}
208
209
void compose_plugin_add(vector<string> options)
210
{
211
  compose_plugin_options(opt_plugin_add, options);
212
}
213
214
void compose_plugin_remove(vector<string> options)
215
{
216
  compose_plugin_options(opt_plugin_remove, options);
217
}
218
219
void notify_plugin_load(string in_plugin_load)
220
{
221
  tokenize(in_plugin_load, opt_plugin_load, ",", true);
222
}
1 by brian
clean slate
223
224
/*
225
  The logic is that we first load and initialize all compiled in plugins.
226
  From there we load up the dynamic types (assuming we have not been told to
227
  skip this part).
228
229
  Finally we initialize everything, aka the dynamic that have yet to initialize.
230
*/
1530.2.5 by Monty Taylor
Renamed classes that were in drizzled::plugin but which were not meant
231
bool plugin_init(module::Registry &registry,
1633.1.1 by Monty Taylor
Added in support for program_options output in --help output.
232
                 po::options_description &long_options)
1 by brian
clean slate
233
{
234
  if (initialized)
1241.10.4 by Monty Taylor
Actually throw errors on failure to init plugins.
235
    return false;
1 by brian
clean slate
236
2207.6.2 by Olaf van der Spek
Refactor
237
  initialized= true;
1 by brian
clean slate
238
1885.2.3 by Monty Taylor
Finalized the static/load_by_default split, supporting now an array of
239
  PluginOptions builtin_load_list;
240
  tokenize(builtin_load_plugins, builtin_load_list, ",", true);
241
1776.4.7 by Monty Taylor
Made a typedef for the plugin vector<string>
242
  PluginOptions builtin_list;
1530.2.3 by Monty Taylor
Changed the builtin plugin code path to work exactly the same as dynamic.
243
  tokenize(builtin_plugins, builtin_list, ",", true);
1 by brian
clean slate
244
1241.10.4 by Monty Taylor
Actually throw errors on failure to init plugins.
245
  bool load_failed= false;
1776.4.1 by Monty Taylor
Migrates the creation of the plugin lists to have program_options directly
246
247
  if (opt_plugin_add.size() > 0)
248
  {
1885.2.3 by Monty Taylor
Finalized the static/load_by_default split, supporting now an array of
249
    for (PluginOptions::iterator iter= opt_plugin_add.begin();
250
         iter != opt_plugin_add.end();
251
         ++iter)
252
    {
253
      if (find(builtin_list.begin(),
254
               builtin_list.end(), *iter) != builtin_list.end())
255
      {
256
        builtin_load_list.push_back(*iter);
257
      }
258
      else
259
      {
260
        opt_plugin_load.push_back(*iter);
261
      }
262
    }
1776.4.1 by Monty Taylor
Migrates the creation of the plugin lists to have program_options directly
263
  }
264
265
  if (opt_plugin_remove.size() > 0)
266
  {
267
    plugin_prune_list(opt_plugin_load, opt_plugin_remove);
1885.2.3 by Monty Taylor
Finalized the static/load_by_default split, supporting now an array of
268
    plugin_prune_list(builtin_load_list, opt_plugin_remove);
1530.2.3 by Monty Taylor
Changed the builtin plugin code path to work exactly the same as dynamic.
269
  }
270
2207.6.3 by Olaf van der Spek
Refactor
271
  memory::Root tmp_root(4096);
1530.2.3 by Monty Taylor
Changed the builtin plugin code path to work exactly the same as dynamic.
272
  /*
273
    First we register builtin plugins
274
  */
1885.2.3 by Monty Taylor
Finalized the static/load_by_default split, supporting now an array of
275
  const set<string> builtin_list_set(builtin_load_list.begin(),
276
                                     builtin_load_list.end());
1757.2.6 by Monty Taylor
We've gotten further. Now things sometimes work, but some things aren't
277
  load_failed= plugin_load_list(registry, &tmp_root,
1633.1.1 by Monty Taylor
Added in support for program_options output in --help output.
278
                                builtin_list_set, long_options, true);
1530.2.3 by Monty Taylor
Changed the builtin plugin code path to work exactly the same as dynamic.
279
  if (load_failed)
280
  {
281
    tmp_root.free_root(MYF(0));
282
    return true;
1283.1.5 by Monty Taylor
Added --plugin-remove option, which prunes plugins from the list of plugins
283
  }
1377.3.11 by Monty Taylor
Suppress duplicate plugin names.
284
285
  /* Uniquify the list */
1776.4.1 by Monty Taylor
Migrates the creation of the plugin lists to have program_options directly
286
  const set<string> plugin_list_set(opt_plugin_load.begin(),
287
                                    opt_plugin_load.end());
1283.1.5 by Monty Taylor
Added --plugin-remove option, which prunes plugins from the list of plugins
288
  
1 by brian
clean slate
289
  /* Register all dynamic plugins */
1757.2.6 by Monty Taylor
We've gotten further. Now things sometimes work, but some things aren't
290
  load_failed= plugin_load_list(registry, &tmp_root,
1633.1.1 by Monty Taylor
Added in support for program_options output in --help output.
291
                                plugin_list_set, long_options);
1241.10.4 by Monty Taylor
Actually throw errors on failure to init plugins.
292
  if (load_failed)
293
  {
1487 by Brian Aker
More updates for memory::Root
294
    tmp_root.free_root(MYF(0));
1241.10.4 by Monty Taylor
Actually throw errors on failure to init plugins.
295
    return true;
1 by brian
clean slate
296
  }
297
1672.2.1 by Monty Taylor
Fixed plugin option processing. Now we pre-load the modules registering
298
  tmp_root.free_root(MYF(0));
299
300
  return false;
301
}
302
1794.3.5 by Monty Taylor
Fixed temporoary dir sequencing.
303
bool plugin_finalize(module::Registry &registry)
1672.2.1 by Monty Taylor
Fixed plugin option processing. Now we pre-load the modules registering
304
{
1 by brian
clean slate
305
  /*
306
    Now we initialize all remaining plugins
307
  */
2207.6.2 by Olaf van der Spek
Refactor
308
  BOOST_FOREACH(module::Registry::ModuleList::const_reference module, registry.getList())
1 by brian
clean slate
309
  {
2207.6.2 by Olaf van der Spek
Refactor
310
    if (not module->isInited && plugin_initialize(registry, module))
1 by brian
clean slate
311
    {
2207.6.2 by Olaf van der Spek
Refactor
312
      registry.remove(module);
313
      delete module;
314
      return true;
1 by brian
clean slate
315
    }
316
  }
1966.2.6 by Brian Aker
This is from the catalog patch (I'm pushing it up as its own little thing
317
  BOOST_FOREACH(plugin::Plugin::map::value_type value, registry.getPluginsMap())
318
  {
319
    value.second->prime();
320
  }
1794.3.5 by Monty Taylor
Fixed temporoary dir sequencing.
321
  return false;
1228.1.3 by Monty Taylor
All of the outstanding plugin loader system cleanups:
322
}
323
2079.4.1 by Brian Aker
Merge in code to all plugins to do whatever they need to do once all other
324
/*
325
  Window of opportunity for plugins to issue any queries with the database up and running but with no user's connected.
326
*/
327
void plugin_startup_window(module::Registry &registry, drizzled::Session &session)
328
{
329
  BOOST_FOREACH(plugin::Plugin::map::value_type value, registry.getPluginsMap())
330
  {
331
    value.second->startup(session);
332
  }
333
}
334
1283.1.5 by Monty Taylor
Added --plugin-remove option, which prunes plugins from the list of plugins
335
class PrunePlugin :
336
  public unary_function<string, bool>
337
{
338
  const string to_match;
339
  PrunePlugin();
340
  PrunePlugin& operator=(const PrunePlugin&);
341
public:
342
  explicit PrunePlugin(const string &match_in) :
343
    to_match(match_in)
344
  { }
345
346
  result_type operator()(const string &match_against)
347
  {
348
    return match_against == to_match;
349
  }
350
};
351
352
static void plugin_prune_list(vector<string> &plugin_list,
353
                              const vector<string> &plugins_to_remove)
354
{
355
  for (vector<string>::const_iterator iter= plugins_to_remove.begin();
356
       iter != plugins_to_remove.end();
357
       ++iter)
358
  {
359
    plugin_list.erase(remove_if(plugin_list.begin(),
360
                                plugin_list.end(),
361
                                PrunePlugin(*iter)),
362
                      plugin_list.end());
363
  }
364
}
1 by brian
clean slate
365
366
/*
367
  called only by plugin_init()
368
*/
1530.2.5 by Monty Taylor
Renamed classes that were in drizzled::plugin but which were not meant
369
static bool plugin_load_list(module::Registry &registry,
1757.2.6 by Monty Taylor
We've gotten further. Now things sometimes work, but some things aren't
370
                             memory::Root *tmp_root,
1530.2.3 by Monty Taylor
Changed the builtin plugin code path to work exactly the same as dynamic.
371
                             const set<string> &plugin_list,
1633.1.1 by Monty Taylor
Added in support for program_options output in --help output.
372
                             po::options_description &long_options,
1530.2.3 by Monty Taylor
Changed the builtin plugin code path to work exactly the same as dynamic.
373
                             bool builtin)
1 by brian
clean slate
374
{
2207.6.3 by Olaf van der Spek
Refactor
375
  BOOST_FOREACH(const string& plugin_name, plugin_list)
1 by brian
clean slate
376
  {
2207.6.3 by Olaf van der Spek
Refactor
377
    module::Library* library= registry.addLibrary(plugin_name, builtin);
1228.1.3 by Monty Taylor
All of the outstanding plugin loader system cleanups:
378
    if (library == NULL)
379
    {
2126.3.3 by Brian Aker
Merge in error message rework. Many error messages are fixed in this patch.
380
      errmsg_printf(error::ERROR,
1284.2.1 by Monty Taylor
Add a fatal error if a plugin has a name which has already been registered.
381
                    _("Couldn't load plugin library named '%s'.\n"),
1228.1.3 by Monty Taylor
All of the outstanding plugin loader system cleanups:
382
                    plugin_name.c_str());
383
      return true;
384
    }
385
1487 by Brian Aker
More updates for memory::Root
386
    tmp_root->free_root(MYF(memory::MARK_BLOCKS_FREE));
1757.2.6 by Monty Taylor
We've gotten further. Now things sometimes work, but some things aren't
387
    if (plugin_add(registry, tmp_root, library, long_options))
1228.1.3 by Monty Taylor
All of the outstanding plugin loader system cleanups:
388
    {
389
      registry.removeLibrary(plugin_name);
2126.3.3 by Brian Aker
Merge in error message rework. Many error messages are fixed in this patch.
390
      errmsg_printf(error::ERROR,
1284.2.1 by Monty Taylor
Add a fatal error if a plugin has a name which has already been registered.
391
                    _("Couldn't load plugin named '%s'.\n"),
1228.1.3 by Monty Taylor
All of the outstanding plugin loader system cleanups:
392
                    plugin_name.c_str());
393
      return true;
394
    }
1 by brian
clean slate
395
  }
1228.1.3 by Monty Taylor
All of the outstanding plugin loader system cleanups:
396
  return false;
1 by brian
clean slate
397
}
398
399
1530.2.5 by Monty Taylor
Renamed classes that were in drizzled::plugin but which were not meant
400
void module_shutdown(module::Registry &registry)
1 by brian
clean slate
401
{
402
403
  if (initialized)
404
  {
405
    reap_needed= true;
406
1110.1.3 by Monty Taylor
Added ListenHandler as a member of PluginRegistry.
407
    reap_plugins(registry);
962.1.6 by Brian Aker
Cut down on shutdown loop of plugins (cutting stuff out in order to simplify
408
    unlock_variables(NULL, &global_system_variables);
409
    unlock_variables(NULL, &max_system_variables);
1 by brian
clean slate
410
1851.1.1 by Monty Taylor
Removed sys_var_chain.
411
    cleanup_variables(&global_system_variables);
412
    cleanup_variables(&max_system_variables);
1 by brian
clean slate
413
414
    initialized= 0;
415
  }
416
417
  /* Dispose of the memory */
1487 by Brian Aker
More updates for memory::Root
418
  plugin_mem_root.free_root(MYF(0));
1 by brian
clean slate
419
420
  global_variables_dynamic_size= 0;
421
}
422
423
424
/****************************************************************************
425
  System Variables support
426
****************************************************************************/
427
428
520.1.22 by Brian Aker
Second pass of thd cleanup
429
430
void plugin_sessionvar_init(Session *session)
431
{
971.1.21 by Monty Taylor
Store StorageEngine in system variables, rather than storage engine plugin.
432
  session->variables.storage_engine= NULL;
1851.1.1 by Monty Taylor
Removed sys_var_chain.
433
  cleanup_variables(&session->variables);
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
434
520.1.22 by Brian Aker
Second pass of thd cleanup
435
  session->variables= global_system_variables;
971.1.21 by Monty Taylor
Store StorageEngine in system variables, rather than storage engine plugin.
436
  session->variables.storage_engine= NULL;
1 by brian
clean slate
437
438
  /* we are going to allocate these lazily */
520.1.22 by Brian Aker
Second pass of thd cleanup
439
  session->variables.dynamic_variables_version= 0;
440
  session->variables.dynamic_variables_size= 0;
441
  session->variables.dynamic_variables_ptr= 0;
1 by brian
clean slate
442
971.1.21 by Monty Taylor
Store StorageEngine in system variables, rather than storage engine plugin.
443
  session->variables.storage_engine= global_system_variables.storage_engine;
1 by brian
clean slate
444
}
445
446
447
/*
448
  Unlocks all system variables which hold a reference
449
*/
1878.3.2 by Monty Taylor
Split out show_type into its own header and made sys_var work through
450
static void unlock_variables(Session *, struct drizzle_system_variables *vars)
1 by brian
clean slate
451
{
971.1.21 by Monty Taylor
Store StorageEngine in system variables, rather than storage engine plugin.
452
  vars->storage_engine= NULL;
1 by brian
clean slate
453
}
454
455
456
/*
457
  Frees memory used by system variables
458
459
  Unlike plugin_vars_free_values() it frees all variables of all plugins,
460
  it's used on shutdown.
461
*/
1878.3.2 by Monty Taylor
Split out show_type into its own header and made sys_var work through
462
static void cleanup_variables(drizzle_system_variables *vars)
1 by brian
clean slate
463
{
971.1.21 by Monty Taylor
Store StorageEngine in system variables, rather than storage engine plugin.
464
  assert(vars->storage_engine == NULL);
1 by brian
clean slate
465
477 by Monty Taylor
Removed my_free(). It turns out that it had been def'd to ignore the flags passed to it in the second arg anyway. Gotta love that.
466
  free(vars->dynamic_variables_ptr);
1 by brian
clean slate
467
  vars->dynamic_variables_ptr= NULL;
468
  vars->dynamic_variables_size= 0;
469
  vars->dynamic_variables_version= 0;
470
}
471
472
520.1.22 by Brian Aker
Second pass of thd cleanup
473
void plugin_sessionvar_cleanup(Session *session)
1 by brian
clean slate
474
{
520.1.22 by Brian Aker
Second pass of thd cleanup
475
  unlock_variables(session, &session->variables);
1851.1.1 by Monty Taylor
Removed sys_var_chain.
476
  cleanup_variables(&session->variables);
1 by brian
clean slate
477
}
478
479
480
481
/*
482
  SYNOPSIS
483
    test_plugin_options()
484
    tmp_root                    temporary scratch space
485
    plugin                      internal plugin structure
486
    default_enabled             default plugin enable status
487
  RETURNS:
488
    0 SUCCESS - plugin should be enabled/loaded
489
  NOTE:
490
    Requires that a write-lock is held on LOCK_system_variables_hash
491
*/
1976.2.21 by Monty Taylor
Removed first stab at plugin_sysvar.
492
static int test_plugin_options(memory::Root *,
1625.1.5 by Monty Taylor
Put in first bits to use program_options for plugin loading in parallel to
493
                               module::Module *test_module,
1633.1.1 by Monty Taylor
Added in support for program_options output in --help output.
494
                               po::options_description &long_options)
1 by brian
clean slate
495
{
496
1625.1.5 by Monty Taylor
Put in first bits to use program_options for plugin loading in parallel to
497
  if (test_module->getManifest().init_options != NULL)
498
  {
1672.2.2 by Monty Taylor
Fixed the headings.
499
    string plugin_section_title("Options used by ");
500
    plugin_section_title.append(test_module->getName());
501
    po::options_description module_options(plugin_section_title);
1625.1.5 by Monty Taylor
Put in first bits to use program_options for plugin loading in parallel to
502
    module::option_context opt_ctx(test_module->getName(),
503
                                   module_options.add_options());
504
    test_module->getManifest().init_options(opt_ctx);
1633.1.1 by Monty Taylor
Added in support for program_options output in --help output.
505
    long_options.add(module_options);
1976.2.21 by Monty Taylor
Removed first stab at plugin_sysvar.
506
  }
507
508
  return 0;
1 by brian
clean slate
509
}
510
511
512
/****************************************************************************
513
  Help Verbose text with Plugin System Variables
514
****************************************************************************/
515
1093.3.5 by Monty Taylor
Removed a dynamic array.
516
class OptionCmp
517
{
518
public:
1410.3.4 by Djellel E. Difallah
update references to old my_'s
519
  bool operator() (const option &a, const option &b)
1093.3.5 by Monty Taylor
Removed a dynamic array.
520
  {
521
    return my_strcasecmp(&my_charset_utf8_general_ci, a.name, b.name);
522
  }
523
};
524
525
1757.2.3 by Monty Taylor
Made printing of --help work via program_options from the core. Removed
526
void my_print_help_inc_plugins(option *main_options)
1093.3.5 by Monty Taylor
Removed a dynamic array.
527
{
1530.2.5 by Monty Taylor
Renamed classes that were in drizzled::plugin but which were not meant
528
  module::Registry &registry= module::Registry::singleton();
1410.3.4 by Djellel E. Difallah
update references to old my_'s
529
  vector<option> all_options;
1485 by Brian Aker
Updates to confine memroot
530
  memory::Root mem_root(4096);
1 by brian
clean slate
531
1530.2.5 by Monty Taylor
Renamed classes that were in drizzled::plugin but which were not meant
532
1 by brian
clean slate
533
  if (initialized)
1228.1.3 by Monty Taylor
All of the outstanding plugin loader system cleanups:
534
  {
1530.2.5 by Monty Taylor
Renamed classes that were in drizzled::plugin but which were not meant
535
    std::map<std::string, module::Module *>::const_iterator modules=
1228.1.3 by Monty Taylor
All of the outstanding plugin loader system cleanups:
536
      registry.getModulesMap().begin();
537
    
538
    while (modules != registry.getModulesMap().end())
1 by brian
clean slate
539
    {
1530.2.5 by Monty Taylor
Renamed classes that were in drizzled::plugin but which were not meant
540
      module::Module *p= (*modules).second;
1228.1.3 by Monty Taylor
All of the outstanding plugin loader system cleanups:
541
      ++modules;
1 by brian
clean slate
542
1633.1.3 by Monty Taylor
Removed duplicate entries from the help output.
543
      /* If we have an init_options function, we are registering
544
         commmand line options that way, so don't do them this way */
545
      if (p->getManifest().init_options != NULL)
546
        continue;
547
1 by brian
clean slate
548
    }
1228.1.3 by Monty Taylor
All of the outstanding plugin loader system cleanups:
549
  }
1 by brian
clean slate
550
551
  for (;main_options->id; main_options++)
1093.3.5 by Monty Taylor
Removed a dynamic array.
552
  {
553
    if (main_options->comment)
554
    {
555
      all_options.push_back(*main_options);
556
    }
557
  }
1 by brian
clean slate
558
1093.3.5 by Monty Taylor
Removed a dynamic array.
559
  /** 
1410.3.4 by Djellel E. Difallah
update references to old my_'s
560
   * @TODO: Fix the option building so that it doens't break sort
1093.3.5 by Monty Taylor
Removed a dynamic array.
561
   *
562
   * sort(all_options.begin(), all_options.end(), OptionCmp());
563
   */
1 by brian
clean slate
564
565
  /* main_options now points to the empty option terminator */
1093.3.5 by Monty Taylor
Removed a dynamic array.
566
  all_options.push_back(*main_options);
567
1757.2.3 by Monty Taylor
Made printing of --help work via program_options from the core. Removed
568
  my_print_help(&*(all_options.begin()));
1093.3.5 by Monty Taylor
Removed a dynamic array.
569
1487 by Brian Aker
More updates for memory::Root
570
  mem_root.free_root(MYF(0));
1 by brian
clean slate
571
}
572
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
573
} /* namespace drizzled */
1530.2.3 by Monty Taylor
Changed the builtin plugin code path to work exactly the same as dynamic.
574
575