Changed sprintf calls to snprintf calls and fixed compiler warnings.
This commit is contained in:
parent
501ea8ffc2
commit
98ab399e6e
@ -106,6 +106,8 @@ int main(int argc, char* argv[])
|
||||
}
|
||||
|
||||
succp = skygw_logmanager_init( log_argc, log_argv);
|
||||
if(!succp)
|
||||
fprintf(stderr, "Log manager initialization failed.\n");
|
||||
ss_dassert(succp);
|
||||
|
||||
t = time(NULL);
|
||||
@ -476,16 +478,22 @@ static void* thr_run(
|
||||
skygw_log_flush(LOGFILE_MESSAGE);
|
||||
logstr = ("Hi, how are you?");
|
||||
err = skygw_log_write(LOGFILE_MESSAGE, logstr);
|
||||
if(err != 0)
|
||||
fprintf(stderr,"Error, log write failed.\n");
|
||||
ss_dassert(err == 0);
|
||||
skygw_logmanager_done();
|
||||
skygw_log_flush(LOGFILE_TRACE);
|
||||
skygw_log_flush(LOGFILE_MESSAGE);
|
||||
logstr = ("I was wondering, you know, it has been such a lovely weather whole morning and I thought that would you like to come to my place and have a little piece of cheese with us. Just me and my mom - and you, of course. Then, if you wish, we could listen to the radio and keep company for our little Steven, my mom's cat, you know.");
|
||||
ss_dassert(err == 0);
|
||||
if(err != 0)
|
||||
fprintf(stderr,"Error, log write failed.\n");
|
||||
ss_dassert(err == 0);
|
||||
err = skygw_log_write(LOGFILE_MESSAGE, logstr);
|
||||
skygw_logmanager_init( 0, NULL);
|
||||
logstr = ("Testing. One, two, three\n");
|
||||
err = skygw_log_write(LOGFILE_ERROR, logstr);
|
||||
if(err != 0)
|
||||
fprintf(stderr,"Error, log write failed.\n");
|
||||
ss_dassert(err == 0);
|
||||
skygw_logmanager_init( 0, NULL);
|
||||
skygw_logmanager_init( 0, NULL);
|
||||
@ -494,11 +502,15 @@ static void* thr_run(
|
||||
|
||||
skygw_log_enable(LOGFILE_TRACE);
|
||||
err = skygw_log_write(LOGFILE_TRACE, logstr);
|
||||
if(err != 0)
|
||||
fprintf(stderr,"Error, log write failed.\n");
|
||||
ss_dassert(err == 0);
|
||||
skygw_logmanager_done();
|
||||
skygw_logmanager_init( 0, NULL);
|
||||
logstr = ("Rather more surprising, at least at first sight, is the fact that a reference to a[i] can also be written as *(a+i). In evaluating a[i], C converts it to *(a+i) immediately; the two forms are equivalent. Applying the operatos & to both parts of this equivalence, it follows that &a[i] and a+i are also identical: a+i is the address of the i-th element beyond a.");
|
||||
err = skygw_log_write(LOGFILE_ERROR, logstr);
|
||||
if(err != 0)
|
||||
fprintf(stderr,"Error, log write failed.\n");
|
||||
ss_dassert(err == 0);
|
||||
skygw_logmanager_init( 0, NULL);
|
||||
skygw_logmanager_done();
|
||||
@ -507,6 +519,8 @@ static void* thr_run(
|
||||
skygw_logmanager_done();
|
||||
logstr = ("..and you?");
|
||||
err = skygw_log_write(LOGFILE_MESSAGE, logstr);
|
||||
if(err != 0)
|
||||
fprintf(stderr,"Error, log write failed.\n");
|
||||
ss_dassert(err == 0);
|
||||
skygw_logmanager_init( 0, NULL);
|
||||
skygw_logmanager_init( 0, NULL);
|
||||
@ -515,14 +529,20 @@ static void* thr_run(
|
||||
skygw_log_enable(LOGFILE_TRACE);
|
||||
#endif
|
||||
err = skygw_log_write(LOGFILE_TRACE, logstr);
|
||||
if(err != 0)
|
||||
fprintf(stderr,"Error, log write failed.\n");
|
||||
ss_dassert(err == 0);
|
||||
skygw_logmanager_init( 0, NULL);
|
||||
logstr = ("Rather more surprising, at least at first sight, is the fact that a reference to a[i] can also be written as *(a+i). In evaluating a[i], C converts it to *(a+i) immediately; the two forms are equivalent. Applying the operatos & to both parts of this equivalence, it follows that &a[i] and a+i are also identical: a+i is the address of the i-th element beyond a.");
|
||||
err = skygw_log_write(LOGFILE_ERROR, logstr);
|
||||
if(err != 0)
|
||||
fprintf(stderr,"Error, log write failed.\n");
|
||||
ss_dassert(err == 0);
|
||||
skygw_logmanager_init( 0, NULL);
|
||||
logstr = ("..... and you too?");
|
||||
err = skygw_log_write(LOGFILE_MESSAGE, logstr);
|
||||
if(err != 0)
|
||||
fprintf(stderr,"Error, log write failed.\n");
|
||||
ss_dassert(err == 0);
|
||||
skygw_logmanager_done();
|
||||
#if !defined(SS_DEBUG)
|
||||
@ -534,14 +554,20 @@ static void* thr_run(
|
||||
skygw_log_enable(LOGFILE_TRACE);
|
||||
#endif
|
||||
err = skygw_log_write(LOGFILE_TRACE, logstr);
|
||||
if(err != 0)
|
||||
fprintf(stderr,"Error, log write failed.\n");
|
||||
ss_dassert(err == 0);
|
||||
skygw_logmanager_done();
|
||||
logstr = ("Testing. One, two, three, four\n");
|
||||
err = skygw_log_write(LOGFILE_ERROR, logstr);
|
||||
if(err != 0)
|
||||
fprintf(stderr,"Error, log write failed.\n");
|
||||
ss_dassert(err == 0);
|
||||
skygw_logmanager_init( 0, NULL);
|
||||
logstr = ("Testing. One, two, three, .. where was I?\n");
|
||||
err = skygw_log_write(LOGFILE_ERROR, logstr);
|
||||
if(err != 0)
|
||||
fprintf(stderr,"Error, log write failed.\n");
|
||||
ss_dassert(err == 0);
|
||||
skygw_logmanager_init( 0, NULL);
|
||||
skygw_logmanager_init( 0, NULL);
|
||||
@ -597,6 +623,8 @@ static void* thr_run_morelog(
|
||||
"%s - iteration # %d",
|
||||
str,
|
||||
i);
|
||||
if(err != 0)
|
||||
fprintf(stderr,"Error, log write failed.\n");
|
||||
}
|
||||
simple_mutex_lock(td->mtx, true);
|
||||
*td->nactive -= 1;
|
||||
|
@ -27,7 +27,7 @@ int main(int argc, char** argv)
|
||||
{
|
||||
int iterations = 0, i, interval = 10;
|
||||
int block_size;
|
||||
int succp = 0, err = 0;
|
||||
int succp, err = 0;
|
||||
char cwd[1024];
|
||||
char tmp[2048];
|
||||
char *message;
|
||||
@ -71,6 +71,8 @@ int main(int argc, char** argv)
|
||||
interval = atoi(argv[2]);
|
||||
|
||||
succp = skygw_logmanager_init( 3, optstr);
|
||||
if(!succp)
|
||||
fprintf(stderr,"Error, log manager initialization failed.\n");
|
||||
ss_dassert(succp);
|
||||
|
||||
skygw_log_disable(LOGFILE_TRACE);
|
||||
|
@ -122,7 +122,8 @@ char fname[1024], *home;
|
||||
char uname[80], passwd[80];
|
||||
|
||||
initialise();
|
||||
sprintf(fname, "%s/passwd", get_datadir());
|
||||
snprintf(fname,1023, "%s/passwd", get_datadir());
|
||||
fname[1023] = '\0';
|
||||
if ((fp = fopen(fname, "r")) == NULL)
|
||||
return NULL;
|
||||
if ((rval = users_alloc()) == NULL)
|
||||
@ -153,8 +154,8 @@ FILE *fp;
|
||||
char fname[1024], *home, *cpasswd;
|
||||
|
||||
initialise();
|
||||
sprintf(fname, "%s/passwd", get_datadir());
|
||||
|
||||
snprintf(fname,1023, "%s/passwd", get_datadir());
|
||||
fname[1023] = '\0';
|
||||
if (users == NULL)
|
||||
{
|
||||
LOGIF(LM,
|
||||
@ -246,8 +247,10 @@ char* admin_remove_user(
|
||||
/**
|
||||
* Open passwd file and remove user from the file.
|
||||
*/
|
||||
sprintf(fname, "%s/passwd", get_datadir());
|
||||
sprintf(fname_tmp, "%s/passwd_tmp", get_datadir());
|
||||
snprintf(fname,1023, "%s/passwd", get_datadir());
|
||||
snprintf(fname_tmp,1023, "%s/passwd_tmp", get_datadir());
|
||||
fname[1023] = '\0';
|
||||
fname_tmp[1023] = '\0';
|
||||
/**
|
||||
* Rewrite passwd file from memory.
|
||||
*/
|
||||
|
@ -719,23 +719,26 @@ static char* check_dir_access(
|
||||
|
||||
if(access(dirname,F_OK) != 0)
|
||||
{
|
||||
sprintf(errbuf,"Can't access '%s'.",dirname);
|
||||
snprintf(errbuf,PATH_MAX*2-1,"Can't access '%s'.",dirname);
|
||||
errbuf[PATH_MAX*2-1] = '\0';
|
||||
errstr = strdup(errbuf);
|
||||
goto retblock;
|
||||
}
|
||||
|
||||
if (rd && !file_is_readable(dirname))
|
||||
{
|
||||
sprintf(errbuf,"MaxScale doesn't have read permission "
|
||||
"to '%s'.",dirname);
|
||||
snprintf(errbuf,PATH_MAX*2-1,"MaxScale doesn't have read permission "
|
||||
"to '%s'.",dirname);
|
||||
errbuf[PATH_MAX*2-1] = '\0';
|
||||
errstr = strdup(errbuf);
|
||||
goto retblock;
|
||||
}
|
||||
|
||||
if (wr && !file_is_writable(dirname))
|
||||
{
|
||||
sprintf(errbuf,"MaxScale doesn't have write permission "
|
||||
"to '%s'.",dirname);
|
||||
snprintf(errbuf,PATH_MAX*2-1,"MaxScale doesn't have write permission "
|
||||
"to '%s'.",dirname);
|
||||
errbuf[PATH_MAX*2-1] = '\0';
|
||||
errstr = strdup(errbuf);
|
||||
goto retblock;
|
||||
}
|
||||
@ -1076,7 +1079,8 @@ int main(int argc, char **argv)
|
||||
sigemptyset(&sigpipe_mask);
|
||||
sigaddset(&sigpipe_mask, SIGPIPE);
|
||||
progname = *argv;
|
||||
sprintf(datadir, "%s", default_datadir);
|
||||
snprintf(datadir,PATH_MAX, "%s", default_datadir);
|
||||
datadir[PATH_MAX] = '\0';
|
||||
#if defined(FAKE_CODE)
|
||||
memset(conn_open, 0, sizeof(bool)*10240);
|
||||
memset(dcb_fake_write_errno, 0, sizeof(unsigned char)*10240);
|
||||
@ -1191,7 +1195,8 @@ int main(int argc, char **argv)
|
||||
}
|
||||
break;
|
||||
case 'D':
|
||||
sprintf(datadir,"%s",optarg);
|
||||
snprintf(datadir,PATH_MAX,"%s",optarg);
|
||||
datadir[PATH_MAX] = '\0';
|
||||
set_datadir(strdup(optarg));
|
||||
datadir_defined = true;
|
||||
break;
|
||||
@ -1566,6 +1571,7 @@ int main(int argc, char **argv)
|
||||
*/
|
||||
char pathbuf[PATH_MAX+1];
|
||||
snprintf(pathbuf,PATH_MAX,"%s",get_configdir());
|
||||
pathbuf[PATH_MAX] = '\0';
|
||||
if(pathbuf[strlen(pathbuf)-1] != '/')
|
||||
strcat(pathbuf,"/");
|
||||
|
||||
@ -1584,7 +1590,8 @@ int main(int argc, char **argv)
|
||||
|
||||
|
||||
/** Use the cache dir for the mysql folder of the embedded library */
|
||||
sprintf(mysql_home, "%s/mysql", get_cachedir());
|
||||
snprintf(mysql_home,PATH_MAX, "%s/mysql", get_cachedir());
|
||||
mysql_home[PATH_MAX] = '\0';
|
||||
setenv("MYSQL_HOME", mysql_home, 1);
|
||||
|
||||
|
||||
@ -1657,7 +1664,8 @@ int main(int argc, char **argv)
|
||||
* machine.
|
||||
*/
|
||||
|
||||
sprintf(datadir,"%s/data",get_datadir());
|
||||
snprintf(datadir,PATH_MAX,"%s/data",get_datadir());
|
||||
datadir[PATH_MAX] = '\0';
|
||||
if(mkdir(datadir, 0777) != 0){
|
||||
|
||||
if(errno != EEXIST){
|
||||
@ -1667,7 +1675,7 @@ int main(int argc, char **argv)
|
||||
}
|
||||
}
|
||||
|
||||
sprintf(datadir, "%s/data/data%d", get_datadir(), getpid());
|
||||
snprintf(datadir,PATH_MAX, "%s/data/data%d", get_datadir(), getpid());
|
||||
|
||||
if(mkdir(datadir, 0777) != 0){
|
||||
|
||||
@ -2139,7 +2147,8 @@ static int cnf_preparser(void* data, const char* section, const char* name, cons
|
||||
{
|
||||
if(handle_path_arg(&tmp,(char*)value,NULL,true,false))
|
||||
{
|
||||
sprintf(datadir,"%s",tmp);
|
||||
snprintf(datadir,PATH_MAX,"%s",tmp);
|
||||
datadir[PATH_MAX] = '\0';
|
||||
set_datadir(tmp);
|
||||
datadir_defined = true;
|
||||
}
|
||||
|
@ -495,9 +495,10 @@ MODULES *ptr;
|
||||
resultset_row_set(row, 0, ptr->module);
|
||||
resultset_row_set(row, 1, ptr->type);
|
||||
resultset_row_set(row, 2, ptr->version);
|
||||
sprintf(buf, "%d.%d.%d", ptr->info->api_version.major,
|
||||
snprintf(buf,19, "%d.%d.%d", ptr->info->api_version.major,
|
||||
ptr->info->api_version.minor,
|
||||
ptr->info->api_version.patch);
|
||||
buf[19] = '\0';
|
||||
resultset_row_set(row, 3, buf);
|
||||
resultset_row_set(row, 4, ptr->info->status == MODULE_IN_DEVELOPMENT
|
||||
? "In Development"
|
||||
|
@ -1645,17 +1645,21 @@ RESULT_ROW *row;
|
||||
resultset_row_set(row, 0, "< 100ms");
|
||||
else if (*rowno == N_QUEUE_TIMES - 1)
|
||||
{
|
||||
sprintf(buf, "> %2d00ms", N_QUEUE_TIMES);
|
||||
snprintf(buf,39, "> %2d00ms", N_QUEUE_TIMES);
|
||||
buf[39] = '\0';
|
||||
resultset_row_set(row, 0, buf);
|
||||
}
|
||||
else
|
||||
{
|
||||
sprintf(buf, "%2d00 - %2d00ms", *rowno, (*rowno) + 1);
|
||||
snprintf(buf,39, "%2d00 - %2d00ms", *rowno, (*rowno) + 1);
|
||||
buf[39] = '\0';
|
||||
resultset_row_set(row, 0, buf);
|
||||
}
|
||||
sprintf(buf, "%d", queueStats.qtimes[*rowno]);
|
||||
snprintf(buf,39, "%d", queueStats.qtimes[*rowno]);
|
||||
buf[39] = '\0';
|
||||
resultset_row_set(row, 1, buf);
|
||||
sprintf(buf, "%d", queueStats.exectimes[*rowno]);
|
||||
snprintf(buf,39, "%d", queueStats.exectimes[*rowno]);
|
||||
buf[39] = '\0';
|
||||
resultset_row_set(row, 2, buf);
|
||||
(*rowno)++;
|
||||
return row;
|
||||
|
@ -234,7 +234,8 @@ if(strlen(path) > PATH_MAX)
|
||||
return 1;
|
||||
}
|
||||
|
||||
sprintf(secret_file,"%s/.secrets",path);
|
||||
snprintf(secret_file,PATH_MAX + 9,"%s/.secrets",path);
|
||||
secret_file[PATH_MAX + 9] = '\0';
|
||||
|
||||
/* Open for writing | Create | Truncate the file for writing */
|
||||
if ((fd = open(secret_file, O_CREAT | O_WRONLY | O_TRUNC, S_IRUSR)) < 0)
|
||||
|
@ -1031,7 +1031,8 @@ SESSION *ptr;
|
||||
}
|
||||
cbdata->index++;
|
||||
row = resultset_make_row(set);
|
||||
sprintf(buf, "%p", ptr);
|
||||
snprintf(buf,19, "%p", ptr);
|
||||
buf[19] = '\0';
|
||||
resultset_row_set(row, 0, buf);
|
||||
resultset_row_set(row, 1, ((ptr->client && ptr->client->remote)
|
||||
? ptr->client->remote : ""));
|
||||
|
@ -37,7 +37,7 @@
|
||||
* test1 Allocate table of users and mess around with it
|
||||
*
|
||||
*/
|
||||
|
||||
void skygw_log_sync_all(void);
|
||||
static int
|
||||
test1()
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user