~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/errmsg_stderr/errmsg_stderr.cc

Merge Stewart's dead code removal

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
18
 */
19
19
 
20
 
#include "config.h"
 
20
#include <drizzled/server_includes.h>
21
21
#include <drizzled/plugin/error_message.h>
22
22
#include <drizzled/gettext.h>
23
 
#include <drizzled/plugin.h>
24
23
 
25
24
#include <stdio.h>  /* for vsnprintf */
26
25
#include <stdarg.h>  /* for va_list */
27
26
#include <unistd.h>  /* for write(2) */
28
27
 
29
 
using namespace drizzled;
30
 
 
31
28
/* todo, make this dynamic as needed */
32
29
#define MAX_MSG_LEN 8192
33
30
 
34
 
class Error_message_stderr : public plugin::ErrorMessage
 
31
class Error_message_stderr : public drizzled::plugin::ErrorMessage
35
32
{
36
33
public:
37
 
  Error_message_stderr()
38
 
   : plugin::ErrorMessage("Error_message_stderr") {}
39
 
  virtual bool errmsg(error::level_t , const char *format, va_list ap)
 
34
  Error_message_stderr() : Error_message_handler("Error_message_stderr") {}
 
35
  virtual bool errmsg(Session *, int , const char *format, va_list ap)
40
36
  {
41
37
    char msgbuf[MAX_MSG_LEN];
42
38
    int prv, wrv;
47
43
    /* a single write has a OS level thread lock
48
44
       so there is no need to have mutexes guarding this write,
49
45
    */
50
 
    wrv= write(fileno(stderr), msgbuf, prv);
51
 
    fputc('\n', stderr);
52
 
    if ((wrv < 0) || (wrv != prv))
53
 
      return true;
 
46
    wrv= write(2, msgbuf, prv);
 
47
    if ((wrv < 0) || (wrv != prv)) return true;
54
48
 
55
49
    return false;
56
50
  }
57
51
};
58
52
 
59
53
static Error_message_stderr *handler= NULL;
60
 
static int errmsg_stderr_plugin_init(module::Context &context)
 
54
static int errmsg_stderr_plugin_init(drizzled::plugin::Registry &registry)
61
55
{
62
56
  handler= new Error_message_stderr();
63
 
  context.add(handler);
64
 
 
65
 
  return 0;
66
 
}
67
 
 
68
 
DRIZZLE_DECLARE_PLUGIN
69
 
{
70
 
  DRIZZLE_VERSION_ID,
 
57
  registry.add(handler);
 
58
 
 
59
  return 0;
 
60
}
 
61
 
 
62
static int errmsg_stderr_plugin_deinit(drizzled::plugin::Registry &registry)
 
63
{
 
64
 
 
65
  if (handler)
 
66
  {
 
67
    registry.remove(handler);
 
68
    delete handler;
 
69
  }
 
70
  return 0;
 
71
}
 
72
 
 
73
drizzle_declare_plugin(errmsg_stderr)
 
74
{
71
75
  "errmsg_stderr",
72
76
  "0.1",
73
77
  "Mark Atwood <mark@fallenpegasus.com>",
74
78
  N_("Error Messages to stderr"),
75
79
  PLUGIN_LICENSE_GPL,
76
80
  errmsg_stderr_plugin_init,
77
 
  NULL, /* depends */
 
81
  errmsg_stderr_plugin_deinit,
 
82
  NULL, /* status variables */
 
83
  NULL, /* system variables */
78
84
  NULL
79
85
}
80
 
DRIZZLE_DECLARE_PLUGIN_END;
 
86
drizzle_declare_plugin_end;