X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=libmemcached%2Fstats.cc;h=78fed03d7d0b8e389d344b0ebd70454a391810ea;hb=5c104c25a61292fd9552cb9587ea595916d554f7;hp=5a2013e815b9d44a5da236dc0250170ee456527e;hpb=28adf7b936c6f5c25b7526ff56ec1256da1246d4;p=m6w6%2Flibmemcached diff --git a/libmemcached/stats.cc b/libmemcached/stats.cc index 5a2013e8..78fed03d 100644 --- a/libmemcached/stats.cc +++ b/libmemcached/stats.cc @@ -55,7 +55,21 @@ static memcached_return_t set_data(memcached_stat_st *memc_stat, char *key, char } else if (not strcmp("pid", key)) { - memc_stat->pid= strtoul(value, (char **)NULL, 10); + int64_t temp= strtoll(value, (char **)NULL, 10); + + if (temp <= INT32_MAX and ( sizeof(pid_t) == sizeof(int32_t) )) + { + memc_stat->pid= temp; + } + else if (temp > -1) + { + memc_stat->pid= temp; + } + else + { + // If we got a value less then -1 then something went wrong in the + // protocol + } } else if (not strcmp("uptime", key)) { @@ -188,7 +202,7 @@ char *memcached_stat_get_value(const memcached_st *ptr, memcached_stat_st *memc_ if (not memcmp("pid", key, sizeof("pid") -1)) { - length= snprintf(buffer, SMALL_STRING_LEN,"%lu", memc_stat->pid); + length= snprintf(buffer, SMALL_STRING_LEN,"%lld", (signed long long)memc_stat->pid); } else if (not memcmp("uptime", key, sizeof("uptime") -1)) { @@ -309,16 +323,18 @@ static memcached_return_t binary_stats_fetch(memcached_stat_st *memc_stat, size_t len= strlen(args); memcached_return_t rc= memcached_validate_key_length(len, true); - unlikely (rc != MEMCACHED_SUCCESS) + if (rc != MEMCACHED_SUCCESS) + { return rc; + } request.message.header.request.keylen= htons((uint16_t)len); request.message.header.request.bodylen= htonl((uint32_t) len); struct libmemcached_io_vector_st vector[]= { - { sizeof(request.bytes), request.bytes }, - { len, args } + { request.bytes, sizeof(request.bytes) }, + { args, len } }; if (memcached_vdo(instance, vector, 2, true) != MEMCACHED_SUCCESS) @@ -384,29 +400,28 @@ static memcached_return_t ascii_stats_fetch(memcached_stat_st *memc_stat, memcached_server_write_instance_st instance, struct local_context *check) { - memcached_return_t rc; char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE]; int send_length; if (args) - send_length= (size_t) snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, - "stats %s\r\n", args); + { + send_length= (size_t) snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, "stats %s\r\n", args); + } else - send_length= (size_t) snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, - "stats\r\n"); + { + send_length= (size_t) snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, "stats\r\n"); + } if (send_length >= MEMCACHED_DEFAULT_COMMAND_SIZE || send_length < 0) - return MEMCACHED_WRITE_FAILURE; - - rc= memcached_do(instance, buffer, (size_t)send_length, true); - if (rc != MEMCACHED_SUCCESS) - goto error; - - while (1) { - rc= memcached_response(instance, buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, NULL); + return memcached_set_error(*instance, MEMCACHED_MEMORY_ALLOCATION_FAILURE, MEMCACHED_AT, + memcached_literal_param("snprintf(MEMCACHED_DEFAULT_COMMAND_SIZE)")); + } - if (rc == MEMCACHED_STAT) + memcached_return_t rc= memcached_do(instance, buffer, (size_t)send_length, true); + if (memcached_success(rc)) + { + while ((rc= memcached_response(instance, buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, NULL)) == MEMCACHED_STAT) { char *string_ptr, *end_ptr; char *key, *value; @@ -420,8 +435,7 @@ static memcached_return_t ascii_stats_fetch(memcached_stat_st *memc_stat, string_ptr= end_ptr + 1; for (end_ptr= string_ptr; !(isspace(*end_ptr)); end_ptr++) {}; value= string_ptr; - value[(size_t)(end_ptr-string_ptr)]= 0; - string_ptr= end_ptr + 2; + value[(size_t)(end_ptr -string_ptr)]= 0; if (memc_stat) { unlikely((set_data(memc_stat, key, value)) == MEMCACHED_UNKNOWN_STAT_KEY) @@ -439,13 +453,8 @@ static memcached_return_t ascii_stats_fetch(memcached_stat_st *memc_stat, check->context); } } - else - { - break; - } } -error: if (rc == MEMCACHED_END) return MEMCACHED_SUCCESS; else @@ -454,21 +463,25 @@ error: memcached_stat_st *memcached_stat(memcached_st *self, char *args, memcached_return_t *error) { + memcached_return_t unused; + if (error == NULL) + { + error= &unused; + } + memcached_return_t rc; - if ((rc= initialize_query(self)) != MEMCACHED_SUCCESS) + if (memcached_failed(rc= initialize_query(self))) { - if (error) - *error= rc; + *error= rc; return NULL; } WATCHPOINT_ASSERT(error); - unlikely (self->flags.use_udp) + if (self->flags.use_udp) { - if (error) - *error= MEMCACHED_NOT_SUPPORTED; + *error= memcached_set_error(*self, MEMCACHED_NOT_SUPPORTED, MEMCACHED_AT); return NULL; } @@ -477,8 +490,7 @@ memcached_stat_st *memcached_stat(memcached_st *self, char *args, memcached_retu if (not stats) { - if (error) - *error= MEMCACHED_MEMORY_ALLOCATION_FAILURE; + *error= MEMCACHED_MEMORY_ALLOCATION_FAILURE; return NULL; } @@ -493,6 +505,7 @@ memcached_stat_st *memcached_stat(memcached_st *self, char *args, memcached_retu stat_instance= stats +x; + stat_instance->pid= -1; stat_instance->root= self; instance= memcached_server_instance_fetch(self, x); @@ -506,12 +519,13 @@ memcached_stat_st *memcached_stat(memcached_st *self, char *args, memcached_retu temp_return= ascii_stats_fetch(stat_instance, args, instance, NULL); } - if (temp_return != MEMCACHED_SUCCESS) + if (memcached_failed(temp_return)) + { rc= MEMCACHED_SOME_ERRORS; + } } - if (error) - *error= rc; + *error= rc; return stats; } @@ -580,7 +594,7 @@ char ** memcached_stat_get_keys(memcached_st *ptr, void memcached_stat_free(const memcached_st *, memcached_stat_st *memc_stat) { WATCHPOINT_ASSERT(memc_stat); // Be polite, but when debugging catch this as an error - if (not memc_stat) + if (memc_stat == NULL) { return; }