aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2016-06-03 23:18:56 +0300
committerSergey Poznyakoff <gray@gnu.org.ua>2016-06-03 23:18:56 +0300
commitccfe04cf8c3c903013dcacf5681d0d826b222224 (patch)
tree5d26d8d1d19cc13af7ee52048e6f7c6cfe840e31
parentcca955986efc0a7736ea0240fae2ce0694b16c5e (diff)
downloadmysqlstat-ccfe04cf8c3c903013dcacf5681d0d826b222224.tar.gz
mysqlstat-ccfe04cf8c3c903013dcacf5681d0d826b222224.tar.bz2
Initial commit
-rw-r--r--.gitignore28
-rw-r--r--NEWS0
-rw-r--r--configure.ac7
-rw-r--r--src/.gitignore1
-rw-r--r--src/Makefile.am8
-rw-r--r--src/mysqlstat.c89
-rw-r--r--src/mysqlstat_mib.mib2c (renamed from src/mysqlstat-mib.mib2c)21
7 files changed, 111 insertions, 43 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..506e185
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,28 @@
1*.a
2*.la
3*.lo
4*.o
5*.tar.*
6*~
7.deps
8.emacs*
9.gdbinit
10.libs
11ABOUT-NLS
12ChangeLog
13INSTALL
14Makefile
15Makefile.in
16TAGS
17aclocal.m4
18autom4te.cache/
19build-aux
20config.h
21config.h.in
22config.log
23config.status
24configure
25core
26libtool
27m4
28stamp-h1
diff --git a/NEWS b/NEWS
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/NEWS
diff --git a/configure.ac b/configure.ac
index f386366..fe20beb 100644
--- a/configure.ac
+++ b/configure.ac
@@ -16,7 +16,7 @@
16 16
17AC_PREREQ(2.69) 17AC_PREREQ(2.69)
18AC_INIT([mysqlstat], 0.0.90, [gray@gnu.org]) 18AC_INIT([mysqlstat], 0.0.90, [gray@gnu.org])
19AC_CONFIG_SRCDIR(src/mysqlstat-mib.mib2c) 19AC_CONFIG_SRCDIR(src/mysqlstat_mib.mib2c)
20AM_CONFIG_HEADER(config.h) 20AM_CONFIG_HEADER(config.h)
21AC_CONFIG_AUX_DIR([build-aux]) 21AC_CONFIG_AUX_DIR([build-aux])
22AC_CONFIG_MACRO_DIR([m4]) 22AC_CONFIG_MACRO_DIR([m4])
@@ -45,10 +45,11 @@ fi
45AC_SUBST(NET_SNMP_CONFIG) 45AC_SUBST(NET_SNMP_CONFIG)
46 46
47# Check for MySQL 47# Check for MySQL
48AC_SUBST(MYSQL_LIBS)
48MY_CHECK_LIB(mysqlclient, mysql_real_connect, -lm, 49MY_CHECK_LIB(mysqlclient, mysql_real_connect, -lm,
49 [MYSQL_LIBS="$pm_cv_lib_mysqlclient"], 50 [MYSQL_LIBS="$my_cv_lib_mysqlclient"],
50 [AC_MSG_ERROR(required library libmysqlclient not found)], 51 [AC_MSG_ERROR(required library libmysqlclient not found)],
51 [/usr/lib/mysql /usr/local/lib/mysql]) 52 [/usr/lib64/mysql /usr/local/lib/mysql])
52 53
53# Checks for header files. 54# Checks for header files.
54AC_HEADER_STDC 55AC_HEADER_STDC
diff --git a/src/.gitignore b/src/.gitignore
new file mode 100644
index 0000000..e89552d
--- /dev/null
+++ b/src/.gitignore
@@ -0,0 +1 @@
mysqlstat_mib.c
diff --git a/src/Makefile.am b/src/Makefile.am
index f3a2970..6463177 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -20,12 +20,12 @@ dlmod_LTLIBRARIES = mysqlstat.la
20mysqlstat_la_SOURCES = \ 20mysqlstat_la_SOURCES = \
21 mysqlstat.c\ 21 mysqlstat.c\
22 mysqlstat.h\ 22 mysqlstat.h\
23 mysqlstat-mib.c 23 mysqlstat_mib.c
24 24
25BUILT_SOURCES = \ 25BUILT_SOURCES = \
26 mysqlstat-mib.c 26 mysqlstat_mib.c
27 27
28mysqlstat-mib.c: mysqlstat-mib.mib2c MYSQL-STAT-MIB.txt 28mysqlstat_mib.c: mysqlstat_mib.mib2c MYSQL-STAT-MIB.txt
29 29
30.mib2c.c: 30.mib2c.c:
31 MIBDIRS=${top_srcdir}/src:${NET_SNMP_MIBDIRS} MIBS="+MYSQL-STAT-MIB" \ 31 MIBDIRS=${top_srcdir}/src:${NET_SNMP_MIBDIRS} MIBS="+MYSQL-STAT-MIB" \
@@ -56,4 +56,4 @@ mib_DATA = MYSQL-STAT-MIB.txt
56 56
57#dist_man_MANS = mysqlstat.8 57#dist_man_MANS = mysqlstat.8
58 58
59EXTRA_DIST = MYSQL-STAT-MIB.txt mysqlstat-mib.mib2c 59EXTRA_DIST = MYSQL-STAT-MIB.txt mysqlstat_mib.mib2c
diff --git a/src/mysqlstat.c b/src/mysqlstat.c
index 1ce7014..c50ae65 100644
--- a/src/mysqlstat.c
+++ b/src/mysqlstat.c
@@ -15,14 +15,40 @@
15 * along with Mysqlstat. If not, see <http://www.gnu.org/licenses/>. 15 * along with Mysqlstat. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18#include <mysqlstat.c> 18#include <mysqlstat.h>
19#include <mysql.c> 19#include <mysql/mysql.h>
20#undef NDEBUG
21#include <assert.h>
20 22
21static char *config_file = CONFDIR "/mysqlstat.cnf"; 23static char *config_file = CONFDIR "/mysqlstat.cnf";
22 24
23struct mysqlstat_connection { 25struct mysqlstat_connection {
24 MYSQL mysql; 26 MYSQL mysql;
25}; 27};
28
29static void *
30xalloc(size_t s)
31{
32 void *p = malloc(s);
33 assert(p != NULL);
34 return p;
35}
36
37static void *
38xcalloc(size_t nmemb, size_t size)
39{
40 void *p = calloc(nmemb, size);
41 assert(p != NULL);
42 return p;
43}
44
45static char *
46xstrdup(char const *s)
47{
48 char *p = strdup(s);
49 assert(p != NULL);
50 return p;
51}
26 52
27mysqlstat_connection_t 53mysqlstat_connection_t
28mysqlstat_connect(void) 54mysqlstat_connect(void)
@@ -30,7 +56,7 @@ mysqlstat_connect(void)
30 struct mysqlstat_connection *conn; 56 struct mysqlstat_connection *conn;
31 my_bool t = 1; 57 my_bool t = 1;
32 58
33 conn = xcalloc(sizeof(*conn)); 59 conn = xcalloc(1, sizeof(*conn));
34 mysql_init(&conn->mysql); 60 mysql_init(&conn->mysql);
35 if (access(config_file, F_OK) == 0) 61 if (access(config_file, F_OK) == 0)
36 mysql_options(&conn->mysql, MYSQL_READ_DEFAULT_FILE, 62 mysql_options(&conn->mysql, MYSQL_READ_DEFAULT_FILE,
@@ -48,7 +74,7 @@ mysqlstat_connect(void)
48} 74}
49 75
50void 76void
51mysqlstat_disconnect(mysqlstat_connection_t *conn) 77mysqlstat_disconnect(mysqlstat_connection_t conn)
52{ 78{
53 if (!conn) 79 if (!conn)
54 return; 80 return;
@@ -85,7 +111,7 @@ syment_free(struct syment *ent)
85static int 111static int
86syment_matches(struct syment *ent, char const *name) 112syment_matches(struct syment *ent, char const *name)
87{ 113{
88 if (!syment->name) 114 if (!ent->name)
89 return 0; 115 return 0;
90 return strcmp(ent->name, name) == 0; 116 return strcmp(ent->name, name) == 0;
91} 117}
@@ -121,16 +147,15 @@ static void
121rehash(struct hashtab *ht) 147rehash(struct hashtab *ht)
122{ 148{
123 struct syment *oldtab = ht->tab; 149 struct syment *oldtab = ht->tab;
124 struct syment *newtab;
125 uint32_t i, n; 150 uint32_t i, n;
126 151
127 assert(ht->hc + 1 < max_rehash); 152 assert(ht->hc + 1 < max_rehash);
128 n = hash_size[ht->hc]; 153 n = hash_size[ht->hc];
129 ++ht->hc; 154 ++ht->hc;
130 newtab = xcalloc(hash_size[ht->hc], sizeof(newtab[0])); 155 ht->tab = xcalloc(hash_size[ht->hc], sizeof(ht->tab[0]));
131 for (i = 0; i < n; i++) { 156 for (i = 0; i < n; i++) {
132 if (ent->name) 157 if (oldtab[i].name)
133 newtab[find_insert_pos(ht, &oldtab[i])] = oldtab[i]; 158 ht->tab[find_insert_pos(ht, &oldtab[i])] = oldtab[i];
134 } 159 }
135 free(oldtab); 160 free(oldtab);
136} 161}
@@ -138,7 +163,7 @@ rehash(struct hashtab *ht)
138static void 163static void
139hashtab_remove(struct hashtab *ht, char const *name) 164hashtab_remove(struct hashtab *ht, char const *name)
140{ 165{
141 uint32_t int pos, i, j, r; 166 uint32_t pos, i, j, r;
142 167
143 pos = hash_string(name, hash_size[ht->hc]); 168 pos = hash_string(name, hash_size[ht->hc]);
144 for (i = pos; ht->tab[i].name;) { 169 for (i = pos; ht->tab[i].name;) {
@@ -149,32 +174,32 @@ hashtab_remove(struct hashtab *ht, char const *name)
149 return;// ENOENT 174 return;// ENOENT
150 } 175 }
151 176
152 syment_free(ht->tab[i]); 177 syment_free(&ht->tab[i]);
153 178
154 for (;;) { 179 for (;;) {
155 st->tab[i] = NULL; 180 ht->tab[i].name = ht->tab[i].value = NULL;
156 j = i; 181 j = i;
157 182
158 do { 183 do {
159 i = (i + 1) % hash_size[ht->hc]; 184 i = (i + 1) % hash_size[ht->hc];
160 if (!st->tab[i].name) 185 if (!ht->tab[i].name)
161 return; 186 return;
162 r = hash_string(ht->tab[i].name, hash_size[ht->hc]); 187 r = hash_string(ht->tab[i].name, hash_size[ht->hc]);
163 } while ((j < r && r <= i) 188 } while ((j < r && r <= i)
164 || (i < j && j < r) || (r <= i && i < j)); 189