1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2008 Mark Atwood
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.
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.
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
21
#include <drizzled/plugin/error_message.h>
22
#include <drizzled/gettext.h>
23
#include <drizzled/plugin.h>
25
#include <stdio.h> /* for vsnprintf */
26
#include <stdarg.h> /* for va_list */
27
#include <unistd.h> /* for write(2) */
29
using namespace drizzled;
31
/* todo, make this dynamic as needed */
32
#define MAX_MSG_LEN 8192
34
class Error_message_stderr : public plugin::ErrorMessage
37
Error_message_stderr()
38
: plugin::ErrorMessage("Error_message_stderr") {}
39
virtual bool errmsg(Session *, int , const char *format, va_list ap)
41
char msgbuf[MAX_MSG_LEN];
44
prv= vsnprintf(msgbuf, MAX_MSG_LEN, format, ap);
45
if (prv < 0) return true;
47
/* a single write has a OS level thread lock
48
so there is no need to have mutexes guarding this write,
50
wrv= write(2, msgbuf, prv);
51
if ((wrv < 0) || (wrv != prv)) return true;
57
static Error_message_stderr *handler= NULL;
58
static int errmsg_stderr_plugin_init(module::Context &context)
60
handler= new Error_message_stderr();
66
DRIZZLE_DECLARE_PLUGIN
71
"Mark Atwood <mark@fallenpegasus.com>",
72
N_("Error Messages to stderr"),
74
errmsg_stderr_plugin_init,
75
NULL, /* system variables */
78
DRIZZLE_DECLARE_PLUGIN_END;