}
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))
{
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))
{
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)
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;
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)
check->context);
}
}
- else
- {
- break;
- }
}
-error:
if (rc == MEMCACHED_END)
return MEMCACHED_SUCCESS;
else
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;
}
- memcached_stat_st *stats= static_cast<memcached_stat_st *>(libmemcached_calloc(self, memcached_server_count(self), sizeof(memcached_stat_st)));
+ memcached_stat_st *stats= libmemcached_xcalloc(self, memcached_server_count(self), memcached_stat_st);
if (not stats)
{
- if (error)
- *error= MEMCACHED_MEMORY_ALLOCATION_FAILURE;
+ *error= MEMCACHED_MEMORY_ALLOCATION_FAILURE;
return NULL;
}
stat_instance= stats +x;
+ stat_instance->pid= -1;
stat_instance->root= self;
instance= memcached_server_instance_fetch(self, x);
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;
}
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;
}