r8014 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r8013‎ | r8014 | r8015 >
Date:18:30, 31 March 2005
Author:kateturner
Status:old
Tags:
Comment:
update readme;
svr4/solaris fixes.
Modified paths:
  • /trunk/servmon/README (modified) (history)
  • /trunk/servmon/SConstruct (modified) (history)
  • /trunk/servmon/buildconfig.sample (added) (history)
  • /trunk/servmon/include/smnet.hxx (modified) (history)
  • /trunk/servmon/include/smstdinc.hxx (modified) (history)
  • /trunk/servmon/l_memcache.c (modified) (history)
  • /trunk/servmon/l_memcache.h (modified) (history)
  • /trunk/servmon/sminfo.sh (modified) (history)
  • /trunk/servmon/smirc.cxx (modified) (history)
  • /trunk/servmon/smlogmsg.c (modified) (history)
  • /trunk/servmon/systatd.c (modified) (history)

Diff [purge]

Index: trunk/servmon/include/smstdinc.hxx
@@ -2,6 +2,10 @@
33 #ifndef SM_SMSTDINC_HXX_INCLUDED_
44 #define SM_SMSTDINC_HXX_INCLUDED_
55
 6+#ifdef SM_COMPILER_SHIMS_ONLY
 7+# define SM_NO_HEADERS
 8+#endif
 9+
610 #define SM_VERSION "2.1.0.0-pre"
711
812 #define SM_RELCVS 1 /* CVS version */
@@ -10,6 +14,7 @@
1115
1216 #define SM_RELTYPE SM_RELCVS
1317
 18+#ifndef SM_NO_HEADERS
1419 #include <iostream>
1520 #include <fstream>
1621 #include <iomanip>
@@ -23,9 +28,11 @@
2429 #include <cerrno>
2530 #include <cctype>
2631 #include <algorithm>
 32+#ifndef SM_NO_USING
2733 using std::pair;
2834 using std::make_pair;
2935 using std::for_each;
 36+#endif
3037
3138 #include <boost/bind.hpp>
3239 #include <boost/function.hpp>
@@ -38,6 +45,7 @@
3946 #include <boost/thread/mutex.hpp>
4047 #include <boost/any.hpp>
4148 #include <boost/regex.hpp>
 49+#ifndef SM_NO_USING
4250 using boost::regex;
4351 using boost::regex_search;
4452 using boost::lexical_cast;
@@ -51,6 +59,7 @@
5260 using boost::tie;
5361 namespace b = boost;
5462 namespace bl = boost::lambda;
 63+#endif
5564
5665 #include <sys/types.h>
5766 #include <sys/socket.h>
@@ -65,5 +74,18 @@
6675 #include <unistd.h>
6776 #include <netdb.h>
6877 #include <fcntl.h>
 78+#endif /* !SM_NO_HEADERS */
6979
 80+/* Fix Solaris brokenness */
 81+#ifndef SUN_LEN
 82+# define SUN_LEN(su) \
 83+ (sizeof(*(su)) - sizeof((su)->sun_path) + strlen((su)->sun_path))
7084 #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 @@
1010
1111 #undef unix
1212 #undef bsd
 13+#undef sun
1314
1415 namespace smnet {
1516
Index: trunk/servmon/README
@@ -2,4 +2,17 @@
33 It's also meant to be usable elsewhere, but may need some tweaking. Please send
44 any changes you make back to me at <keturner@livejournal.com>.
55
 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+
619 @(#) $Header$
Index: trunk/servmon/l_memcache.c
@@ -38,8 +38,49 @@
3939 * included, therefore it is assumed that this code is public
4040 * domain. Attribution still noted. */
4141
 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+
4281 #include <ctype.h>
43 -#include <err.h>
 82+#ifdef HAVE_ERR_H
 83+# include <err.h>
 84+#endif
4485 #include <string.h>
4586 #include <strings.h>
4687 #include <stdio.h>
@@ -72,9 +113,9 @@
73114
74115
75116 /* 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,
77118 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);
79120 static void mcm_fetch_cmd(const struct memcache_ctxt *ctxt, struct memcache *mc,
80121 struct memcache_req *req, const char *cmd, const size_t cmd_len);
81122 static char *mcm_get_line(const struct memcache_ctxt *ctxt, struct memcache *mc,
@@ -87,7 +128,7 @@
88129 const char *cmd, const size_t cmd_len,
89130 const char *key, const size_t key_len,
90131 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);
92133
93134
94135 #ifdef __STRICT_ANSI__
@@ -133,6 +174,110 @@
134175 /* # endif */
135176 /* #endif */
136177
 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+
137282 /* Set the default memory handling routines to be system defaults. */
138283 static struct memcache_ctxt mcGlobalCtxt = {
139284 (mcFreeFunc)free,
@@ -146,13 +291,13 @@
147292 mc_add(struct memcache *mc,
148293 const char *key, const size_t key_len,
149294 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) {
151296 return mcm_storage_cmd(&mcGlobalCtxt, mc, str_add_cmd, str_add_len, key, key_len, val, bytes, expire, flags);
152297 }
153298
154299
155300 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) {
157302 mcm_aget(&mcGlobalCtxt, mc, key, len, value, value_len);
158303 }
159304
@@ -163,8 +308,8 @@
164309 }
165310
166311
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) {
169314 return mcm_atomic_cmd(&mcGlobalCtxt, mc, str_decr_cmd, str_decr_len, key, key_len, val);
170315 }
171316
@@ -199,8 +344,8 @@
200345 }
201346
202347
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) {
205350 return mcm_atomic_cmd(&mcGlobalCtxt, mc, str_incr_cmd, str_incr_len, key, key_len, val);
206351 }
207352
@@ -217,7 +362,7 @@
218363 }
219364
220365
221 -u_int32_t
 366+uint32_t
222367 mc_reldate(void) {
223368 return MEMCACHE_RELDATE;
224369 }
@@ -227,7 +372,7 @@
228373 mc_replace(struct memcache *mc,
229374 const char *key, const size_t key_len,
230375 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) {
232377 return mcm_storage_cmd(&mcGlobalCtxt, mc, str_replace_cmd, str_replace_len, key, key_len, val, bytes, expire, flags);
233378 }
234379
@@ -298,7 +443,7 @@
299444
300445
301446 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) {
303448 return mcm_server_find(mc, hash);
304449 }
305450
@@ -331,7 +476,7 @@
332477 mc_set(struct memcache *mc,
333478 const char *key, const size_t key_len,
334479 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) {
336481 return mcm_storage_cmd(&mcGlobalCtxt, mc, str_set_cmd, str_set_len, key, key_len, val, bytes, expire, flags);
337482 }
338483
@@ -354,7 +499,7 @@
355500 }
356501
357502
358 -u_int32_t
 503+uint32_t
359504 mc_vernum(void) {
360505 return MEMCACHE_VERNUM;
361506 }
@@ -372,7 +517,7 @@
373518 mcm_add(const struct memcache_ctxt *ctxt, struct memcache *mc,
374519 const char *key, const size_t key_len,
375520 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) {
377522 return mcm_storage_cmd(ctxt, mc, str_add_cmd, str_add_len, key, key_len, val, bytes, expire, flags);
378523 }
379524
@@ -381,7 +526,7 @@
382527 * the key. The result is mcMalloc(3)'ed and it is assumed that the
383528 * caller is required to mcFree(3) the memory. */
384529 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) {
386531 struct memcache_req *req;
387532 struct memcache_res *res;
388533
@@ -414,16 +559,16 @@
415560 }
416561
417562
418 -static u_int32_t
 563+static uint32_t
419564 mcm_atomic_cmd(const struct memcache_ctxt *ctxt, struct memcache *mc,
420565 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) {
422567 struct memcache_server *ms;
423 - u_int32_t hash;
 568+ uint32_t hash;
424569 char *cp, *cur;
425570 size_t buf_left, i;
426571 struct iovec av[5];
427 - u_int32_t ret;
 572+ uint32_t ret;
428573
429574 /* If we have only one server, don't bother actually hashing. */
430575 if (mc->num_live_servers == 1)
@@ -483,7 +628,7 @@
484629
485630 /* Try converting the value to an integer. If it succeeds, we've got
486631 * a winner. */
487 - ret = (u_int32_t)strtol(cur, &cp, 10);
 632+ ret = (uint32_t)strtol(cur, &cp, 10);
488633 if (ret == 0 && (errno == EINVAL || errno == ERANGE))
489634 err(EX_PROTOCOL, "%s:%u\tstrtol(): invalid value \"%.*s\"", __FILE__, __LINE__, (int)(cp - cur), cur);
490635
@@ -496,8 +641,8 @@
497642 }
498643
499644
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) {
502647 return mcm_atomic_cmd(ctxt, mc, str_decr_cmd, str_decr_len, key, key_len, val);
503648 }
504649
@@ -506,7 +651,7 @@
507652 mcm_delete(const struct memcache_ctxt *ctxt, struct memcache *mc,
508653 const char *key, const size_t key_len, const time_t hold) {
509654 struct memcache_server *ms;
510 - u_int32_t hash;
 655+ uint32_t hash;
511656 char *cur;
512657 size_t buf_left, i;
513658 struct iovec dv[5];
@@ -579,7 +724,7 @@
580725 struct memcache_res_cb *cb;
581726 struct memcache_server *ms;
582727 struct iovec *rv;
583 - u_int32_t i, num_vec;
 728+ uint32_t i, num_vec;
584729
585730 if (req->num_keys == 0)
586731 return;
@@ -884,7 +1029,7 @@
8851030 size_t bytes;
8861031 size_t read_cur_offset;
8871032 size_t cp_offset;
888 - u_int16_t flags;
 1033+ uint16_t flags;
8891034 int ret;
8901035
8911036 cp = ms->read_cur = ms->start = ms->cur = ms->buf;
@@ -984,7 +1129,7 @@
9851130 cp = &cp[res->len];
9861131 end = ms->read_cur;
9871132
988 - flags = (u_int16_t)strtol(cp, &end, 10);
 1133+ flags = (uint16_t)strtol(cp, &end, 10);
9891134 if (flags == 0 && (errno == EINVAL || errno == ERANGE)) {
9901135 warn("%s:%u\tstrtol(): invalid flags", __FILE__, __LINE__);
9911136 }
@@ -1064,10 +1209,10 @@
10651210 #endif /* USE_CRC32_HASH */
10661211
10671212
1068 -u_int32_t
 1213+uint32_t
10691214 mc_hash_key(const char *key, const size_t len) {
10701215 unsigned char res[MD5_DIGEST_LENGTH];
1071 - u_int32_t i;
 1216+ uint32_t i;
10721217 int j;
10731218 char result[33];
10741219 char php[9] = {};
@@ -1089,9 +1234,9 @@
10901235 }
10911236
10921237
1093 -u_int32_t
 1238+uint32_t
10941239 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) {
10961241 return mcm_atomic_cmd(ctxt, mc, str_incr_cmd, str_incr_len, key, key_len, val);
10971242 }
10981243
@@ -1124,7 +1269,7 @@
11251270 mcm_replace(const struct memcache_ctxt *ctxt, struct memcache *mc,
11261271 const char *key, const size_t key_len,
11271272 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) {
11291274 return mcm_storage_cmd(ctxt, mc, str_replace_cmd, str_replace_len, key, key_len, val, bytes, expire, flags);
11301275 }
11311276
@@ -1587,7 +1732,7 @@
15881733 void
15891734 mc_server_deactivate(struct memcache *mc,
15901735 struct memcache_server *ms) {
1591 - u_int32_t i, found;
 1736+ uint32_t i, found;
15921737
15931738 /* Since adding servers is so rare, and servers do come back, don't
15941739 * bother mcRealloc(3)'ing mc->live_servers. Instead, just find the
@@ -1645,7 +1790,7 @@
16461791
16471792
16481793 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) {
16501795 if (mc->num_live_servers < 1)
16511796 return NULL;
16521797
@@ -1831,82 +1976,82 @@
18321977 }
18331978 } else if (memcmp(cur, "curr_items ", MCM_CSTRLEN("curr_items ")) == 0) {
18341979 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);
18361981 if (s->curr_items == 0 && (errno == EINVAL || errno == ERANGE))
18371982 err(EX_PROTOCOL, "%s:%u\tstrtol(): invalid curr_items \"%.*s\"", __FILE__, __LINE__, (int)(cp - cur), cur);
18381983 } else if (memcmp(cur, "total_items ", MCM_CSTRLEN("total_items ")) == 0) {
18391984 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);
18411986 if (s->total_items == 0 && (errno == EINVAL || errno == ERANGE))
18421987 err(EX_PROTOCOL, "%s:%u\tstrtoll(): invalid total_items \"%.*s\"", __FILE__, __LINE__, (int)(cp - cur), cur);
18431988 } else if (memcmp(cur, "bytes ", MCM_CSTRLEN("bytes ")) == 0) {
18441989 cur = &cur[MCM_CSTRLEN("bytes")];
1845 - s->bytes = (u_int64_t)strtoll(cur, &cp, 10);
 1990+ s->bytes = (uint64_t)strtoll(cur, &cp, 10);
18461991 if (s->bytes == 0 && (errno == EINVAL || errno == ERANGE))
18471992 err(EX_PROTOCOL, "%s:%u\tstrtol(): invalid bytes \"%.*s\"", __FILE__, __LINE__, (int)(cp - cur), cur);
18481993 } else if (memcmp(cur, "curr_connections ", MCM_CSTRLEN("curr_connections ")) == 0) {
18491994 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);
18511996 if (s->curr_connections == 0 && (errno == EINVAL || errno == ERANGE))
18521997 err(EX_PROTOCOL, "%s:%u\tstrtol(): invalid curr_connections \"%.*s\"", __FILE__, __LINE__, (int)(cp - cur), cur);
18531998 } else if (memcmp(cur, "total_connections ", MCM_CSTRLEN("total_connections ")) == 0) {
18541999 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);
18562001 if (s->total_connections == 0 && (errno == EINVAL || errno == ERANGE))
18572002 err(EX_PROTOCOL, "%s:%u\tstrtoll(): invalid total_connections \"%.*s\"", __FILE__, __LINE__, (int)(cp - cur), cur);
18582003 } else if (memcmp(cur, "connection_structures ", MCM_CSTRLEN("connection_structures ")) == 0) {
18592004 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);
18612006 if (s->connection_structures == 0 && (errno == EINVAL || errno == ERANGE))
18622007 err(EX_PROTOCOL, "%s:%u\tstrtol(): invalid connection_structures \"%.*s\"", __FILE__, __LINE__, (int)(cp - cur), cur);
18632008 } else if (memcmp(cur, "cmd_get ", MCM_CSTRLEN("cmd_get ")) == 0) {
18642009 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);
18662011 if (s->cmd_get == 0 && (errno == EINVAL || errno == ERANGE))
18672012 err(EX_PROTOCOL, "%s:%u\tstrtoll(): invalid cmd_get \"%.*s\"", __FILE__, __LINE__, (int)(cp - cur), cur);
18682013 } else if (memcmp(cur, "cmd_refresh ", MCM_CSTRLEN("cmd_refresh ")) == 0) {
18692014 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);
18712016 if (s->cmd_refresh == 0 && (errno == EINVAL || errno == ERANGE))
18722017 err(EX_PROTOCOL, "%s:%u\tstrtoll(): invalid cmd_refresh \"%.*s\"", __FILE__, __LINE__, (int)(cp - cur), cur);
18732018 } else if (memcmp(cur, "cmd_set ", MCM_CSTRLEN("cmd_set ")) == 0) {
18742019 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);
18762021 if (s->cmd_set == 0 && (errno == EINVAL || errno == ERANGE))
18772022 err(EX_PROTOCOL, "%s:%u\tstrtoll(): invalid cmd_set \"%.*s\"", __FILE__, __LINE__, (int)(cp - cur), cur);
18782023 } else if (memcmp(cur, "get_hits ", MCM_CSTRLEN("get_hits ")) == 0) {
18792024 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);
18812026 if (s->get_hits == 0 && (errno == EINVAL || errno == ERANGE))
18822027 err(EX_PROTOCOL, "%s:%u\tstrtoll(): invalid get_hits \"%.*s\"", __FILE__, __LINE__, (int)(cp - cur), cur);
18832028 } else if (memcmp(cur, "get_misses ", MCM_CSTRLEN("get_misses ")) == 0) {
18842029 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);
18862031 if (s->get_misses == 0 && (errno == EINVAL || errno == ERANGE))
18872032 err(EX_PROTOCOL, "%s:%u\tstrtoll(): invalid get_misses \"%.*s\"", __FILE__, __LINE__, (int)(cp - cur), cur);
18882033 } else if (memcmp(cur, "refresh_hits ", MCM_CSTRLEN("refresh_hits ")) == 0) {
18892034 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);
18912036 if (s->refresh_hits == 0 && (errno == EINVAL || errno == ERANGE))
18922037 err(EX_PROTOCOL, "%s:%u\tstrtoll(): invalid refresh_hits \"%.*s\"", __FILE__, __LINE__, (int)(cp - cur), cur);
18932038 } else if (memcmp(cur, "refresh_misses ", MCM_CSTRLEN("refresh_misses ")) == 0) {
18942039 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);
18962041 if (s->refresh_misses == 0 && (errno == EINVAL || errno == ERANGE))
18972042 err(EX_PROTOCOL, "%s:%u\tstrtoll(): invalid refresh_misses \"%.*s\"", __FILE__, __LINE__, (int)(cp - cur), cur);
18982043 } else if (memcmp(cur, "bytes_read ", MCM_CSTRLEN("bytes_read ")) == 0) {
18992044 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);
19012046 if (s->bytes_read == 0 && (errno == EINVAL || errno == ERANGE))
19022047 err(EX_PROTOCOL, "%s:%u\tstrtoll(): invalid bytes_read \"%.*s\"", __FILE__, __LINE__, (int)(cp - cur), cur);
19032048 } else if (memcmp(cur, "bytes_written ", MCM_CSTRLEN("bytes_written ")) == 0) {
19042049 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);
19062051 if (s->bytes_written == 0 && (errno == EINVAL || errno == ERANGE))
19072052 err(EX_PROTOCOL, "%s:%u\tstrtoll(): invalid bytes_written \"%.*s\"", __FILE__, __LINE__, (int)(cp - cur), cur);
19082053 } else if (memcmp(cur, "limit_maxbytes ", MCM_CSTRLEN("limit_maxbytes ")) == 0) {
19092054 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);
19112056 if (s->limit_maxbytes == 0 && (errno == EINVAL || errno == ERANGE))
19122057 err(EX_PROTOCOL, "%s:%u\tstrtoll(): invalid limit_maxbytes \"%.*s\"", __FILE__, __LINE__, (int)(cp - cur), cur);
19132058 } else {
@@ -1962,7 +2107,7 @@
19632108 mcm_set(const struct memcache_ctxt *ctxt, struct memcache *mc,
19642109 const char *key, const size_t key_len,
19652110 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) {
19672112 return mcm_storage_cmd(ctxt, mc, str_set_cmd, str_set_len, key, key_len, val, bytes, expire, flags);
19682113 }
19692114
@@ -2029,9 +2174,9 @@
20302175 const char *cmd, const size_t cmd_len,
20312176 const char *key, const size_t key_len,
20322177 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) {
20342179 struct memcache_server *ms;
2035 - u_int32_t hash;
 2180+ uint32_t hash;
20362181 char *cur;
20372182 size_t buf_left, i;
20382183 struct iovec wv[11];
Index: trunk/servmon/l_memcache.h
@@ -216,7 +216,7 @@
217217 /* The number of addresses in the cached copy. If there is more
218218 * than one per DNS entry (discouraged), we establish a connection
219219 * to them all. */
220 - u_int32_t num_addrs;
 220+ uint32_t num_addrs;
221221
222222 #ifdef HAVE_SELECT
223223 /* Reduces the amount of user time required when reading data. */
@@ -255,22 +255,22 @@
256256 char *version;
257257 struct timeval rusage_user;
258258 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;
275275 };
276276
277277
@@ -285,7 +285,7 @@
286286
287287 /* The number of servers in live_servers in the live_servers
288288 * list. */
289 - u_int32_t num_live_servers;
 289+ uint32_t num_live_servers;
290290
291291 /* A generic pointer not used by memcache(3), but can be used by
292292 * calling programs. */
@@ -334,7 +334,7 @@
335335 struct memcache_res {
336336 const char *key; /* key */
337337 size_t len; /* length of key */
338 - u_int32_t hash; /* hash of the key */
 338+ uint32_t hash; /* hash of the key */
339339 void *val; /* the value */
340340 size_t bytes; /* length of val */
341341
@@ -359,7 +359,7 @@
360360 /* This is the client supplied flags. Please note, this flags is
361361 * very different than _flags (_flags is an internal bit and
362362 * shouldn't be read/changed, etc). */
363 - u_int16_t flags;
 363+ uint16_t flags;
364364
365365 /* If _flags has 0x01 set, val will be free(3)'ed on when this
366366 * struct is cleaned up via mc_res_free() or the request is cleaned
@@ -380,7 +380,7 @@
381381
382382 TAILQ_HEAD(memcache_res_list, memcache_res) query;
383383 TAILQ_HEAD(memcache_res_cb_list, memcache_res_cb) cb;
384 - u_int16_t num_keys;
 384+ uint16_t num_keys;
385385 };
386386
387387
@@ -443,12 +443,12 @@
444444 int mc_add(struct memcache *mc,
445445 const char *key, const size_t key_len,
446446 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);
448448
449449 /* Gets the value from memcache and allocates the data for the caller.
450450 * It is the caller's responsibility to free the returned value.
451451 * 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*);
453453
454454 /* Gets the value from memcache and allocates the data for the caller.
455455 * It is the caller's responsibility to free the returned value.
@@ -456,7 +456,7 @@
457457 void *mc_arefresh(struct memcache *mc, const char *key, const size_t len);
458458
459459 /* 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);
461461
462462 /* Deletes a given key */
463463 int mc_delete(struct memcache *mc, const char *key, const size_t key_len, const time_t hold);
@@ -477,7 +477,7 @@
478478 void mc_get(struct memcache *mc, struct memcache_req *req);
479479
480480 /* 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);
482482
483483 /* Allocates a new memcache object */
484484 struct memcache *mc_new(void);
@@ -492,13 +492,13 @@
493493 void mc_refresh(struct memcache *mc, struct memcache_req *req);
494494
495495 /* Returns the release date for the library */
496 -u_int32_t mc_reldate(void);
 496+uint32_t mc_reldate(void);
497497
498498 /* Replaces a given key to the cache */
499499 int mc_replace(struct memcache *mc,
500500 const char *key, const size_t key_len,
501501 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);
503503
504504 /* Safely adds a key to a given request (the key is mc_strdup()'ed).
505505 See mc_req_add_ref() to avoid the mc_strdup(): note the warning in
@@ -594,7 +594,7 @@
595595 int mc_set(struct memcache *mc,
596596 const char *key, const size_t key_len,
597597 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);
599599
600600 /* Creates a stats object for all available servers and returns the
601601 * cumulative stats. Per host-specific data is generally the same as
@@ -613,7 +613,7 @@
614614 void mc_timeout(struct memcache *mc, const int sec, const int usec);
615615
616616 /* Returns a numeric version of the library */
617 -u_int32_t mc_vernum(void);
 617+uint32_t mc_vernum(void);
618618
619619 /* Returns a string version of the library */
620620 const char *mc_version(void);
@@ -669,13 +669,13 @@
670670 int mcm_add(const struct memcache_ctxt *ctxt, struct memcache *mc,
671671 const char *key, const size_t key_len,
672672 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);
674674 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*);
676676 void *mcm_arefresh(const struct memcache_ctxt *ctxt, struct memcache *mc,
677677 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);
680680 int mcm_delete(const struct memcache_ctxt *ctxt, struct memcache *mc,
681681 const char *key, const size_t key_len, const time_t hold);
682682 int mcm_flush(const struct memcache_ctxt *ctxt, struct memcache *mc,
@@ -683,16 +683,16 @@
684684 int mcm_flush_all(const struct memcache_ctxt *ctxt, struct memcache *mc);
685685 void mcm_free(const struct memcache_ctxt *ctxt, struct memcache *mc);
686686 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);
690690 struct memcache *mcm_new(const struct memcache_ctxt *ctxt);
691691 void mcm_refresh(const struct memcache_ctxt *ctxt, struct memcache *mc,
692692 struct memcache_req *req);
693693 int mcm_replace(const struct memcache_ctxt *ctxt, struct memcache *mc,
694694 const char *key, const size_t key_len,
695695 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);
697697 struct memcache_res *mcm_req_add(const struct memcache_ctxt *ctxt, struct memcache_req *req,
698698 const char *key, const size_t len);
699699 struct memcache_res *mcm_req_add_ref(const struct memcache_ctxt *ctxt, struct memcache_req *req,
@@ -716,7 +716,7 @@
717717 struct memcache_server *ms);
718718 void mcm_server_disconnect(struct memcache_server *ms);
719719 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);
721721 void mcm_server_free(const struct memcache_ctxt *ctxt, struct memcache_server *ms);
722722 struct memcache_server *mcm_server_new(const struct memcache_ctxt *ctxt);
723723 void mcm_server_stats_free(const struct memcache_ctxt *ctxt, struct memcache_server_stats *s);
@@ -724,12 +724,12 @@
725725 int mcm_set(const struct memcache_ctxt *ctxt, struct memcache *mc,
726726 const char *key, const size_t key_len,
727727 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);
729729 struct memcache_server_stats *mcm_stats(const struct memcache_ctxt *ctxt, struct memcache *mc);
730730 char *mcm_strdup(const struct memcache_ctxt *ctxt, const char *str);
731731 char *mcm_strndup(const struct memcache_ctxt *ctxt, const char *str, const size_t len);
732732 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);
734734 const char *mcm_version(const struct memcache_ctxt *ctxt);
735735 /* END memory management API functions */
736736
Index: trunk/servmon/sminfo.sh
@@ -1,13 +1,23 @@
22 #! /bin/sh
33 # $Header$
44
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
616
717 cat <<_EOF_
818 /* this file in generated automatically. do not edit it. */
919 #ifndef SM_SMINFO_CXX_
1020 #define SM_SMINFO_CXX_
11 -static char const *sm\$compile_user = "`whoami`";
 21+static char const *sm\$compile_user = "$USER";
1222 static char const *sm\$compile_host = "`hostname`";
1323 static char const *sm\$compile_time = "`date +"%d-%b-%Y %H:%M:%S"`";
1424 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
126 + native
Added: svn:keywords
227 + Author Date Id Revision
Index: trunk/servmon/SConstruct
@@ -1,20 +1,21 @@
22 # @(#) $Header$
33
4 -# Set build options here.
5 -#
6 -# Compiler
7 -cc = 'gcc'
8 -cxx = 'g++'
 4+config = dict()
 5+execfile('buildconfig', config)
96
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'])
139
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'])
1613
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+
1920 import os
2021 try:
2122 os.remove('sminfo.cxx')
@@ -25,18 +26,49 @@
2627 'smauth.cxx smtmr.cxx smmon.cxx smqb.cxx smmc.cxx smalrm.cxx l_memcache.c '
2728 'smlog.cxx smstdrt.cxx smtrm.cxx msgtab.cxx')
2829
 30+conflags = []
2931 env = Environment(CPPFLAGS = cppflags + ' -DPFX="\\"' + prefix + '\\""',
3032 CCFLAGS = cflags,
 33+ LDFLAGS = ldflags,
3134 CC = cc,
3235 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'])
3668 env.Command('sminfo.cxx', 'sminfo.sh', '/bin/sh $SOURCE >$TARGET')
3769 env.Command(['msgtab.hxx', 'msgtab.cxx'], ['mktab', 'messages.tab'], './mktab messages.tab')
3870
39 -env.Program ('mktab', ['mktab.cxx'])
 71+env.Program ('mktab', ['mktab.cxx'], LIBS = [])
4072 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)
4375 env.Alias('install', prefix)
Index: trunk/servmon/smlogmsg.c
@@ -7,6 +7,7 @@
88
99 #include <stdio.h>
1010 #include <string.h>
 11+#include <strings.h>
1112 #include <stdlib.h>
1213 #include <errno.h>
1314 #include <unistd.h>
Index: trunk/servmon/systatd.c
@@ -11,17 +11,39 @@
1212 #include <stdlib.h>
1313 #include <string.h>
1414
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+
1627 #include <unistd.h>
17 -#include <mntent.h>
1828 #include <errno.h>
1929
20 -#ifdef _PATH_MOUNTED
 30+#ifdef _PATH_MOUNTED /* BSD, glibc */
2131 # define PATH_MTAB _PATH_MOUNTED
2232 #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
2438 #endif
2539
 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+
2648 #define PORT 8576
2749
2850 static void print_mntents(FILE *where);
@@ -73,22 +95,81 @@
7496 return 0;
7597 }
7698
 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+
77158 static void
78159 print_mntents(where)
79 -FILE *where;
 160+ FILE *where;
80161 {
81 - struct mntent *ent;
82162 struct statvfs sbuf;
83163 FILE *mtab;
84164 fsblkcnt_t cnt;
85 -
 165+ struct mnttab ent;
 166+
86167 if ((mtab = setmntent(PATH_MTAB, "r")) == NULL) {
87 - perror("setmntent");
 168+ perror(PATH_MTAB);
88169 return;
89170 }
90171
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) {
93174 perror("statvfs");
94175 goto end;
95176 }
@@ -96,7 +177,7 @@
97178 cnt = sbuf.f_bavail;
98179 if (cnt == 0)
99180 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);
101182
102183 }
103184
Index: trunk/servmon/smirc.cxx
@@ -342,7 +342,8 @@
343343
344344 ircclnt::~ircclnt()
345345 {
346 - SMI(smnet::smpx)->rm(sckt);
 346+ if (sckt)
 347+ SMI(smnet::smpx)->rm(sckt);
347348 delete trmpimpl;
348349 }
349350

Status & tagging log