~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/errmsg_stderr/errmsg_stderr.cc

  • Committer: Brian Aker
  • Date: 2008-10-06 06:47:29 UTC
  • Revision ID: brian@tangent.org-20081006064729-2i9mhjkzyvow9xsm
RemoveĀ uint.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 
 *
4
 
 *  Copyright (C) 2008 Mark Atwood
5
 
 *
6
 
 *  This program is free software; you can redistribute it and/or modify
7
 
 *  it under the terms of the GNU General Public License as published by
8
 
 *  the Free Software Foundation; version 2 of the License.
9
 
 *
10
 
 *  This program is distributed in the hope that it will be useful,
11
 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 
 *  GNU General Public License for more details.
14
 
 *
15
 
 *  You should have received a copy of the GNU General Public License
16
 
 *  along with this program; if not, write to the Free Software
17
 
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
 
 */
19
 
 
20
 
#include <drizzled/server_includes.h>
21
 
#include <drizzled/plugin/error_message.h>
22
 
#include <drizzled/gettext.h>
23
 
 
24
 
#include <stdio.h>  /* for vsnprintf */
25
 
#include <stdarg.h>  /* for va_list */
26
 
#include <unistd.h>  /* for write(2) */
27
 
 
28
 
/* todo, make this dynamic as needed */
29
 
#define MAX_MSG_LEN 8192
30
 
 
31
 
class Error_message_stderr : public drizzled::plugin::ErrorMessage
32
 
{
33
 
public:
34
 
  Error_message_stderr() : Error_message_handler("Error_message_stderr") {}
35
 
  virtual bool errmsg(Session *, int , const char *format, va_list ap)
36
 
  {
37
 
    char msgbuf[MAX_MSG_LEN];
38
 
    int prv, wrv;
39
 
 
40
 
    prv= vsnprintf(msgbuf, MAX_MSG_LEN, format, ap);
41
 
    if (prv < 0) return true;
42
 
 
43
 
    /* a single write has a OS level thread lock
44
 
       so there is no need to have mutexes guarding this write,
45
 
    */
46
 
    wrv= write(2, msgbuf, prv);
47
 
    if ((wrv < 0) || (wrv != prv)) return true;
48
 
 
49
 
    return false;
50
 
  }
51
 
};
52
 
 
53
 
static Error_message_stderr *handler= NULL;
54
 
static int errmsg_stderr_plugin_init(drizzled::plugin::Registry &registry)
55
 
{
56
 
  handler= new Error_message_stderr();
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
 
{
75
 
  "errmsg_stderr",
76
 
  "0.1",
77
 
  "Mark Atwood <mark@fallenpegasus.com>",
78
 
  N_("Error Messages to stderr"),
79
 
  PLUGIN_LICENSE_GPL,
80
 
  errmsg_stderr_plugin_init,
81
 
  errmsg_stderr_plugin_deinit,
82
 
  NULL, /* status variables */
83
 
  NULL, /* system variables */
84
 
  NULL
85
 
}
86
 
drizzle_declare_plugin_end;