can call sched_add_entries many times before schedule

pull/3/head
yuqing 2014-12-05 18:12:02 +08:00
parent 60b1f50c1f
commit e7b2874e2a
3 changed files with 59 additions and 13 deletions

View File

@ -1,6 +1,7 @@
Version 1.12 2014-12-05
* bug fixed: must check the return value of vsnprintf
* can call sched_add_entries many times before schedule
Version 1.11 2014-11-20
* remove usleep call in logger.c

View File

@ -800,9 +800,9 @@ void log_it_ex(LogContext *pContext, const int priority, const char *format, ...
va_start(ap, format);
len = vsnprintf(text, sizeof(text), format, ap);
va_end(ap);
if (len > sizeof(text))
if (len >= sizeof(text))
{
len = sizeof(text);
len = sizeof(text) - 1;
}
switch(priority)
@ -863,9 +863,9 @@ void log_it_ex(LogContext *pContext, const int priority, const char *format, ...
va_start(ap, format); \
len = vsnprintf(text, sizeof(text), format, ap); \
va_end(ap); \
if (len > sizeof(text)) \
if (len >= sizeof(text)) \
{ \
len = sizeof(text); \
len = sizeof(text) - 1; \
} \
} \
\
@ -922,9 +922,9 @@ void logAccess(LogContext *pContext, struct timeval *tvStart, \
va_start(ap, format);
len = vsnprintf(text, sizeof(text), format, ap);
va_end(ap);
if (len > sizeof(text))
if (len >= sizeof(text))
{
len = sizeof(text);
len = sizeof(text) - 1;
}
doLogEx(pContext, tvStart, NULL, text, len, false, true);
}

View File

@ -408,6 +408,44 @@ static int sched_dup_array(const ScheduleArray *pSrcArray, \
return 0;
}
static int sched_append_array(const ScheduleArray *pSrcArray, \
ScheduleArray *pDestArray)
{
int result;
int bytes;
ScheduleEntry *new_entries;
if (pSrcArray->count == 0)
{
return 0;
}
bytes = sizeof(ScheduleEntry) * (pDestArray->count + pSrcArray->count);
new_entries = (ScheduleEntry *)malloc(bytes);
if (new_entries == NULL)
{
result = errno != 0 ? errno : ENOMEM;
logError("file: "__FILE__", line: %d, " \
"malloc %d bytes failed, " \
"errno: %d, error info: %s", \
__LINE__, bytes, result, STRERROR(result));
return result;
}
if (pDestArray->entries != NULL)
{
memcpy(new_entries, pDestArray->entries,
sizeof(ScheduleEntry) * pDestArray->count);
free(pDestArray->entries);
}
memcpy(new_entries + pDestArray->count, pSrcArray->entries,
sizeof(ScheduleEntry) * pSrcArray->count);
pDestArray->entries = new_entries;
pDestArray->count += pSrcArray->count;
return 0;
}
int sched_add_entries(const ScheduleArray *pScheduleArray)
{
int result;
@ -419,14 +457,21 @@ int sched_add_entries(const ScheduleArray *pScheduleArray)
return ENOENT;
}
while (waiting_schedule_array.entries != NULL)
{
logDebug("file: "__FILE__", line: %d, " \
"waiting for schedule array ready ...", __LINE__);
sleep(1);
}
if (waiting_schedule_array.entries != NULL)
{
if (g_schedule_flag)
{
while (waiting_schedule_array.entries != NULL)
{
logDebug("file: "__FILE__", line: %d, " \
"waiting for schedule array ready ...", __LINE__);
sleep(1);
}
}
}
if ((result=sched_dup_array(pScheduleArray, &waiting_schedule_array))!=0)
if ((result=sched_append_array(pScheduleArray,
&waiting_schedule_array)) != 0)
{
return result;
}