Index: trunk/servmon/include/smstdinc.hxx |
— | — | @@ -2,6 +2,10 @@ |
3 | 3 | #ifndef SM_SMSTDINC_HXX_INCLUDED_ |
4 | 4 | #define SM_SMSTDINC_HXX_INCLUDED_ |
5 | 5 | |
| 6 | +#ifdef SM_COMPILER_SHIMS_ONLY |
| 7 | +# define SM_NO_HEADERS |
| 8 | +#endif |
| 9 | + |
6 | 10 | #define SM_VERSION "2.1.0.0-pre" |
7 | 11 | |
8 | 12 | #define SM_RELCVS 1 /* CVS version */ |
— | — | @@ -10,6 +14,7 @@ |
11 | 15 | |
12 | 16 | #define SM_RELTYPE SM_RELCVS |
13 | 17 | |
| 18 | +#ifndef SM_NO_HEADERS |
14 | 19 | #include <iostream> |
15 | 20 | #include <fstream> |
16 | 21 | #include <iomanip> |
— | — | @@ -23,9 +28,11 @@ |
24 | 29 | #include <cerrno> |
25 | 30 | #include <cctype> |
26 | 31 | #include <algorithm> |
| 32 | +#ifndef SM_NO_USING |
27 | 33 | using std::pair; |
28 | 34 | using std::make_pair; |
29 | 35 | using std::for_each; |
| 36 | +#endif |
30 | 37 | |
31 | 38 | #include <boost/bind.hpp> |
32 | 39 | #include <boost/function.hpp> |
— | — | @@ -38,6 +45,7 @@ |
39 | 46 | #include <boost/thread/mutex.hpp> |
40 | 47 | #include <boost/any.hpp> |
41 | 48 | #include <boost/regex.hpp> |
| 49 | +#ifndef SM_NO_USING |
42 | 50 | using boost::regex; |
43 | 51 | using boost::regex_search; |
44 | 52 | using boost::lexical_cast; |
— | — | @@ -51,6 +59,7 @@ |
52 | 60 | using boost::tie; |
53 | 61 | namespace b = boost; |
54 | 62 | namespace bl = boost::lambda; |
| 63 | +#endif |
55 | 64 | |
56 | 65 | #include <sys/types.h> |
57 | 66 | #include <sys/socket.h> |
— | — | @@ -65,5 +74,18 @@ |
66 | 75 | #include <unistd.h> |
67 | 76 | #include <netdb.h> |
68 | 77 | #include <fcntl.h> |
| 78 | +#endif /* !SM_NO_HEADERS */ |
69 | 79 | |
| 80 | +/* Fix Solaris brokenness */ |
| 81 | +#ifndef SUN_LEN |
| 82 | +# define SUN_LEN(su) \ |
| 83 | + (sizeof(*(su)) - sizeof((su)->sun_path) + strlen((su)->sun_path)) |
70 | 84 | #endif |
| 85 | + |
| 86 | +#if defined(__GNUC__) || defined(__INTEL_COMPILER) |
| 87 | +# define SM_NORETURN __attribute__((__noreturn__)) |
| 88 | +#else |
| 89 | +# define SM_NORETURN |
| 90 | +#endif |
| 91 | + |
| 92 | +#endif |
Index: trunk/servmon/include/smnet.hxx |
— | — | @@ -9,6 +9,7 @@ |
10 | 10 | |
11 | 11 | #undef unix |
12 | 12 | #undef bsd |
| 13 | +#undef sun |
13 | 14 | |
14 | 15 | namespace smnet { |
15 | 16 | |
Index: trunk/servmon/README |
— | — | @@ -2,4 +2,17 @@ |
3 | 3 | It's also meant to be usable elsewhere, but may need some tweaking. Please send |
4 | 4 | any changes you make back to me at <keturner@livejournal.com>. |
5 | 5 | |
| 6 | +To use servmon you will need: |
| 7 | + - Unix. It's tested on Solaris and RedHat Linux. Other systems may or may |
| 8 | + not work; if you have to make any changes to build it, please let me know. |
| 9 | + I am interested in supporting non-Unix systems but do not have access to any. |
| 10 | + - A C++ compiler. GCC <2.95 will not work. GCC 2.95 may work. Tested with |
| 11 | + >= 3.3. |
| 12 | + - The Boost library (http://www.boost.org/). |
| 13 | + - SCons (http://www.scons.org/). |
| 14 | + |
| 15 | +To build: |
| 16 | + copy buildconfig.sample to buildconfig and edit as needed; |
| 17 | + run 'scons' |
| 18 | + |
6 | 19 | @(#) $Header$ |
Index: trunk/servmon/l_memcache.c |
— | — | @@ -38,8 +38,49 @@ |
39 | 39 | * included, therefore it is assumed that this code is public |
40 | 40 | * domain. Attribution still noted. */ |
41 | 41 | |
| 42 | + |
| 43 | +/* $NetBSD: err.c,v 1.23 2003/10/27 00:12:42 lukem Exp $ */ |
| 44 | +/* $NetBSD: errx.c,v 1.11 2003/10/27 00:12:42 lukem Exp $ */ |
| 45 | +/* $NetBSD: warn.c,v 1.11 2003/10/27 00:12:42 lukem Exp $ */ |
| 46 | +/* $NetBSD: warnx.c,v 1.10 2003/10/27 00:12:42 lukem Exp $ */ |
| 47 | +/* $NetBSD: verr.c,v 1.12 2003/10/27 02:17:18 lukem Exp $ */ |
| 48 | +/* $NetBSD: verrx.c,v 1.12 2003/10/27 00:12:42 lukem Exp $ */ |
| 49 | +/* $NetBSD: vwarn.c,v 1.12 2003/10/27 00:12:42 lukem Exp $ */ |
| 50 | +/* $NetBSD: vwarnx.c,v 1.12 2003/10/27 00:12:42 lukem Exp $ */ |
| 51 | + |
| 52 | +/*- |
| 53 | + * Copyright (c) 1993 |
| 54 | + * The Regents of the University of California. All rights reserved. |
| 55 | + * |
| 56 | + * Redistribution and use in source and binary forms, with or without |
| 57 | + * modification, are permitted provided that the following conditions |
| 58 | + * are met: |
| 59 | + * 1. Redistributions of source code must retain the above copyright |
| 60 | + * notice, this list of conditions and the following disclaimer. |
| 61 | + * 2. Redistributions in binary form must reproduce the above copyright |
| 62 | + * notice, this list of conditions and the following disclaimer in the |
| 63 | + * documentation and/or other materials provided with the distribution. |
| 64 | + * 3. Neither the name of the University nor the names of its contributors |
| 65 | + * may be used to endorse or promote products derived from this software |
| 66 | + * without specific prior written permission. |
| 67 | + * |
| 68 | + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND |
| 69 | + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 70 | + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 71 | + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
| 72 | + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 73 | + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| 74 | + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 75 | + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 76 | + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
| 77 | + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 78 | + * SUCH DAMAGE. |
| 79 | + */ |
| 80 | + |
42 | 81 | #include <ctype.h> |
43 | | -#include <err.h> |
| 82 | +#ifdef HAVE_ERR_H |
| 83 | +# include <err.h> |
| 84 | +#endif |
44 | 85 | #include <string.h> |
45 | 86 | #include <strings.h> |
46 | 87 | #include <stdio.h> |
— | — | @@ -72,9 +113,9 @@ |
73 | 114 | |
74 | 115 | |
75 | 116 | /* Prototypes for static functions that require a memory context */ |
76 | | -static u_int32_t mcm_atomic_cmd(const struct memcache_ctxt *ctxt, struct memcache *mc, |
| 117 | +static uint32_t mcm_atomic_cmd(const struct memcache_ctxt *ctxt, struct memcache *mc, |
77 | 118 | const char *cmd, const size_t cmd_len, |
78 | | - const char *key, const size_t key_len, const u_int32_t val); |
| 119 | + const char *key, const size_t key_len, const uint32_t val); |
79 | 120 | static void mcm_fetch_cmd(const struct memcache_ctxt *ctxt, struct memcache *mc, |
80 | 121 | struct memcache_req *req, const char *cmd, const size_t cmd_len); |
81 | 122 | static char *mcm_get_line(const struct memcache_ctxt *ctxt, struct memcache *mc, |
— | — | @@ -87,7 +128,7 @@ |
88 | 129 | const char *cmd, const size_t cmd_len, |
89 | 130 | const char *key, const size_t key_len, |
90 | 131 | const void *val, const size_t bytes, |
91 | | - const time_t expire, const u_int16_t flags); |
| 132 | + const time_t expire, const uint16_t flags); |
92 | 133 | |
93 | 134 | |
94 | 135 | #ifdef __STRICT_ANSI__ |
— | — | @@ -133,6 +174,110 @@ |
134 | 175 | /* # endif */ |
135 | 176 | /* #endif */ |
136 | 177 | |
| 178 | +#define SM_COMPILER_SHIMS_ONLY |
| 179 | +#include "smstdinc.hxx" |
| 180 | + |
| 181 | +#define PROGNAME "servmon" |
| 182 | + |
| 183 | +SM_NORETURN void |
| 184 | +verr(eval, fmt, ap) |
| 185 | + int eval; |
| 186 | + const char *fmt; |
| 187 | + va_list ap; |
| 188 | +{ |
| 189 | + int sverrno; |
| 190 | + |
| 191 | + sverrno = errno; |
| 192 | + (void)fprintf(stderr, "%s: ", PROGNAME); |
| 193 | + if (fmt != NULL) { |
| 194 | + (void)vfprintf(stderr, fmt, ap); |
| 195 | + (void)fprintf(stderr, ": "); |
| 196 | + } |
| 197 | + (void)fprintf(stderr, "%s\n", strerror(sverrno)); |
| 198 | + exit(eval); |
| 199 | +} |
| 200 | + |
| 201 | +SM_NORETURN void |
| 202 | +verrx(eval, fmt, ap) |
| 203 | + int eval; |
| 204 | + const char *fmt; |
| 205 | + va_list ap; |
| 206 | +{ |
| 207 | + (void)fprintf(stderr, "%s: ", PROGNAME); |
| 208 | + if (fmt != NULL) |
| 209 | + (void)vfprintf(stderr, fmt, ap); |
| 210 | + (void)fprintf(stderr, "\n"); |
| 211 | + exit(eval); |
| 212 | +} |
| 213 | + |
| 214 | + |
| 215 | +void |
| 216 | +vwarn(fmt, ap) |
| 217 | + const char *fmt; |
| 218 | + va_list ap; |
| 219 | +{ |
| 220 | + int sverrno; |
| 221 | + |
| 222 | + sverrno = errno; |
| 223 | + (void)fprintf(stderr, "%s: ", PROGNAME); |
| 224 | + if (fmt != NULL) { |
| 225 | + (void)vfprintf(stderr, fmt, ap); |
| 226 | + (void)fprintf(stderr, ": "); |
| 227 | + } |
| 228 | + (void)fprintf(stderr, "%s\n", strerror(sverrno)); |
| 229 | +} |
| 230 | + |
| 231 | +void |
| 232 | +vwarnx(fmt, ap) |
| 233 | + const char *fmt; |
| 234 | + va_list ap; |
| 235 | +{ |
| 236 | + (void)fprintf(stderr, "%s: ", PROGNAME); |
| 237 | + if (fmt != NULL) |
| 238 | + (void)vfprintf(stderr, fmt, ap); |
| 239 | + (void)fprintf(stderr, "\n"); |
| 240 | +} |
| 241 | + |
| 242 | +SM_NORETURN void |
| 243 | +err(int eval, const char *fmt, ...) |
| 244 | +{ |
| 245 | + va_list ap; |
| 246 | + |
| 247 | + va_start(ap, fmt); |
| 248 | + verr(eval, fmt, ap); |
| 249 | + va_end(ap); |
| 250 | +} |
| 251 | + |
| 252 | +void |
| 253 | +warn(const char *fmt, ...) |
| 254 | +{ |
| 255 | + va_list ap; |
| 256 | + |
| 257 | + va_start(ap, fmt); |
| 258 | + vwarn(fmt, ap); |
| 259 | + va_end(ap); |
| 260 | +} |
| 261 | + |
| 262 | +void |
| 263 | +warnx(const char *fmt, ...) |
| 264 | +{ |
| 265 | + va_list ap; |
| 266 | + |
| 267 | + va_start(ap, fmt); |
| 268 | + vwarnx(fmt, ap); |
| 269 | + va_end(ap); |
| 270 | +} |
| 271 | + |
| 272 | +SM_NORETURN void |
| 273 | +errx(int eval, const char *fmt, ...) |
| 274 | +{ |
| 275 | + va_list ap; |
| 276 | + |
| 277 | + va_start(ap, fmt); |
| 278 | + verrx(eval, fmt, ap); |
| 279 | + va_end(ap); |
| 280 | +} |
| 281 | + |
137 | 282 | /* Set the default memory handling routines to be system defaults. */ |
138 | 283 | static struct memcache_ctxt mcGlobalCtxt = { |
139 | 284 | (mcFreeFunc)free, |
— | — | @@ -146,13 +291,13 @@ |
147 | 292 | mc_add(struct memcache *mc, |
148 | 293 | const char *key, const size_t key_len, |
149 | 294 | const void *val, const size_t bytes, |
150 | | - const time_t expire, const u_int16_t flags) { |
| 295 | + const time_t expire, const uint16_t flags) { |
151 | 296 | return mcm_storage_cmd(&mcGlobalCtxt, mc, str_add_cmd, str_add_len, key, key_len, val, bytes, expire, flags); |
152 | 297 | } |
153 | 298 | |
154 | 299 | |
155 | 300 | void |
156 | | -mc_aget(struct memcache *mc, const char *key, const size_t len, void **value, u_int32_t *value_len) { |
| 301 | +mc_aget(struct memcache *mc, const char *key, const size_t len, void **value, uint32_t *value_len) { |
157 | 302 | mcm_aget(&mcGlobalCtxt, mc, key, len, value, value_len); |
158 | 303 | } |
159 | 304 | |
— | — | @@ -163,8 +308,8 @@ |
164 | 309 | } |
165 | 310 | |
166 | 311 | |
167 | | -u_int32_t |
168 | | -mc_decr(struct memcache *mc, const char *key, const size_t key_len, const u_int32_t val) { |
| 312 | +uint32_t |
| 313 | +mc_decr(struct memcache *mc, const char *key, const size_t key_len, const uint32_t val) { |
169 | 314 | return mcm_atomic_cmd(&mcGlobalCtxt, mc, str_decr_cmd, str_decr_len, key, key_len, val); |
170 | 315 | } |
171 | 316 | |
— | — | @@ -199,8 +344,8 @@ |
200 | 345 | } |
201 | 346 | |
202 | 347 | |
203 | | -u_int32_t |
204 | | -mc_incr(struct memcache *mc, const char *key, const size_t key_len, const u_int32_t val) { |
| 348 | +uint32_t |
| 349 | +mc_incr(struct memcache *mc, const char *key, const size_t key_len, const uint32_t val) { |
205 | 350 | return mcm_atomic_cmd(&mcGlobalCtxt, mc, str_incr_cmd, str_incr_len, key, key_len, val); |
206 | 351 | } |
207 | 352 | |
— | — | @@ -217,7 +362,7 @@ |
218 | 363 | } |
219 | 364 | |
220 | 365 | |
221 | | -u_int32_t |
| 366 | +uint32_t |
222 | 367 | mc_reldate(void) { |
223 | 368 | return MEMCACHE_RELDATE; |
224 | 369 | } |
— | — | @@ -227,7 +372,7 @@ |
228 | 373 | mc_replace(struct memcache *mc, |
229 | 374 | const char *key, const size_t key_len, |
230 | 375 | const void *val, const size_t bytes, |
231 | | - const time_t expire, const u_int16_t flags) { |
| 376 | + const time_t expire, const uint16_t flags) { |
232 | 377 | return mcm_storage_cmd(&mcGlobalCtxt, mc, str_replace_cmd, str_replace_len, key, key_len, val, bytes, expire, flags); |
233 | 378 | } |
234 | 379 | |
— | — | @@ -298,7 +443,7 @@ |
299 | 444 | |
300 | 445 | |
301 | 446 | struct memcache_server * |
302 | | -mc_server_find(struct memcache *mc, const u_int32_t hash) { |
| 447 | +mc_server_find(struct memcache *mc, const uint32_t hash) { |
303 | 448 | return mcm_server_find(mc, hash); |
304 | 449 | } |
305 | 450 | |
— | — | @@ -331,7 +476,7 @@ |
332 | 477 | mc_set(struct memcache *mc, |
333 | 478 | const char *key, const size_t key_len, |
334 | 479 | const void *val, const size_t bytes, |
335 | | - const time_t expire, const u_int16_t flags) { |
| 480 | + const time_t expire, const uint16_t flags) { |
336 | 481 | return mcm_storage_cmd(&mcGlobalCtxt, mc, str_set_cmd, str_set_len, key, key_len, val, bytes, expire, flags); |
337 | 482 | } |
338 | 483 | |
— | — | @@ -354,7 +499,7 @@ |
355 | 500 | } |
356 | 501 | |
357 | 502 | |
358 | | -u_int32_t |
| 503 | +uint32_t |
359 | 504 | mc_vernum(void) { |
360 | 505 | return MEMCACHE_VERNUM; |
361 | 506 | } |
— | — | @@ -372,7 +517,7 @@ |
373 | 518 | mcm_add(const struct memcache_ctxt *ctxt, struct memcache *mc, |
374 | 519 | const char *key, const size_t key_len, |
375 | 520 | const void *val, const size_t bytes, |
376 | | - const time_t expire, const u_int16_t flags) { |
| 521 | + const time_t expire, const uint16_t flags) { |
377 | 522 | return mcm_storage_cmd(ctxt, mc, str_add_cmd, str_add_len, key, key_len, val, bytes, expire, flags); |
378 | 523 | } |
379 | 524 | |
— | — | @@ -381,7 +526,7 @@ |
382 | 527 | * the key. The result is mcMalloc(3)'ed and it is assumed that the |
383 | 528 | * caller is required to mcFree(3) the memory. */ |
384 | 529 | void |
385 | | -mcm_aget(const struct memcache_ctxt *ctxt, struct memcache *mc, const char *key, const size_t len, void **value, u_int32_t *value_len) { |
| 530 | +mcm_aget(const struct memcache_ctxt *ctxt, struct memcache *mc, const char *key, const size_t len, void **value, uint32_t *value_len) { |
386 | 531 | struct memcache_req *req; |
387 | 532 | struct memcache_res *res; |
388 | 533 | |
— | — | @@ -414,16 +559,16 @@ |
415 | 560 | } |
416 | 561 | |
417 | 562 | |
418 | | -static u_int32_t |
| 563 | +static uint32_t |
419 | 564 | mcm_atomic_cmd(const struct memcache_ctxt *ctxt, struct memcache *mc, |
420 | 565 | const char *cmd, const size_t cmd_len, |
421 | | - const char *key, const size_t key_len, const u_int32_t val) { |
| 566 | + const char *key, const size_t key_len, const uint32_t val) { |
422 | 567 | struct memcache_server *ms; |
423 | | - u_int32_t hash; |
| 568 | + uint32_t hash; |
424 | 569 | char *cp, *cur; |
425 | 570 | size_t buf_left, i; |
426 | 571 | struct iovec av[5]; |
427 | | - u_int32_t ret; |
| 572 | + uint32_t ret; |
428 | 573 | |
429 | 574 | /* If we have only one server, don't bother actually hashing. */ |
430 | 575 | if (mc->num_live_servers == 1) |
— | — | @@ -483,7 +628,7 @@ |
484 | 629 | |
485 | 630 | /* Try converting the value to an integer. If it succeeds, we've got |
486 | 631 | * a winner. */ |
487 | | - ret = (u_int32_t)strtol(cur, &cp, 10); |
| 632 | + ret = (uint32_t)strtol(cur, &cp, 10); |
488 | 633 | if (ret == 0 && (errno == EINVAL || errno == ERANGE)) |
489 | 634 | err(EX_PROTOCOL, "%s:%u\tstrtol(): invalid value \"%.*s\"", __FILE__, __LINE__, (int)(cp - cur), cur); |
490 | 635 | |
— | — | @@ -496,8 +641,8 @@ |
497 | 642 | } |
498 | 643 | |
499 | 644 | |
500 | | -u_int32_t |
501 | | -mcm_decr(const struct memcache_ctxt *ctxt, struct memcache *mc, const char *key, const size_t key_len, const u_int32_t val) { |
| 645 | +uint32_t |
| 646 | +mcm_decr(const struct memcache_ctxt *ctxt, struct memcache *mc, const char *key, const size_t key_len, const uint32_t val) { |
502 | 647 | return mcm_atomic_cmd(ctxt, mc, str_decr_cmd, str_decr_len, key, key_len, val); |
503 | 648 | } |
504 | 649 | |
— | — | @@ -506,7 +651,7 @@ |
507 | 652 | mcm_delete(const struct memcache_ctxt *ctxt, struct memcache *mc, |
508 | 653 | const char *key, const size_t key_len, const time_t hold) { |
509 | 654 | struct memcache_server *ms; |
510 | | - u_int32_t hash; |
| 655 | + uint32_t hash; |
511 | 656 | char *cur; |
512 | 657 | size_t buf_left, i; |
513 | 658 | struct iovec dv[5]; |
— | — | @@ -579,7 +724,7 @@ |
580 | 725 | struct memcache_res_cb *cb; |
581 | 726 | struct memcache_server *ms; |
582 | 727 | struct iovec *rv; |
583 | | - u_int32_t i, num_vec; |
| 728 | + uint32_t i, num_vec; |
584 | 729 | |
585 | 730 | if (req->num_keys == 0) |
586 | 731 | return; |
— | — | @@ -884,7 +1029,7 @@ |
885 | 1030 | size_t bytes; |
886 | 1031 | size_t read_cur_offset; |
887 | 1032 | size_t cp_offset; |
888 | | - u_int16_t flags; |
| 1033 | + uint16_t flags; |
889 | 1034 | int ret; |
890 | 1035 | |
891 | 1036 | cp = ms->read_cur = ms->start = ms->cur = ms->buf; |
— | — | @@ -984,7 +1129,7 @@ |
985 | 1130 | cp = &cp[res->len]; |
986 | 1131 | end = ms->read_cur; |
987 | 1132 | |
988 | | - flags = (u_int16_t)strtol(cp, &end, 10); |
| 1133 | + flags = (uint16_t)strtol(cp, &end, 10); |
989 | 1134 | if (flags == 0 && (errno == EINVAL || errno == ERANGE)) { |
990 | 1135 | warn("%s:%u\tstrtol(): invalid flags", __FILE__, __LINE__); |
991 | 1136 | } |
— | — | @@ -1064,10 +1209,10 @@ |
1065 | 1210 | #endif /* USE_CRC32_HASH */ |
1066 | 1211 | |
1067 | 1212 | |
1068 | | -u_int32_t |
| 1213 | +uint32_t |
1069 | 1214 | mc_hash_key(const char *key, const size_t len) { |
1070 | 1215 | unsigned char res[MD5_DIGEST_LENGTH]; |
1071 | | - u_int32_t i; |
| 1216 | + uint32_t i; |
1072 | 1217 | int j; |
1073 | 1218 | char result[33]; |
1074 | 1219 | char php[9] = {}; |
— | — | @@ -1089,9 +1234,9 @@ |
1090 | 1235 | } |
1091 | 1236 | |
1092 | 1237 | |
1093 | | -u_int32_t |
| 1238 | +uint32_t |
1094 | 1239 | mcm_incr(const struct memcache_ctxt *ctxt, struct memcache *mc, |
1095 | | - const char *key, const size_t key_len, const u_int32_t val) { |
| 1240 | + const char *key, const size_t key_len, const uint32_t val) { |
1096 | 1241 | return mcm_atomic_cmd(ctxt, mc, str_incr_cmd, str_incr_len, key, key_len, val); |
1097 | 1242 | } |
1098 | 1243 | |
— | — | @@ -1124,7 +1269,7 @@ |
1125 | 1270 | mcm_replace(const struct memcache_ctxt *ctxt, struct memcache *mc, |
1126 | 1271 | const char *key, const size_t key_len, |
1127 | 1272 | const void *val, const size_t bytes, |
1128 | | - const time_t expire, const u_int16_t flags) { |
| 1273 | + const time_t expire, const uint16_t flags) { |
1129 | 1274 | return mcm_storage_cmd(ctxt, mc, str_replace_cmd, str_replace_len, key, key_len, val, bytes, expire, flags); |
1130 | 1275 | } |
1131 | 1276 | |
— | — | @@ -1587,7 +1732,7 @@ |
1588 | 1733 | void |
1589 | 1734 | mc_server_deactivate(struct memcache *mc, |
1590 | 1735 | struct memcache_server *ms) { |
1591 | | - u_int32_t i, found; |
| 1736 | + uint32_t i, found; |
1592 | 1737 | |
1593 | 1738 | /* Since adding servers is so rare, and servers do come back, don't |
1594 | 1739 | * bother mcRealloc(3)'ing mc->live_servers. Instead, just find the |
— | — | @@ -1645,7 +1790,7 @@ |
1646 | 1791 | |
1647 | 1792 | |
1648 | 1793 | struct memcache_server * |
1649 | | -mcm_server_find(struct memcache *mc, const u_int32_t hash) { |
| 1794 | +mcm_server_find(struct memcache *mc, const uint32_t hash) { |
1650 | 1795 | if (mc->num_live_servers < 1) |
1651 | 1796 | return NULL; |
1652 | 1797 | |
— | — | @@ -1831,82 +1976,82 @@ |
1832 | 1977 | } |
1833 | 1978 | } else if (memcmp(cur, "curr_items ", MCM_CSTRLEN("curr_items ")) == 0) { |
1834 | 1979 | cur = &cur[MCM_CSTRLEN("curr_items ")]; |
1835 | | - s->curr_items = (u_int32_t)strtol(cur, &cp, 10); |
| 1980 | + s->curr_items = (uint32_t)strtol(cur, &cp, 10); |
1836 | 1981 | if (s->curr_items == 0 && (errno == EINVAL || errno == ERANGE)) |
1837 | 1982 | err(EX_PROTOCOL, "%s:%u\tstrtol(): invalid curr_items \"%.*s\"", __FILE__, __LINE__, (int)(cp - cur), cur); |
1838 | 1983 | } else if (memcmp(cur, "total_items ", MCM_CSTRLEN("total_items ")) == 0) { |
1839 | 1984 | cur = &cur[MCM_CSTRLEN("total_items ")]; |
1840 | | - s->total_items = (u_int64_t)strtoll(cur, &cp, 10); |
| 1985 | + s->total_items = (uint64_t)strtoll(cur, &cp, 10); |
1841 | 1986 | if (s->total_items == 0 && (errno == EINVAL || errno == ERANGE)) |
1842 | 1987 | err(EX_PROTOCOL, "%s:%u\tstrtoll(): invalid total_items \"%.*s\"", __FILE__, __LINE__, (int)(cp - cur), cur); |
1843 | 1988 | } else if (memcmp(cur, "bytes ", MCM_CSTRLEN("bytes ")) == 0) { |
1844 | 1989 | cur = &cur[MCM_CSTRLEN("bytes")]; |
1845 | | - s->bytes = (u_int64_t)strtoll(cur, &cp, 10); |
| 1990 | + s->bytes = (uint64_t)strtoll(cur, &cp, 10); |
1846 | 1991 | if (s->bytes == 0 && (errno == EINVAL || errno == ERANGE)) |
1847 | 1992 | err(EX_PROTOCOL, "%s:%u\tstrtol(): invalid bytes \"%.*s\"", __FILE__, __LINE__, (int)(cp - cur), cur); |
1848 | 1993 | } else if (memcmp(cur, "curr_connections ", MCM_CSTRLEN("curr_connections ")) == 0) { |
1849 | 1994 | cur = &cur[MCM_CSTRLEN("curr_connections ")]; |
1850 | | - s->curr_connections = (u_int32_t)strtol(cur, &cp, 10); |
| 1995 | + s->curr_connections = (uint32_t)strtol(cur, &cp, 10); |
1851 | 1996 | if (s->curr_connections == 0 && (errno == EINVAL || errno == ERANGE)) |
1852 | 1997 | err(EX_PROTOCOL, "%s:%u\tstrtol(): invalid curr_connections \"%.*s\"", __FILE__, __LINE__, (int)(cp - cur), cur); |
1853 | 1998 | } else if (memcmp(cur, "total_connections ", MCM_CSTRLEN("total_connections ")) == 0) { |
1854 | 1999 | cur = &cur[MCM_CSTRLEN("total_connections ")]; |
1855 | | - s->total_connections = (u_int64_t)strtoll(cur, &cp, 10); |
| 2000 | + s->total_connections = (uint64_t)strtoll(cur, &cp, 10); |
1856 | 2001 | if (s->total_connections == 0 && (errno == EINVAL || errno == ERANGE)) |
1857 | 2002 | err(EX_PROTOCOL, "%s:%u\tstrtoll(): invalid total_connections \"%.*s\"", __FILE__, __LINE__, (int)(cp - cur), cur); |
1858 | 2003 | } else if (memcmp(cur, "connection_structures ", MCM_CSTRLEN("connection_structures ")) == 0) { |
1859 | 2004 | cur = &cur[MCM_CSTRLEN("connection_structures ")]; |
1860 | | - s->connection_structures = (u_int32_t)strtol(cur, &cp, 10); |
| 2005 | + s->connection_structures = (uint32_t)strtol(cur, &cp, 10); |
1861 | 2006 | if (s->connection_structures == 0 && (errno == EINVAL || errno == ERANGE)) |
1862 | 2007 | err(EX_PROTOCOL, "%s:%u\tstrtol(): invalid connection_structures \"%.*s\"", __FILE__, __LINE__, (int)(cp - cur), cur); |
1863 | 2008 | } else if (memcmp(cur, "cmd_get ", MCM_CSTRLEN("cmd_get ")) == 0) { |
1864 | 2009 | cur = &cur[MCM_CSTRLEN("cmd_get ")]; |
1865 | | - s->cmd_get = (u_int64_t)strtoll(cur, &cp, 10); |
| 2010 | + s->cmd_get = (uint64_t)strtoll(cur, &cp, 10); |
1866 | 2011 | if (s->cmd_get == 0 && (errno == EINVAL || errno == ERANGE)) |
1867 | 2012 | err(EX_PROTOCOL, "%s:%u\tstrtoll(): invalid cmd_get \"%.*s\"", __FILE__, __LINE__, (int)(cp - cur), cur); |
1868 | 2013 | } else if (memcmp(cur, "cmd_refresh ", MCM_CSTRLEN("cmd_refresh ")) == 0) { |
1869 | 2014 | cur = &cur[MCM_CSTRLEN("cmd_refresh ")]; |
1870 | | - s->cmd_refresh = (u_int64_t)strtoll(cur, &cp, 10); |
| 2015 | + s->cmd_refresh = (uint64_t)strtoll(cur, &cp, 10); |
1871 | 2016 | if (s->cmd_refresh == 0 && (errno == EINVAL || errno == ERANGE)) |
1872 | 2017 | err(EX_PROTOCOL, "%s:%u\tstrtoll(): invalid cmd_refresh \"%.*s\"", __FILE__, __LINE__, (int)(cp - cur), cur); |
1873 | 2018 | } else if (memcmp(cur, "cmd_set ", MCM_CSTRLEN("cmd_set ")) == 0) { |
1874 | 2019 | cur = &cur[MCM_CSTRLEN("cmd_set ")]; |
1875 | | - s->cmd_set = (u_int64_t)strtoll(cur, &cp, 10); |
| 2020 | + s->cmd_set = (uint64_t)strtoll(cur, &cp, 10); |
1876 | 2021 | if (s->cmd_set == 0 && (errno == EINVAL || errno == ERANGE)) |
1877 | 2022 | err(EX_PROTOCOL, "%s:%u\tstrtoll(): invalid cmd_set \"%.*s\"", __FILE__, __LINE__, (int)(cp - cur), cur); |
1878 | 2023 | } else if (memcmp(cur, "get_hits ", MCM_CSTRLEN("get_hits ")) == 0) { |
1879 | 2024 | cur = &cur[MCM_CSTRLEN("get_hits ")]; |
1880 | | - s->get_hits = (u_int64_t)strtoll(cur, &cp, 10); |
| 2025 | + s->get_hits = (uint64_t)strtoll(cur, &cp, 10); |
1881 | 2026 | if (s->get_hits == 0 && (errno == EINVAL || errno == ERANGE)) |
1882 | 2027 | err(EX_PROTOCOL, "%s:%u\tstrtoll(): invalid get_hits \"%.*s\"", __FILE__, __LINE__, (int)(cp - cur), cur); |
1883 | 2028 | } else if (memcmp(cur, "get_misses ", MCM_CSTRLEN("get_misses ")) == 0) { |
1884 | 2029 | cur = &cur[MCM_CSTRLEN("get_misses ")]; |
1885 | | - s->get_misses = (u_int64_t)strtoll(cur, &cp, 10); |
| 2030 | + s->get_misses = (uint64_t)strtoll(cur, &cp, 10); |
1886 | 2031 | if (s->get_misses == 0 && (errno == EINVAL || errno == ERANGE)) |
1887 | 2032 | err(EX_PROTOCOL, "%s:%u\tstrtoll(): invalid get_misses \"%.*s\"", __FILE__, __LINE__, (int)(cp - cur), cur); |
1888 | 2033 | } else if (memcmp(cur, "refresh_hits ", MCM_CSTRLEN("refresh_hits ")) == 0) { |
1889 | 2034 | cur = &cur[MCM_CSTRLEN("refresh_hits ")]; |
1890 | | - s->refresh_hits = (u_int64_t)strtoll(cur, &cp, 10); |
| 2035 | + s->refresh_hits = (uint64_t)strtoll(cur, &cp, 10); |
1891 | 2036 | if (s->refresh_hits == 0 && (errno == EINVAL || errno == ERANGE)) |
1892 | 2037 | err(EX_PROTOCOL, "%s:%u\tstrtoll(): invalid refresh_hits \"%.*s\"", __FILE__, __LINE__, (int)(cp - cur), cur); |
1893 | 2038 | } else if (memcmp(cur, "refresh_misses ", MCM_CSTRLEN("refresh_misses ")) == 0) { |
1894 | 2039 | cur = &cur[MCM_CSTRLEN("refresh_misses ")]; |
1895 | | - s->refresh_misses = (u_int64_t)strtoll(cur, &cp, 10); |
| 2040 | + s->refresh_misses = (uint64_t)strtoll(cur, &cp, 10); |
1896 | 2041 | if (s->refresh_misses == 0 && (errno == EINVAL || errno == ERANGE)) |
1897 | 2042 | err(EX_PROTOCOL, "%s:%u\tstrtoll(): invalid refresh_misses \"%.*s\"", __FILE__, __LINE__, (int)(cp - cur), cur); |
1898 | 2043 | } else if (memcmp(cur, "bytes_read ", MCM_CSTRLEN("bytes_read ")) == 0) { |
1899 | 2044 | cur = &cur[MCM_CSTRLEN("bytes_read ")]; |
1900 | | - s->bytes_read = (u_int64_t)strtoll(cur, &cp, 10); |
| 2045 | + s->bytes_read = (uint64_t)strtoll(cur, &cp, 10); |
1901 | 2046 | if (s->bytes_read == 0 && (errno == EINVAL || errno == ERANGE)) |
1902 | 2047 | err(EX_PROTOCOL, "%s:%u\tstrtoll(): invalid bytes_read \"%.*s\"", __FILE__, __LINE__, (int)(cp - cur), cur); |
1903 | 2048 | } else if (memcmp(cur, "bytes_written ", MCM_CSTRLEN("bytes_written ")) == 0) { |
1904 | 2049 | cur = &cur[MCM_CSTRLEN("bytes_written ")]; |
1905 | | - s->bytes_written = (u_int64_t)strtoll(cur, &cp, 10); |
| 2050 | + s->bytes_written = (uint64_t)strtoll(cur, &cp, 10); |
1906 | 2051 | if (s->bytes_written == 0 && (errno == EINVAL || errno == ERANGE)) |
1907 | 2052 | err(EX_PROTOCOL, "%s:%u\tstrtoll(): invalid bytes_written \"%.*s\"", __FILE__, __LINE__, (int)(cp - cur), cur); |
1908 | 2053 | } else if (memcmp(cur, "limit_maxbytes ", MCM_CSTRLEN("limit_maxbytes ")) == 0) { |
1909 | 2054 | cur = &cur[MCM_CSTRLEN("limit_maxbytes ")]; |
1910 | | - s->limit_maxbytes = (u_int64_t)strtoll(cur, &cp, 10); |
| 2055 | + s->limit_maxbytes = (uint64_t)strtoll(cur, &cp, 10); |
1911 | 2056 | if (s->limit_maxbytes == 0 && (errno == EINVAL || errno == ERANGE)) |
1912 | 2057 | err(EX_PROTOCOL, "%s:%u\tstrtoll(): invalid limit_maxbytes \"%.*s\"", __FILE__, __LINE__, (int)(cp - cur), cur); |
1913 | 2058 | } else { |
— | — | @@ -1962,7 +2107,7 @@ |
1963 | 2108 | mcm_set(const struct memcache_ctxt *ctxt, struct memcache *mc, |
1964 | 2109 | const char *key, const size_t key_len, |
1965 | 2110 | const void *val, const size_t bytes, |
1966 | | - const time_t expire, const u_int16_t flags) { |
| 2111 | + const time_t expire, const uint16_t flags) { |
1967 | 2112 | return mcm_storage_cmd(ctxt, mc, str_set_cmd, str_set_len, key, key_len, val, bytes, expire, flags); |
1968 | 2113 | } |
1969 | 2114 | |
— | — | @@ -2029,9 +2174,9 @@ |
2030 | 2175 | const char *cmd, const size_t cmd_len, |
2031 | 2176 | const char *key, const size_t key_len, |
2032 | 2177 | const void *val, const size_t bytes, |
2033 | | - const time_t expire, const u_int16_t flags) { |
| 2178 | + const time_t expire, const uint16_t flags) { |
2034 | 2179 | struct memcache_server *ms; |
2035 | | - u_int32_t hash; |
| 2180 | + uint32_t hash; |
2036 | 2181 | char *cur; |
2037 | 2182 | size_t buf_left, i; |
2038 | 2183 | struct iovec wv[11]; |
Index: trunk/servmon/l_memcache.h |
— | — | @@ -216,7 +216,7 @@ |
217 | 217 | /* The number of addresses in the cached copy. If there is more |
218 | 218 | * than one per DNS entry (discouraged), we establish a connection |
219 | 219 | * to them all. */ |
220 | | - u_int32_t num_addrs; |
| 220 | + uint32_t num_addrs; |
221 | 221 | |
222 | 222 | #ifdef HAVE_SELECT |
223 | 223 | /* Reduces the amount of user time required when reading data. */ |
— | — | @@ -255,22 +255,22 @@ |
256 | 256 | char *version; |
257 | 257 | struct timeval rusage_user; |
258 | 258 | struct timeval rusage_system; |
259 | | - u_int32_t curr_items; |
260 | | - u_int64_t total_items; |
261 | | - u_int64_t bytes; |
262 | | - u_int32_t curr_connections; |
263 | | - u_int64_t total_connections; |
264 | | - u_int32_t connection_structures; |
265 | | - u_int64_t cmd_get; |
266 | | - u_int64_t cmd_refresh; |
267 | | - u_int64_t cmd_set; |
268 | | - u_int64_t get_hits; |
269 | | - u_int64_t get_misses; |
270 | | - u_int64_t refresh_hits; |
271 | | - u_int64_t refresh_misses; |
272 | | - u_int64_t bytes_read; |
273 | | - u_int64_t bytes_written; |
274 | | - u_int64_t limit_maxbytes; |
| 259 | + uint32_t curr_items; |
| 260 | + uint64_t total_items; |
| 261 | + uint64_t bytes; |
| 262 | + uint32_t curr_connections; |
| 263 | + uint64_t total_connections; |
| 264 | + uint32_t connection_structures; |
| 265 | + uint64_t cmd_get; |
| 266 | + uint64_t cmd_refresh; |
| 267 | + uint64_t cmd_set; |
| 268 | + uint64_t get_hits; |
| 269 | + uint64_t get_misses; |
| 270 | + uint64_t refresh_hits; |
| 271 | + uint64_t refresh_misses; |
| 272 | + uint64_t bytes_read; |
| 273 | + uint64_t bytes_written; |
| 274 | + uint64_t limit_maxbytes; |
275 | 275 | }; |
276 | 276 | |
277 | 277 | |
— | — | @@ -285,7 +285,7 @@ |
286 | 286 | |
287 | 287 | /* The number of servers in live_servers in the live_servers |
288 | 288 | * list. */ |
289 | | - u_int32_t num_live_servers; |
| 289 | + uint32_t num_live_servers; |
290 | 290 | |
291 | 291 | /* A generic pointer not used by memcache(3), but can be used by |
292 | 292 | * calling programs. */ |
— | — | @@ -334,7 +334,7 @@ |
335 | 335 | struct memcache_res { |
336 | 336 | const char *key; /* key */ |
337 | 337 | size_t len; /* length of key */ |
338 | | - u_int32_t hash; /* hash of the key */ |
| 338 | + uint32_t hash; /* hash of the key */ |
339 | 339 | void *val; /* the value */ |
340 | 340 | size_t bytes; /* length of val */ |
341 | 341 | |
— | — | @@ -359,7 +359,7 @@ |
360 | 360 | /* This is the client supplied flags. Please note, this flags is |
361 | 361 | * very different than _flags (_flags is an internal bit and |
362 | 362 | * shouldn't be read/changed, etc). */ |
363 | | - u_int16_t flags; |
| 363 | + uint16_t flags; |
364 | 364 | |
365 | 365 | /* If _flags has 0x01 set, val will be free(3)'ed on when this |
366 | 366 | * struct is cleaned up via mc_res_free() or the request is cleaned |
— | — | @@ -380,7 +380,7 @@ |
381 | 381 | |
382 | 382 | TAILQ_HEAD(memcache_res_list, memcache_res) query; |
383 | 383 | TAILQ_HEAD(memcache_res_cb_list, memcache_res_cb) cb; |
384 | | - u_int16_t num_keys; |
| 384 | + uint16_t num_keys; |
385 | 385 | }; |
386 | 386 | |
387 | 387 | |
— | — | @@ -443,12 +443,12 @@ |
444 | 444 | int mc_add(struct memcache *mc, |
445 | 445 | const char *key, const size_t key_len, |
446 | 446 | const void *val, const size_t bytes, |
447 | | - const time_t expire, const u_int16_t flags); |
| 447 | + const time_t expire, const uint16_t flags); |
448 | 448 | |
449 | 449 | /* Gets the value from memcache and allocates the data for the caller. |
450 | 450 | * It is the caller's responsibility to free the returned value. |
451 | 451 | * mc_get() is the preferred interface, however. */ |
452 | | -void mc_aget(struct memcache *mc, const char *key, const size_t len, void**, u_int32_t*); |
| 452 | +void mc_aget(struct memcache *mc, const char *key, const size_t len, void**, uint32_t*); |
453 | 453 | |
454 | 454 | /* Gets the value from memcache and allocates the data for the caller. |
455 | 455 | * It is the caller's responsibility to free the returned value. |
— | — | @@ -456,7 +456,7 @@ |
457 | 457 | void *mc_arefresh(struct memcache *mc, const char *key, const size_t len); |
458 | 458 | |
459 | 459 | /* Decrements a given key */ |
460 | | -u_int32_t mc_decr(struct memcache *mc, const char *key, const size_t key_len, const u_int32_t val); |
| 460 | +uint32_t mc_decr(struct memcache *mc, const char *key, const size_t key_len, const uint32_t val); |
461 | 461 | |
462 | 462 | /* Deletes a given key */ |
463 | 463 | int mc_delete(struct memcache *mc, const char *key, const size_t key_len, const time_t hold); |
— | — | @@ -477,7 +477,7 @@ |
478 | 478 | void mc_get(struct memcache *mc, struct memcache_req *req); |
479 | 479 | |
480 | 480 | /* Increments a given key */ |
481 | | -u_int32_t mc_incr(struct memcache *mc, const char *key, const size_t key_len, const u_int32_t val); |
| 481 | +uint32_t mc_incr(struct memcache *mc, const char *key, const size_t key_len, const uint32_t val); |
482 | 482 | |
483 | 483 | /* Allocates a new memcache object */ |
484 | 484 | struct memcache *mc_new(void); |
— | — | @@ -492,13 +492,13 @@ |
493 | 493 | void mc_refresh(struct memcache *mc, struct memcache_req *req); |
494 | 494 | |
495 | 495 | /* Returns the release date for the library */ |
496 | | -u_int32_t mc_reldate(void); |
| 496 | +uint32_t mc_reldate(void); |
497 | 497 | |
498 | 498 | /* Replaces a given key to the cache */ |
499 | 499 | int mc_replace(struct memcache *mc, |
500 | 500 | const char *key, const size_t key_len, |
501 | 501 | const void *val, const size_t bytes, |
502 | | - const time_t expire, const u_int16_t flags); |
| 502 | + const time_t expire, const uint16_t flags); |
503 | 503 | |
504 | 504 | /* Safely adds a key to a given request (the key is mc_strdup()'ed). |
505 | 505 | See mc_req_add_ref() to avoid the mc_strdup(): note the warning in |
— | — | @@ -594,7 +594,7 @@ |
595 | 595 | int mc_set(struct memcache *mc, |
596 | 596 | const char *key, const size_t key_len, |
597 | 597 | const void *val, const size_t bytes, |
598 | | - const time_t expire, const u_int16_t flags); |
| 598 | + const time_t expire, const uint16_t flags); |
599 | 599 | |
600 | 600 | /* Creates a stats object for all available servers and returns the |
601 | 601 | * cumulative stats. Per host-specific data is generally the same as |
— | — | @@ -613,7 +613,7 @@ |
614 | 614 | void mc_timeout(struct memcache *mc, const int sec, const int usec); |
615 | 615 | |
616 | 616 | /* Returns a numeric version of the library */ |
617 | | -u_int32_t mc_vernum(void); |
| 617 | +uint32_t mc_vernum(void); |
618 | 618 | |
619 | 619 | /* Returns a string version of the library */ |
620 | 620 | const char *mc_version(void); |
— | — | @@ -669,13 +669,13 @@ |
670 | 670 | int mcm_add(const struct memcache_ctxt *ctxt, struct memcache *mc, |
671 | 671 | const char *key, const size_t key_len, |
672 | 672 | const void *val, const size_t bytes, |
673 | | - const time_t expire, const u_int16_t flags); |
| 673 | + const time_t expire, const uint16_t flags); |
674 | 674 | void mcm_aget(const struct memcache_ctxt *ctxt, struct memcache *mc, |
675 | | - const char *key, const size_t len, void**, u_int32_t*); |
| 675 | + const char *key, const size_t len, void**, uint32_t*); |
676 | 676 | void *mcm_arefresh(const struct memcache_ctxt *ctxt, struct memcache *mc, |
677 | 677 | const char *key, const size_t len); |
678 | | -u_int32_t mcm_decr(const struct memcache_ctxt *ctxt, struct memcache *mc, |
679 | | - const char *key, const size_t key_len, const u_int32_t val); |
| 678 | +uint32_t mcm_decr(const struct memcache_ctxt *ctxt, struct memcache *mc, |
| 679 | + const char *key, const size_t key_len, const uint32_t val); |
680 | 680 | int mcm_delete(const struct memcache_ctxt *ctxt, struct memcache *mc, |
681 | 681 | const char *key, const size_t key_len, const time_t hold); |
682 | 682 | int mcm_flush(const struct memcache_ctxt *ctxt, struct memcache *mc, |
— | — | @@ -683,16 +683,16 @@ |
684 | 684 | int mcm_flush_all(const struct memcache_ctxt *ctxt, struct memcache *mc); |
685 | 685 | void mcm_free(const struct memcache_ctxt *ctxt, struct memcache *mc); |
686 | 686 | void mcm_get(const struct memcache_ctxt *ctxt, struct memcache *mc, struct memcache_req *req); |
687 | | -u_int32_t mc_hash_key(const char *key, const size_t len); |
688 | | -u_int32_t mcm_incr(const struct memcache_ctxt *ctxt, struct memcache *mc, |
689 | | - const char *key, const size_t key_len, const u_int32_t val); |
| 687 | +uint32_t mc_hash_key(const char *key, const size_t len); |
| 688 | +uint32_t mcm_incr(const struct memcache_ctxt *ctxt, struct memcache *mc, |
| 689 | + const char *key, const size_t key_len, const uint32_t val); |
690 | 690 | struct memcache *mcm_new(const struct memcache_ctxt *ctxt); |
691 | 691 | void mcm_refresh(const struct memcache_ctxt *ctxt, struct memcache *mc, |
692 | 692 | struct memcache_req *req); |
693 | 693 | int mcm_replace(const struct memcache_ctxt *ctxt, struct memcache *mc, |
694 | 694 | const char *key, const size_t key_len, |
695 | 695 | const void *val, const size_t bytes, |
696 | | - const time_t expire, const u_int16_t flags); |
| 696 | + const time_t expire, const uint16_t flags); |
697 | 697 | struct memcache_res *mcm_req_add(const struct memcache_ctxt *ctxt, struct memcache_req *req, |
698 | 698 | const char *key, const size_t len); |
699 | 699 | struct memcache_res *mcm_req_add_ref(const struct memcache_ctxt *ctxt, struct memcache_req *req, |
— | — | @@ -716,7 +716,7 @@ |
717 | 717 | struct memcache_server *ms); |
718 | 718 | void mcm_server_disconnect(struct memcache_server *ms); |
719 | 719 | void mcm_server_disconnect_all(const struct memcache *mc); |
720 | | -struct memcache_server *mcm_server_find(struct memcache *mc, const u_int32_t hash); |
| 720 | +struct memcache_server *mcm_server_find(struct memcache *mc, const uint32_t hash); |
721 | 721 | void mcm_server_free(const struct memcache_ctxt *ctxt, struct memcache_server *ms); |
722 | 722 | struct memcache_server *mcm_server_new(const struct memcache_ctxt *ctxt); |
723 | 723 | void mcm_server_stats_free(const struct memcache_ctxt *ctxt, struct memcache_server_stats *s); |
— | — | @@ -724,12 +724,12 @@ |
725 | 725 | int mcm_set(const struct memcache_ctxt *ctxt, struct memcache *mc, |
726 | 726 | const char *key, const size_t key_len, |
727 | 727 | const void *val, const size_t bytes, |
728 | | - const time_t expire, const u_int16_t flags); |
| 728 | + const time_t expire, const uint16_t flags); |
729 | 729 | struct memcache_server_stats *mcm_stats(const struct memcache_ctxt *ctxt, struct memcache *mc); |
730 | 730 | char *mcm_strdup(const struct memcache_ctxt *ctxt, const char *str); |
731 | 731 | char *mcm_strndup(const struct memcache_ctxt *ctxt, const char *str, const size_t len); |
732 | 732 | void mcm_timeout(struct memcache *mc, const int sec, const int usec); |
733 | | -u_int32_t mcm_vernum(const struct memcache_ctxt *ctxt); |
| 733 | +uint32_t mcm_vernum(const struct memcache_ctxt *ctxt); |
734 | 734 | const char *mcm_version(const struct memcache_ctxt *ctxt); |
735 | 735 | /* END memory management API functions */ |
736 | 736 | |
Index: trunk/servmon/sminfo.sh |
— | — | @@ -1,13 +1,23 @@ |
2 | 2 | #! /bin/sh |
3 | 3 | # $Header$ |
4 | 4 | |
5 | | -idents=`ident -q \`find . -name \*.\[ch\]xx\`|grep \\\$Head|(while read foo; do echo " \"$foo\"",; done)` |
| 5 | +haveident=no |
| 6 | +for dir in `echo $PATH | tr : ' '`; do |
| 7 | + if [ -x $dir/ident ]; then |
| 8 | + haveident=yes |
| 9 | + fi |
| 10 | +done |
| 11 | +if [ $haveident = yes ]; then |
| 12 | + idents=`ident -q \`find . -name \*.\[ch\] -o -name \*.\[ch\]xx\`|egrep '\\$(Head|NetBSD|FreeBSD|Nexadesic)'|(while read foo; do echo " \"$foo\"",; done)` |
| 13 | +else |
| 14 | + idents='"ident not available at compile time",' |
| 15 | +fi |
6 | 16 | |
7 | 17 | cat <<_EOF_ |
8 | 18 | /* this file in generated automatically. do not edit it. */ |
9 | 19 | #ifndef SM_SMINFO_CXX_ |
10 | 20 | #define SM_SMINFO_CXX_ |
11 | | -static char const *sm\$compile_user = "`whoami`"; |
| 21 | +static char const *sm\$compile_user = "$USER"; |
12 | 22 | static char const *sm\$compile_host = "`hostname`"; |
13 | 23 | static char const *sm\$compile_time = "`date +"%d-%b-%Y %H:%M:%S"`"; |
14 | 24 | static char const *sm\$compile_os = "`uname`"; |
Index: trunk/servmon/buildconfig.sample |
— | — | @@ -0,0 +1,24 @@ |
| 2 | +# $Id$ |
| 3 | + |
| 4 | +# C compiler |
| 5 | +cc = 'cc' |
| 6 | + |
| 7 | +# C++ compiler |
| 8 | +cxx = 'c++' |
| 9 | + |
| 10 | +# Where to install to |
| 11 | +prefix = '/opt/servmon' |
| 12 | + |
| 13 | +# Options to pass to compiler |
| 14 | +cflags = '-W -Wall -g' |
| 15 | + |
| 16 | +# Options to pass to compiler when not linking |
| 17 | +cppflags = '' |
| 18 | + |
| 19 | +# Options to pass to the compiler when linking |
| 20 | +ldflags = '' |
| 21 | + |
| 22 | +# If your boost libraries are installed with names like |
| 23 | +# "libboost_signals-gcc-mt-d", set this to the suffix part |
| 24 | +# (i.e. "-gcc-mt-d"). |
| 25 | +boostsuffix = '' |
Property changes on: trunk/servmon/buildconfig.sample |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 26 | + native |
Added: svn:keywords |
2 | 27 | + Author Date Id Revision |
Index: trunk/servmon/SConstruct |
— | — | @@ -1,20 +1,21 @@ |
2 | 2 | # @(#) $Header$ |
3 | 3 | |
4 | | -# Set build options here. |
5 | | -# |
6 | | -# Compiler |
7 | | -cc = 'gcc' |
8 | | -cxx = 'g++' |
| 4 | +config = dict() |
| 5 | +execfile('buildconfig', config) |
9 | 6 | |
10 | | -#cflags = '-O2 -g -W -Wall' |
11 | | -cflags = '-g -W -Wall' |
12 | | -cppflags = '' |
| 7 | +cc = ARGUMENTS.get('cc', config['cc']) |
| 8 | +cxx = ARGUMENTS.get('cxx', config['cxx']) |
13 | 9 | |
14 | | -# Where things are installed to. |
15 | | -prefix = ARGUMENTS.get('prefix', '/opt/servmon') |
| 10 | +cflags = ARGUMENTS.get('cflags', config['cflags']) |
| 11 | +cppflags = ARGUMENTS.get('cppflags', config['cppflags']) |
| 12 | +ldflags = ARGUMENTS.get('ldflags', config['ldflags']) |
16 | 13 | |
17 | | -# Don't change anything below here. |
18 | | -#################################### |
| 14 | +prefix = ARGUMENTS.get('prefix', config['prefix']) |
| 15 | +boostsuffix = ARGUMENTS.get('boostsuffix', config['boostsuffix']) |
| 16 | + |
| 17 | +libpath = ARGUMENTS.get('libpath', config['libpath']) |
| 18 | +cpppath = ARGUMENTS.get('cpppath', config['cpppath']) |
| 19 | + |
19 | 20 | import os |
20 | 21 | try: |
21 | 22 | os.remove('sminfo.cxx') |
— | — | @@ -25,18 +26,49 @@ |
26 | 27 | 'smauth.cxx smtmr.cxx smmon.cxx smqb.cxx smmc.cxx smalrm.cxx l_memcache.c ' |
27 | 28 | 'smlog.cxx smstdrt.cxx smtrm.cxx msgtab.cxx') |
28 | 29 | |
| 30 | +conflags = [] |
29 | 31 | env = Environment(CPPFLAGS = cppflags + ' -DPFX="\\"' + prefix + '\\""', |
30 | 32 | CCFLAGS = cflags, |
| 33 | + LDFLAGS = ldflags, |
31 | 34 | CC = cc, |
32 | 35 | CXX = cxx, |
33 | | - CPPPATH = ['.', 'include'], |
34 | | - LIBPATH = '/usr/lib/mysql', |
35 | | - LIBS = ['pthread', 'boost_thread', 'boost_regex', 'netsnmp', 'ssl', 'mysqlclient']) |
| 36 | + CPPPATH = cpppath + ['.', 'include'], |
| 37 | + LIBPATH = libpath, |
| 38 | + LIBS = []) |
| 39 | +conf = Configure(env) |
| 40 | +socketlibs = [] |
| 41 | +# BSD & glibc has err.h. Most others don't. |
| 42 | +if conf.CheckCHeader('err.h'): |
| 43 | + env.Append(CPPFLAGS = ' -DHAVE_ERR_H') |
| 44 | +if conf.CheckCHeader('paths.h'): |
| 45 | + env.Append(CPPFLAGS = ' -DHAVE_PATHS_H') |
| 46 | +if conf.CheckCHeader('mntent.h'): |
| 47 | + env.Append(CPPFLAGS = ' -DHAVE_MNTENT_H') |
| 48 | +if conf.CheckCHeader(['stdio.h', 'sys/mnttab.h']): |
| 49 | + env.Append(CPPFLAGS = ' -DHAVE_SYS_MNTTAB_H') |
| 50 | +# snmp needs kstat on Solaris. |
| 51 | +conf.CheckLib('kstat') |
| 52 | +if conf.CheckLib('nsl'): |
| 53 | + socketlibs += ['nsl'] |
| 54 | +if conf.CheckLib('socket'): |
| 55 | + socketlibs += ['socket'] |
| 56 | +if conf.CheckLib('resolv'): |
| 57 | + socketlibs += ['resolv'] |
| 58 | +conf.CheckLib('pkcs11') |
| 59 | +if conf.CheckFunc('setmntent'): |
| 60 | + env.Append(CPPFLAGS = ' -DHAVE_SETMNTENT') |
| 61 | +if conf.CheckFunc('getmntent'): |
| 62 | + env.Append(CPPFLAGS = ' -DHAVE_GETMNTENT') |
| 63 | +if conf.CheckFunc('daemon'): |
| 64 | + env.Append(CPPFLAGS = ' -DHAVE_DAEMON') |
| 65 | +env = conf.Finish() |
| 66 | +# these aren't checked above because they're required... except maybe pthread. |
| 67 | +env.Append(LIBS = ['pthread', 'boost_thread'+boostsuffix, 'boost_regex'+boostsuffix, 'netsnmp', 'ssl', 'crypto', 'mysqlclient']) |
36 | 68 | env.Command('sminfo.cxx', 'sminfo.sh', '/bin/sh $SOURCE >$TARGET') |
37 | 69 | env.Command(['msgtab.hxx', 'msgtab.cxx'], ['mktab', 'messages.tab'], './mktab messages.tab') |
38 | 70 | |
39 | | -env.Program ('mktab', ['mktab.cxx']) |
| 71 | +env.Program ('mktab', ['mktab.cxx'], LIBS = []) |
40 | 72 | env.Program ('servmon', srcs) |
41 | | -env.Program ('smlogmsg', ['smlogmsg.c'], LIBS = []) |
42 | | -env.Program ('systatd', ['systatd.c'], LIBS = []) |
| 73 | +env.Program ('smlogmsg', ['smlogmsg.c'], LIBS = socketlibs) |
| 74 | +env.Program ('systatd', ['systatd.c'], LIBS = socketlibs) |
43 | 75 | env.Alias('install', prefix) |
Index: trunk/servmon/smlogmsg.c |
— | — | @@ -7,6 +7,7 @@ |
8 | 8 | |
9 | 9 | #include <stdio.h> |
10 | 10 | #include <string.h> |
| 11 | +#include <strings.h> |
11 | 12 | #include <stdlib.h> |
12 | 13 | #include <errno.h> |
13 | 14 | #include <unistd.h> |
Index: trunk/servmon/systatd.c |
— | — | @@ -11,17 +11,39 @@ |
12 | 12 | #include <stdlib.h> |
13 | 13 | #include <string.h> |
14 | 14 | |
15 | | -#include <paths.h> |
| 15 | +#ifdef HAVE_PATHS_H |
| 16 | +# include <paths.h> |
| 17 | +#endif |
| 18 | + |
| 19 | +#ifdef HAVE_MNTENT_H |
| 20 | +# include <mntent.h> |
| 21 | +#endif |
| 22 | + |
| 23 | +#ifdef HAVE_SYS_MNTTAB_H |
| 24 | +# include <sys/mnttab.h> |
| 25 | +#endif |
| 26 | + |
16 | 27 | #include <unistd.h> |
17 | | -#include <mntent.h> |
18 | 28 | #include <errno.h> |
19 | 29 | |
20 | | -#ifdef _PATH_MOUNTED |
| 30 | +#ifdef _PATH_MOUNTED /* BSD, glibc */ |
21 | 31 | # define PATH_MTAB _PATH_MOUNTED |
22 | 32 | #else |
23 | | -# define PATH_MTAB "/etc/mtab" |
| 33 | +# ifdef MNTTAB /* SVr4 */ |
| 34 | +# define PATH_MTAB MNTTAB |
| 35 | +# else |
| 36 | +# define PATH_MTAB "/etc/mtab" /* Others */ |
| 37 | +# endif |
24 | 38 | #endif |
25 | 39 | |
| 40 | +/* |
| 41 | + * SVr4 doesn't provide daemon() itself, but libresolv includes it |
| 42 | + * so we win anyway. |
| 43 | + */ |
| 44 | +#if defined(HAVE_DAEMON) && defined(__svr4__) |
| 45 | + int daemon(int, int); |
| 46 | +#endif |
| 47 | + |
26 | 48 | #define PORT 8576 |
27 | 49 | |
28 | 50 | static void print_mntents(FILE *where); |
— | — | @@ -73,22 +95,81 @@ |
74 | 96 | return 0; |
75 | 97 | } |
76 | 98 | |
| 99 | +/* |
| 100 | + * There are two different *mntent APIs. |
| 101 | + * |
| 102 | + * BSD: |
| 103 | + * setmntent() and endmntent() are available. |
| 104 | + * getmntent() returns a struct mntent* |
| 105 | + * the name of the mount point is mnt_dir. |
| 106 | + * |
| 107 | + * SVr4: |
| 108 | + * setmntent() and endmntent() are not available; getmntent() |
| 109 | + * expects us to fopen() and fclose() ourselves. |
| 110 | + * getmntent() takes the address of a struct mntent as an argment |
| 111 | + * and return !0 on error. |
| 112 | + * the name of the mount point is mnt_mountp. |
| 113 | + * |
| 114 | + * We emulate the BSD set/endmntent(), but the SVr4 getmntent(), |
| 115 | + * because it makes memory allocation easier (and it's also thread-safe |
| 116 | + * on SVr4, but we aren't threaded here anyway...). |
| 117 | + */ |
| 118 | +#ifndef __svr4__ |
| 119 | +# define mnt_mountp mnt_dir |
| 120 | +#endif |
| 121 | + |
| 122 | +#ifndef HAVE_SETMNTENT |
| 123 | +static FILE* |
| 124 | +setmntent(path, mode) |
| 125 | + char const *path, *mode; |
| 126 | +{ |
| 127 | + return fopen(path, mode); |
| 128 | +} |
| 129 | +#endif |
| 130 | + |
| 131 | +#ifndef HAVE_ENDMNTENT |
| 132 | +static int |
| 133 | +endmntent(mtab) |
| 134 | + FILE *mtab; |
| 135 | +{ |
| 136 | + return fclose(mtab); |
| 137 | +} |
| 138 | +#endif |
| 139 | + |
| 140 | +static int |
| 141 | +my_getmntent(mtab, ent) |
| 142 | + FILE *mtab; |
| 143 | + struct mnttab *ent; |
| 144 | +{ |
| 145 | +#ifdef __svr4__ |
| 146 | + return getmntent(mtab, ent) == 0 ? 0 : -1; |
| 147 | +#else /* BSD */ |
| 148 | + struct mnttab *tent; |
| 149 | + |
| 150 | + if ((tent = getmntent(mtab)) == NULL) |
| 151 | + return -1; |
| 152 | + |
| 153 | + memcpy(ent, tent, sizeof(*ent)); |
| 154 | + return 0; |
| 155 | +#endif /* SVr4 */ |
| 156 | +} |
| 157 | + |
77 | 158 | static void |
78 | 159 | print_mntents(where) |
79 | | -FILE *where; |
| 160 | + FILE *where; |
80 | 161 | { |
81 | | - struct mntent *ent; |
82 | 162 | struct statvfs sbuf; |
83 | 163 | FILE *mtab; |
84 | 164 | fsblkcnt_t cnt; |
85 | | - |
| 165 | + struct mnttab ent; |
| 166 | + |
86 | 167 | if ((mtab = setmntent(PATH_MTAB, "r")) == NULL) { |
87 | | - perror("setmntent"); |
| 168 | + perror(PATH_MTAB); |
88 | 169 | return; |
89 | 170 | } |
90 | 171 | |
91 | | - while ((ent = getmntent(mtab)) != NULL) { |
92 | | - if (statvfs(ent->mnt_dir, &sbuf) < 0) { |
| 172 | + while (my_getmntent(mtab, &ent) == 0) { |
| 173 | + if (statvfs(ent.mnt_mountp, &sbuf) < 0) { |
93 | 174 | perror("statvfs"); |
94 | 175 | goto end; |
95 | 176 | } |
— | — | @@ -96,7 +177,7 @@ |
97 | 178 | cnt = sbuf.f_bavail; |
98 | 179 | if (cnt == 0) |
99 | 180 | continue; |
100 | | - fprintf(where, "%s %lu %lu\n", ent->mnt_dir, (unsigned long) cnt, sbuf.f_bsize); |
| 181 | + fprintf(where, "%s %lu %lu\n", ent.mnt_mountp, (unsigned long) cnt, sbuf.f_bsize); |
101 | 182 | |
102 | 183 | } |
103 | 184 | |
Index: trunk/servmon/smirc.cxx |
— | — | @@ -342,7 +342,8 @@ |
343 | 343 | |
344 | 344 | ircclnt::~ircclnt() |
345 | 345 | { |
346 | | - SMI(smnet::smpx)->rm(sckt); |
| 346 | + if (sckt) |
| 347 | + SMI(smnet::smpx)->rm(sckt); |
347 | 348 | delete trmpimpl; |
348 | 349 | } |
349 | 350 | |