Tidy dcb_free (prefer use of dcb_close) and remove from test code; add good random number generator.

This commit is contained in:
counterpoint
2015-08-26 15:43:21 +01:00
parent 72b301785b
commit 1f6b544f33
7 changed files with 14 additions and 23 deletions

View File

@ -230,23 +230,15 @@ DCB *newdcb;
/**
* Free a DCB that has not been associated with a descriptor.
* Provided only for consistency, simply calls dcb_close to guarantee
* safe disposal of a DCB
*
* @param dcb The DCB to free
*/
void
dcb_free(DCB *dcb)
{
if (dcb->fd != DCBFD_CLOSED)
{
LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR,
"Error : Attempt to free a DCB via dcb_free "
"that has been associated with a descriptor.")));
}
raise(SIGABRT);
/* Another statement to avoid a compiler warning */
dcb_final_free(dcb);
dcb_close(dcb);
}
/*

View File

@ -23,6 +23,7 @@
#include <ctype.h>
#include <mysql_client_server_protocol.h>
#include <gwdirs.h>
#include <random.h>
/** Defined in log_manager.cc */
extern int lm_enabled_logfiles_bitmask;
@ -36,15 +37,13 @@ extern __thread log_info_t tls_log_info;
static unsigned char
secrets_randomchar()
{
return (char)((rand() % ('~' - ' ')) + ' ');
return (char)((random_jkiss() % ('~' - ' ')) + ' ');
}
static int
secrets_random_str(unsigned char *output, int len)
{
int i;
srand((unsigned long )time(0L) ^ (unsigned long )output);
for ( i = 0; i < len; ++i )
{
output[i] = secrets_randomchar();
@ -273,7 +272,6 @@ if(strlen(path) > PATH_MAX)
}
close(randfd);
srand(randval);
secrets_random_str(key.enckey, MAXSCALE_KEYLEN);
secrets_random_str(key.initvector, MAXSCALE_IV_LEN);

View File

@ -59,9 +59,9 @@ int buflen;
printAllDCBs();
ss_info_dassert(true, "Something is true");
ss_dfprintf(stderr, "\t..done\n");
dcb_free(dcb);
ss_dfprintf(stderr, "Freed original dcb");
ss_info_dassert(!dcb_isvalid(dcb), "Freed DCB must not be valid");
dcb_close(dcb);
ss_dfprintf(stderr, "Closed original dcb");
ss_info_dassert(!dcb_isvalid(dcb), "Closed DCB must not be valid");
ss_dfprintf(stderr, "\t..done\nMake clone DCB a zombie");
clone->state = DCB_STATE_NOPOLLING;
dcb_close(clone);

View File

@ -85,7 +85,7 @@ int result;
sleep(10);
poll_shutdown();
ss_dfprintf(stderr, "\t..done\nTidy up.");
dcb_free(dcb);
dcb_close(dcb);
ss_dfprintf(stderr, "\t..done\n");
return 0;

View File

@ -59,7 +59,7 @@ int result;
sleep(10);
poll_shutdown();
ss_dfprintf(stderr, "\t..done\nTidy up.");
dcb_free(dcb);
dcb_close(dcb);
ss_dfprintf(stderr, "\t..done\n");
return 0;

View File

@ -43,6 +43,7 @@
#include <skygw_utils.h>
#include <log_manager.h>
#include <secrets.h>
#include <random.h>
/** Defined in log_manager.cc */
extern int lm_enabled_logfiles_bitmask;
@ -100,7 +101,7 @@ char *gw_strend(register const char *s) {
* generate a random char
*****************************************/
static char gw_randomchar() {
return (char)((rand() % 78) + 30);
return (char)((random_jkiss() % 78) + 30);
}
/*****************************************
@ -110,7 +111,6 @@ static char gw_randomchar() {
int gw_generate_random_str(char *output, int len) {
int i;
srand(time(0L));
for ( i = 0; i < len; ++i ) {
output[i] = gw_randomchar();

View File

@ -30,6 +30,7 @@
#include <sys/time.h>
#include "skygw_utils.h"
#include <atomic.h>
#include <random.h>
#if defined(MLIST)
@ -1265,7 +1266,7 @@ void acquire_lock(
misscount += 1;
if (misscount > 10)
{
ts1.tv_nsec = (rand()%misscount)*1000000;
ts1.tv_nsec = (random_jkiss()%misscount)*1000000;
nanosleep(&ts1, NULL);
}
}