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
20
/* need to define DRIZZLE_SERVER to get inside the Session */
21
#define DRIZZLE_SERVER 1
22
#include <drizzled/server_includes.h>
23
#include <drizzled/plugin_errmsg.h>
24
#include <drizzled/gettext.h>
26
#include <stdio.h> /* for vsnprintf */
27
#include <stdarg.h> /* for va_list */
28
#include <unistd.h> /* for write(2) */
30
/* todo, make this dynamic as needed */
31
#define MAX_MSG_LEN 8192
33
bool errmsg_stderr_func (Session *session __attribute__((unused)),
34
int priority __attribute__((unused)),
35
const char *format, va_list ap)
37
char msgbuf[MAX_MSG_LEN];
40
prv= vsnprintf(msgbuf, MAX_MSG_LEN, format, ap);
41
if (prv < 0) return true;
43
/* a single write has a OS level thread lock
44
so there is no need to have mutexes guarding this write,
46
wrv= write(2, msgbuf, prv);
47
if ((wrv < 0) || (wrv != prv)) return true;
52
static int errmsg_stderr_plugin_init(void *p)
54
errmsg_t *l= (errmsg_t *) p;
56
l->errmsg_func= errmsg_stderr_func;
61
static int errmsg_stderr_plugin_deinit(void *p)
63
errmsg_t *l= (errmsg_t *) p;
70
mysql_declare_plugin(errmsg_stderr)
72
DRIZZLE_ERRMSG_PLUGIN,
75
"Mark Atwood <mark@fallenpegasus.com>",
76
N_("Error Messages to stderr"),
78
errmsg_stderr_plugin_init,
79
errmsg_stderr_plugin_deinit,
80
NULL, /* status variables */
81
NULL, /* system variables */
84
mysql_declare_plugin_end;