drizzle
C++ MySQL-protocol-compatible database server
Loading...
Searching...
No Matches
errmsg_stderr.cc
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 <config.h>
21#include <drizzled/plugin/error_message.h>
22#include <drizzled/gettext.h>
23#include <drizzled/plugin.h>
24
25#include <stdio.h> /* for vsnprintf */
26#include <stdarg.h> /* for va_list */
27#include <unistd.h> /* for write(2) */
28
29using namespace drizzled;
30
31/* todo, make this dynamic as needed */
32#define MAX_MSG_LEN 8192
33
34class Error_message_stderr : public plugin::ErrorMessage
35{
36public:
37 Error_message_stderr()
38 : plugin::ErrorMessage("stderr_error_message") {}
39 virtual bool errmsg(error::priority_t , const char *format, va_list ap)
40 {
41 char msgbuf[MAX_MSG_LEN];
42 int prv, wrv;
43
44 prv= vsnprintf(msgbuf, MAX_MSG_LEN, format, ap);
45 if (prv < 0) return true;
46
47 /* a single write has a OS level thread lock
48 so there is no need to have mutexes guarding this write,
49 */
50 wrv= write(fileno(stderr), msgbuf, prv);
51 fputc('\n', stderr);
52 if ((wrv < 0) || (wrv != prv))
53 return true;
54
55 return false;
56 }
57};
58
59static Error_message_stderr *handler= NULL;
60static int errmsg_stderr_plugin_init(module::Context &context)
61{
62 handler= new Error_message_stderr();
63 context.add(handler);
64
65 return 0;
66}
67
68DRIZZLE_DECLARE_PLUGIN
69{
70 DRIZZLE_VERSION_ID,
71 "errmsg_stderr",
72 "0.1",
73 "Mark Atwood",
74 N_("Prints error messages to STDERR"),
75 PLUGIN_LICENSE_GPL,
76 errmsg_stderr_plugin_init,
77 NULL,
78 NULL
79}
80DRIZZLE_DECLARE_PLUGIN_END;
TODO: Rename this file - func.h is stupid.