diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2016-06-03 23:18:56 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2016-06-03 23:18:56 +0300 |
commit | ccfe04cf8c3c903013dcacf5681d0d826b222224 (patch) | |
tree | 5d26d8d1d19cc13af7ee52048e6f7c6cfe840e31 | |
parent | cca955986efc0a7736ea0240fae2ce0694b16c5e (diff) | |
download | mysqlstat-ccfe04cf8c3c903013dcacf5681d0d826b222224.tar.gz mysqlstat-ccfe04cf8c3c903013dcacf5681d0d826b222224.tar.bz2 |
Initial commit
-rw-r--r-- | .gitignore | 28 | ||||
-rw-r--r-- | NEWS | 0 | ||||
-rw-r--r-- | configure.ac | 7 | ||||
-rw-r--r-- | src/.gitignore | 1 | ||||
-rw-r--r-- | src/Makefile.am | 8 | ||||
-rw-r--r-- | src/mysqlstat.c | 89 | ||||
-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 | ||
11 | ABOUT-NLS | ||
12 | ChangeLog | ||
13 | INSTALL | ||
14 | Makefile | ||
15 | Makefile.in | ||
16 | TAGS | ||
17 | aclocal.m4 | ||
18 | autom4te.cache/ | ||
19 | build-aux | ||
20 | config.h | ||
21 | config.h.in | ||
22 | config.log | ||
23 | config.status | ||
24 | configure | ||
25 | core | ||
26 | libtool | ||
27 | m4 | ||
28 | stamp-h1 | ||
diff --git a/configure.ac b/configure.ac index f386366..fe20beb 100644 --- a/configure.ac +++ b/configure.ac | |||
@@ -16,7 +16,7 @@ | |||
16 | 16 | ||
17 | AC_PREREQ(2.69) | 17 | AC_PREREQ(2.69) |
18 | AC_INIT([mysqlstat], 0.0.90, [gray@gnu.org]) | 18 | AC_INIT([mysqlstat], 0.0.90, [gray@gnu.org]) |
19 | AC_CONFIG_SRCDIR(src/mysqlstat-mib.mib2c) | 19 | AC_CONFIG_SRCDIR(src/mysqlstat_mib.mib2c) |
20 | AM_CONFIG_HEADER(config.h) | 20 | AM_CONFIG_HEADER(config.h) |
21 | AC_CONFIG_AUX_DIR([build-aux]) | 21 | AC_CONFIG_AUX_DIR([build-aux]) |
22 | AC_CONFIG_MACRO_DIR([m4]) | 22 | AC_CONFIG_MACRO_DIR([m4]) |
@@ -45,10 +45,11 @@ fi | |||
45 | AC_SUBST(NET_SNMP_CONFIG) | 45 | AC_SUBST(NET_SNMP_CONFIG) |
46 | 46 | ||
47 | # Check for MySQL | 47 | # Check for MySQL |
48 | AC_SUBST(MYSQL_LIBS) | ||
48 | MY_CHECK_LIB(mysqlclient, mysql_real_connect, -lm, | 49 | MY_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. |
54 | AC_HEADER_STDC | 55 | AC_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 | |||
20 | mysqlstat_la_SOURCES = \ | 20 | mysqlstat_la_SOURCES = \ |
21 | mysqlstat.c\ | 21 | mysqlstat.c\ |
22 | mysqlstat.h\ | 22 | mysqlstat.h\ |
23 | mysqlstat-mib.c | 23 | mysqlstat_mib.c |
24 | 24 | ||
25 | BUILT_SOURCES = \ | 25 | BUILT_SOURCES = \ |
26 | mysqlstat-mib.c | 26 | mysqlstat_mib.c |
27 | 27 | ||
28 | mysqlstat-mib.c: mysqlstat-mib.mib2c MYSQL-STAT-MIB.txt | 28 | mysqlstat_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 | ||
59 | EXTRA_DIST = MYSQL-STAT-MIB.txt mysqlstat-mib.mib2c | 59 | EXTRA_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 | ||
21 | static char *config_file = CONFDIR "/mysqlstat.cnf"; | 23 | static char *config_file = CONFDIR "/mysqlstat.cnf"; |
22 | 24 | ||
23 | struct mysqlstat_connection { | 25 | struct mysqlstat_connection { |
24 | MYSQL mysql; | 26 | MYSQL mysql; |
25 | }; | 27 | }; |
28 | |||
29 | static void * | ||
30 | xalloc(size_t s) | ||
31 | { | ||
32 | void *p = malloc(s); | ||
33 | assert(p != NULL); | ||
34 | return p; | ||
35 | } | ||
36 | |||
37 | static void * | ||
38 | xcalloc(size_t nmemb, size_t size) | ||
39 | { | ||
40 | void *p = calloc(nmemb, size); | ||
41 | assert(p != NULL); | ||
42 | return p; | ||
43 | } | ||
44 | |||
45 | static char * | ||
46 | xstrdup(char const *s) | ||
47 | { | ||
48 | char *p = strdup(s); | ||
49 | assert(p != NULL); | ||
50 | return p; | ||
51 | } | ||
26 | 52 | ||
27 | mysqlstat_connection_t | 53 | mysqlstat_connection_t |
28 | mysqlstat_connect(void) | 54 | mysqlstat_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 | ||
50 | void | 76 | void |
51 | mysqlstat_disconnect(mysqlstat_connection_t *conn) | 77 | mysqlstat_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) | |||
85 | static int | 111 | static int |
86 | syment_matches(struct syment *ent, char const *name) | 112 | syment_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 | |||
121 | rehash(struct hashtab *ht) | 147 | rehash(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) | |||
138 | static void | 163 | static void |
139 | hashtab_remove(struct hashtab *ht, char const *name) | 164 | hashtab_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 |