~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/errmsg_stderr/errmsg_stderr.cc

  • Committer: Monty Taylor
  • Date: 2009-03-08 23:45:12 UTC
  • mto: (923.2.1 mordred)
  • mto: This revision was merged to the branch mainline in revision 921.
  • Revision ID: mordred@inaugust.com-20090308234512-tqkygxtu1iaig23s
Removed C99 isnan() usage, which allows us to remove the util/math.{cc,h} workarounds. Yay for standards!

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
18
 */
19
19
 
20
 
#include <config.h>
21
 
#include <drizzled/plugin/error_message.h>
 
20
#include <drizzled/server_includes.h>
 
21
#include <drizzled/plugin_errmsg.h>
22
22
#include <drizzled/gettext.h>
23
 
#include <drizzled/plugin.h>
24
23
 
25
24
#include <stdio.h>  /* for vsnprintf */
26
25
#include <stdarg.h>  /* for va_list */
27
26
#include <unistd.h>  /* for write(2) */
28
27
 
29
 
using namespace drizzled;
30
 
 
31
28
/* todo, make this dynamic as needed */
32
29
#define MAX_MSG_LEN 8192
33
30
 
34
 
class Error_message_stderr : public plugin::ErrorMessage
35
 
{
36
 
public:
37
 
  Error_message_stderr()
38
 
   : plugin::ErrorMessage("Error_message_stderr") {}
39
 
  virtual bool errmsg(error::level_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
 
 
59
 
static Error_message_stderr *handler= NULL;
60
 
static 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
 
 
68
 
DRIZZLE_DECLARE_PLUGIN
69
 
{
70
 
  DRIZZLE_VERSION_ID,
 
31
bool errmsg_stderr_func (Session *,
 
32
                         int ,
 
33
                         const char *format, va_list ap)
 
34
{
 
35
  char msgbuf[MAX_MSG_LEN];
 
36
  int prv, wrv;
 
37
 
 
38
  prv= vsnprintf(msgbuf, MAX_MSG_LEN, format, ap);
 
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
{
 
61
  errmsg_t *l= (errmsg_t *) p;
 
62
 
 
63
  l->errmsg_func= NULL;
 
64
 
 
65
  return 0;
 
66
}
 
67
 
 
68
drizzle_declare_plugin(errmsg_stderr)
 
69
{
 
70
  DRIZZLE_ERRMSG_PLUGIN,
71
71
  "errmsg_stderr",
72
72
  "0.1",
73
73
  "Mark Atwood <mark@fallenpegasus.com>",
74
74
  N_("Error Messages to stderr"),
75
75
  PLUGIN_LICENSE_GPL,
76
76
  errmsg_stderr_plugin_init,
77
 
  NULL, /* depends */
 
77
  errmsg_stderr_plugin_deinit,
 
78
  NULL, /* status variables */
 
79
  NULL, /* system variables */
78
80
  NULL
79
81
}
80
 
DRIZZLE_DECLARE_PLUGIN_END;
 
82
drizzle_declare_plugin_end;