Skip to content

Commit

Permalink
Refuse to start if we detect libevent 1.[12]
Browse files Browse the repository at this point in the history
  • Loading branch information
trondn committed Jun 4, 2010
1 parent 2cead02 commit d0941ce
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
27 changes: 27 additions & 0 deletions memcached.c
Expand Up @@ -3323,6 +3323,7 @@ static void server_stats(ADD_STAT add_stats, conn *c, bool aggregate) {
APPEND_STAT("uptime", "%u", now);
APPEND_STAT("time", "%ld", now + (long)process_started);
APPEND_STAT("version", "%s", VERSION);
APPEND_STAT("libevent", "%s", event_get_version());
APPEND_STAT("pointer_size", "%d", (int)(8 * sizeof(void *)));

#ifndef __WIN32__
Expand Down Expand Up @@ -5878,6 +5879,28 @@ static bool load_extension(const char *soname, const char *config) {
return true;
}

/**
* Do basic sanity check of the runtime environment
* @return true if no errors found, false if we can't use this env
*/
static bool sanitycheck(void) {
/* One of our biggest problems is old and bogus libevents */
const char *ever = event_get_version();
if (ever != NULL) {
if (strncmp(ever, "1.", 2) == 0) {
/* Require at least 1.3 (that's still a couple of years old) */
if ((ever[2] == '1' || ever[2] == '2') && !isdigit(ever[3])) {
fprintf(stderr, "You are using libevent %s.\nPlease upgrade to"
" a more recent version (1.3 or newer)\n",
event_get_version());
return false;
}
}
}

return true;
}

int main (int argc, char **argv) {
int c;
bool lock_memory = false;
Expand All @@ -5900,6 +5923,10 @@ int main (int argc, char **argv) {
char old_options[1024] = { [0] = '\0' };
char *old_opts = old_options;

if (!sanitycheck()) {
return EX_OSERR;
}

/* init settings */
settings_init();

Expand Down
2 changes: 1 addition & 1 deletion t/binary.t
Expand Up @@ -2,7 +2,7 @@

use strict;
use warnings;
use Test::More tests => 3388;
use Test::More tests => 3400;
use FindBin qw($Bin);
use lib "$Bin/lib";
use MemcachedTest;
Expand Down
3 changes: 2 additions & 1 deletion t/stats.t
Expand Up @@ -16,6 +16,7 @@ my $sock = $server->sock;
## STAT uptime 13
## STAT time 1259170891
## STAT version 1.4.3
## STAT libevent 1.4.13-stable.
## STAT pointer_size 32
## STAT rusage_user 0.001198
## STAT rusage_system 0.003523
Expand Down Expand Up @@ -61,7 +62,7 @@ if ($stats->{'auth_sasl_enabled'} == 'yes') {
$sasl_enabled = 1;
}

is(scalar(keys(%$stats)), 39, "39 stats values");
is(scalar(keys(%$stats)), 40, "40 stats values");

# Test initial state
foreach my $key (qw(curr_items total_items bytes cmd_get cmd_set get_hits evictions get_misses
Expand Down

0 comments on commit d0941ce

Please sign in to comment.