~drizzle-trunk/drizzle/development

499.2.14 by Mark Atwood
fixes as per MontyT's comments, prep for internationalization
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
499.2.10 by Mark Atwood
add editor format hints, and other useful metadata comments
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
499.2.14 by Mark Atwood
fixes as per MontyT's comments, prep for internationalization
3
 *
499.2.10 by Mark Atwood
add editor format hints, and other useful metadata comments
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
 */
499.2.6 by Mark Atwood
an implemention of the errmsg plugin
19
20
#include <drizzled/server_includes.h>
21
#include <drizzled/plugin_errmsg.h>
549 by Monty Taylor
Took gettext.h out of header files.
22
#include <drizzled/gettext.h>
499.2.6 by Mark Atwood
an implemention of the errmsg plugin
23
24
#include <stdio.h>  /* for vsnprintf */
25
#include <stdarg.h>  /* for va_list */
26
#include <unistd.h>  /* for write(2) */
27
499.2.10 by Mark Atwood
add editor format hints, and other useful metadata comments
28
/* todo, make this dynamic as needed */
499.2.7 by Mark Atwood
some bugs in errmsg plugin
29
#define MAX_MSG_LEN 8192
30
520.1.22 by Brian Aker
Second pass of thd cleanup
31
bool errmsg_stderr_func (Session *session __attribute__((unused)),
499.2.7 by Mark Atwood
some bugs in errmsg plugin
32
			 int priority __attribute__((unused)),
33
			 const char *format, va_list ap)
499.2.6 by Mark Atwood
an implemention of the errmsg plugin
34
{
35
  char msgbuf[MAX_MSG_LEN];
36
  int prv, wrv;
37
499.2.7 by Mark Atwood
some bugs in errmsg plugin
38
  prv= vsnprintf(msgbuf, MAX_MSG_LEN, format, ap);
499.2.6 by Mark Atwood
an implemention of the errmsg plugin
39
  if (prv < 0) return true;
40
41
  /* a single write has a OS level thread lock
42
     so there is no need to have mutexes guarding this write,
43
  */
44
  wrv= write(2, msgbuf, prv);
45
  if ((wrv < 0) || (wrv != prv)) return true;
46
47
  return false;
48
}
49
50
static int errmsg_stderr_plugin_init(void *p)
51
{
52
  errmsg_t *l= (errmsg_t *) p;
53
54
  l->errmsg_func= errmsg_stderr_func;
55
56
  return 0;
57
}
58
59
static int errmsg_stderr_plugin_deinit(void *p)
60
{
572.3.1 by moriyoshi
Fix for bug #292633
61
  errmsg_t *l= (errmsg_t *) p;
499.2.6 by Mark Atwood
an implemention of the errmsg plugin
62
63
  l->errmsg_func= NULL;
64
65
  return 0;
66
}
67
68
mysql_declare_plugin(errmsg_stderr)
69
{
572.3.1 by moriyoshi
Fix for bug #292633
70
  DRIZZLE_ERRMSG_PLUGIN,
499.2.6 by Mark Atwood
an implemention of the errmsg plugin
71
  "errmsg_stderr",
72
  "0.1",
73
  "Mark Atwood <mark@fallenpegasus.com>",
499.2.14 by Mark Atwood
fixes as per MontyT's comments, prep for internationalization
74
  N_("Error Messages to stderr"),
499.2.6 by Mark Atwood
an implemention of the errmsg plugin
75
  PLUGIN_LICENSE_GPL,
76
  errmsg_stderr_plugin_init,
77
  errmsg_stderr_plugin_deinit,
499.2.14 by Mark Atwood
fixes as per MontyT's comments, prep for internationalization
78
  NULL, /* status variables */
79
  NULL, /* system variables */
499.2.6 by Mark Atwood
an implemention of the errmsg plugin
80
  NULL
81
}
82
mysql_declare_plugin_end;