MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
log_listner.cpp
1 /*
2  Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
3 
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; version 2 of the License.
7 
8  This program is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  GNU General Public License for more details.
12 
13  You should have received a copy of the GNU General Public License
14  along with this program; if not, write to the Free Software
15  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
16 */
17 
18 #include <mgmapi.h>
19 #include <ndb_global.h>
20 #include <ndb_opts.h>
21 #include <NDBT.hpp>
22 
23 static struct my_option my_long_options[] =
24 {
25  NDB_STD_OPTS("eventlog"),
26  { 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
27 };
28 
29 int filter[] = { 15, NDB_MGM_EVENT_CATEGORY_BACKUP,
38  0 };
39 
40 extern "C"
41 void catch_signal(int signum)
42 {
43 }
44 
45 int
46 main(int argc, char** argv)
47 {
48  NDB_INIT(argv[0]);
49  const char *load_default_groups[]= { "mysql_cluster",0 };
50  load_defaults("my",load_default_groups,&argc,&argv);
51  int ho_error;
52 #ifndef DBUG_OFF
53  opt_debug= "d:t:O,/tmp/eventlog.trace";
54 #endif
55 
56 #ifndef _WIN32
57  // Catching signal to allow testing of EINTR safeness
58  // with "while killall -USR1 eventlog; do true; done"
59  signal(SIGUSR1, catch_signal);
60 #endif
61 
62  if ((ho_error=handle_options(&argc, &argv, my_long_options,
63  ndb_std_get_one_option)))
64  return NDBT_ProgramExit(NDBT_WRONGARGS);
65 
67  ndb_mgm_set_connectstring(handle, opt_ndb_connectstring);
68 
69  while (true)
70  {
71  if (ndb_mgm_connect(handle,0,0,0) == -1)
72  {
73  ndbout_c("Failed to connect");
74  exit(0);
75  }
76 
78  if (le == 0)
79  {
80  ndbout_c("Failed to create logevent handle");
81  exit(0);
82  }
83 
84  struct ndb_logevent event;
85  while (true)
86  {
87  int r= ndb_logevent_get_next(le, &event,5000);
88  if (r < 0)
89  {
90  ndbout_c("Error while getting next event");
91  break;
92  }
93  if (r == 0)
94  {
95  continue;
96  }
97  ndbout_c("Got event: %d", event.type);
98  }
99 
100  ndb_mgm_destroy_logevent_handle(&le);
101  ndb_mgm_disconnect(handle);
102  }
103 
104  return 0;
105 }