~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/errmsg_stderr/errmsg_stderr.cc

  • Committer: Monty Taylor
  • Date: 2008-10-20 08:48:34 UTC
  • mfrom: (520.1.22 drizzle)
  • Revision ID: monty@inaugust.com-20081020084834-xpb3w01vkcp55o02
Merged trunk.

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
/* 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
 
 
25
#include <stdio.h>  /* for vsnprintf */
 
26
#include <stdarg.h>  /* for va_list */
 
27
#include <unistd.h>  /* for write(2) */
 
28
 
 
29
/* todo, make this dynamic as needed */
 
30
#define MAX_MSG_LEN 8192
 
31
 
 
32
bool errmsg_stderr_func (Session *session __attribute__((unused)),
 
33
                         int priority __attribute__((unused)),
 
34
                         const char *format, va_list ap)
 
35
{
 
36
  char msgbuf[MAX_MSG_LEN];
 
37
  int prv, wrv;
 
38
 
 
39
  prv= vsnprintf(msgbuf, MAX_MSG_LEN, format, ap);
 
40
  if (prv < 0) return true;
 
41
 
 
42
  /* a single write has a OS level thread lock
 
43
     so there is no need to have mutexes guarding this write,
 
44
  */
 
45
  wrv= write(2, msgbuf, prv);
 
46
  if ((wrv < 0) || (wrv != prv)) return true;
 
47
 
 
48
  return false;
 
49
}
 
50
 
 
51
static int errmsg_stderr_plugin_init(void *p)
 
52
{
 
53
  errmsg_t *l= (errmsg_t *) p;
 
54
 
 
55
  l->errmsg_func= errmsg_stderr_func;
 
56
 
 
57
  return 0;
 
58
}
 
59
 
 
60
static int errmsg_stderr_plugin_deinit(void *p)
 
61
{
 
62
  errmsg_st *l= (errmsg_st *) p;
 
63
 
 
64
  l->errmsg_func= NULL;
 
65
 
 
66
  return 0;
 
67
}
 
68
 
 
69
mysql_declare_plugin(errmsg_stderr)
 
70
{
 
71
  DRIZZLE_LOGGER_PLUGIN,
 
72
  "errmsg_stderr",
 
73
  "0.1",
 
74
  "Mark Atwood <mark@fallenpegasus.com>",
 
75
  N_("Error Messages to stderr"),
 
76
  PLUGIN_LICENSE_GPL,
 
77
  errmsg_stderr_plugin_init,
 
78
  errmsg_stderr_plugin_deinit,
 
79
  NULL, /* status variables */
 
80
  NULL, /* system variables */
 
81
  NULL
 
82
}
 
83
mysql_declare_plugin_end;